GNU Linux-libre 4.19.264-gnu1
[releases.git] / arch / nds32 / include / asm / swab.h
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2005-2017 Andes Technology Corporation
3
4 #ifndef __NDS32_SWAB_H__
5 #define __NDS32_SWAB_H__
6
7 #include <linux/types.h>
8 #include <linux/compiler.h>
9
10 static __inline__ __attribute_const__ __u32 ___arch__swab32(__u32 x)
11 {
12         __asm__("wsbh   %0, %0\n\t"     /* word swap byte within halfword */
13                 "rotri  %0, %0, #16\n"
14                 :"=r"(x)
15                 :"0"(x));
16         return x;
17 }
18
19 static __inline__ __attribute_const__ __u16 ___arch__swab16(__u16 x)
20 {
21         __asm__("wsbh   %0, %0\n"       /* word swap byte within halfword */
22                 :"=r"(x)
23                 :"0"(x));
24         return x;
25 }
26
27 #define __arch_swab32(x) ___arch__swab32(x)
28 #define __arch_swab16(x) ___arch__swab16(x)
29
30 #if !defined(__STRICT_ANSI__) || defined(__KERNEL__)
31 #define __BYTEORDER_HAS_U64__
32 #define __SWAB_64_THRU_32__
33 #endif
34
35 #endif /* __NDS32_SWAB_H__ */