byteorder.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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__ (
  17. " lrvg %0,%1"
  18. : "=d" (result) : "m" (*x) );
  19. return result;
  20. }
  21. static __inline__ __u64 ___arch__swab64(__u64 x)
  22. {
  23. __u64 result;
  24. __asm__ __volatile__ (
  25. " lrvgr %0,%1"
  26. : "=d" (result) : "d" (x) );
  27. return result;
  28. }
  29. static __inline__ void ___arch__swab64s(__u64 *x)
  30. {
  31. *x = ___arch__swab64p(x);
  32. }
  33. #endif /* __s390x__ */
  34. static __inline__ __u32 ___arch__swab32p(const __u32 *x)
  35. {
  36. __u32 result;
  37. __asm__ __volatile__ (
  38. #ifndef __s390x__
  39. " icm %0,8,3(%1)\n"
  40. " icm %0,4,2(%1)\n"
  41. " icm %0,2,1(%1)\n"
  42. " ic %0,0(%1)"
  43. : "=&d" (result) : "a" (x), "m" (*x) : "cc" );
  44. #else /* __s390x__ */
  45. " lrv %0,%1"
  46. : "=d" (result) : "m" (*x) );
  47. #endif /* __s390x__ */
  48. return result;
  49. }
  50. static __inline__ __u32 ___arch__swab32(__u32 x)
  51. {
  52. #ifndef __s390x__
  53. return ___arch__swab32p(&x);
  54. #else /* __s390x__ */
  55. __u32 result;
  56. __asm__ __volatile__ (
  57. " lrvr %0,%1"
  58. : "=d" (result) : "d" (x) );
  59. return result;
  60. #endif /* __s390x__ */
  61. }
  62. static __inline__ void ___arch__swab32s(__u32 *x)
  63. {
  64. *x = ___arch__swab32p(x);
  65. }
  66. static __inline__ __u16 ___arch__swab16p(const __u16 *x)
  67. {
  68. __u16 result;
  69. __asm__ __volatile__ (
  70. #ifndef __s390x__
  71. " icm %0,2,1(%1)\n"
  72. " ic %0,0(%1)\n"
  73. : "=&d" (result) : "a" (x), "m" (*x) : "cc" );
  74. #else /* __s390x__ */
  75. " lrvh %0,%1"
  76. : "=d" (result) : "m" (*x) );
  77. #endif /* __s390x__ */
  78. return result;
  79. }
  80. static __inline__ __u16 ___arch__swab16(__u16 x)
  81. {
  82. return ___arch__swab16p(&x);
  83. }
  84. static __inline__ void ___arch__swab16s(__u16 *x)
  85. {
  86. *x = ___arch__swab16p(x);
  87. }
  88. #ifdef __s390x__
  89. #define __arch__swab64(x) ___arch__swab64(x)
  90. #define __arch__swab64p(x) ___arch__swab64p(x)
  91. #define __arch__swab64s(x) ___arch__swab64s(x)
  92. #endif /* __s390x__ */
  93. #define __arch__swab32(x) ___arch__swab32(x)
  94. #define __arch__swab16(x) ___arch__swab16(x)
  95. #define __arch__swab32p(x) ___arch__swab32p(x)
  96. #define __arch__swab16p(x) ___arch__swab16p(x)
  97. #define __arch__swab32s(x) ___arch__swab32s(x)
  98. #define __arch__swab16s(x) ___arch__swab16s(x)
  99. #ifndef __s390x__
  100. #if !defined(__STRICT_ANSI__) || defined(__KERNEL__)
  101. # define __BYTEORDER_HAS_U64__
  102. # define __SWAB_64_THRU_32__
  103. #endif
  104. #else /* __s390x__ */
  105. #define __BYTEORDER_HAS_U64__
  106. #endif /* __s390x__ */
  107. #endif /* __GNUC__ */
  108. #include <linux/byteorder/big_endian.h>
  109. #endif /* _S390_BYTEORDER_H */