some ifdef --> if fixes
[coreboot.git] / src / include / swab.h
1 #ifndef _SWAB_H
2 #define _SWAB_H
3
4 /*
5  * linux/byteorder/swab.h
6  * Byte-swapping, independently from CPU endianness
7  *      swabXX[ps]?(foo)
8  *
9  * Francois-Rene Rideau <fare@tunes.org> 19971205
10  *    separated swab functions from cpu_to_XX,
11  *    to clean up support for bizarre-endian architectures.
12  *
13  * See asm-i386/byteorder.h and suches for examples of how to provide
14  * architecture-dependent optimized versions
15  *
16  */
17
18 /* casts are necessary for constants, because we never know how for sure
19  * how U/UL/ULL map to __u16, __u32, __u64. At least not in a portable way.
20  */
21 #define swab16(x) \
22         ((unsigned short)( \
23                 (((unsigned short)(x) & (unsigned short)0x00ffU) << 8) | \
24                 (((unsigned short)(x) & (unsigned short)0xff00U) >> 8) ))
25
26 #define swab32(x) \
27         ((unsigned int)( \
28                 (((unsigned int)(x) & (unsigned int)0x000000ffUL) << 24) | \
29                 (((unsigned int)(x) & (unsigned int)0x0000ff00UL) <<  8) | \
30                 (((unsigned int)(x) & (unsigned int)0x00ff0000UL) >>  8) | \
31                 (((unsigned int)(x) & (unsigned int)0xff000000UL) >> 24) ))
32
33 #endif /* _SWAB_H */