byteorder.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #define __BIG_ENDIAN
  12. #ifndef __s390x__
  13. # define __SWAB_64_THRU_32__
  14. #endif
  15. #ifdef __s390x__
  16. static inline __u64 __arch_swab64p(const __u64 *x)
  17. {
  18. __u64 result;
  19. asm volatile("lrvg %0,%1" : "=d" (result) : "m" (*x));
  20. return result;
  21. }
  22. #define __arch_swab64p __arch_swab64p
  23. static inline __u64 __arch_swab64(__u64 x)
  24. {
  25. __u64 result;
  26. asm volatile("lrvgr %0,%1" : "=d" (result) : "d" (x));
  27. return result;
  28. }
  29. #define __arch_swab64 __arch_swab64
  30. static inline void __arch_swab64s(__u64 *x)
  31. {
  32. *x = __arch_swab64p(x);
  33. }
  34. #define __arch_swab64s __arch_swab64s
  35. #endif /* __s390x__ */
  36. static inline __u32 __arch_swab32p(const __u32 *x)
  37. {
  38. __u32 result;
  39. asm volatile(
  40. #ifndef __s390x__
  41. " icm %0,8,3(%1)\n"
  42. " icm %0,4,2(%1)\n"
  43. " icm %0,2,1(%1)\n"
  44. " ic %0,0(%1)"
  45. : "=&d" (result) : "a" (x), "m" (*x) : "cc");
  46. #else /* __s390x__ */
  47. " lrv %0,%1"
  48. : "=d" (result) : "m" (*x));
  49. #endif /* __s390x__ */
  50. return result;
  51. }
  52. #define __arch_swab32p __arch_swab32p
  53. #ifdef __s390x__
  54. static inline __u32 __arch_swab32(__u32 x)
  55. {
  56. __u32 result;
  57. asm volatile("lrvr %0,%1" : "=d" (result) : "d" (x));
  58. return result;
  59. }
  60. #define __arch_swab32 __arch_swab32
  61. #endif /* __s390x__ */
  62. static inline __u16 __arch_swab16p(const __u16 *x)
  63. {
  64. __u16 result;
  65. asm volatile(
  66. #ifndef __s390x__
  67. " icm %0,2,1(%1)\n"
  68. " ic %0,0(%1)\n"
  69. : "=&d" (result) : "a" (x), "m" (*x) : "cc");
  70. #else /* __s390x__ */
  71. " lrvh %0,%1"
  72. : "=d" (result) : "m" (*x));
  73. #endif /* __s390x__ */
  74. return result;
  75. }
  76. #define __arch_swab16p __arch_swab16p
  77. #include <linux/byteorder.h>
  78. #endif /* _S390_BYTEORDER_H */