swab.h 1016 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #ifndef __ASM_SH_SWAB_H
  2. #define __ASM_SH_SWAB_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. #include <asm-generic/swab.h>
  10. static inline __attribute_const__ __u32 __arch_swab32(__u32 x)
  11. {
  12. __asm__(
  13. #ifdef __SH5__
  14. "byterev %1, %0\n\t"
  15. "shari %0, 32, %0"
  16. #else
  17. "swap.b %1, %0\n\t"
  18. "swap.w %0, %0\n\t"
  19. "swap.b %0, %0"
  20. #endif
  21. : "=r" (x)
  22. : "r" (x));
  23. return x;
  24. }
  25. #define __arch_swab32 __arch_swab32
  26. static inline __attribute_const__ __u16 __arch_swab16(__u16 x)
  27. {
  28. __asm__(
  29. #ifdef __SH5__
  30. "byterev %1, %0\n\t"
  31. "shari %0, 32, %0"
  32. #else
  33. "swap.b %1, %0"
  34. #endif
  35. : "=r" (x)
  36. : "r" (x));
  37. return x;
  38. }
  39. #define __arch_swab16 __arch_swab16
  40. static inline __u64 __arch_swab64(__u64 val)
  41. {
  42. union {
  43. struct { __u32 a,b; } s;
  44. __u64 u;
  45. } v, w;
  46. v.u = val;
  47. w.s.b = __arch_swab32(v.s.a);
  48. w.s.a = __arch_swab32(v.s.b);
  49. return w.u;
  50. }
  51. #define __arch_swab64 __arch_swab64
  52. #endif /* __ASM_SH_SWAB_H */