aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/bitrev.h
diff options
context:
space:
mode:
authorJoshua Clayton <stillcompiling@gmail.com>2017-06-14 11:36:31 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-07-17 11:26:14 -0400
commit3b88da4aba2549497ac8868877562f1b1913ca62 (patch)
tree71ab6007d676f87e817333e560cfaa8a7b1df671 /include/linux/bitrev.h
parent60acfa593731f496a9f258d2e118297ef956d98d (diff)
lib: add bitrev8x4()
Add a function to reverse bytes within a 32 bit word. Operate on a u32 rather than individual bytes. Signed-off-by: Joshua Clayton <stillcompiling@gmail.com> Signed-off-by: Alan Tull <atull@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include/linux/bitrev.h')
-rw-r--r--include/linux/bitrev.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/include/linux/bitrev.h b/include/linux/bitrev.h
index fb790b8449c1..b97be27e5a85 100644
--- a/include/linux/bitrev.h
+++ b/include/linux/bitrev.h
@@ -29,6 +29,8 @@ static inline u32 __bitrev32(u32 x)
29 29
30#endif /* CONFIG_HAVE_ARCH_BITREVERSE */ 30#endif /* CONFIG_HAVE_ARCH_BITREVERSE */
31 31
32#define __bitrev8x4(x) (__bitrev32(swab32(x)))
33
32#define __constant_bitrev32(x) \ 34#define __constant_bitrev32(x) \
33({ \ 35({ \
34 u32 __x = x; \ 36 u32 __x = x; \
@@ -50,6 +52,15 @@ static inline u32 __bitrev32(u32 x)
50 __x; \ 52 __x; \
51}) 53})
52 54
55#define __constant_bitrev8x4(x) \
56({ \
57 u32 __x = x; \
58 __x = ((__x & (u32)0xF0F0F0F0UL) >> 4) | ((__x & (u32)0x0F0F0F0FUL) << 4); \
59 __x = ((__x & (u32)0xCCCCCCCCUL) >> 2) | ((__x & (u32)0x33333333UL) << 2); \
60 __x = ((__x & (u32)0xAAAAAAAAUL) >> 1) | ((__x & (u32)0x55555555UL) << 1); \
61 __x; \
62})
63
53#define __constant_bitrev8(x) \ 64#define __constant_bitrev8(x) \
54({ \ 65({ \
55 u8 __x = x; \ 66 u8 __x = x; \
@@ -75,6 +86,14 @@ static inline u32 __bitrev32(u32 x)
75 __bitrev16(__x); \ 86 __bitrev16(__x); \
76 }) 87 })
77 88
89#define bitrev8x4(x) \
90({ \
91 u32 __x = x; \
92 __builtin_constant_p(__x) ? \
93 __constant_bitrev8x4(__x) : \
94 __bitrev8x4(__x); \
95 })
96
78#define bitrev8(x) \ 97#define bitrev8(x) \
79({ \ 98({ \
80 u8 __x = x; \ 99 u8 __x = x; \