1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * arch/arm/include/asm/byteorder.h
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * ARM Endian-ness. In little endian mode, the data bus is connected such
6*4882a593Smuzhiyun * that byte accesses appear as:
7*4882a593Smuzhiyun * 0 = d0...d7, 1 = d8...d15, 2 = d16...d23, 3 = d24...d31
8*4882a593Smuzhiyun * and word accesses (data or instruction) appear as:
9*4882a593Smuzhiyun * d0...d31
10*4882a593Smuzhiyun *
11*4882a593Smuzhiyun * When in big endian mode, byte accesses appear as:
12*4882a593Smuzhiyun * 0 = d24...d31, 1 = d16...d23, 2 = d8...d15, 3 = d0...d7
13*4882a593Smuzhiyun * and word accesses (data or instruction) appear as:
14*4882a593Smuzhiyun * d0...d31
15*4882a593Smuzhiyun */
16*4882a593Smuzhiyun #ifndef _UAPI__ASM_ARM_SWAB_H
17*4882a593Smuzhiyun #define _UAPI__ASM_ARM_SWAB_H
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun #include <linux/compiler.h>
20*4882a593Smuzhiyun #include <linux/types.h>
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun #if !defined(__STRICT_ANSI__) || defined(__KERNEL__)
23*4882a593Smuzhiyun # define __SWAB_64_THRU_32__
24*4882a593Smuzhiyun #endif
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun #if !defined(__KERNEL__) || __LINUX_ARM_ARCH__ < 6
__arch_swab32(__u32 x)28*4882a593Smuzhiyun static inline __attribute_const__ __u32 __arch_swab32(__u32 x)
29*4882a593Smuzhiyun {
30*4882a593Smuzhiyun __u32 t;
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun #ifndef __thumb__
33*4882a593Smuzhiyun if (!__builtin_constant_p(x)) {
34*4882a593Smuzhiyun /*
35*4882a593Smuzhiyun * The compiler needs a bit of a hint here to always do the
36*4882a593Smuzhiyun * right thing and not screw it up to different degrees
37*4882a593Smuzhiyun * depending on the gcc version.
38*4882a593Smuzhiyun */
39*4882a593Smuzhiyun asm ("eor\t%0, %1, %1, ror #16" : "=r" (t) : "r" (x));
40*4882a593Smuzhiyun } else
41*4882a593Smuzhiyun #endif
42*4882a593Smuzhiyun t = x ^ ((x << 16) | (x >> 16)); /* eor r1,r0,r0,ror #16 */
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun x = (x << 24) | (x >> 8); /* mov r0,r0,ror #8 */
45*4882a593Smuzhiyun t &= ~0x00FF0000; /* bic r1,r1,#0x00FF0000 */
46*4882a593Smuzhiyun x ^= (t >> 8); /* eor r0,r0,r1,lsr #8 */
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun return x;
49*4882a593Smuzhiyun }
50*4882a593Smuzhiyun #define __arch_swab32 __arch_swab32
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun #endif
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun #endif /* _UAPI__ASM_ARM_SWAB_H */
55