byteorder.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #ifdef __GNUC__
  13. #ifdef CONFIG_CPU_MIPSR2
  14. static __inline__ __attribute_const__ __u16 ___arch__swab16(__u16 x)
  15. {
  16. __asm__(
  17. " wsbh %0, %1 \n"
  18. : "=r" (x)
  19. : "r" (x));
  20. return x;
  21. }
  22. #define __arch__swab16(x) ___arch__swab16(x)
  23. static __inline__ __attribute_const__ __u32 ___arch__swab32(__u32 x)
  24. {
  25. __asm__(
  26. " wsbh %0, %1 \n"
  27. " rotr %0, %0, 16 \n"
  28. : "=r" (x)
  29. : "r" (x));
  30. return x;
  31. }
  32. #define __arch__swab32(x) ___arch__swab32(x)
  33. #ifdef CONFIG_CPU_MIPS64_R2
  34. static __inline__ __attribute_const__ __u64 ___arch__swab64(__u64 x)
  35. {
  36. __asm__(
  37. " dsbh %0, %1 \n"
  38. " dshd %0, %0 \n"
  39. " drotr %0, %0, 32 \n"
  40. : "=r" (x)
  41. : "r" (x));
  42. return x;
  43. }
  44. #define __arch__swab64(x) ___arch__swab64(x)
  45. #endif /* CONFIG_CPU_MIPS64_R2 */
  46. #endif /* CONFIG_CPU_MIPSR2 */
  47. #if !defined(__STRICT_ANSI__) || defined(__KERNEL__)
  48. # define __BYTEORDER_HAS_U64__
  49. # define __SWAB_64_THRU_32__
  50. #endif
  51. #endif /* __GNUC__ */
  52. #if defined(__MIPSEB__)
  53. # include <linux/byteorder/big_endian.h>
  54. #elif defined(__MIPSEL__)
  55. # include <linux/byteorder/little_endian.h>
  56. #else
  57. # error "MIPS, but neither __MIPSEB__, nor __MIPSEL__???"
  58. #endif
  59. #endif /* _ASM_BYTEORDER_H */