compiler.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (C) 2004, 2007 Maciej W. Rozycki
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. */
  8. #ifndef _ASM_COMPILER_H
  9. #define _ASM_COMPILER_H
  10. /*
  11. * With GCC 4.5 onwards we can use __builtin_unreachable to indicate to the
  12. * compiler that a particular code path will never be hit. This allows it to be
  13. * optimised out of the generated binary.
  14. *
  15. * Unfortunately at least GCC 4.6.3 through 7.3.0 inclusive suffer from a bug
  16. * that can lead to instructions from beyond an unreachable statement being
  17. * incorrectly reordered into earlier delay slots if the unreachable statement
  18. * is the only content of a case in a switch statement. This can lead to
  19. * seemingly random behaviour, such as invalid memory accesses from incorrectly
  20. * reordered loads or stores. See this potential GCC fix for details:
  21. *
  22. * https://gcc.gnu.org/ml/gcc-patches/2015-09/msg00360.html
  23. *
  24. * It is unclear whether GCC 8 onwards suffer from the same issue - nothing
  25. * relevant is mentioned in GCC 8 release notes and nothing obviously relevant
  26. * stands out in GCC commit logs, but these newer GCC versions generate very
  27. * different code for the testcase which doesn't exhibit the bug.
  28. *
  29. * GCC also handles stack allocation suboptimally when calling noreturn
  30. * functions or calling __builtin_unreachable():
  31. *
  32. * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82365
  33. *
  34. * We work around both of these issues by placing a volatile asm statement,
  35. * which GCC is prevented from reordering past, prior to __builtin_unreachable
  36. * calls.
  37. *
  38. * The .insn statement is required to ensure that any branches to the
  39. * statement, which sadly must be kept due to the asm statement, are known to
  40. * be branches to code and satisfy linker requirements for microMIPS kernels.
  41. */
  42. #undef barrier_before_unreachable
  43. #define barrier_before_unreachable() asm volatile(".insn")
  44. #define GCC_OFF_SMALL_ASM() "ZC"
  45. #ifdef CONFIG_CPU_MIPSR6
  46. #define MIPS_ISA_LEVEL "mips64r6"
  47. #define MIPS_ISA_ARCH_LEVEL MIPS_ISA_LEVEL
  48. #define MIPS_ISA_LEVEL_RAW mips64r6
  49. #define MIPS_ISA_ARCH_LEVEL_RAW MIPS_ISA_LEVEL_RAW
  50. #elif defined(CONFIG_CPU_MIPSR5)
  51. #define MIPS_ISA_LEVEL "mips64r5"
  52. #define MIPS_ISA_ARCH_LEVEL MIPS_ISA_LEVEL
  53. #define MIPS_ISA_LEVEL_RAW mips64r5
  54. #define MIPS_ISA_ARCH_LEVEL_RAW MIPS_ISA_LEVEL_RAW
  55. #else
  56. /* MIPS64 is a superset of MIPS32 */
  57. #define MIPS_ISA_LEVEL "mips64r2"
  58. #define MIPS_ISA_ARCH_LEVEL "arch=r4000"
  59. #define MIPS_ISA_LEVEL_RAW mips64r2
  60. #define MIPS_ISA_ARCH_LEVEL_RAW MIPS_ISA_LEVEL_RAW
  61. #endif /* CONFIG_CPU_MIPSR6 */
  62. #endif /* _ASM_COMPILER_H */