1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
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 Technologies, Inc.  All rights reserved.
8 * Authors: Jun Yi <yijun@loongson.cn>
9 */
10#ifndef _ASM_SWAB_H
11#define _ASM_SWAB_H
12
13#include <linux/compiler.h>
14#include <linux/types.h>
15
16#define __SWAB_64_THRU_32__
17
18static inline __attribute_const__ __u16 __arch_swab16(__u16 x)
19{
20	__asm__(
21	"	revb.2h	%0, %1			\n"
22	: "=r" (x)
23	: "r" (x));
24
25	return x;
26}
27#define __arch_swab16 __arch_swab16
28
29static inline __attribute_const__ __u32 __arch_swab32(__u32 x)
30{
31	__asm__(
32	"	revb.2h	%0, %1			\n"
33	"	rotri.w	%0, %0, 16		\n"
34	: "=r" (x)
35	: "r" (x));
36
37	return x;
38}
39#define __arch_swab32 __arch_swab32
40
41#ifdef __loongarch64
42static inline __attribute_const__ __u64 __arch_swab64(__u64 x)
43{
44	__asm__(
45	"	revb.4h	%0, %1			\n"
46	"	revh.d	%0, %0			\n"
47	: "=r" (x)
48	: "r" (x));
49
50	return x;
51}
52#define __arch_swab64 __arch_swab64
53#endif /* __loongarch64 */
54#endif /* _ASM_SWAB_H */
55