xref: /linux/arch/arm/include/asm/bitrev.h (revision b24413180f5600bcb3bb70fbed5cf186b60864bd)
1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
20b7857dbSYalin Wang #ifndef __ASM_BITREV_H
30b7857dbSYalin Wang #define __ASM_BITREV_H
40b7857dbSYalin Wang 
50b7857dbSYalin Wang static __always_inline __attribute_const__ u32 __arch_bitrev32(u32 x)
60b7857dbSYalin Wang {
70b7857dbSYalin Wang 	__asm__ ("rbit %0, %1" : "=r" (x) : "r" (x));
80b7857dbSYalin Wang 	return x;
90b7857dbSYalin Wang }
100b7857dbSYalin Wang 
110b7857dbSYalin Wang static __always_inline __attribute_const__ u16 __arch_bitrev16(u16 x)
120b7857dbSYalin Wang {
130b7857dbSYalin Wang 	return __arch_bitrev32((u32)x) >> 16;
140b7857dbSYalin Wang }
150b7857dbSYalin Wang 
160b7857dbSYalin Wang static __always_inline __attribute_const__ u8 __arch_bitrev8(u8 x)
170b7857dbSYalin Wang {
180b7857dbSYalin Wang 	return __arch_bitrev32((u32)x) >> 24;
190b7857dbSYalin Wang }
200b7857dbSYalin Wang 
210b7857dbSYalin Wang #endif
22