1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
5 #include <asm/bitsperlong.h>
6 #include <linux/types.h>
7 #include <linux/compiler.h>
9 #define __SWAB_64_THRU_32__
11 static inline __attribute_const__ __u16
__arch_swab16(__u16 x
)
13 __asm__("dep %0, 15, 8, %0\n\t" /* deposit 00ab -> 0bab */
14 "shd %%r0, %0, 8, %0" /* shift 000000ab -> 00ba */
19 #define __arch_swab16 __arch_swab16
21 static inline __attribute_const__ __u32
__arch_swab24(__u32 x
)
23 __asm__("shd %0, %0, 8, %0\n\t" /* shift xabcxabc -> cxab */
24 "dep %0, 15, 8, %0\n\t" /* deposit cxab -> cbab */
25 "shd %%r0, %0, 8, %0" /* shift 0000cbab -> 0cba */
31 static inline __attribute_const__ __u32
__arch_swab32(__u32 x
)
34 __asm__("shd %0, %0, 16, %1\n\t" /* shift abcdabcd -> cdab */
35 "dep %1, 15, 8, %1\n\t" /* deposit cdab -> cbab */
36 "shd %0, %1, 8, %0" /* shift abcdcbab -> dcba */
37 : "=r" (x
), "=&r" (temp
)
41 #define __arch_swab32 __arch_swab32
43 #if __BITS_PER_LONG > 32
45 ** From "PA-RISC 2.0 Architecture", HP Professional Books.
46 ** See Appendix I page 8 , "Endian Byte Swapping".
48 ** Pretty cool algorithm: (* == zero'd bits)
49 ** PERMH 01234567 -> 67452301 into %0
50 ** HSHL 67452301 -> 7*5*3*1* into %1
51 ** HSHR 67452301 -> *6*4*2*0 into %0
52 ** OR %0 | %1 -> 76543210 into %0 (all done!)
54 static inline __attribute_const__ __u64
__arch_swab64(__u64 x
)
57 __asm__("permh,3210 %0, %0\n\t"
59 "hshr,u %0, 8, %0\n\t"
61 : "=r" (x
), "=&r" (temp
)
65 #define __arch_swab64 __arch_swab64
66 #endif /* __BITS_PER_LONG > 32 */
68 #endif /* _PARISC_SWAB_H */