xref: /openbmc/linux/arch/arm64/include/asm/bitrev.h (revision 498495dba268b20e8eadd7fe93c140c68b6cc9d2)
1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
28e7a4cefSYalin Wang #ifndef __ASM_BITREV_H
38e7a4cefSYalin Wang #define __ASM_BITREV_H
__arch_bitrev32(u32 x)48e7a4cefSYalin Wang static __always_inline __attribute_const__ u32 __arch_bitrev32(u32 x)
58e7a4cefSYalin Wang {
68e7a4cefSYalin Wang 	__asm__ ("rbit %w0, %w1" : "=r" (x) : "r" (x));
78e7a4cefSYalin Wang 	return x;
88e7a4cefSYalin Wang }
98e7a4cefSYalin Wang 
__arch_bitrev16(u16 x)108e7a4cefSYalin Wang static __always_inline __attribute_const__ u16 __arch_bitrev16(u16 x)
118e7a4cefSYalin Wang {
128e7a4cefSYalin Wang 	return __arch_bitrev32((u32)x) >> 16;
138e7a4cefSYalin Wang }
148e7a4cefSYalin Wang 
__arch_bitrev8(u8 x)158e7a4cefSYalin Wang static __always_inline __attribute_const__ u8 __arch_bitrev8(u8 x)
168e7a4cefSYalin Wang {
178e7a4cefSYalin Wang 	return __arch_bitrev32((u32)x) >> 24;
188e7a4cefSYalin Wang }
198e7a4cefSYalin Wang 
208e7a4cefSYalin Wang #endif
21