Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
0002 /*
0003  *  arch/arm/include/asm/byteorder.h
0004  *
0005  * ARM Endian-ness.  In little endian mode, the data bus is connected such
0006  * that byte accesses appear as:
0007  *  0 = d0...d7, 1 = d8...d15, 2 = d16...d23, 3 = d24...d31
0008  * and word accesses (data or instruction) appear as:
0009  *  d0...d31
0010  *
0011  * When in big endian mode, byte accesses appear as:
0012  *  0 = d24...d31, 1 = d16...d23, 2 = d8...d15, 3 = d0...d7
0013  * and word accesses (data or instruction) appear as:
0014  *  d0...d31
0015  */
0016 #ifndef _UAPI__ASM_ARM_SWAB_H
0017 #define _UAPI__ASM_ARM_SWAB_H
0018 
0019 #include <linux/compiler.h>
0020 #include <linux/types.h>
0021 
0022 #if !defined(__STRICT_ANSI__) || defined(__KERNEL__)
0023 #  define __SWAB_64_THRU_32__
0024 #endif
0025 
0026 
0027 #if !defined(__KERNEL__) || __LINUX_ARM_ARCH__ < 6
0028 static inline __attribute_const__ __u32 __arch_swab32(__u32 x)
0029 {
0030     __u32 t;
0031 
0032 #ifndef __thumb__
0033     if (!__builtin_constant_p(x)) {
0034         /*
0035          * The compiler needs a bit of a hint here to always do the
0036          * right thing and not screw it up to different degrees
0037          * depending on the gcc version.
0038          */
0039         asm ("eor\t%0, %1, %1, ror #16" : "=r" (t) : "r" (x));
0040     } else
0041 #endif
0042         t = x ^ ((x << 16) | (x >> 16)); /* eor r1,r0,r0,ror #16 */
0043 
0044     x = (x << 24) | (x >> 8);       /* mov r0,r0,ror #8      */
0045     t &= ~0x00FF0000;           /* bic r1,r1,#0x00FF0000 */
0046     x ^= (t >> 8);              /* eor r0,r0,r1,lsr #8   */
0047 
0048     return x;
0049 }
0050 #define __arch_swab32 __arch_swab32
0051 
0052 #endif
0053 
0054 #endif /* _UAPI__ASM_ARM_SWAB_H */