Commit 5a17cb84 authored by Sven Greiner's avatar Sven Greiner

Try to optimize delay in LVP

A normal for loop like

    for (int i=5; i; --i) {

is unrolled until i=9. This is bad because a loop makes sense starting
at i=4. If the loop version (i>8) requires x byte, the unrolled version
(i=8) requires x+12 bytes. Due to compiler optimization this assembler
implementation requires x+4 bytes, although it just kind of forces
no-unroll of the loop.

So until we can tell the compiler to improve the jumps this does not
help to reduce the binary size.
parent 84b2a318
......@@ -509,9 +509,15 @@ int main(void) {
// that the flashlight is still turned on but the battery is dying.
// TODO If free space in flash, disable as many components as possible
blink(3, FLASH_TIME/2);
uint8_t delay_seconds;
asm volatile (
"ldi %[i], 5" "\n\t"
"0:" "\n\t"
"rcall delay_s" "\n\t"
"dec %[i]" "\n\t"
"brne 0b" "\n\t"
: [i] "=&r" (delay_seconds)
} else if (voltage <= BAT_LOW) {
blink(16, FLICKER_TIME);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment