swab.h 933 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. #ifndef __ASM_SH_SWAB_H
  3. #define __ASM_SH_SWAB_H
  4. /*
  5. * Copyright (C) 1999 Niibe Yutaka
  6. * Copyright (C) 2000, 2001 Paolo Alberelli
  7. */
  8. #include <linux/compiler.h>
  9. #include <linux/types.h>
  10. #include <asm-generic/swab.h>
  11. static inline __attribute_const__ __u32 __arch_swab32(__u32 x)
  12. {
  13. __asm__(
  14. "swap.b %1, %0\n\t"
  15. "swap.w %0, %0\n\t"
  16. "swap.b %0, %0"
  17. : "=r" (x)
  18. : "r" (x));
  19. return x;
  20. }
  21. #define __arch_swab32 __arch_swab32
  22. static inline __attribute_const__ __u16 __arch_swab16(__u16 x)
  23. {
  24. __asm__(
  25. "swap.b %1, %0"
  26. : "=r" (x)
  27. : "r" (x));
  28. return x;
  29. }
  30. #define __arch_swab16 __arch_swab16
  31. static inline __u64 __arch_swab64(__u64 val)
  32. {
  33. union {
  34. struct { __u32 a,b; } s;
  35. __u64 u;
  36. } v, w;
  37. v.u = val;
  38. w.s.b = __arch_swab32(v.s.a);
  39. w.s.a = __arch_swab32(v.s.b);
  40. return w.u;
  41. }
  42. #define __arch_swab64 __arch_swab64
  43. #endif /* __ASM_SH_SWAB_H */