1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2#ifndef _PARISC_SWAB_H 3#define _PARISC_SWAB_H 4 5#include <asm/bitsperlong.h> 6#include <linux/types.h> 7#include <linux/compiler.h> 8 9#define __SWAB_64_THRU_32__ 10 11static inline __attribute_const__ __u16 __arch_swab16(__u16 x) 12{ 13 __asm__("dep %0, 15, 8, %0\n\t" /* deposit 00ab -> 0bab */ 14 "shd %%r0, %0, 8, %0" /* shift 000000ab -> 00ba */ 15 : "=r" (x) 16 : "0" (x)); 17 return x; 18} 19#define __arch_swab16 __arch_swab16 20 21static inline __attribute_const__ __u32 __arch_swab24(__u32 x) 22{ 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 */ 26 : "=r" (x) 27 : "0" (x)); 28 return x; 29} 30 31static inline __attribute_const__ __u32 __arch_swab32(__u32 x) 32{ 33 unsigned int temp; 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) 38 : "0" (x)); 39 return x; 40} 41#define __arch_swab32 __arch_swab32 42 43#if __BITS_PER_LONG > 32 44/* 45** From "PA-RISC 2.0 Architecture", HP Professional Books. 46** See Appendix I page 8 , "Endian Byte Swapping". 47** 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!) 53*/ 54static inline __attribute_const__ __u64 __arch_swab64(__u64 x) 55{ 56 __u64 temp; 57 __asm__("permh,3210 %0, %0\n\t" 58 "hshl %0, 8, %1\n\t" 59 "hshr,u %0, 8, %0\n\t" 60 "or %1, %0, %0" 61 : "=r" (x), "=&r" (temp) 62 : "0" (x)); 63 return x; 64} 65#define __arch_swab64 __arch_swab64 66#endif /* __BITS_PER_LONG > 32 */ 67 68#endif /* _PARISC_SWAB_H */ 69