Skip to contentSkip to conversation

Ignore __arch_swab{16,32,64} when using MIPS16

PATCH New Yousong Zhou 1 participant 3 messages Sep 26, 2015 MIPS

lore
Share & tools
lore
#0 lore raw

v3 cover Ignore __arch_swab{16,32,64} when using MIPS16

v3 <- v2

- Revert the previous fix that adding nomips16 attributes and assembler directives to those functions
- Exclude __SWAB_64_THRU_32 from the #ifdef..#endif block

v2 <- v1

	Also ignore __arch_swab64 instead of just __arch_swab{16,32}.

Yousong Zhou (2):
Revert "MIPS: UAPI: Fix unrecognized opcode WSBH/DSBH/DSHD when using

    MIPS16."

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

 arch/mips/include/uapi/asm/swab.h |   19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH v3 1/2 Revert "MIPS: UAPI: Fix unrecognized opcode WSBH/DSBH/DSHD when using MIPS16."

This reverts commit e0d8b2ec532852d4b5aabcec3e7611848c32237d.

For at least GCC 4.8.3, adding nomips16 function attribute still cannot prevent it from being inlined in mips16 context. So revert it first in preparation for a better workaround.

[1] Inlining nomips16 function into mips16 function can result in undefined builtins, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55777

---
 arch/mips/include/uapi/asm/swab.h |   12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
arch/mips/include/uapi/asm/swab.h +3 -9
index c4ddc4f..8f2d184 100644
@@ -16,13 +16,11 @@
 #if (defined(__mips_isa_rev) && (__mips_isa_rev >= 2)) ||		\
     defined(_MIPS_ARCH_LOONGSON3A)
 
-static inline __attribute__((nomips16)) __attribute_const__
-		__u16 __arch_swab16(__u16 x)
+static inline __attribute_const__ __u16 __arch_swab16(__u16 x)
 {
 	__asm__(
 	"	.set	push			\n"
 	"	.set	arch=mips32r2		\n"
-	"	.set	nomips16		\n"
 	"	wsbh	%0, %1			\n"
 	"	.set	pop			\n"
 	: "=r" (x)
@@ -32,13 +30,11 @@ static inline __attribute__((nomips16)) __attribute_const__
 }
 #define __arch_swab16 __arch_swab16
 
-static inline __attribute__((nomips16)) __attribute_const__
-		__u32 __arch_swab32(__u32 x)
+static inline __attribute_const__ __u32 __arch_swab32(__u32 x)
 {
 	__asm__(
 	"	.set	push			\n"
 	"	.set	arch=mips32r2		\n"
-	"	.set	nomips16		\n"
 	"	wsbh	%0, %1			\n"
 	"	rotr	%0, %0, 16		\n"
 	"	.set	pop			\n"
@@ -54,13 +50,11 @@ static inline __attribute__((nomips16)) __attribute_const__
  * 64-bit kernel on r2 CPUs.
  */
 #ifdef __mips64
-static inline __attribute__((nomips16)) __attribute_const__
-		__u64 __arch_swab64(__u64 x)
+static inline __attribute_const__ __u64 __arch_swab64(__u64 x)
 {
 	__asm__(
 	"	.set	push			\n"
 	"	.set	arch=mips64r2		\n"
-	"	.set	nomips16		\n"
 	"	dsbh	%0, %1			\n"
 	"	dshd	%0, %0			\n"
 	"	.set	pop			\n"
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH v3 2/2 MIPS: UAPI: Ignore __arch_swab{16,32,64} when using MIPS16

In reply to Yousong Zhou

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] Inlining nomips16 function into mips16 function can result in undefined builtins, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55777

---
 arch/mips/include/uapi/asm/swab.h |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/mips/include/uapi/asm/swab.h +4 -3
index 8f2d184..23cd9b1 100644
@@ -13,8 +13,9 @@
 
 #define __SWAB_64_THRU_32__
 
-#if (defined(__mips_isa_rev) && (__mips_isa_rev >= 2)) ||		\
-    defined(_MIPS_ARCH_LOONGSON3A)
+#if !defined(__mips16) &&					\
+	((defined(__mips_isa_rev) && (__mips_isa_rev >= 2)) ||	\
+	 defined(_MIPS_ARCH_LOONGSON3A))
 
 static inline __attribute_const__ __u16 __arch_swab16(__u16 x)
 {
@@ -65,5 +66,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 /* (not __mips16) and (MIPS R2 or newer or Loongson 3A) */
 #endif /* _ASM_SWAB_H */
Signature · 1 line
1.7.10.4