From patchwork Fri Oct 28 16:56: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: 9402373 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 7A47260588 for ; Fri, 28 Oct 2016 16:58:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E1F82A77E for ; Fri, 28 Oct 2016 16:58:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6210D2A8AF; Fri, 28 Oct 2016 16:58:58 +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 1D5E42A77E for ; Fri, 28 Oct 2016 16:58:58 +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 1c0ATI-0002j5-P1; Fri, 28 Oct 2016 16:57:36 +0000 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1c0ASt-0002YN-7Z for linux-arm-kernel@lists.infradead.org; Fri, 28 Oct 2016 16:57:12 +0000 Received: by mail-pf0-x242.google.com with SMTP id i85so1721256pfa.0 for ; Fri, 28 Oct 2016 09:56:50 -0700 (PDT) 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=S7GF62CcwTbYqXLfrTDZBQf+KdvxHcqsM+076NmsZ+M=; b=0d16ILkWV/k5txIy6UJTtwQQppzXyF94z8cxOE//zk2qDTMmL8d3soY7z8eJGqmPHX U299Qypj3SKH0bAWqWB0mgMEddOM1d8STuJNIEE9v92E0IG7aZGwRCq2n5VSiLS4RE5x xOEtAtHpCSKan48H42g1dBJ8qatogQDbD9/TSseeiNQBdUwF4dTCGhCXdZZYDqgxU48D o8LpSX9BdNrCzjdckSGBFjI98Qmz0r4UR6gA4zcCHJ7XNsDkcM9gggg15WBkPyeUty9A oZ+xwgRupIWUOCX/aQDISNjYEHQLL6VA0A+sI+PwhGHRQLfuzGKMR+PrUDxvDHN4ywiT Nxdw== 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=S7GF62CcwTbYqXLfrTDZBQf+KdvxHcqsM+076NmsZ+M=; b=bwwZQjw/nDFiRPgGtaJQdOm/WvtmwBez9GOiDwNtsF5dTGs8fHmp+h5+VSK1Zk7KKZ qrwTZHJKOJBXZkY9aDBYYi6FYYjQ6nI5pghm7VKclSxrITRh9v2AMBE0hLLSG4vymPCY KBbGB7+yJ5f+2Pzwt+csTx6Tmdrhc2oC2tcQrziWra8RmajXPavxuFBz82YMvxN6D6W7 70nF3FG4glbz+31NSwfmH7xeUorUL09H3w2avQ7yoZB58uScDI7xMwtf0l3CpglOQg8l 2QfBMFB0soBuygRZrl4oo8vnlZOeK1KEOI/to7r04Ng5QqvyOnZztR6Xc7xlbPum/Ic2 ddSg== X-Gm-Message-State: ABUngvey+ZvuHk39wIvMV8sYVEH2qkRrx0pYYFoLCaYnrVZj8nb0BqO/L0QULiz1qOZPFQ== X-Received: by 10.99.192.69 with SMTP id z5mr17037641pgi.169.1477673810221; Fri, 28 Oct 2016 09:56:50 -0700 (PDT) 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 h85sm20106124pfj.89.2016.10.28.09.56.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 28 Oct 2016 09:56:49 -0700 (PDT) From: Joshua Clayton To: Alan Tull , Moritz Fischer Subject: [PATCH v2 1/5] lib: add bitrev8x4() Date: Fri, 28 Oct 2016 09:56:38 -0700 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161028_095711_349989_4C9BD68A X-CRM114-Status: GOOD ( 11.85 ) 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 , Sascha Hauer , Fabio Estevam , Shawn Guo , 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; \