discovery
discovery copied to clipboard
f3discovery/09-clocks-and-timers: aux9::nop() optimized away
In https://docs.rust-embedded.org/discovery/f3discovery/09-clocks-and-timers/nop.html, it was suggested that doing a aux9::nop()
would prevent the loop from being optimized away. When I tried it, I got the following assembly:
(gdb) disassemble /m
Dump of assembler code for function _ZN17clocks_and_timers5delay17h4e291ad62a2b0e58E:
7 fn delay(tim6: &tim6::RegisterBlock, ms: u16) {
0x08000220 <+0>: push {r4, r5, r7, lr}
0x08000222 <+2>: add r7, sp, #8
0x08000224 <+4>: movs r4, #0
8 const K: u16 = 3; // this value needs to be tweaked
9 for _ in 0..(K * ms) {
10 aux9::nop()
11 }
12 }
0x08000232 <+18>: pop {r4, r5, r7, pc}
End of assembler dump.
In the empty loop case, the delay function was not even called in the assembly. With a nop, the function did get called, but the loop itself was skipped.
Did the compiler get smarter or did I do something wrong? I'm using rust 1.57 on a mac.