arm: Add armv6 and armv7 optimized swab functions
PATCH 1/1 arm: Add armv6 and armv7 optimized swab functions
From: Rob Herring <[email protected]>
swab functions are heavily used by FDT code, so enable optimized assembly code for ARMv6 and later.
--- arch/arm/include/asm/byteorder.h | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-)
arch/arm/include/asm/byteorder.h +16 -0
@@ -23,6 +23,22 @@# define __SWAB_64_THRU_32__#endif +#if defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_6__) +static inline __u16 __attribute__((const))___arch_swab16 (__u16 x) +{ + __asm__ ("rev16 %0, %1" :"=r" (x) :"r" (x)); +return x; +} +#define __arch_swab16 ___arch_swab16 + +static inline __u32 __attribute__((const))___arch_swab32 (__u32 x) +{ + __asm__ ("rev %0, %1" :"=r" (x) :"r" (x)); +return x; +} +#define __arch_swab32 ___arch_swab32 +#endif +#ifdef __ARMEB__#include <linux/byteorder/big_endian.h> #else
Signature · 1 line
1.7.1
PATCH 1/1 arm: Add armv6 and armv7 optimized swab functions
Dear Rob Herring,
Quoted 9 lines · In message <[email protected]> you wrote:
From: Rob Herring <[email protected]>
swab functions are heavily used by FDT code, so enable optimized assembly code for ARMv6 and later.
Signed-off-by Rob Herring <[email protected]>--- arch/arm/include/asm/byteorder.h | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-)
Do you have any numbers if this changes gives any measurable improvement?
Best regards,
Wolfgang Denk
Signature · 4 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de A modem is a baudy house.
PATCH 1/1 arm: Add armv6 and armv7 optimized swab functions
Wolfgang,
Quoted 8 lines · Wolfgang Denk
Dear Rob Herring,
Quoted 5 lines · In message<[email protected]> you wrote:
From: Rob Herring<[email protected]>
swab functions are heavily used by FDT code, so enable optimized assembly code for ARMv6 and later.
Quoted 7 lines
Quoted 4 lines
Signed-off-by Rob Herring<[email protected]>--- arch/arm/include/asm/byteorder.h | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-)Do you have any numbers if this changes gives any measurable improvement?
I have an instruction trace capture and see repeated calls to swab32 by the fdt code. It's an obvious low hanging fruit. The boot time for device tree vs. non-device tree is noticeably longer, but I don't have any formal measurements.
Rob
PATCH 1/1 arm: Add armv6 and armv7 optimized swab functions
In reply to Rob HerringQuoted 15 lines · Rob Herring
From: Rob Herring <[email protected]>
swab functions are heavily used by FDT code, so enable optimized assembly code for ARMv6 and later.
Signed-off-by Rob Herring <[email protected]>--- arch/arm/include/asm/byteorder.h | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-)arch/arm/include/asm/byteorder.h +0
-0
arch/arm/include/asm/byteorder.h line 31
Quoted 9 lines
arch/arm/include/asm/byteorder.h +6
-0@@ -23,6 +23,22 @@# define __SWAB_64_THRU_32__#endif +#if defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_6__) +static inline __u16 __attribute__((const))___arch_swab16 (__u16 x) +{ + __asm__ ("rev16 %0, %1" :"=r" (x) :"r" (x)); +return x; +}
Pay close attention to what gcc does with this as it is prone to add unnecessary masking of the low halfword. If the callers are well-behaved (argument having top halfword clear), making the parameter and return types here plain unsigned (or u32) gives better code.
Signature · 2 lines
M?ns Rullg?rd mans at mansr.com
PATCH 1/1 arm: Add armv6 and armv7 optimized swab functions
Quoted 20 lines · M?ns Rullg?rd
Quoted 18 lines · Rob Herring
From: Rob Herring<[email protected]>
swab functions are heavily used by FDT code, so enable optimized assembly code for ARMv6 and later.
Signed-off-by Rob Herring<[email protected]>--- arch/arm/include/asm/byteorder.h | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-)arch/arm/include/asm/byteorder.h +0
-0@@ -23,6 +23,22 @@# define __SWAB_64_THRU_32__#endif
Quoted 12 lines
arch/arm/include/asm/byteorder.h line 31
Quoted 6 lines
arch/arm/include/asm/byteorder.h +6
-0+#if defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_6__) +static inline __u16 __attribute__((const))___arch_swab16 (__u16 x) +{ + __asm__ ("rev16 %0, %1" :"=r" (x) :"r" (x)); +return x; +}Pay close attention to what gcc does with this as it is prone to add unnecessary masking of the low halfword. If the callers are well-behaved (argument having top halfword clear), making the parameter and return types here plain unsigned (or u32) gives better code.
This straight from the Linux code and there are only a few users of swab16 (none in my build).
Rob
PATCH 1/1 arm: Add armv6 and armv7 optimized swab functions
Quoted 34 lines · Rob Herring
Quoted 20 lines · M?ns Rullg?rd
Quoted 18 lines · Rob Herring
From: Rob Herring<[email protected]>
swab functions are heavily used by FDT code, so enable optimized assembly code for ARMv6 and later.
Signed-off-by Rob Herring<[email protected]>--- arch/arm/include/asm/byteorder.h | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-)arch/arm/include/asm/byteorder.h +0
-0@@ -23,6 +23,22 @@# define __SWAB_64_THRU_32__#endif Quoted 12 lines
arch/arm/include/asm/byteorder.h line 31
Quoted 6 lines
arch/arm/include/asm/byteorder.h +6
-0+#if defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_6__) +static inline __u16 __attribute__((const))___arch_swab16 (__u16 x) +{ + __asm__ ("rev16 %0, %1" :"=r" (x) :"r" (x)); +return x; +}Pay close attention to what gcc does with this as it is prone to add unnecessary masking of the low halfword. If the callers are well-behaved (argument having top halfword clear), making the parameter and return types here plain unsigned (or u32) gives better code.
Quoted 2 lines
This straight from the Linux code and there are only a few users of swab16 (none in my build).
Look at the generated code if you don't believe me.
Signature · 2 lines
M?ns Rullg?rd mans at mansr.com
PATCH 1/1 arm: Add armv6 and armv7 optimized swab functions
In reply to Rob HerringDear Rob Herring,
Quoted 3 lines · In message <[email protected]> you wrote:
This straight from the Linux code and there are only a few users of swab16 (none in my build).
Given that we have no idea if this code really gives any measurable performance improvement, and that it appears to be dangerous as well, I tend to not include that as is.
Thanks.
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de It is surely a great calamity for a human being to have no ob- sessions. - Robert Bly