From patchwork Wed Dec 7 21:04:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Clayton X-Patchwork-Id: 9465233 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 31C7C6022E for ; Wed, 7 Dec 2016 21:07:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A0DB28574 for ; Wed, 7 Dec 2016 21:07:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1EA9228576; Wed, 7 Dec 2016 21:07:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A808D28574 for ; Wed, 7 Dec 2016 21:07:06 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1cEjPK-0004BV-GF; Wed, 07 Dec 2016 21:05:42 +0000 Received: from mail-pg0-x241.google.com ([2607:f8b0:400e:c05::241]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cEjOt-0002bj-U1 for linux-arm-kernel@lists.infradead.org; Wed, 07 Dec 2016 21:05:18 +0000 Received: by mail-pg0-x241.google.com with SMTP id 3so24560197pgd.0 for ; Wed, 07 Dec 2016 13:04:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=cAtHt4cn287zrVRvomlPVWm8VYA/dY/LsKKL3NIN7jk=; b=P+JEDFi6KZ4kmGWJ6c62UsSP0/3qk3grZ18Jd313LdcG5czYvL7HNPvKwwufOADNdG OJBtIuSQ9AGwRCe9Q5mw35JYNpwd+VyPxMUlM+KsnS9WIRDg3GpntGKt6VqvGaSKgUp4 jXmJjMTnhgTEGSGK6wz3U4soWbVrBbWGqVymbLP0mkZcQIBLBkNTjHVOQrRaFhgMaHJ2 dtg4KNarnVi9YEg00EkQ+lJj96GZFw/HNbyN0oa0ord0lyelLLlToJ7VkgHjqdP8M5ud wD7Pr0tPrBqrVrl6iQTbUXU7rKw+gWU2vzu41OBWHoudEOc19L/hxGqbmm8ZopIH9cV3 UH4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=cAtHt4cn287zrVRvomlPVWm8VYA/dY/LsKKL3NIN7jk=; b=W7UxnO/PkY70zZl8R2zl1NIjrRHVw2fSIaKAw5YWsn8I7g82mEb/A8YowDgoSAGQYA JzT5rVx9gYSWBYEt+I/qIpP15aGvraymkFMNlmRnILLKUqBT7j2leqvK3wh0vLMLelG1 rsv3g7oxPx37OEFIYf0tNWOlD0pI4lnc0otelbckoidLBg24Z7CBS46NMfeRtu4M1JRb RHV+xVxFFbA61bLtIiE6nNgcLa34OGqoQXw8sMcZZfkaksxJXTBBnMnRkuaQJx6KNfdR I5z1saOZ4SyZMMZxFC9jaxY/0l+pYc6ROpJRkA0VxViU77hgu+8cwIzQhuJMPbnBKG5q AUzA== X-Gm-Message-State: AKaTC03hgJZLMjQAPNLDxSoOdi+1tXvcBZkg/7cNTgM4dqyDV1hZ84Q3ubUkNP0jbiSFcg== X-Received: by 10.99.2.142 with SMTP id 136mr125197461pgc.25.1481144696316; Wed, 07 Dec 2016 13:04:56 -0800 (PST) Received: from jclayton-pc.columbia.uniwest.com (68-185-59-186.static.knwc.wa.charter.com. [68.185.59.186]) by smtp.gmail.com with ESMTPSA id 24sm44704876pfh.41.2016.12.07.13.04.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Dec 2016 13:04:55 -0800 (PST) From: Joshua Clayton To: Alan Tull , Moritz Fischer , Mark Rutland , Russell King Subject: [PATCH v5 1/3] lib: add bitrev8x4() Date: Wed, 7 Dec 2016 13:04:38 -0800 Message-Id: X-Mailer: git-send-email 2.9.3 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161207_130516_246793_1CDBBB78 X-CRM114-Status: GOOD ( 10.52 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Joshua Clayton , linux-kernel@vger.kernel.org, Rob Herring , Anatolij Gustschin , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add a function to reverse bytes within a 32 bit word. This function is more efficient than using the 8 bit version when iterating over an array Signed-off-by: Joshua Clayton --- arch/arm/include/asm/bitrev.h | 6 ++++++ include/linux/bitrev.h | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/arch/arm/include/asm/bitrev.h b/arch/arm/include/asm/bitrev.h index ec291c3..9482f78 100644 --- a/arch/arm/include/asm/bitrev.h +++ b/arch/arm/include/asm/bitrev.h @@ -17,4 +17,10 @@ static __always_inline __attribute_const__ u8 __arch_bitrev8(u8 x) return __arch_bitrev32((u32)x) >> 24; } +static __always_inline __attribute_const__ u32 __arch_bitrev8x4(u32 x) +{ + __asm__ ("rbit %0, %1; rev %0, %0" : "=r" (x) : "r" (x)); + return x; +} + #endif diff --git a/include/linux/bitrev.h b/include/linux/bitrev.h index fb790b8..b1cfa1a 100644 --- a/include/linux/bitrev.h +++ b/include/linux/bitrev.h @@ -9,6 +9,7 @@ #define __bitrev32 __arch_bitrev32 #define __bitrev16 __arch_bitrev16 #define __bitrev8 __arch_bitrev8 +#define __bitrev8x4 __arch_bitrev8x4 #else extern u8 const byte_rev_table[256]; @@ -27,6 +28,14 @@ static inline u32 __bitrev32(u32 x) return (__bitrev16(x & 0xffff) << 16) | __bitrev16(x >> 16); } +static inline u32 __bitrev8x4(u32 x) +{ + return(__bitrev8(x & 0xff) | + (__bitrev8((x >> 8) & 0xff) << 8) | + (__bitrev8((x >> 16) & 0xff) << 16) | + (__bitrev8((x >> 24) & 0xff) << 24)); +} + #endif /* CONFIG_HAVE_ARCH_BITREVERSE */ #define __constant_bitrev32(x) \ @@ -50,6 +59,15 @@ static inline u32 __bitrev32(u32 x) __x; \ }) +#define __constant_bitrev8x4(x) \ +({ \ + u32 __x = x; \ + __x = ((__x & (u32)0xF0F0F0F0UL) >> 4) | ((__x & (u32)0x0F0F0F0FUL) << 4); \ + __x = ((__x & (u32)0xCCCCCCCCUL) >> 2) | ((__x & (u32)0x33333333UL) << 2); \ + __x = ((__x & (u32)0xAAAAAAAAUL) >> 1) | ((__x & (u32)0x55555555UL) << 1); \ + __x; \ +}) + #define __constant_bitrev8(x) \ ({ \ u8 __x = x; \ @@ -75,6 +93,14 @@ static inline u32 __bitrev32(u32 x) __bitrev16(__x); \ }) +#define bitrev8x4(x) \ +({ \ + u32 __x = x; \ + __builtin_constant_p(__x) ? \ + __constant_bitrev8x4(__x) : \ + __bitrev8x4(__x); \ +}) + #define bitrev8(x) \ ({ \ u8 __x = x; \