From patchwork Thu May 25 17:29:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Clayton X-Patchwork-Id: 9748799 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 F0CFE60209 for ; Thu, 25 May 2017 17:31:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D84FC2223E for ; Thu, 25 May 2017 17:31:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CBFDE27968; Thu, 25 May 2017 17:31: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=-1.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7C9572223E for ; Thu, 25 May 2017 17:31:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=R+zAucJ/fvAsV9V2JtHx6iz9eSC9GuGt+q427+tQeTo=; b=b63jmvBK0wTP7hcawiM9vUFZOv OZHRPqgr+9STvpMrg8mDHGJv0eQubRECP6ZfeoiUyEM/SugK+OKEaiHoJRYcYpWZN27EKdGK0zQkU Pa1t2hPGF9IgNLXIx48/ukUwKLwidGCUgS7Q6VV8Is/9lKx6PkmPXS4sCaMX3QgVmO9i0OKUf0T7Y ntwKJmWnu5YUjfXB4g+C9JR4dfok8cFQSsMyv+faJExm+znFrafA51C4Z+hI07ocnSeZFIlLGDbe5 0Dvnu/XshdgFC4T+gvrQJB8issw9caIEz+1bZTi/TtiZzZ+8/rjRObmWKfzxjA5tnxV2jAIkZEJk4 0GDyFtXA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dDwbG-0007eR-6d; Thu, 25 May 2017 17:31:02 +0000 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dDwa3-0004vb-Ok for linux-arm-kernel@lists.infradead.org; Thu, 25 May 2017 17:29:51 +0000 Received: by mail-pf0-x241.google.com with SMTP id w69so40531085pfk.1 for ; Thu, 25 May 2017 10:29:28 -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; bh=eiwaXMHDe28AIDe8O6m1YguZ9DsjmcGEmLs8XlV+zrU=; b=kNSrbKTPWk0pXQMQPZ2KtafHmYc2tLuIgFW3m1cHe5OnDBaPwn3+73r4QTn6XTCXql 94fejcukYHUo8NwAp1lIgqEKtbG/aLBr5mtm9ZM1P3q4L07JK3HafAD9dyhxtZnmb2+P x/+Lp+FqJuLQLq0l6cIeHR91Jzn9GADvZ+1AlJuohNlspKayJHcuDh8y/YrC0Xd4NLx+ 4m6Su0smev7ZkAxi8n/3c86mTJ9CdaRd1+QBCJqZI+nH9ARYxXPfbEf01rURpoRW8ZCD HMqjrCubO4k9I++13dDYMPNl4tVLzOUiKw5NUh4v6SdQN0mOeEXHjar4zr2EwsT6hBoP /+Yw== 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; bh=eiwaXMHDe28AIDe8O6m1YguZ9DsjmcGEmLs8XlV+zrU=; b=O7n+7xxQ+/Np1CfOD24EgDcwCBggHeeK6GnLIRrRkNr1oesZWbKe8DzIgj/NKnGVqG 2VDapgeLpTeOegKQGCCJUC6Lo0IuSNR8hxxFvDpzTFQT4AlS5VZK07/ah5DJnIZKzgy9 sSC+O0U8T9dNkuIISeWukddxJ4EoExuu4ZAUBM/5zbnK7mNFXbZmFxXxUUM3tLdWZFc1 g6wlx1Yvd7p0AY1Isst4OWbm0X044n3rVB6JLWcurN1dmrbcqVcqh9j4G4DpGN+C7CS8 wgw9McHe2Z6iqANPCQJuVfsSoRanoPB+jd+06l9rxL2ET7A6dpxdHauXnJPXu46r3jwv kJHw== X-Gm-Message-State: AODbwcBCs3S0MPddB0G0sPJp5oG1yvgrJ6iDgJHT7DryTse8spq25x+V ff4mwodKY9dZPQ== X-Received: by 10.98.217.7 with SMTP id s7mr45694655pfg.39.1495733368056; Thu, 25 May 2017 10:29:28 -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 b72sm16579738pfj.36.2017.05.25.10.29.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 May 2017 10:29:27 -0700 (PDT) From: Joshua Clayton To: Alan Tull , Moritz Fischer , Anatolij Gustschin , Bastian Stender , Shawn Guo , Joshua Clayton Subject: [PATCH v11 5/6] lib: add bitrev8x4() Date: Thu, 25 May 2017 10:29:10 -0700 Message-Id: <20170525172911.11467-6-stillcompiling@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170525172911.11467-1-stillcompiling@gmail.com> References: <20170525172911.11467-1-stillcompiling@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170525_102948_333423_B3CB00AE X-CRM114-Status: GOOD ( 11.57 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, linux-fpga@vger.kernel.org, Russell King , linux-kernel@vger.kernel.org, Rob Herring , Sascha Hauer , Fabio Estevam , 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. 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; \