From patchwork Fri Jun 9 22:39:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Clayton X-Patchwork-Id: 9779505 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 5EA1B60352 for ; Fri, 9 Jun 2017 22:40:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 51875286C4 for ; Fri, 9 Jun 2017 22:40:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 45F7E286DB; Fri, 9 Jun 2017 22:40:42 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E17FA286C4 for ; Fri, 9 Jun 2017 22:40:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751807AbdFIWkB (ORCPT ); Fri, 9 Jun 2017 18:40:01 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:33121 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751633AbdFIWj7 (ORCPT ); Fri, 9 Jun 2017 18:39:59 -0400 Received: by mail-pf0-f194.google.com with SMTP id f27so9883048pfe.0; Fri, 09 Jun 2017 15:39:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=eiwaXMHDe28AIDe8O6m1YguZ9DsjmcGEmLs8XlV+zrU=; b=VWbguEWz66+DZi1hKcdbtXNSk/vZNiGoqT7WsdlZOf1xHPPOKnNoJ1Hhg42nOb+n+1 N4zn83kilON76jdUIdWvsDuGZnppJrK07s6NBxImpfJmng8Gf4n7cUT8LD/vkyhcA/xB dCsBl/DXbpjUWTOKI4LtzZ5V4zi+jlOtuDcPQOGLcSURWSjM9+1dA/irrfynu5ZiMgVG sK8s+q69jV+K0GI8ZkCYPyRR7GOlCgEgRnEGD2+B7+fuZyYALg8gucZEMiOhLOlMgnb1 izs1+s4SQkuqyinv4RbM1kmTj54ucFR0eWeCBaqK8v7wH+Jgv/8yzoXBX8tA8RlTY5KD PjNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=eiwaXMHDe28AIDe8O6m1YguZ9DsjmcGEmLs8XlV+zrU=; b=pqZxopa65YfnMsZsAhKyk9ho3053FZBhgHijvoAQADd0pMEL2BwH6jwq+6tiP/JK6v 819vevFGhhLPdCJ+BAhIuNNJF2EBp82LbwhBhMmxZk9iLLWM2hJ0P+Ew8jL65lm2dhwb k6tbQnG8VxfH9NDe5u+mroZtaTR96YKfB0ds/ESwPfd9CYdk2+MSBbAKoS2xymo14swA Q++2jMQQ0nR2Wf9crgMVlcz2MA/9uU1UFUD19G6MsGcKVCjOIIggLssNf0L73+0HSsM0 JwbThfDaQvQrJK/6VdVbKn2luVysk/bs9RrI8ngdi1RjwNJBcuyMvV2qbA3jF9LhT7Ty pauQ== X-Gm-Message-State: AODbwcCLpANRW9crficXFQDZ2YmVnZJcfBpquy+5Chu8/ww9EGlCgpBQ ey7MxbMy0QDC6g== X-Received: by 10.98.88.196 with SMTP id m187mr29231254pfb.87.1497047998712; Fri, 09 Jun 2017 15:39:58 -0700 (PDT) Received: from localhost.localdomain (68-185-59-186.static.knwc.wa.charter.com. [68.185.59.186]) by smtp.gmail.com with ESMTPSA id s4sm4771804pgr.10.2017.06.09.15.39.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Jun 2017 15:39:57 -0700 (PDT) From: Joshua Clayton To: Alan Tull , Moritz Fischer , Anatolij Gustschin , Bastian Stender , Shawn Guo , Joshua Clayton Cc: Rob Herring , Mark Rutland , Sascha Hauer , Fabio Estevam , Russell King , linux-fpga@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v13 5/6] lib: add bitrev8x4() Date: Fri, 9 Jun 2017 15:39:38 -0700 Message-Id: <74028f801ba1d69e44b21d0f6d3d6ea8352fde4a.1497047816.git.stillcompiling@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <03e591707dc72f4c2b5e63a1272060956294ea51.1497047816.git.stillcompiling@gmail.com> References: <03e591707dc72f4c2b5e63a1272060956294ea51.1497047816.git.stillcompiling@gmail.com> In-Reply-To: <03e591707dc72f4c2b5e63a1272060956294ea51.1497047816.git.stillcompiling@gmail.com> References: <03e591707dc72f4c2b5e63a1272060956294ea51.1497047816.git.stillcompiling@gmail.com> Sender: linux-fpga-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add a function to reverse bytes within a 32 bit word. Operate on a u32 rather than individual bytes. Signed-off-by: Joshua Clayton --- include/linux/bitrev.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/linux/bitrev.h b/include/linux/bitrev.h index fb790b8449c1..b97be27e5a85 100644 --- a/include/linux/bitrev.h +++ b/include/linux/bitrev.h @@ -29,6 +29,8 @@ static inline u32 __bitrev32(u32 x) #endif /* CONFIG_HAVE_ARCH_BITREVERSE */ +#define __bitrev8x4(x) (__bitrev32(swab32(x))) + #define __constant_bitrev32(x) \ ({ \ u32 __x = x; \ @@ -50,6 +52,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 +86,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; \