From patchwork Thu Nov 24 11:23:18 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 5306 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 90BBC23E04 for ; Thu, 24 Nov 2011 11:23:38 +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 385FBA18084 for ; Thu, 24 Nov 2011 11:23:38 +0000 (UTC) Received: by yenl7 with SMTP id l7so1942609yen.11 for ; Thu, 24 Nov 2011 03:23:37 -0800 (PST) Received: by 10.152.111.170 with SMTP id ij10mr14005853lab.5.1322133817033; Thu, 24 Nov 2011 03:23:37 -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 h6cs299817lal; Thu, 24 Nov 2011 03:23:36 -0800 (PST) Received: by 10.204.152.25 with SMTP id e25mr29292077bkw.51.1322133814572; Thu, 24 Nov 2011 03:23:34 -0800 (PST) Received: from mail-fx0-f50.google.com (mail-fx0-f50.google.com [209.85.161.50]) by mx.google.com with ESMTPS id y4si10117826faj.113.2011.11.24.03.23.33 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 24 Nov 2011 03:23:34 -0800 (PST) Received-SPF: neutral (google.com: 209.85.161.50 is neither permitted nor denied by best guess record for domain of dave.martin@linaro.org) client-ip=209.85.161.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.161.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 faao26 with SMTP id o26so1361383faa.37 for ; Thu, 24 Nov 2011 03:23:33 -0800 (PST) Received: by 10.180.96.166 with SMTP id dt6mr28060281wib.47.1322133813721; Thu, 24 Nov 2011 03:23: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 fw16sm23857691wbb.13.2011.11.24.03.23.32 (version=SSLv3 cipher=OTHER); Thu, 24 Nov 2011 03:23:33 -0800 (PST) From: Dave Martin To: patches@arm.linux.org.uk Cc: patches@linaro.org, Dave Martin Subject: [PATCH] ARM: Add optimised swahb32() byteswap helper for v6 and above Date: Thu, 24 Nov 2011 11:23:18 +0000 Message-Id: <1322133798-2954-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 --- KernelVersion: v3.2-rc2 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) {