byteorder.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef _PARISC_BYTEORDER_H
  2. #define _PARISC_BYTEORDER_H
  3. #include <asm/types.h>
  4. #include <linux/compiler.h>
  5. #ifdef __GNUC__
  6. static __inline__ __attribute_const__ __u16 ___arch__swab16(__u16 x)
  7. {
  8. __asm__("dep %0, 15, 8, %0\n\t" /* deposit 00ab -> 0bab */
  9. "shd %%r0, %0, 8, %0" /* shift 000000ab -> 00ba */
  10. : "=r" (x)
  11. : "0" (x));
  12. return x;
  13. }
  14. static __inline__ __attribute_const__ __u32 ___arch__swab24(__u32 x)
  15. {
  16. __asm__("shd %0, %0, 8, %0\n\t" /* shift xabcxabc -> cxab */
  17. "dep %0, 15, 8, %0\n\t" /* deposit cxab -> cbab */
  18. "shd %%r0, %0, 8, %0" /* shift 0000cbab -> 0cba */
  19. : "=r" (x)
  20. : "0" (x));
  21. return x;
  22. }
  23. static __inline__ __attribute_const__ __u32 ___arch__swab32(__u32 x)
  24. {
  25. unsigned int temp;
  26. __asm__("shd %0, %0, 16, %1\n\t" /* shift abcdabcd -> cdab */
  27. "dep %1, 15, 8, %1\n\t" /* deposit cdab -> cbab */
  28. "shd %0, %1, 8, %0" /* shift abcdcbab -> dcba */
  29. : "=r" (x), "=&r" (temp)
  30. : "0" (x));
  31. return x;
  32. }
  33. #if BITS_PER_LONG > 32
  34. /*
  35. ** From "PA-RISC 2.0 Architecture", HP Professional Books.
  36. ** See Appendix I page 8 , "Endian Byte Swapping".
  37. **
  38. ** Pretty cool algorithm: (* == zero'd bits)
  39. ** PERMH 01234567 -> 67452301 into %0
  40. ** HSHL 67452301 -> 7*5*3*1* into %1
  41. ** HSHR 67452301 -> *6*4*2*0 into %0
  42. ** OR %0 | %1 -> 76543210 into %0 (all done!)
  43. */
  44. static __inline__ __attribute_const__ __u64 ___arch__swab64(__u64 x) {
  45. __u64 temp;
  46. __asm__("permh,3210 %0, %0\n\t"
  47. "hshl %0, 8, %1\n\t"
  48. "hshr,u %0, 8, %0\n\t"
  49. "or %1, %0, %0"
  50. : "=r" (x), "=&r" (temp)
  51. : "0" (x));
  52. return x;
  53. }
  54. #define __arch__swab64(x) ___arch__swab64(x)
  55. #define __BYTEORDER_HAS_U64__
  56. #elif !defined(__STRICT_ANSI__)
  57. static __inline__ __attribute_const__ __u64 ___arch__swab64(__u64 x)
  58. {
  59. __u32 t1 = ___arch__swab32((__u32) x);
  60. __u32 t2 = ___arch__swab32((__u32) (x >> 32));
  61. return (((__u64) t1 << 32) | t2);
  62. }
  63. #define __arch__swab64(x) ___arch__swab64(x)
  64. #define __BYTEORDER_HAS_U64__
  65. #endif
  66. #define __arch__swab16(x) ___arch__swab16(x)
  67. #define __arch__swab24(x) ___arch__swab24(x)
  68. #define __arch__swab32(x) ___arch__swab32(x)
  69. #endif /* __GNUC__ */
  70. #include <linux/byteorder/big_endian.h>
  71. #endif /* _PARISC_BYTEORDER_H */