byteorder.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. static inline __attribute_const__ __u32 ___arch__swab32(__u32 x)
  10. {
  11. __asm__(
  12. #ifdef __SH5__
  13. "byterev %0, %0\n\t"
  14. "shari %0, 32, %0"
  15. #else
  16. "swap.b %0, %0\n\t"
  17. "swap.w %0, %0\n\t"
  18. "swap.b %0, %0"
  19. #endif
  20. : "=r" (x)
  21. : "0" (x));
  22. return x;
  23. }
  24. static inline __attribute_const__ __u16 ___arch__swab16(__u16 x)
  25. {
  26. __asm__(
  27. #ifdef __SH5__
  28. "byterev %0, %0\n\t"
  29. "shari %0, 32, %0"
  30. #else
  31. "swap.b %0, %0"
  32. #endif
  33. : "=r" (x)
  34. : "0" (x));
  35. return x;
  36. }
  37. static inline __u64 ___arch__swab64(__u64 val)
  38. {
  39. union {
  40. struct { __u32 a,b; } s;
  41. __u64 u;
  42. } v, w;
  43. v.u = val;
  44. w.s.b = ___arch__swab32(v.s.a);
  45. w.s.a = ___arch__swab32(v.s.b);
  46. return w.u;
  47. }
  48. #define __arch__swab64(x) ___arch__swab64(x)
  49. #define __arch__swab32(x) ___arch__swab32(x)
  50. #define __arch__swab16(x) ___arch__swab16(x)
  51. #if !defined(__STRICT_ANSI__) || defined(__KERNEL__)
  52. # define __BYTEORDER_HAS_U64__
  53. # define __SWAB_64_THRU_32__
  54. #endif
  55. #ifdef __LITTLE_ENDIAN__
  56. #include <linux/byteorder/little_endian.h>
  57. #else
  58. #include <linux/byteorder/big_endian.h>
  59. #endif
  60. #endif /* __ASM_SH_BYTEORDER_H */