byteorder.h 1.4 KB

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