Skip to content

Commit d08b8cc

Browse files
committed
MIPS: Simplify GCC_OFF_SMALL_ASM definition
The GCC_OFF_SMALL_ASM macro defines the constraint to use for instructions needing "small offsets", typically the LL or SC instructions. Historically these had 16 bit offsets, but microMIPS & MIPS32/MIPS64r6 onwards reduced the width of the offset field. GCC 4.9 & higher supports a ZC constraint which matches the offset requirements of the LL & SC instructions. Where supported we can use the ZC constraint regardless of ISA, and it will handle the requirements of the ISA correctly. As such we require 3 cases: - GCC 4.9 & higher can use ZC. - GCC older than 4.9 must use the older R constraint, which does not take into account microMIPS or MIPSr6. - microMIPS builds therefore require GCC 4.9 or higher. MIPSr6 support was only introduced in newer compilers anyway so it can be ignored here. The current code complicates this a little by specifically having MIPSr6 bypass the GCC version check, and using the R constraint for pre-MIPSr6 builds even if the compiler supports ZC which would be equivalent. Simplify this such that the code straightforwardly implements the 3 cases outlined above. For non-GCC compilers we presume that ZC is safe to use. In practice the only non-GCC compiler of interest is clang and it has supported the ZC constraint since version 3.7.0. It seems safe enough to presume that nobody will expect to built a working kernel using a clang version older than that, and if they do then they'll have bigger problems. As such we don't check the clang version number & just presume ZC is usable when the compiler is not GCC. Signed-off-by: Paul Burton <[email protected]> Patchwork: https://patchwork.linux-mips.org/patch/20999/ Cc: [email protected]
1 parent 57810ec commit d08b8cc

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

arch/mips/include/asm/compiler.h

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,14 @@
4343
#undef barrier_before_unreachable
4444
#define barrier_before_unreachable() asm volatile(".insn")
4545

46-
#ifdef CONFIG_CPU_MIPSR6
47-
/* All MIPS R6 toolchains support the ZC constrain */
48-
#define GCC_OFF_SMALL_ASM() "ZC"
49-
#else
50-
#ifndef CONFIG_CPU_MICROMIPS
51-
#define GCC_OFF_SMALL_ASM() "R"
52-
#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)
53-
#define GCC_OFF_SMALL_ASM() "ZC"
46+
#if !defined(CONFIG_CC_IS_GCC) || \
47+
(__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)
48+
# define GCC_OFF_SMALL_ASM() "ZC"
49+
#elif defined(CONFIG_CPU_MICROMIPS)
50+
# error "microMIPS compilation unsupported with GCC older than 4.9"
5451
#else
55-
#error "microMIPS compilation unsupported with GCC older than 4.9"
56-
#endif /* CONFIG_CPU_MICROMIPS */
57-
#endif /* CONFIG_CPU_MIPSR6 */
52+
# define GCC_OFF_SMALL_ASM() "R"
53+
#endif
5854

5955
#ifdef CONFIG_CPU_MIPSR6
6056
#define MIPS_ISA_LEVEL "mips64r6"

0 commit comments

Comments
 (0)