linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Dave.Martin@arm.com (Dave Martin)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH 2/4] ARM: Add common compile-time swab32 for asm code
Date: Wed,  9 Oct 2013 15:29:51 +0100	[thread overview]
Message-ID: <1381328993-12724-3-git-send-email-Dave.Martin@arm.com> (raw)
In-Reply-To: <1381328993-12724-1-git-send-email-Dave.Martin@arm.com>

<linux/swab.h> doesn't work for asm code, yet swabbing constants
for asm is still useful, such as when writing code which needs to
build with different target endiannesses.

This patch adds a simple asm_swab32() macro so that this operation
doesn't need to be reinvented repeatedly.

Since <asm/opcodes.h> already defines this operation, this patch
lifts the definition into assembler.h and makes opcodes.h use it.

The other swab variants defined by opcodes.h could be transferred
too, but there is no clear need for that yet.

Signed-off-by: Dave Martin <Dave.Martin@arm.com>
---
 arch/arm/include/asm/assembler.h |   23 +++++++++++++++++++++++
 arch/arm/include/asm/opcodes.h   |    9 +++------
 2 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h
index a71d117..860256c 100644
--- a/arch/arm/include/asm/assembler.h
+++ b/arch/arm/include/asm/assembler.h
@@ -380,4 +380,27 @@ THUMB(	orr	\reg , \reg , #PSR_T_BIT	)
 
 #endif /* __ASSEMBLY__ */
 
+/*
+ * Use asm_swab32() only for compile-time swabbing of constants for
+ * assembly code.  in inline asm, the argument is a string
+ * representation of an expression which will be passed through to the
+ * assembler, so it can't contain embedded C expressions or preprocessor
+ * macros.  Macros would need to be pre-expanded using __stringify().
+ */
+#ifdef __ASSEMBLY__
+#define __asm_swab32(x) (			\
+	  (((x) >> 24) & 0x000000ff)		\
+	| (((x) >> 8)  & 0x0000ff00)		\
+	| (((x) << 8)  & 0x00ff0000)		\
+	| (((x) << 24) & 0xff000000)		\
+)
+#else /* ! __ASSEMBLY__ */
+#define __asm_swab32(x) "( "			\
+	  "(((" x ") >> 24) & 0x000000ff) "	\
+	"| (((" x ") >> 8)  & 0x0000ff00) "	\
+	"| (((" x ") << 8)  & 0x00ff0000) "	\
+	"| (((" x ") << 24) & 0xff000000) "	\
+")"
+#endif /* ! __ASSEMBLY__ */
+
 #endif /* __ASM_ASSEMBLER_H__ */
diff --git a/arch/arm/include/asm/opcodes.h b/arch/arm/include/asm/opcodes.h
index e796c59..b2e93c9 100644
--- a/arch/arm/include/asm/opcodes.h
+++ b/arch/arm/include/asm/opcodes.h
@@ -9,6 +9,8 @@
 #ifndef __ASM_ARM_OPCODES_H
 #define __ASM_ARM_OPCODES_H
 
+#include <asm/assembler.h>
+
 #ifndef __ASSEMBLY__
 #include <linux/linkage.h>
 extern asmlinkage unsigned int arm_check_condition(u32 opcode, u32 psr);
@@ -24,12 +26,7 @@ extern asmlinkage unsigned int arm_check_condition(u32 opcode, u32 psr);
  * These are only intended for use by this header: don't use them directly,
  * because they will be suboptimal in most cases.
  */
-#define ___asm_opcode_swab32(x) (	\
-	  (((x) << 24) & 0xFF000000)	\
-	| (((x) <<  8) & 0x00FF0000)	\
-	| (((x) >>  8) & 0x0000FF00)	\
-	| (((x) >> 24) & 0x000000FF)	\
-)
+#define ___asm_opcode_swab32(x) __asm_swab32(x)
 #define ___asm_opcode_swab16(x) (	\
 	  (((x) << 8) & 0xFF00)		\
 	| (((x) >> 8) & 0x00FF)		\
-- 
1.7.9.5

  parent reply	other threads:[~2013-10-09 14:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-09 14:29 [RFC PATCH 0/4] ARM: Unify const-swabbing and conditional asm Dave Martin
2013-10-09 14:29 ` [RFC PATCH 1/4] ARM: Allow assembler.h to be used with inline asm Dave Martin
2013-10-09 14:42   ` Russell King - ARM Linux
2013-10-09 15:00     ` Dave Martin
2013-10-09 15:32       ` Nicolas Pitre
2013-10-09 14:29 ` Dave Martin [this message]
2013-10-09 14:29 ` [RFC PATCH 3/4] ARM: Add const cpu_to_le32 for asm Dave Martin
2013-10-09 14:29 ` [RFC PATCH 4/4] drivers/bus: arm-cci: Fix CCI enable code for BE32 Dave Martin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1381328993-12724-3-git-send-email-Dave.Martin@arm.com \
    --to=dave.martin@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).