qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kuo-Jung Su <dantesu@gmail.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	i.mitsyanko@samsung.com, Blue Swirl <blauwirbel@gmail.com>,
	Kuo-Jung Su <dantesu@gmail.com>,
	Paul Brook <paul@codesourcery.com>, Andreas <afaerber@suse.de>,
	fred.konrad@greensocs.com
Subject: [Qemu-devel] [PATCH v6 17/24] qemu/bitops.h: add the bit ordering reversal functions stolen from linux
Date: Wed,  6 Mar 2013 15:27:30 +0800	[thread overview]
Message-ID: <1362554857-3896-18-git-send-email-dantesu@gmail.com> (raw)
In-Reply-To: <1362554857-3896-1-git-send-email-dantesu@gmail.com>

Signed-off-by: Kuo-Jung Su <dantesu@gmail.com>
---
 include/qemu/bitops.h |   63 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 62 insertions(+), 1 deletion(-)

diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h
index affcc96..920d028 100644
--- a/include/qemu/bitops.h
+++ b/include/qemu/bitops.h
@@ -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,64 @@ 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)
+{
+    int i;
+    uint8_t ret = 0;
+    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);
+}
+
+/**
+ * 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

  parent reply	other threads:[~2013-03-06  7:28 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-06  7:27 [Qemu-devel] [PATCH v6 00/24] Add Faraday A369 SoC platform support Kuo-Jung Su
2013-03-06  7:27 ` [Qemu-devel] [PATCH v6 01/24] target-arm: add Faraday ARMv5TE processors support Kuo-Jung Su
2013-03-06  7:27 ` [Qemu-devel] [PATCH v6 02/24] hw/arm: add Faraday a369 SoC platform support Kuo-Jung Su
2013-03-06  7:27 ` [Qemu-devel] [PATCH v6 03/24] hw/arm: add Faraday FTINTC020 interrupt controller support Kuo-Jung Su
2013-03-12  3:42   ` Peter Crosthwaite
2013-03-06  7:27 ` [Qemu-devel] [PATCH v6 04/24] hw/arm: add Faraday FTAHBC020 support Kuo-Jung Su
2013-03-06  7:27 ` [Qemu-devel] [PATCH v6 05/24] hw/arm: add Faraday FTDDRII030 support Kuo-Jung Su
2013-03-06  7:27 ` [Qemu-devel] [PATCH v6 06/24] hw/arm: add Faraday FTPWMTMR010 timer support Kuo-Jung Su
2013-03-06  7:27 ` [Qemu-devel] [PATCH v6 07/24] hw/arm: add Faraday FTWDT010 watchdog " Kuo-Jung Su
2013-03-06  8:22   ` Paolo Bonzini
2013-03-06  8:56     ` Kuo-Jung Su
2013-03-06 10:46       ` Paolo Bonzini
2013-03-07  2:44         ` Kuo-Jung Su
2013-03-07  5:53           ` Kuo-Jung Su
2013-03-06  7:27 ` [Qemu-devel] [PATCH v6 08/24] hw/arm: add Faraday FTRTC011 RTC " Kuo-Jung Su
2013-03-06  8:24   ` Paolo Bonzini
2013-03-07  6:39     ` Kuo-Jung Su
2013-03-07  7:24       ` Paolo Bonzini
2013-03-07  7:27       ` 陳韋任 (Wei-Ren Chen)
2013-03-07  7:41         ` Paolo Bonzini
2013-03-07  8:01           ` 陳韋任 (Wei-Ren Chen)
2013-03-07  8:08           ` Kuo-Jung Su
2013-03-06  7:27 ` [Qemu-devel] [PATCH v6 09/24] hw/arm: add Faraday FTDMAC020 AHB DMA support Kuo-Jung Su
2013-03-06  7:27 ` [Qemu-devel] [PATCH v6 10/24] hw/arm: add Faraday FTAPBBRG020 APB " Kuo-Jung Su
2013-03-06  7:27 ` [Qemu-devel] [PATCH v6 11/24] hw/nand.c: correct the sense of the BUSY/READY status bit Kuo-Jung Su
2013-03-07  2:11   ` Peter Crosthwaite
2013-03-07  3:40     ` Kuo-Jung Su
2013-03-07  8:37     ` Edgar E. Iglesias
2013-03-06  7:27 ` [Qemu-devel] [PATCH v6 12/24] hw/nand.c: bug fix to erase operation Kuo-Jung Su
2013-03-07  2:18   ` Peter Crosthwaite
2013-03-07  2:28     ` Peter Maydell
2013-03-07  3:32       ` Peter Crosthwaite
2013-03-07  4:10         ` Kuo-Jung Su
2013-03-07  3:35       ` Kuo-Jung Su
2013-03-06  7:27 ` [Qemu-devel] [PATCH v6 13/24] hw/arm: add Faraday FTNANDC021 nand flash controller support Kuo-Jung Su
2013-03-06  7:27 ` [Qemu-devel] [PATCH v6 14/24] hw/arm: add Faraday FTI2C010 I2C " Kuo-Jung Su
2013-03-06  7:27 ` [Qemu-devel] [PATCH v6 15/24] hw: add WM8731 codec support Kuo-Jung Su
2013-03-06  7:27 ` [Qemu-devel] [PATCH v6 16/24] hw/arm: add Faraday FTSSP010 multi-function controller support Kuo-Jung Su
2013-03-06  7:27 ` Kuo-Jung Su [this message]
2013-03-06  8:26   ` [Qemu-devel] [PATCH v6 17/24] qemu/bitops.h: add the bit ordering reversal functions stolen from linux Paolo Bonzini
2013-03-07  2:58     ` Kuo-Jung Su
2013-03-06  7:27 ` [Qemu-devel] [PATCH v6 18/24] hw/arm: add Faraday FTGMAC100 1Gbps ethernet support Kuo-Jung Su
2013-03-06  7:27 ` [Qemu-devel] [PATCH v6 19/24] hw/arm: add Faraday FTLCDC200 LCD controller support Kuo-Jung Su
2013-03-06  7:27 ` [Qemu-devel] [PATCH v6 20/24] hw/arm: add Faraday FTTSC010 touchscreen " Kuo-Jung Su
2013-03-06  7:27 ` [Qemu-devel] [PATCH v6 21/24] hw/arm: add Faraday FTSDC010 MMC/SD " Kuo-Jung Su
2013-03-06  7:27 ` [Qemu-devel] [PATCH v6 22/24] hw/arm: add Faraday FTMAC110 10/100Mbps ethernet support Kuo-Jung Su
2013-03-06  7:27 ` [Qemu-devel] [PATCH v6 23/24] hw/arm: add Faraday FTTMR010 timer support Kuo-Jung Su
2013-03-06  7:27 ` [Qemu-devel] [PATCH v6 24/24] hw/arm: add Faraday FTSPI020 SPI flash controller support Kuo-Jung Su

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1362554857-3896-18-git-send-email-dantesu@gmail.com \
    --to=dantesu@gmail.com \
    --cc=afaerber@suse.de \
    --cc=blauwirbel@gmail.com \
    --cc=fred.konrad@greensocs.com \
    --cc=i.mitsyanko@samsung.com \
    --cc=paul@codesourcery.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).