Changing a constant's value changes Flash usage

While writing code for an ATtiny13 I accidentally came across something. I have this _delay_us() function in my code and I noticed that when I change the delay value it changes my code size by 2-4 bytes.

Here’s a very simple code that you can test this with:

void setup() {
}
void loop() {
  _delay_us(500);
}

Here is my code size with different delay values:
_delay_us(500): 52 bytes
_delay_us(499): 50 bytes
_delay_us(498): 48 bytes
_delay_us(497): 52 bytes
_delay_us(496): 50 bytes
_delay_us(495): 52 bytes
_delay_us(494): 50 bytes
_delay_us(493): 48 bytes
_delay_us(492): 52 bytes
_delay_us(491): 50 bytes
_delay_us(490): 52 bytes

I’m using MicroCore v1.0.6 @9.6MHz

I don’t understand what’s going on here. But I suppose it’s the optimizer doing something. Or perhaps the internal workings of _delay_us().
I was wondering if someone can tell me exactly what’s going on here, so that I can take advantage of this to reduce my code size. Because I have 6 delay functions and if I can modify all my constants to use 4 bytes less that would be like 24 bytes less Flash space used. Which would be awesome.

Did you look at the __delay_us() function?

Maybe it has something to do with the conversion from your integer to the 'double' argument:

void _delay_us(double __us)

johnwasser:
Did you look at the __delay_us() function?

Maybe it has something to do with the conversion from your integer to the ‘double’ argument:

void _delay_us(double __us)

I tried using const double delay = 500 and the results were the same. Also I suppose since it’s a compile-time constant the optimizer takes care of any conversion necessary.

Is that the only call to __delay_us()? Maybe the compiler decided to compile it in place and some operation can be optimized into fewer instructions to certain bit patterns.

It looks like, at least for the very limited sample, that the pattern repeats every 5:

(490) 52, 50, 52, 48, 50,
52, 50, 52, 48, 50,
52 (500)

I don't know why there would be a pattern repeating this way.

johnwasser:
I don’t know why there would be a pattern repeating this way.

You could disassemble the generated code…