From patchwork Wed Nov 23 14:42:25 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 5298 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 3950A23E07 for ; Wed, 23 Nov 2011 14:42:39 +0000 (UTC) Received: from mail-yx0-f180.google.com (mail-yx0-f180.google.com [209.85.213.180]) by fiordland.canonical.com (Postfix) with ESMTP id 00418A182E1 for ; Wed, 23 Nov 2011 14:42:38 +0000 (UTC) Received: by yenl7 with SMTP id l7so621954yen.11 for ; Wed, 23 Nov 2011 06:42:38 -0800 (PST) Received: by 10.152.135.225 with SMTP id pv1mr14597286lab.19.1322059358040; Wed, 23 Nov 2011 06:42:38 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.152.41.198 with SMTP id h6cs234147lal; Wed, 23 Nov 2011 06:42:37 -0800 (PST) Received: by 10.52.88.5 with SMTP id bc5mr25598830vdb.15.1322059355027; Wed, 23 Nov 2011 06:42:35 -0800 (PST) Received: from mail-yw0-f50.google.com (mail-yw0-f50.google.com [209.85.213.50]) by mx.google.com with ESMTPS id b46si3878158yhe.49.2011.11.23.06.42.34 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 23 Nov 2011 06:42:35 -0800 (PST) Received-SPF: neutral (google.com: 209.85.213.50 is neither permitted nor denied by best guess record for domain of dave.martin@linaro.org) client-ip=209.85.213.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.213.50 is neither permitted nor denied by best guess record for domain of dave.martin@linaro.org) smtp.mail=dave.martin@linaro.org Received: by ywb26 with SMTP id 26so420351ywb.37 for ; Wed, 23 Nov 2011 06:42:34 -0800 (PST) Received: by 10.152.104.6 with SMTP id ga6mr14629021lab.45.1322059353821; Wed, 23 Nov 2011 06:42:33 -0800 (PST) Received: from e103592.peterhouse.linaro.org (fw-lnat.cambridge.arm.com. [217.140.96.63]) by mx.google.com with ESMTPS id pw12sm16089085lab.13.2011.11.23.06.42.32 (version=SSLv3 cipher=OTHER); Wed, 23 Nov 2011 06:42:33 -0800 (PST) From: Dave Martin To: linux-arm-kernel@lists.infradead.org Cc: patches@linaro.org Subject: [PATCH] ARM: Add optimised swahb32() byteswap helper for v6 and above Date: Wed, 23 Nov 2011 14:42:25 +0000 Message-Id: <1322059345-18842-1-git-send-email-dave.martin@linaro.org> X-Mailer: git-send-email 1.7.4.1 ARMv6 and later processors have the REV16 instruction, which swaps the bytes within each halfword of a register value. This is already used to implement swab16(), but since the native operation performaed by REV16 is actually swahb32(), this patch renames the existing swab16() helper accordingly and defines __arch_swab16() in terms of it. This allows calls to both swab16() and swahb32() to be optimised. The compiler's generated code might improve someday, but as of 4.5.2 the code generated for pure C implementing these 16-bit bytesswaps remains pessimal. swahb32() is useful for converting 32-bit Thumb instructions between integer and memory representation on BE8 platforms (among other uses). Signed-off-by: Dave Martin Reviewed-by: Nicolas Pitre --- arch/arm/include/asm/swab.h | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/arm/include/asm/swab.h b/arch/arm/include/asm/swab.h index 9997ad2..32ee164 100644 --- a/arch/arm/include/asm/swab.h +++ b/arch/arm/include/asm/swab.h @@ -24,12 +24,13 @@ #if defined(__KERNEL__) && __LINUX_ARM_ARCH__ >= 6 -static inline __attribute_const__ __u16 __arch_swab16(__u16 x) +static inline __attribute_const__ __u32 __arch_swahb32(__u32 x) { __asm__ ("rev16 %0, %1" : "=r" (x) : "r" (x)); return x; } -#define __arch_swab16 __arch_swab16 +#define __arch_swahb32 __arch_swahb32 +#define __arch_swab16(x) ((__u16)__arch_swahb32(x)) static inline __attribute_const__ __u32 __arch_swab32(__u32 x) {