Comments
Patch
@@ -3,7 +3,8 @@
*
* Copyright (C) 2010 Corentin Chary <corentin.chary@gmail.com>
*
- * Mostly inspired by (stolen from) linux/bitmap.h and linux/bitops.h
+ * Mostly inspired by (stolen from) linux/bitmap.h, linux/bitops.h
+ * and linux/bitrev.h
*
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
* See the COPYING.LIB file in the top-level directory.
@@ -273,4 +274,50 @@ static inline uint64_t deposit64(uint64_t value,
int start, int length,
return (value & ~mask) | ((fieldval << start) & mask);
}
+/**
+ * bitrev8:
+ * @value: the value to reverse bit ordering from
+ *
+ * Reverse the 8 bit input @value
+ *
+ * Returns: the input @value with reversed bit ordering
+ */
+static inline uint8_t bitrev8(uint8_t value)
+{
+ uint8_t ret = 0;
+ int i;
+ for (i = 0; i < 8; ++i) {
+ if (value & BIT(i)) {
+ ret |= BIT(7 - i);
+ }
+ }
+ return ret;
+}
+
+/**
+ * bitrev16:
+ * @value: the value to reverse bit ordering from
+ *
+ * Reverse the 16 bit input @value
+ *
+ * Returns: the input @value with reversed bit ordering
+ */
+static inline uint16_t bitrev16(uint16_t value)
+{
+ return (bitrev8(value & 0xff) << 8) | bitrev8(value >> 8);
+}
+
+/**
+ * bitrev32:
+ * @value: the value to reverse bit ordering from
+ *
+ * Reverse the 32 bit input @value
+ *
+ * Returns: the input @value with reversed bit ordering
+ */
+static inline uint32_t bitrev32(uint32_t value)
+{
+ return (bitrev16(value & 0xffff) << 16) | bitrev16(value >> 16);
+}
+