From 20d31c114a9a7fa8d79ce7487eb28e36d20ba593 Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Tue, 30 Dec 2025 15:15:24 +0000 Subject: [PATCH] arm: use optimized find_first_set_bit() on Cortex-M Use the optimized version based on __buitlin_ctz() which GCC will compile to two instructions (rbit, ctz) on Cortex-M4/M7; faster and smaller than the handcoded assembly version. Change-Id: I33f69ff829b048f1e53fc7ead1bd6ac3c5bd7a4c --- firmware/export/system.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/firmware/export/system.h b/firmware/export/system.h index bc6a33d190..748b56629d 100644 --- a/firmware/export/system.h +++ b/firmware/export/system.h @@ -163,7 +163,8 @@ int get_cpu_boost_counter(void); #endif /* returns index of first set bit or 32 if no bits are set */ -#if defined(CPU_ARM) && ARM_ARCH >= 5 && !defined(__thumb__) +#if (defined(CPU_ARM) && ARM_ARCH >= 5 && !defined(__thumb__)) || \ + defined(CPU_ARM_MICRO) static inline int find_first_set_bit(uint32_t val) { return LIKELY(val) ? __builtin_ctz(val) : 32; } #else