From patchwork Thu Dec 1 17:04:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Clayton X-Patchwork-Id: 9456619 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 4305F60585 for ; Thu, 1 Dec 2016 17:22:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 30E252851E for ; Thu, 1 Dec 2016 17:22:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2538A28527; Thu, 1 Dec 2016 17:22:23 +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 B45622851E for ; Thu, 1 Dec 2016 17:22:22 +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 1cCV3m-0003nU-Kz; Thu, 01 Dec 2016 17:22:14 +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 1cCUnW-0000e0-2t for linux-arm-kernel@lists.infradead.org; Thu, 01 Dec 2016 17:05:41 +0000 Received: by mail-pg0-x243.google.com with SMTP id x23so5149611pgx.3 for ; Thu, 01 Dec 2016 09:05:05 -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=OqWLKzfilzz2OBw2X7SQ+sw7Ep4ueRTMVX8SH7Z61gY=; b=UZXhMEwvyY2Y/89uqGrU7llx3yd1HtynoSbFdUhjfT8zyyZChdJYCUbHfeRYmzThED j4oNM+W8WIDsSgZyMFo6EY49y2v09PpJd2+fFUlAFzYuT4ug67Zfh/w+nFAIDR84C8oH Jaa57U8zeiWccczdxHFEzm/7Y2SwiHrUaPn5jGcSyw7CNoGQwjP01IF4CnmnI7twb0lT hsO6WtcJnKHV9846dfuEFThmRGUH8NAPFmnXxG/lBLi6SeqF3jHFa4EQVgHVY5xWZXdd dsgcJJ0tKVbN7bnACX+5S+qFOKGME5MKMYJC8MnMFqhuhUKqg7ejpPknOk7oKLhbI5p0 1ZXw== 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=OqWLKzfilzz2OBw2X7SQ+sw7Ep4ueRTMVX8SH7Z61gY=; b=haqGVqZkdWUI/qgXKejs4F1gkhyoCmHyqVJbEAd1iZVqwHGv4v/6pfgwGCB9/qLgta pd01fd/dnEM/FnGpRIU15tHygQqU6P0m61gZxIjQzJ1femZWHkKWy1koV53eixx8lzed wHz8wwwl0BC0dJ4/E7vSJoYh8bQt7DLU2VzJtFBpbcYe1ykHeJbeBBEiPyL9B3Am32fq PVirZkQdgcv391mf0aFh2dp7zMmm7DZAhu+C/k8uUK14Ky7jJQz+DVgoery67knuGmM1 egn0oyHxMqm0SpEaxV7IaEbMxPNuuatuBz5y3Qc/F7WkW9q56Jw10BO9/qmL6n+f5/Z/ /Ixg== X-Gm-Message-State: AKaTC03Gu7FXCt5Oug1TGxAmAfsjYqeQtbz79VtVFqL/2h/10h0RvFj9v3b/PkNdFFwHVQ== X-Received: by 10.84.202.12 with SMTP id w12mr87407134pld.156.1480611903576; Thu, 01 Dec 2016 09:05:03 -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 13sm1563530pfz.30.2016.12.01.09.05.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Dec 2016 09:05:02 -0800 (PST) From: Joshua Clayton To: Alan Tull , Moritz Fischer , Rob Herring , Mark Rutland , Russell King Subject: [PATCH v4 1/3] lib: add bitrev8x4() Date: Thu, 1 Dec 2016 09:04:50 -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-20161201_090527_185331_3FA041BA X-CRM114-Status: GOOD ( 10.82 ) 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, 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 --- Looking for an ACK from Russell King on this patch (or at least the arm specific implementation) 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; \