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