Atomic compare_exchange(_weak) functions produce overly complicated asm code on thumbv7(e)m-none-eabi(hf) targets #79418
Labels
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
C-optimization
Category: An issue highlighting optimization opportunities or PRs implementing such
I-heavy
Issue: Problems and improvements with respect to binary size of generated code.
O-Arm
Target: 32-bit Arm processors (armv6, armv7, thumb...), including 64-bit Arm in AArch32 state
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
WG-embedded
Working group: Embedded systems
This code perform atomic increment:
Expected asm:
Produced asm godbolt:
Code size is very important on Cortex-M targets (thumbv*) because some controllers have only 20KB flash!
Besides the increment instruction (
adds r2, #1
) was moved into ldrex/strex section. This code lostcompare_exchange
advantage: evaluation before ldrex to reduce tick count when Exclusive Monitor is set.This code is useless because we can call
fetch_add
. But other tasks can requirescompare_exchange_weak
, for example atomic increment with max condition (pseudocode):Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: