byteorder.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #ifndef _S390_BYTEORDER_H
  2. #define _S390_BYTEORDER_H
  3. /*
  4. * include/asm-s390/byteorder.h
  5. *
  6. * S390 version
  7. * Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
  8. * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
  9. */
  10. #include <asm/types.h>
  11. #ifdef __GNUC__
  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. static inline __u64 ___arch__swab64(__u64 x)
  20. {
  21. __u64 result;
  22. asm volatile("lrvgr %0,%1" : "=d" (result) : "d" (x));
  23. return result;
  24. }
  25. static inline void ___arch__swab64s(__u64 *x)
  26. {
  27. *x = ___arch__swab64p(x);
  28. }
  29. #endif /* __s390x__ */
  30. static inline __u32 ___arch__swab32p(const __u32 *x)
  31. {
  32. __u32 result;
  33. asm volatile(
  34. #ifndef __s390x__
  35. " icm %0,8,3(%1)\n"
  36. " icm %0,4,2(%1)\n"
  37. " icm %0,2,1(%1)\n"
  38. " ic %0,0(%1)"
  39. : "=&d" (result) : "a" (x), "m" (*x) : "cc");
  40. #else /* __s390x__ */
  41. " lrv %0,%1"
  42. : "=d" (result) : "m" (*x));
  43. #endif /* __s390x__ */
  44. return result;
  45. }
  46. static inline __u32 ___arch__swab32(__u32 x)
  47. {
  48. #ifndef __s390x__
  49. return ___arch__swab32p(&x);
  50. #else /* __s390x__ */
  51. __u32 result;
  52. asm volatile("lrvr %0,%1" : "=d" (result) : "d" (x));
  53. return result;
  54. #endif /* __s390x__ */
  55. }
  56. static __inline__ void ___arch__swab32s(__u32 *x)
  57. {
  58. *x = ___arch__swab32p(x);
  59. }
  60. static __inline__ __u16 ___arch__swab16p(const __u16 *x)
  61. {
  62. __u16 result;
  63. asm volatile(
  64. #ifndef __s390x__
  65. " icm %0,2,1(%1)\n"
  66. " ic %0,0(%1)\n"
  67. : "=&d" (result) : "a" (x), "m" (*x) : "cc");
  68. #else /* __s390x__ */
  69. " lrvh %0,%1"
  70. : "=d" (result) : "m" (*x));
  71. #endif /* __s390x__ */
  72. return result;
  73. }
  74. static __inline__ __u16 ___arch__swab16(__u16 x)
  75. {
  76. return ___arch__swab16p(&x);
  77. }
  78. static __inline__ void ___arch__swab16s(__u16 *x)
  79. {
  80. *x = ___arch__swab16p(x);
  81. }
  82. #ifdef __s390x__
  83. #define __arch__swab64(x) ___arch__swab64(x)
  84. #define __arch__swab64p(x) ___arch__swab64p(x)
  85. #define __arch__swab64s(x) ___arch__swab64s(x)
  86. #endif /* __s390x__ */
  87. #define __arch__swab32(x) ___arch__swab32(x)
  88. #define __arch__swab16(x) ___arch__swab16(x)
  89. #define __arch__swab32p(x) ___arch__swab32p(x)
  90. #define __arch__swab16p(x) ___arch__swab16p(x)
  91. #define __arch__swab32s(x) ___arch__swab32s(x)
  92. #define __arch__swab16s(x) ___arch__swab16s(x)
  93. #ifndef __s390x__
  94. #if !defined(__STRICT_ANSI__) || defined(__KERNEL__)
  95. # define __BYTEORDER_HAS_U64__
  96. # define __SWAB_64_THRU_32__
  97. #endif
  98. #else /* __s390x__ */
  99. #define __BYTEORDER_HAS_U64__
  100. #endif /* __s390x__ */
  101. #endif /* __GNUC__ */
  102. #include <linux/byteorder/big_endian.h>
  103. #endif /* _S390_BYTEORDER_H */