From 162e8f6326632306cd81605aa7d335c9de7ace28 Mon Sep 17 00:00:00 2001 From: ALTracer Date: Sat, 2 Dec 2023 23:28:42 +0300 Subject: [PATCH] jtagtap, swdptap, timing: fixup! Update the delay_busy, for-loop form --- src/platforms/common/jtagtap.c | 11 ++--------- src/platforms/common/stm32/timing_stm32.c | 10 ++++++++++ src/platforms/common/swdptap.c | 11 ++--------- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/platforms/common/jtagtap.c b/src/platforms/common/jtagtap.c index a0e5c33aa1d..23866cbabb9 100644 --- a/src/platforms/common/jtagtap.c +++ b/src/platforms/common/jtagtap.c @@ -73,15 +73,8 @@ static void jtagtap_reset(void) /* Busy-looping delay snippet for GPIO bitbanging (rely on inlining) */ static inline void platform_delay_busy(const uint32_t loops) { -#if 1 - register uint32_t i = loops; - do { - __asm__("nop"); - } while (--i > 0U); -#else - for (register uint32_t counter = loops; --counter > 0;) - __asm__("nop"); -#endif + for (register uint32_t counter = loops; --counter > 0U;) + __asm__(""); } static bool jtagtap_next_clk_delay() diff --git a/src/platforms/common/stm32/timing_stm32.c b/src/platforms/common/stm32/timing_stm32.c index f1cb68c994f..de0187df33a 100644 --- a/src/platforms/common/stm32/timing_stm32.c +++ b/src/platforms/common/stm32/timing_stm32.c @@ -216,6 +216,7 @@ uint32_t platform_max_frequency_get(void) void platform_delay_busy(const uint32_t loops) { /* Avoid using `volatile` variables which incur stack accesses */ +#if 0 register uint32_t i = loops; do { /* @@ -226,4 +227,13 @@ void platform_delay_busy(const uint32_t loops) */ __asm__("nop"); } while (--i > 0U); +#else + /* + * Another version which still assembles to SUBS+BNE.N; the NOP can be eliminated + * in favor of an empty inline asm/volatile block if it's enough to suppress DCE. + * Note that the predecrement has to be merged into the condition expression. + */ + for (register uint32_t i = loops; --i > 0U;) + __asm__(""); +#endif } diff --git a/src/platforms/common/swdptap.c b/src/platforms/common/swdptap.c index b862bfd8cb6..b5e93e6fed7 100644 --- a/src/platforms/common/swdptap.c +++ b/src/platforms/common/swdptap.c @@ -57,15 +57,8 @@ void swdptap_init(void) /* Busy-looping delay snippet for GPIO bitbanging (rely on inlining) */ static inline void platform_delay_busy(const uint32_t loops) { -#if 1 - register uint32_t i = loops; - do { - __asm__("nop"); - } while (--i > 0U); -#else - for (register uint32_t counter = loops; counter > 0; --counter) - __asm__("nop"); -#endif + for (register uint32_t counter = loops; --counter > 0U;) + __asm__(""); } static void swdptap_turnaround(const swdio_status_t dir)