From patchwork Mon Mar 25 12:09:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuo-Jung Su X-Patchwork-Id: 230677 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 04F162C00AE for ; Mon, 25 Mar 2013 23:19:23 +1100 (EST) Received: from localhost ([::1]:47125 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UK6Mz-0008E4-3U for incoming@patchwork.ozlabs.org; Mon, 25 Mar 2013 08:19:21 -0400 Received: from eggs.gnu.org ([208.118.235.92]:37807) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UK6FD-0003z2-48 for qemu-devel@nongnu.org; Mon, 25 Mar 2013 08:11:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UK6FA-0006jI-4T for qemu-devel@nongnu.org; Mon, 25 Mar 2013 08:11:19 -0400 Received: from mail-pd0-f173.google.com ([209.85.192.173]:54897) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UK6F9-0006jA-V8 for qemu-devel@nongnu.org; Mon, 25 Mar 2013 08:11:16 -0400 Received: by mail-pd0-f173.google.com with SMTP id v10so2495150pde.32 for ; Mon, 25 Mar 2013 05:11:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=zKYvgQNFhWG6lAhW4eRZevcsad6ngeXdkdzrSMChVnA=; b=CCdek1+0jBbvIq2Pc3Dttma1S38TMPRnfqRMLYjxQC++D/hPzvlHgilSC1RiRJAIdp 8XSW9nJSsMhrMHE+KzmyJrx86663iziLC6k6yAku6Qzseing5Pc6marFlE1Cs8Zj/vhd kors7Zsby7LO5LVmePEYX1zX03npirKD7MLNjHtBJe3NMqQAFpkD+xbu3HOvp1VsYjsc hQqBULPxyguEUFTGjl7aJ64wML4Ca1bjQK/BM1KoGWttqmCqK6aGjlTuy5E1xvEBTBTj F20ARHjq39XtBc0Gn2Ex8XGLnSZZE5jR2YNVFFd6Q8CyPKP86pVserHu7l0DSKH37zR0 9m1w== X-Received: by 10.68.106.4 with SMTP id gq4mr17306770pbb.50.1364213475294; Mon, 25 Mar 2013 05:11:15 -0700 (PDT) Received: from localhost.localdomain ([220.132.37.35]) by mx.google.com with ESMTPS id wi7sm14669199pac.9.2013.03.25.05.11.12 (version=TLSv1 cipher=DES-CBC3-SHA bits=168/168); Mon, 25 Mar 2013 05:11:14 -0700 (PDT) From: Kuo-Jung Su To: qemu-devel@nongnu.org Date: Mon, 25 Mar 2013 20:09:53 +0800 Message-Id: <1364213400-10266-18-git-send-email-dantesu@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1364213400-10266-1-git-send-email-dantesu@gmail.com> References: <1364213400-10266-1-git-send-email-dantesu@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.192.173 Cc: Peter Maydell , i.mitsyanko@samsung.com, Blue Swirl , Paul Brook , Kuo-Jung Su , Andreas , fred.konrad@greensocs.com Subject: [Qemu-devel] [PATCH v9 17/24] qemu/bitops.h: add the bit ordering reversal functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Kuo-Jung Su Signed-off-by: Kuo-Jung Su --- 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 * - * 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