18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
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 Technologies, Inc.  All rights reserved.
88c2ecf20Sopenharmony_ci * Authors: Jun Yi <yijun@loongson.cn>
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci#ifndef _ASM_SWAB_H
118c2ecf20Sopenharmony_ci#define _ASM_SWAB_H
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#include <linux/compiler.h>
148c2ecf20Sopenharmony_ci#include <linux/types.h>
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#define __SWAB_64_THRU_32__
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_cistatic inline __attribute_const__ __u16 __arch_swab16(__u16 x)
198c2ecf20Sopenharmony_ci{
208c2ecf20Sopenharmony_ci	__asm__(
218c2ecf20Sopenharmony_ci	"	revb.2h	%0, %1			\n"
228c2ecf20Sopenharmony_ci	: "=r" (x)
238c2ecf20Sopenharmony_ci	: "r" (x));
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci	return x;
268c2ecf20Sopenharmony_ci}
278c2ecf20Sopenharmony_ci#define __arch_swab16 __arch_swab16
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_cistatic inline __attribute_const__ __u32 __arch_swab32(__u32 x)
308c2ecf20Sopenharmony_ci{
318c2ecf20Sopenharmony_ci	__asm__(
328c2ecf20Sopenharmony_ci	"	revb.2h	%0, %1			\n"
338c2ecf20Sopenharmony_ci	"	rotri.w	%0, %0, 16		\n"
348c2ecf20Sopenharmony_ci	: "=r" (x)
358c2ecf20Sopenharmony_ci	: "r" (x));
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci	return x;
388c2ecf20Sopenharmony_ci}
398c2ecf20Sopenharmony_ci#define __arch_swab32 __arch_swab32
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci#ifdef __loongarch64
428c2ecf20Sopenharmony_cistatic inline __attribute_const__ __u64 __arch_swab64(__u64 x)
438c2ecf20Sopenharmony_ci{
448c2ecf20Sopenharmony_ci	__asm__(
458c2ecf20Sopenharmony_ci	"	revb.4h	%0, %1			\n"
468c2ecf20Sopenharmony_ci	"	revh.d	%0, %0			\n"
478c2ecf20Sopenharmony_ci	: "=r" (x)
488c2ecf20Sopenharmony_ci	: "r" (x));
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci	return x;
518c2ecf20Sopenharmony_ci}
528c2ecf20Sopenharmony_ci#define __arch_swab64 __arch_swab64
538c2ecf20Sopenharmony_ci#endif /* __loongarch64 */
548c2ecf20Sopenharmony_ci#endif /* _ASM_SWAB_H */
55