18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public
48c2ecf20Sopenharmony_ci * License.  See the file "COPYING" in the main directory of this archive
58c2ecf20Sopenharmony_ci * for more details.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Copyright (C) 2020 Loongson Technology Corporation Limited
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci#ifndef __LOONGARCH_ASM_BITREV_H__
108c2ecf20Sopenharmony_ci#define __LOONGARCH_ASM_BITREV_H__
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/swab.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_cistatic __always_inline __attribute_const__ u32 __arch_bitrev32(u32 x)
158c2ecf20Sopenharmony_ci{
168c2ecf20Sopenharmony_ci	u32 ret;
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci	asm("bitrev.4b	%0, %1" : "=r"(ret) : "r"(__swab32(x)));
198c2ecf20Sopenharmony_ci	return ret;
208c2ecf20Sopenharmony_ci}
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_cistatic __always_inline __attribute_const__ u16 __arch_bitrev16(u16 x)
238c2ecf20Sopenharmony_ci{
248c2ecf20Sopenharmony_ci	u16 ret;
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci	asm("bitrev.4b	%0, %1" : "=r"(ret) : "r"(__swab16(x)));
278c2ecf20Sopenharmony_ci	return ret;
288c2ecf20Sopenharmony_ci}
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_cistatic __always_inline __attribute_const__ u8 __arch_bitrev8(u8 x)
318c2ecf20Sopenharmony_ci{
328c2ecf20Sopenharmony_ci	u8 ret;
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci	asm("bitrev.4b	%0, %1" : "=r"(ret) : "r"(x));
358c2ecf20Sopenharmony_ci	return ret;
368c2ecf20Sopenharmony_ci}
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#endif /* __LOONGARCH_ASM_BITREV_H__ */
39