byteorder.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #ifndef __ASM_SH_BYTEORDER_H
  2. #define __ASM_SH_BYTEORDER_H
  3. /*
  4. * Copyright (C) 1999 Niibe Yutaka
  5. * Copyright (C) 2000, 2001 Paolo Alberelli
  6. */
  7. #include <linux/compiler.h>
  8. #include <linux/types.h>
  9. #ifdef __LITTLE_ENDIAN__
  10. # define __LITTLE_ENDIAN
  11. #else
  12. # define __BIG_ENDIAN
  13. #endif
  14. #define __SWAB_64_THRU_32__
  15. static inline __attribute_const__ __u32 __arch_swab32(__u32 x)
  16. {
  17. __asm__(
  18. #ifdef __SH5__
  19. "byterev %0, %0\n\t"
  20. "shari %0, 32, %0"
  21. #else
  22. "swap.b %0, %0\n\t"
  23. "swap.w %0, %0\n\t"
  24. "swap.b %0, %0"
  25. #endif
  26. : "=r" (x)
  27. : "0" (x));
  28. return x;
  29. }
  30. #define __arch_swab32 __arch_swab32
  31. static inline __attribute_const__ __u16 __arch_swab16(__u16 x)
  32. {
  33. __asm__(
  34. #ifdef __SH5__
  35. "byterev %0, %0\n\t"
  36. "shari %0, 32, %0"
  37. #else
  38. "swap.b %0, %0"
  39. #endif
  40. : "=r" (x)
  41. : "0" (x));
  42. return x;
  43. }
  44. #define __arch_swab16 __arch_swab16
  45. static inline __u64 __arch_swab64(__u64 val)
  46. {
  47. union {
  48. struct { __u32 a,b; } s;
  49. __u64 u;
  50. } v, w;
  51. v.u = val;
  52. w.s.b = __arch_swab32(v.s.a);
  53. w.s.a = __arch_swab32(v.s.b);
  54. return w.u;
  55. }
  56. #define __arch_swab64 __arch_swab64
  57. #include <linux/byteorder.h>
  58. #endif /* __ASM_SH_BYTEORDER_H */