byteorder.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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/compiler.h>
  11. #include <asm/types.h>
  12. #if defined(__MIPSEB__)
  13. # define __BIG_ENDIAN
  14. #elif defined(__MIPSEL__)
  15. # define __LITTLE_ENDIAN
  16. #else
  17. # error "MIPS, but neither __MIPSEB__, nor __MIPSEL__???"
  18. #endif
  19. #define __SWAB_64_THRU_32__
  20. #ifdef CONFIG_CPU_MIPSR2
  21. static inline __attribute_const__ __u16 __arch_swab16(__u16 x)
  22. {
  23. __asm__(
  24. " wsbh %0, %1 \n"
  25. : "=r" (x)
  26. : "r" (x));
  27. return x;
  28. }
  29. #define __arch_swab16 __arch_swab16
  30. static inline __attribute_const__ __u32 __arch_swab32(__u32 x)
  31. {
  32. __asm__(
  33. " wsbh %0, %1 \n"
  34. " rotr %0, %0, 16 \n"
  35. : "=r" (x)
  36. : "r" (x));
  37. return x;
  38. }
  39. #define __arch_swab32 __arch_swab32
  40. #ifdef CONFIG_CPU_MIPS64_R2
  41. static inline __attribute_const__ __u64 __arch_swab64(__u64 x)
  42. {
  43. __asm__(
  44. " dsbh %0, %1\n"
  45. " dshd %0, %0"
  46. : "=r" (x)
  47. : "r" (x));
  48. return x;
  49. }
  50. #define __arch_swab64 __arch_swab64
  51. #endif /* CONFIG_CPU_MIPS64_R2 */
  52. #endif /* CONFIG_CPU_MIPSR2 */
  53. #include <linux/byteorder.h>
  54. #endif /* _ASM_BYTEORDER_H */