byteorder.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #ifdef CONFIG_CPU_MIPS64_R2
  35. static __inline__ __attribute_const__ __u64 ___arch__swab64(__u64 x)
  36. {
  37. __asm__(
  38. " dsbh %0, %1 \n"
  39. " dshd %0, %0 \n"
  40. " drotr %0, %0, 32 \n"
  41. : "=r" (x)
  42. : "r" (x));
  43. return x;
  44. }
  45. #define __arch__swab64(x) ___arch__swab64(x)
  46. #endif /* CONFIG_CPU_MIPS64_R2 */
  47. #endif /* CONFIG_CPU_MIPSR2 */
  48. #if !defined(__STRICT_ANSI__) || defined(__KERNEL__)
  49. # define __BYTEORDER_HAS_U64__
  50. # define __SWAB_64_THRU_32__
  51. #endif
  52. #endif /* __GNUC__ */
  53. #if defined (__MIPSEB__)
  54. # include <linux/byteorder/big_endian.h>
  55. #elif defined (__MIPSEL__)
  56. # include <linux/byteorder/little_endian.h>
  57. #else
  58. # error "MIPS, but neither __MIPSEB__, nor __MIPSEL__???"
  59. #endif
  60. #endif /* _ASM_BYTEORDER_H */