public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Dirk Behme <dirk.behme@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC PATCH] ARM: byteorder: add optimized swab16 and swab32
Date: Fri, 10 May 2013 18:23:20 +0200	[thread overview]
Message-ID: <1368203000-3386-1-git-send-email-dirk.behme@gmail.com> (raw)

Use the specialized ARM instructions for swapping 16 and 32 bit values
instead of using the generic ones from include/linux/byteorder/swab.h.

The x86 version in arch/x86/include/asm/byteorder.h was taken as an
example for this.

E.g. for the mx6qsabrelite target this results in ~4k less code.

Signed-off-by: Dirk Behme <dirk.behme@gmail.com>
---

This patch is marked as RFC due to two questions:

1) These ARM instructions are available in ARMv6 and above. Do we have to limit
   this code somehow to >= ARMv6? I couldn't find any #define to do this in
   U-Boot (?)

2) I'm not sure about the rev16. The rev16 instruction swaps *both* half words,
   the lower _and_ the upper one: 

   REV16 Rd, Rm => Rd[15:8] := Rm[7:0], Rd[7:0] := Rm[15:8], Rd[31:24] := Rm[23:16], Rd[23:16] := Rm[31:24]

   I'm not sure if we want this? Most probably we only want to swap the lower
   half word with swap16()?

 arch/arm/include/asm/byteorder.h |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/arch/arm/include/asm/byteorder.h b/arch/arm/include/asm/byteorder.h
index c3489f1..f21baf0 100644
--- a/arch/arm/include/asm/byteorder.h
+++ b/arch/arm/include/asm/byteorder.h
@@ -15,6 +15,23 @@
 #ifndef __ASM_ARM_BYTEORDER_H
 #define __ASM_ARM_BYTEORDER_H
 
+static __inline__ __u32 ___arch__swab32(__u32 x)
+{
+	__asm__("rev %0,%1"		/* swap bytes */ \
+		: "=r" (x) \
+		:  "0" (x)); \
+		return x;
+}
+#define __arch__swab32(x) ___arch__swab32(x)
+
+static __inline__ __u16 ___arch__swab16(__u16 x)
+{
+	__asm__("rev16 %0,%1"		/* swap bytes */ \
+		: "=r" (x) \
+		:  "0" (x)); \
+		return x;
+}
+#define __arch__swab16(x) ___arch__swab16(x)
 
 #include <asm/types.h>
 
-- 
1.7.10.4

             reply	other threads:[~2013-05-10 16:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-10 16:23 Dirk Behme [this message]
2013-05-10 16:56 ` [U-Boot] [RFC PATCH] ARM: byteorder: add optimized swab16 and swab32 Måns Rullgård
2013-05-10 17:42   ` Dirk Behme
2013-05-11  0:05     ` Wolfgang Denk

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=1368203000-3386-1-git-send-email-dirk.behme@gmail.com \
    --to=dirk.behme@gmail.com \
    --cc=u-boot@lists.denx.de \
    /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