18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci// Copyright (C) 2005-2017 Andes Technology Corporation
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#ifndef __NDS32_SWAB_H__
58c2ecf20Sopenharmony_ci#define __NDS32_SWAB_H__
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include <linux/types.h>
88c2ecf20Sopenharmony_ci#include <linux/compiler.h>
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_cistatic __inline__ __attribute_const__ __u32 ___arch__swab32(__u32 x)
118c2ecf20Sopenharmony_ci{
128c2ecf20Sopenharmony_ci	__asm__("wsbh   %0, %0\n\t"	/* word swap byte within halfword */
138c2ecf20Sopenharmony_ci		"rotri  %0, %0, #16\n"
148c2ecf20Sopenharmony_ci		:"=r"(x)
158c2ecf20Sopenharmony_ci		:"0"(x));
168c2ecf20Sopenharmony_ci	return x;
178c2ecf20Sopenharmony_ci}
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_cistatic __inline__ __attribute_const__ __u16 ___arch__swab16(__u16 x)
208c2ecf20Sopenharmony_ci{
218c2ecf20Sopenharmony_ci	__asm__("wsbh   %0, %0\n"	/* word swap byte within halfword */
228c2ecf20Sopenharmony_ci		:"=r"(x)
238c2ecf20Sopenharmony_ci		:"0"(x));
248c2ecf20Sopenharmony_ci	return x;
258c2ecf20Sopenharmony_ci}
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci#define __arch_swab32(x) ___arch__swab32(x)
288c2ecf20Sopenharmony_ci#define __arch_swab16(x) ___arch__swab16(x)
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#if !defined(__STRICT_ANSI__) || defined(__KERNEL__)
318c2ecf20Sopenharmony_ci#define __BYTEORDER_HAS_U64__
328c2ecf20Sopenharmony_ci#define __SWAB_64_THRU_32__
338c2ecf20Sopenharmony_ci#endif
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#endif /* __NDS32_SWAB_H__ */
36