From 4c41934bb4a38414c14805529fdac7addd1913f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Thu, 11 Aug 2022 09:42:36 +0200 Subject: [PATCH] commander: inline HealthComponentIndex::HealthComponentIndex Saves around 1KB flash --- src/modules/commander/HealthAndArmingChecks/Common.hpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/modules/commander/HealthAndArmingChecks/Common.hpp b/src/modules/commander/HealthAndArmingChecks/Common.hpp index 4207222ffb..6124d2434b 100644 --- a/src/modules/commander/HealthAndArmingChecks/Common.hpp +++ b/src/modules/commander/HealthAndArmingChecks/Common.hpp @@ -91,7 +91,7 @@ static inline NavModes operator~(NavModes a) class HealthComponentIndex { public: - constexpr uint8_t log2(uint64_t x) + __attribute__((always_inline)) constexpr uint8_t log2(uint64_t x) { uint8_t i = 0; @@ -102,7 +102,10 @@ public: return i; } - constexpr HealthComponentIndex(health_component_t component) + + // The compiler is expected to evaluate this at compile-time, which generally works, but not + // with GCC 9.3.1 for ARM, so we ensure it's inlined and optimized away. + __attribute__((always_inline)) constexpr HealthComponentIndex(health_component_t component) : index(log2((uint64_t)component)) { }