swab.h 1.1 KB

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