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