byteorder.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #ifndef __ASM_SH_BYTEORDER_H
  2. #define __ASM_SH_BYTEORDER_H
  3. /*
  4. * Copyright (C) 1999 Niibe Yutaka
  5. */
  6. #include <asm/types.h>
  7. #include <linux/compiler.h>
  8. static __inline__ __attribute_const__ __u32 ___arch__swab32(__u32 x)
  9. {
  10. __asm__("swap.b %0, %0\n\t"
  11. "swap.w %0, %0\n\t"
  12. "swap.b %0, %0"
  13. : "=r" (x)
  14. : "0" (x));
  15. return x;
  16. }
  17. static __inline__ __attribute_const__ __u16 ___arch__swab16(__u16 x)
  18. {
  19. __asm__("swap.b %0, %0"
  20. : "=r" (x)
  21. : "0" (x));
  22. return x;
  23. }
  24. static inline __u64 ___arch__swab64(__u64 val)
  25. {
  26. union {
  27. struct { __u32 a,b; } s;
  28. __u64 u;
  29. } v, w;
  30. v.u = val;
  31. w.s.b = ___arch__swab32(v.s.a);
  32. w.s.a = ___arch__swab32(v.s.b);
  33. return w.u;
  34. }
  35. #define __arch__swab64(x) ___arch__swab64(x)
  36. #define __arch__swab32(x) ___arch__swab32(x)
  37. #define __arch__swab16(x) ___arch__swab16(x)
  38. #if !defined(__STRICT_ANSI__) || defined(__KERNEL__)
  39. # define __BYTEORDER_HAS_U64__
  40. # define __SWAB_64_THRU_32__
  41. #endif
  42. #ifdef __LITTLE_ENDIAN__
  43. #include <linux/byteorder/little_endian.h>
  44. #else
  45. #include <linux/byteorder/big_endian.h>
  46. #endif
  47. #endif /* __ASM_SH_BYTEORDER_H */