1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
4  */
5 #ifndef __LOONGARCH_ASM_BITREV_H__
6 #define __LOONGARCH_ASM_BITREV_H__
7 
8 #include <linux/swab.h>
9 
__arch_bitrev32(u32 x)10 static __always_inline __attribute_const__ u32 __arch_bitrev32(u32 x)
11 {
12 	u32 ret;
13 
14 	asm("bitrev.4b	%0, %1" : "=r"(ret) : "r"(__swab32(x)));
15 	return ret;
16 }
17 
__arch_bitrev16(u16 x)18 static __always_inline __attribute_const__ u16 __arch_bitrev16(u16 x)
19 {
20 	u16 ret;
21 
22 	asm("bitrev.4b	%0, %1" : "=r"(ret) : "r"(__swab16(x)));
23 	return ret;
24 }
25 
__arch_bitrev8(u8 x)26 static __always_inline __attribute_const__ u8 __arch_bitrev8(u8 x)
27 {
28 	u8 ret;
29 
30 	asm("bitrev.4b	%0, %1" : "=r"(ret) : "r"(x));
31 	return ret;
32 }
33 
34 #endif /* __LOONGARCH_ASM_BITREV_H__ */
35