1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * This file is subject to the terms and conditions of the GNU General Public
4 * License.  See the file "COPYING" in the main directory of this archive
5 * for more details.
6 *
7 * Copyright (C) 2020 Loongson Technology Corporation Limited
8 */
9#ifndef __LOONGARCH_ASM_BITREV_H__
10#define __LOONGARCH_ASM_BITREV_H__
11
12#include <linux/swab.h>
13
14static __always_inline __attribute_const__ u32 __arch_bitrev32(u32 x)
15{
16	u32 ret;
17
18	asm("bitrev.4b	%0, %1" : "=r"(ret) : "r"(__swab32(x)));
19	return ret;
20}
21
22static __always_inline __attribute_const__ u16 __arch_bitrev16(u16 x)
23{
24	u16 ret;
25
26	asm("bitrev.4b	%0, %1" : "=r"(ret) : "r"(__swab16(x)));
27	return ret;
28}
29
30static __always_inline __attribute_const__ u8 __arch_bitrev8(u8 x)
31{
32	u8 ret;
33
34	asm("bitrev.4b	%0, %1" : "=r"(ret) : "r"(x));
35	return ret;
36}
37
38#endif /* __LOONGARCH_ASM_BITREV_H__ */
39