Skip to contentSkip to conversation

kernel: add bit rotation helpers for 16 and 8 bit

PATCH In review Harvey Harrison 2 participants 2 messages Mar 19, 2008 – Mar 20, 2008 Bitops API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel: add bit rotation helpers for 16 and 8 bit

Will replace open-coded variants elsewhere. Done in the same style as the 32-bit versions.

---
Andrew, these will be used to replace some open-coded variants in the mac80211 code, there are currently no users so it can go in with little risk.

Randy, CC'd in case I screwed up the kerneldoc.

 include/linux/bitops.h |   40 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 40 insertions(+), 0 deletions(-)
include/linux/bitops.h +40 -0
index 69c1edb..40d5473 100644
@@ -65,6 +65,46 @@ static inline __u32 ror32(__u32 word, unsigned int shift)
 	return (word >> shift) | (word << (32 - shift));
 }
 
+/**
+ * rol16 - rotate a 16-bit value left
+ * @word: value to rotate
+ * @shift: bits to roll
+ */
+static inline __u16 rol16(__u16 word, unsigned int shift)
+{
+	return (word << shift) | (word >> (16 - shift));
+}
+
+/**
+ * ror16 - rotate a 16-bit value right
+ * @word: value to rotate
+ * @shift: bits to roll
+ */
+static inline __u16 ror16(__u16 word, unsigned int shift)
+{
+	return (word >> shift) | (word << (16 - shift));
+}
+
+/**
+ * rol8 - rotate an 8-bit value left
+ * @word: value to rotate
+ * @shift: bits to roll
+ */
+static inline __u8 rol8(__u8 word, unsigned int shift)
+{
+	return (word << shift) | (word >> (8 - shift));
+}
+
+/**
+ * ror8 - rotate an 8-bit value right
+ * @word: value to rotate
+ * @shift: bits to roll
+ */
+static inline __u8 ror8(__u8 word, unsigned int shift)
+{
+	return (word >> shift) | (word << (8 - shift));
+}
+
 static inline unsigned fls_long(unsigned long l)
 {
 	if (sizeof(l) == 4)
Signature · 1 line
1.5.4.4.684.g0e08
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Harvey Harrison

Will replace open-coded variants elsewhere. Done in the same style as the 32-bit versions.

---
Andrew, these will be used to replace some open-coded variants in the mac80211 code, there are currently no users so it can go in with little risk.

Randy, CC'd in case I screwed up the kerneldoc.

Looks good.

Quoted 54 lines
 include/linux/bitops.h |   40 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 40 insertions(+), 0 deletions(-)
include/linux/bitops.h +40 -0
index 69c1edb..40d5473 100644
@@ -65,6 +65,46 @@ static inline __u32 ror32(__u32 word, unsigned int shift)
 	return (word >> shift) | (word << (32 - shift));
 }
 
+/**
+ * rol16 - rotate a 16-bit value left
+ * @word: value to rotate
+ * @shift: bits to roll
+ */
+static inline __u16 rol16(__u16 word, unsigned int shift)
+{
+	return (word << shift) | (word >> (16 - shift));
+}
+
+/**
+ * ror16 - rotate a 16-bit value right
+ * @word: value to rotate
+ * @shift: bits to roll
+ */
+static inline __u16 ror16(__u16 word, unsigned int shift)
+{
+	return (word >> shift) | (word << (16 - shift));
+}
+
+/**
+ * rol8 - rotate an 8-bit value left
+ * @word: value to rotate
+ * @shift: bits to roll
+ */
+static inline __u8 rol8(__u8 word, unsigned int shift)
+{
+	return (word << shift) | (word >> (8 - shift));
+}
+
+/**
+ * ror8 - rotate an 8-bit value right
+ * @word: value to rotate
+ * @shift: bits to roll
+ */
+static inline __u8 ror8(__u8 word, unsigned int shift)
+{
+	return (word >> shift) | (word << (8 - shift));
+}
+
 static inline unsigned fls_long(unsigned long l)
 {
 	if (sizeof(l) == 4)
Signature · 1 line
~Randy