From patchwork Fri Mar 15 13:15:29 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: 227990 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 C2AC92C0090 for ; Sat, 16 Mar 2013 00:28:03 +1100 (EST) Received: from localhost ([::1]:44434 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UGUfx-0001D2-Ub for incoming@patchwork.ozlabs.org; Fri, 15 Mar 2013 09:28:01 -0400 Received: from eggs.gnu.org ([208.118.235.92]:34430) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UGUUn-00012X-2o for qemu-devel@nongnu.org; Fri, 15 Mar 2013 09:16:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UGUUk-0005Al-AH for qemu-devel@nongnu.org; Fri, 15 Mar 2013 09:16:29 -0400 Received: from mail-pb0-f50.google.com ([209.85.160.50]:55769) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UGUUk-0005Ab-3z for qemu-devel@nongnu.org; Fri, 15 Mar 2013 09:16:26 -0400 Received: by mail-pb0-f50.google.com with SMTP id up1so3784853pbc.9 for ; Fri, 15 Mar 2013 06:16:25 -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=b5Hbs3gwzme7XeXTjykx596knY3aey9gh+FZ08YRDYPOJYCD9wjKjxXDJtyaMwT7el GGF/4cklcvKfwfzYXAG/KZrJZ3QJXJdtQWHEO5EOZryvS8cXb39ZNlpfJmwZvoDgwlA3 wzinXW81zzS4DWZ6CdVE36r6LFrCmm9NaIVakU0VQy428hvDgS1do8d/si30Wl1KlRtt 0VzYCbk32nlTi1lgvDgv+GWYtADZvRAQi3yvqDTlQoygmnG5tu+Aw1Zhb0bSnhJYkpP+ Z/yiFSKx0zZeumpA6YxmymLNstqR3LdWKa8AKFhPPZIBVLGSoOX5o8n+TYhgKstCeWUc I/ww== X-Received: by 10.68.189.65 with SMTP id gg1mr15719811pbc.122.1363353385518; Fri, 15 Mar 2013 06:16:25 -0700 (PDT) Received: from localhost.localdomain ([220.132.37.35]) by mx.google.com with ESMTPS id xr3sm8729551pbc.46.2013.03.15.06.16.22 (version=TLSv1 cipher=DES-CBC3-SHA bits=168/168); Fri, 15 Mar 2013 06:16:24 -0700 (PDT) From: Kuo-Jung Su To: qemu-devel@nongnu.org Date: Fri, 15 Mar 2013 21:15:29 +0800 Message-Id: <1363353336-11237-18-git-send-email-dantesu@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1363353336-11237-1-git-send-email-dantesu@gmail.com> References: <1363353336-11237-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.160.50 Cc: Peter Maydell , i.mitsyanko@samsung.com, Blue Swirl , Paul Brook , Kuo-Jung Su , Andreas , fred.konrad@greensocs.com Subject: [Qemu-devel] [PATCH v8 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