swab.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #ifndef _S390_SWAB_H
  2. #define _S390_SWAB_H
  3. /*
  4. * S390 version
  5. * Copyright IBM Corp. 1999
  6. * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
  7. */
  8. #include <linux/types.h>
  9. #ifndef __s390x__
  10. # define __SWAB_64_THRU_32__
  11. #endif
  12. #ifdef __s390x__
  13. static inline __u64 __arch_swab64p(const __u64 *x)
  14. {
  15. __u64 result;
  16. asm volatile("lrvg %0,%1" : "=d" (result) : "m" (*x));
  17. return result;
  18. }
  19. #define __arch_swab64p __arch_swab64p
  20. static inline __u64 __arch_swab64(__u64 x)
  21. {
  22. __u64 result;
  23. asm volatile("lrvgr %0,%1" : "=d" (result) : "d" (x));
  24. return result;
  25. }
  26. #define __arch_swab64 __arch_swab64
  27. static inline void __arch_swab64s(__u64 *x)
  28. {
  29. *x = __arch_swab64p(x);
  30. }
  31. #define __arch_swab64s __arch_swab64s
  32. #endif /* __s390x__ */
  33. static inline __u32 __arch_swab32p(const __u32 *x)
  34. {
  35. __u32 result;
  36. asm volatile(
  37. #ifndef __s390x__
  38. " icm %0,8,%O1+3(%R1)\n"
  39. " icm %0,4,%O1+2(%R1)\n"
  40. " icm %0,2,%O1+1(%R1)\n"
  41. " ic %0,%1"
  42. : "=&d" (result) : "Q" (*x) : "cc");
  43. #else /* __s390x__ */
  44. " lrv %0,%1"
  45. : "=d" (result) : "m" (*x));
  46. #endif /* __s390x__ */
  47. return result;
  48. }
  49. #define __arch_swab32p __arch_swab32p
  50. #ifdef __s390x__
  51. static inline __u32 __arch_swab32(__u32 x)
  52. {
  53. __u32 result;
  54. asm volatile("lrvr %0,%1" : "=d" (result) : "d" (x));
  55. return result;
  56. }
  57. #define __arch_swab32 __arch_swab32
  58. #endif /* __s390x__ */
  59. static inline __u16 __arch_swab16p(const __u16 *x)
  60. {
  61. __u16 result;
  62. asm volatile(
  63. #ifndef __s390x__
  64. " icm %0,2,%O1+1(%R1)\n"
  65. " ic %0,%1\n"
  66. : "=&d" (result) : "Q" (*x) : "cc");
  67. #else /* __s390x__ */
  68. " lrvh %0,%1"
  69. : "=d" (result) : "m" (*x));
  70. #endif /* __s390x__ */
  71. return result;
  72. }
  73. #define __arch_swab16p __arch_swab16p
  74. #endif /* _S390_SWAB_H */