From patchwork Wed Nov 30 01:11:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Clayton X-Patchwork-Id: 9453361 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 D573E6071E for ; Wed, 30 Nov 2016 01:14:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8B902839B for ; Wed, 30 Nov 2016 01:14:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BCCDA283E0; Wed, 30 Nov 2016 01:14:04 +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=unavailable 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 79C022839B for ; Wed, 30 Nov 2016 01:14:04 +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 1cBtRo-0002Bb-4c; Wed, 30 Nov 2016 01:12:32 +0000 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cBtQw-0001Ca-Vm for linux-arm-kernel@lists.infradead.org; Wed, 30 Nov 2016 01:11:44 +0000 Received: by mail-pg0-x243.google.com with SMTP id 3so17933748pgd.0 for ; Tue, 29 Nov 2016 17:11:18 -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=AslEWRliJb+JL2oMtV/5YBcRJqAx8Z2fFgovAKym71g=; b=HTW9VXq8egMsOTmaIwS5HZWTqOmjS1+4O+8bY9zr7GSZWfOFDYsph+JuHT0RJweH+e CZBaZMyP6Lv5m0SMwyatC8ycth0OocR9OQKHkpo6wUc+RJEjZDyfxkMSIsjXf0UryzwW KgexkxFcI6TqAJJ21G6iFQgruMtEjbwEUa2Fl8BJmFpQxepWjOKryVE7BLky/l+tExhJ yTajxYOAGcqgt2K1Ex46gMZuP+C6dvZun4i7HsadmDCR09MwG0is4eyqP9+493bRdM2e 0DzaEsW6ZFNyZrw7kYta/z0jJfjukT/FC5lGBdl+tPG2juAM+rQhu4XVYR9UqNIgbZ/M 0fMA== 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=AslEWRliJb+JL2oMtV/5YBcRJqAx8Z2fFgovAKym71g=; b=gJ3+wbWnxDCr35cE56/snLKYNkIoYSp/2G4tlZogdAeasIXTbzfr9v0hQ0CChdpTBP rW9FCXriEBO1o/9bsMWxWavcduBihsuL62/kqGhT+BEN6TxT6zmWYFUNgfPYEM43OaLd 3TujMv2rd6ydLctGl1cvHcWQH/OY8q+6Pe4WqfxNYSP6gvhTYgsl8C9mLnB+oZ0D8gEr q6+Vy/fnUfBKu84X4ew2vgbtHiT5GLYjb7MkT9BeXt9zkaNqWxIciasZgZ8Y4/VbesuU AvJYpb2VhShvoOdV7d4UcO43MHBp/HhZ0vT2ldaftt2M0Gnh+3LAjZhFkmd42NQXGE7w A83A== X-Gm-Message-State: AKaTC02A62JxHwgk2g+NwFUqORzMmcBLXWOQF8w2N391dxglFka8JBRxY+wXWCP7coemVQ== X-Received: by 10.99.111.78 with SMTP id k75mr55536619pgc.114.1480468278399; Tue, 29 Nov 2016 17:11:18 -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 4sm79910873pgd.32.2016.11.29.17.11.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Nov 2016 17:11:17 -0800 (PST) From: Joshua Clayton To: Alan Tull , Moritz Fischer Subject: [PATCH v3 1/3] lib: add bitrev8x4() Date: Tue, 29 Nov 2016 17:11:03 -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-20161129_171139_479143_26D2BC3A X-CRM114-Status: GOOD ( 10.84 ) 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: Mark Rutland , devicetree@vger.kernel.org, Joshua Clayton , Russell King , linux-kernel@vger.kernel.org, Rob Herring , 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 | 5 +++++ include/linux/bitrev.h | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/arch/arm/include/asm/bitrev.h b/arch/arm/include/asm/bitrev.h index ec291c3..6d2e9ca 100644 --- a/arch/arm/include/asm/bitrev.h +++ b/arch/arm/include/asm/bitrev.h @@ -17,4 +17,9 @@ 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)); +} + #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; \