generic: fix unrecognized opcode wsbh when building for MIPS16.
[openwrt/svn-archive/archive.git] / target / linux / generic / patches-4.1 / 133-MIPS-UAPI-Ignore-__arch_swab-16-32-64-when-using-MIP.patch
1 From 71a0a72456b48de972d7ed613b06a22a3aa9057f Mon Sep 17 00:00:00 2001
2 From: Yousong Zhou <yszhou4tech@gmail.com>
3 Date: Sat, 26 Sep 2015 13:41:43 +0800
4 Subject: [PATCH] MIPS: UAPI: Ignore __arch_swab{16,32,64} when using MIPS16
5
6 Some GCC versions (e.g. 4.8.3) can incorrectly inline a function with
7 MIPS32 instructions into another function with MIPS16 code [1], causing
8 the assembler to genereate incorrect binary code or fail right away
9 complaining about unrecognized opcode.
10
11 In the case of __arch_swab{16,32}, when inlined by the compiler with
12 flags `-mips32r2 -mips16 -Os', the assembler can fail with the following
13 error.
14
15 {standard input}:79: Error: unrecognized opcode `wsbh $2,$2'
16
17 For performance concerns and to workaround the issue already existing in
18 older compilers, just ignore these 2 functions when compiling with
19 mips16 enabled.
20
21 [1] Inlining nomips16 function into mips16 function can result in
22 undefined builtins, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55777
23
24 Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
25 Cc: Maciej W. Rozycki <macro@linux-mips.org>
26 Cc: linux-mips@linux-mips.org
27 Patchwork: https://patchwork.linux-mips.org/patch/11241/
28 Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
29 ---
30 arch/mips/include/uapi/asm/swab.h | 7 ++++---
31 1 file changed, 4 insertions(+), 3 deletions(-)
32
33 diff --git a/arch/mips/include/uapi/asm/swab.h b/arch/mips/include/uapi/asm/swab.h
34 index 8f2d184..23cd9b1 100644
35 --- a/arch/mips/include/uapi/asm/swab.h
36 +++ b/arch/mips/include/uapi/asm/swab.h
37 @@ -13,8 +13,9 @@
38
39 #define __SWAB_64_THRU_32__
40
41 -#if (defined(__mips_isa_rev) && (__mips_isa_rev >= 2)) || \
42 - defined(_MIPS_ARCH_LOONGSON3A)
43 +#if !defined(__mips16) && \
44 + ((defined(__mips_isa_rev) && (__mips_isa_rev >= 2)) || \
45 + defined(_MIPS_ARCH_LOONGSON3A))
46
47 static inline __attribute_const__ __u16 __arch_swab16(__u16 x)
48 {
49 @@ -65,5 +66,5 @@ static inline __attribute_const__ __u64 __arch_swab64(__u64 x)
50 }
51 #define __arch_swab64 __arch_swab64
52 #endif /* __mips64 */
53 -#endif /* MIPS R2 or newer or Loongson 3A */
54 +#endif /* (not __mips16) and (MIPS R2 or newer or Loongson 3A) */
55 #endif /* _ASM_SWAB_H */
56 --
57 1.7.10.4
58