swab.h 1.7 KB

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