From 3711bf8a7a3892a2f68ad32cf03cd8d92c8cfdc3 Mon Sep 17 00:00:00 2001 From: "Bobby R. Bruce" Date: Wed, 4 Dec 2024 20:57:34 -0800 Subject: [PATCH] base,arch-arm: Add GEM5_NO_OPTIMIZE; use in ARM's vfp.hh (#1834) GCC and CLANG have different annotations for declaring code should not be optimized. Adding GEM5_NO_OPTIMZE provides gem5 developers a MACRO that works in both cases. This change replaces the GCC pragmas in vfp.hh with GEM5_NO_OPTIMIZE as this solution didn't work with clang. --- src/arch/arm/insts/vfp.hh | 2 ++ src/base/compiler.hh | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/arch/arm/insts/vfp.hh b/src/arch/arm/insts/vfp.hh index 1fccba3253..29f7547021 100644 --- a/src/arch/arm/insts/vfp.hh +++ b/src/arch/arm/insts/vfp.hh @@ -266,6 +266,7 @@ setFPExceptions(int exceptions) { template uint64_t +GEM5_NO_OPTIMIZE vfpFpToFixed(T val, bool isSigned, uint8_t width, uint8_t imm, bool useRmode = true, VfpRoundingMode roundMode = VfpRoundZero, bool aarch64 = false) @@ -437,6 +438,7 @@ vfpFpToFixed(T val, bool isSigned, uint8_t width, uint8_t imm, bool template T +GEM5_NO_OPTIMIZE vfpFpRint(T val, bool exact, bool defaultNan, bool useRmode = true, VfpRoundingMode roundMode = VfpRoundZero) { diff --git a/src/base/compiler.hh b/src/base/compiler.hh index 9c80c3ef09..f31478081a 100644 --- a/src/base/compiler.hh +++ b/src/base/compiler.hh @@ -131,6 +131,16 @@ do { [[maybe_unused]] int i[] = { 0, ((void)(__VA_ARGS__), 0)... }; } while (0) # error "Don't know what to do for your compiler." #endif + +// GEM5_NO_OPTIMIZE can be used to prevent the compiler from optimizing a +// function. Clang and GCC have different ways of doing this, so we need to +// check which compiler is being used. +#if defined(__clang__) +# define GEM5_NO_OPTIMIZE __attribute__((optnone)) +#else +# define GEM5_NO_OPTIMIZE __attribute__((optimize("O0"))) +#endif + // When a member variable may be unused, mark it with GEM5_CLASS_VAR_USED. This // needs to be limitted to clang only since clang warns on these unused // variables, and g++ will actually warn if you use this attribute since it