Skip to contentSkip to conversation

MIPS: UAPI: Disable __arch_swab{16,32} when using MIPS16

PATCH Superseded Yousong Zhou 2 participants 2 messages Sep 7, 2015 MIPS

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 MIPS: UAPI: Disable __arch_swab{16,32} when using MIPS16

Some GCC versions (e.g. 4.8.3) can incorrectly inline a function with MIPS32 instructions into another function with MIPS16 code [1], causing the assembler to genereate incorrect binary code or fail right away complaining about unrecognized opcode.

In the case of __arch_swab{16,32}, when inlined by the compiler with flags `-mips32r2 -mips16 -Os', the assembler can fail with the following error.

{standard input}:79: Error: unrecognized opcode `wsbh $2,$2'

For performance concerns and to workaround the issue already existing in older compilers, just ignore these 2 functions when compiling with mips16 enabled.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55777

---
 arch/mips/include/uapi/asm/swab.h |    5 +++++
 1 file changed, 5 insertions(+)
arch/mips/include/uapi/asm/swab.h +5 -0
index 8f2d184..8396d5a 100644
@@ -16,6 +16,10 @@
 #if (defined(__mips_isa_rev) && (__mips_isa_rev >= 2)) ||		\
     defined(_MIPS_ARCH_LOONGSON3A)
 
+/*
+ * Enable the optimized version only when compiling without MIPS16.
+ */
+#ifndef __mips16
 static inline __attribute_const__ __u16 __arch_swab16(__u16 x)
 {
 	__asm__(
@@ -44,6 +48,7 @@ static inline __attribute_const__ __u32 __arch_swab32(__u32 x)
 	return x;
 }
 #define __arch_swab32 __arch_swab32
+#endif /* ifndef __mips16 */
 
 /*
  * Having already checked for MIPS R2, enable the optimized version for
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 15 lines · Yousong Zhou

index 8f2d184..8396d5a 100644

arch/mips/include/uapi/asm/swab.h +4 -0
@@ -16,6 +16,10 @@
 #if (defined(__mips_isa_rev) && (__mips_isa_rev >= 2)) ||		\
     defined(_MIPS_ARCH_LOONGSON3A)
 
+/*
+ * Enable the optimized version only when compiling without MIPS16.
+ */
+#ifndef __mips16
 static inline __attribute_const__ __u16 __arch_swab16(__u16 x)
 {
 	__asm__(

arch/mips/include/uapi/asm/swab.h static inline __attribute_const__ __u32 __arch_swab32(__u32 x) · line 54

Quoted 7 lines
arch/mips/include/uapi/asm/swab.h +1 -0
@@ -44,6 +48,7 @@ static inline __attribute_const__ __u32 __arch_swab32(__u32 x)
 	return x;
 }
 #define __arch_swab32 __arch_swab32
+#endif /* ifndef __mips16 */
 
 /*
  * Having already checked for MIPS R2, enable the optimized version for

Please #ifdef-out all the functions, there's nothing about
`__arch_swab64' making it worth being a special exception.

Maciej