swab.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #ifndef _PARISC_SWAB_H
  2. #define _PARISC_SWAB_H
  3. #include <asm/bitsperlong.h>
  4. #include <linux/types.h>
  5. #include <linux/compiler.h>
  6. #define __SWAB_64_THRU_32__
  7. static inline __attribute_const__ __u16 __arch_swab16(__u16 x)
  8. {
  9. __asm__("dep %0, 15, 8, %0\n\t" /* deposit 00ab -> 0bab */
  10. "shd %%r0, %0, 8, %0" /* shift 000000ab -> 00ba */
  11. : "=r" (x)
  12. : "0" (x));
  13. return x;
  14. }
  15. #define __arch_swab16 __arch_swab16
  16. static inline __attribute_const__ __u32 __arch_swab24(__u32 x)
  17. {
  18. __asm__("shd %0, %0, 8, %0\n\t" /* shift xabcxabc -> cxab */
  19. "dep %0, 15, 8, %0\n\t" /* deposit cxab -> cbab */
  20. "shd %%r0, %0, 8, %0" /* shift 0000cbab -> 0cba */
  21. : "=r" (x)
  22. : "0" (x));
  23. return x;
  24. }
  25. static inline __attribute_const__ __u32 __arch_swab32(__u32 x)
  26. {
  27. unsigned int temp;
  28. __asm__("shd %0, %0, 16, %1\n\t" /* shift abcdabcd -> cdab */
  29. "dep %1, 15, 8, %1\n\t" /* deposit cdab -> cbab */
  30. "shd %0, %1, 8, %0" /* shift abcdcbab -> dcba */
  31. : "=r" (x), "=&r" (temp)
  32. : "0" (x));
  33. return x;
  34. }
  35. #define __arch_swab32 __arch_swab32
  36. #if __BITS_PER_LONG > 32
  37. /*
  38. ** From "PA-RISC 2.0 Architecture", HP Professional Books.
  39. ** See Appendix I page 8 , "Endian Byte Swapping".
  40. **
  41. ** Pretty cool algorithm: (* == zero'd bits)
  42. ** PERMH 01234567 -> 67452301 into %0
  43. ** HSHL 67452301 -> 7*5*3*1* into %1
  44. ** HSHR 67452301 -> *6*4*2*0 into %0
  45. ** OR %0 | %1 -> 76543210 into %0 (all done!)
  46. */
  47. static inline __attribute_const__ __u64 __arch_swab64(__u64 x)
  48. {
  49. __u64 temp;
  50. __asm__("permh,3210 %0, %0\n\t"
  51. "hshl %0, 8, %1\n\t"
  52. "hshr,u %0, 8, %0\n\t"
  53. "or %1, %0, %0"
  54. : "=r" (x), "=&r" (temp)
  55. : "0" (x));
  56. return x;
  57. }
  58. #define __arch_swab64 __arch_swab64
  59. #endif /* __BITS_PER_LONG > 32 */
  60. #endif /* _PARISC_SWAB_H */