MIPS: UAPI: Ignore __arch_swab{16,32,64} when using MIPS16
PATCH v2 1/1 MIPS: UAPI: Ignore __arch_swab{16,32,64} 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
---
v2 <- v1
Also ignore __arch_swab64 instead of just __arch_swab{16,32}.arch/mips/include/uapi/asm/swab.h | 6 ++++++ 1 file changed, 6 insertions(+)
arch/mips/include/uapi/asm/swab.h +6 -0
@@ -8,6 +8,11 @@#ifndef _ASM_SWAB_H#define _ASM_SWAB_H +/* +* Enable the optimized version only when compiling without MIPS16. +*/ +#ifndef __mips16 +#include <linux/compiler.h> #include <linux/types.h>
@@ -66,4 +71,5 @@ static inline __attribute_const__ __u64 __arch_swab64(__u64 x)#define __arch_swab64 __arch_swab64#endif /* __mips64 */ #endif /* MIPS R2 or newer or Loongson 3A */ +#endif /* ifndef __mips16 */ #endif /* _ASM_SWAB_H */
Signature · 1 line
1.7.10.4
Quoted 17 lines · Yousong Zhou
arch/mips/include/uapi/asm/swab.h +5
-0@@ -8,6 +8,11 @@#ifndef _ASM_SWAB_H#define _ASM_SWAB_H +/* +* Enable the optimized version only when compiling without MIPS16. +*/ +#ifndef __mips16 +#include <linux/compiler.h> #include <linux/types.h>
arch/mips/include/uapi/asm/swab.h static inline __attribute_const__ __u64 __arch_swab64(__u64 x) · line 75
Quoted 5 lines
arch/mips/include/uapi/asm/swab.h +1
-0@@ -66,4 +71,5 @@ static inline __attribute_const__ __u64 __arch_swab64(__u64 x)#define __arch_swab64 __arch_swab64#endif /* __mips64 */ #endif /* MIPS R2 or newer or Loongson 3A */ +#endif /* ifndef __mips16 */ #endif /* _ASM_SWAB_H */
I think it will best go with the main #if which checks the conditions
that have to be met for this optimisation to be possible; there is no gain from nesting the conditions here.
Also you need a second patch paired with this to undo your previousnomips16' change which will be no longer needed (and in the case of the .set' part not wanted either).
Maciej
Quoted 18 lines · Maciej W. Rozycki
Quoted 16 lines · Yousong Zhou
arch/mips/include/uapi/asm/swab.h +5
-0@@ -8,6 +8,11 @@#ifndef _ASM_SWAB_H#define _ASM_SWAB_H +/* +* Enable the optimized version only when compiling without MIPS16. +*/ +#ifndef __mips16 +#include <linux/compiler.h> #include <linux/types.h>
Quoted 11 lines
arch/mips/include/uapi/asm/swab.h static inline __attribute_const__ __u64 __arch_swab64(__u64 x) · line 75
Quoted 6 lines
arch/mips/include/uapi/asm/swab.h +1
-0@@ -66,4 +71,5 @@ static inline __attribute_const__ __u64 __arch_swab64(__u64 x)#define __arch_swab64 __arch_swab64#endif /* __mips64 */ #endif /* MIPS R2 or newer or Loongson 3A */ +#endif /* ifndef __mips16 */ #endif /* _ASM_SWAB_H */ I think it will best go with the main #if which checks the conditions
that have to be met for this optimisation to be possible; there is no gain from nesting the conditions here.
Yes, you are right, and I should not wrap that __SWAB_64_THRU_32__ inside the #if check.
Quoted 3 lines
Also you need a second patch paired with this to undo your previous
nomips16' change which will be no longer needed (and in the case of the.set' part not wanted either).
Wow, I did not know that my previous patch was merged, also into all those stable branches, and some with kind minor modifications... Is it the case that I only need to firstly revert that commit in mips-upstream-sfr/mips-for-linux-next, then followed by refreshed version of this one?
Regards,
yousong