[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v7 17/24] qemu/bitops.h: add the bit ordering revers
From: |
Kuo-Jung Su |
Subject: |
[Qemu-devel] [PATCH v7 17/24] qemu/bitops.h: add the bit ordering reversal functions |
Date: |
Tue, 12 Mar 2013 14:13:02 +0800 |
From: Kuo-Jung Su <address@hidden>
Signed-off-by: Kuo-Jung Su <address@hidden>
---
include/qemu/bitops.h | 59 ++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 58 insertions(+), 1 deletion(-)
diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h
index affcc96..64cbb04 100644
--- a/include/qemu/bitops.h
+++ b/include/qemu/bitops.h
@@ -3,7 +3,8 @@
*
* Copyright (C) 2010 Corentin Chary <address@hidden>
*
- * 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,60 @@ 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)
+{
+ value = (value & 0xF0) >> 4 | (value & 0x0F) << 4;
+ value = (value & 0xCC) >> 2 | (value & 0x33) << 2;
+ value = (value & 0xAA) >> 1 | (value & 0x55) << 1;
+ return value;
+}
+
+/**
+ * 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);
+}
+
+/**
+ * bitrev64:
+ * @value: the value to reverse bit ordering from
+ *
+ * Reverse the 64 bit input @value
+ *
+ * Returns: the input @value with reversed bit ordering
+ */
+static inline uint64_t bitrev64(uint64_t value)
+{
+ return ((uint64_t)bitrev32(value & 0xffffffffULL) << 32)
+ | (uint64_t)bitrev32(value >> 32);
+}
+
#endif
--
1.7.9.5
- [Qemu-devel] [PATCH v7 06/24] hw/arm: add FTPWMTMR010 timer support, (continued)
- [Qemu-devel] [PATCH v7 06/24] hw/arm: add FTPWMTMR010 timer support, Kuo-Jung Su, 2013/03/12
- [Qemu-devel] [PATCH v7 07/24] hw/arm: add FTWDT010 watchdog timer support, Kuo-Jung Su, 2013/03/12
- [Qemu-devel] [PATCH v7 08/24] hw/arm: add FTRTC011 RTC timer support, Kuo-Jung Su, 2013/03/12
- [Qemu-devel] [PATCH v7 09/24] tests: add QTest for FTRTC011, Kuo-Jung Su, 2013/03/12
- [Qemu-devel] [PATCH v7 10/24] hw/arm: add FTDMAC020 AHB DMA support, Kuo-Jung Su, 2013/03/12
- [Qemu-devel] [PATCH v7 11/24] hw/arm: add FTAPBBRG020 APB DMA support, Kuo-Jung Su, 2013/03/12
- [Qemu-devel] [PATCH v7 12/24] hw/arm: add FTNANDC021 nand flash controller support, Kuo-Jung Su, 2013/03/12
- [Qemu-devel] [PATCH v7 13/24] hw/arm: add FTI2C010 I2C controller support, Kuo-Jung Su, 2013/03/12
- [Qemu-devel] [PATCH v7 14/24] hw: add AudioCodecClass for wm87xx audio class abstration., Kuo-Jung Su, 2013/03/12
- [Qemu-devel] [PATCH v7 15/24] hw: add WM8731 audio codec support, Kuo-Jung Su, 2013/03/12
- [Qemu-devel] [PATCH v7 17/24] qemu/bitops.h: add the bit ordering reversal functions,
Kuo-Jung Su <=
- [Qemu-devel] [PATCH v7 16/24] hw/arm: add FTSSP010 multi-function controller support, Kuo-Jung Su, 2013/03/12
- [Qemu-devel] [PATCH v7 18/24] hw/arm: add FTGMAC100 1Gbps ethernet support, Kuo-Jung Su, 2013/03/12
- [Qemu-devel] [PATCH v7 19/24] hw/arm: add FTLCDC200 LCD controller support, Kuo-Jung Su, 2013/03/12
- [Qemu-devel] [PATCH v7 20/24] hw/arm: add FTTSC010 touchscreen controller support, Kuo-Jung Su, 2013/03/12
- [Qemu-devel] [PATCH v7 21/24] hw/arm: add FTSDC010 MMC/SD controller support, Kuo-Jung Su, 2013/03/12
- [Qemu-devel] [PATCH v7 22/24] hw/arm: add FTMAC110 10/100Mbps ethernet support, Kuo-Jung Su, 2013/03/12
- [Qemu-devel] [PATCH v7 23/24] hw/arm: add FTTMR010 timer support, Kuo-Jung Su, 2013/03/12
- [Qemu-devel] [PATCH v7 24/24] hw/arm: add FTSPI020 SPI flash controller support, Kuo-Jung Su, 2013/03/12