byteorder.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1996, 99, 2003 by Ralf Baechle
  7. */
  8. #ifndef _ASM_BYTEORDER_H
  9. #define _ASM_BYTEORDER_H
  10. #include <linux/config.h>
  11. #include <linux/compiler.h>
  12. #include <asm/types.h>
  13. #ifdef __GNUC__
  14. #ifdef CONFIG_CPU_MIPSR2
  15. static __inline__ __attribute_const__ __u16 ___arch__swab16(__u16 x)
  16. {
  17. __asm__(
  18. " wsbh %0, %1 \n"
  19. : "=r" (x)
  20. : "r" (x));
  21. return x;
  22. }
  23. #define __arch__swab16(x) ___arch__swab16(x)
  24. static __inline__ __attribute_const__ __u32 ___arch__swab32(__u32 x)
  25. {
  26. __asm__(
  27. " wsbh %0, %1 \n"
  28. " rotr %0, %0, 16 \n"
  29. : "=r" (x)
  30. : "r" (x));
  31. return x;
  32. }
  33. #define __arch__swab32(x) ___arch__swab32(x)
  34. #endif /* CONFIG_CPU_MIPSR2 */
  35. #if !defined(__STRICT_ANSI__) || defined(__KERNEL__)
  36. # define __BYTEORDER_HAS_U64__
  37. # define __SWAB_64_THRU_32__
  38. #endif
  39. #endif /* __GNUC__ */
  40. #if defined (__MIPSEB__)
  41. # include <linux/byteorder/big_endian.h>
  42. #elif defined (__MIPSEL__)
  43. # include <linux/byteorder/little_endian.h>
  44. #else
  45. # error "MIPS, but neither __MIPSEB__, nor __MIPSEL__???"
  46. #endif
  47. #endif /* _ASM_BYTEORDER_H */