[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Strange Code generated when using Global Register Var
From: |
Christian Steer |
Subject: |
Re: [avr-gcc-list] Strange Code generated when using Global Register Variables |
Date: |
Sat, 30 Apr 2011 14:18:55 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.14) Gecko/20110223 Thunderbird/3.1.8 |
Hi,
this is only a small example to demonstrate the compiled result.
I do not expect good or small code from -O0, but for me it explains
what the
compiler is thinking: r24 is a storage location like ram, not able to
perform
calculations.
But also the most optimised case (-O3) is far from what I expected.
Why the calculation cannot be performed directly on the register?
It is not important which register is used, the output does not match
my expectation. When using register variables my expectation is
that calculations are done directly on the register, or the register
is used directly as operand source or target.
Some notes:
- I will not use the Lib so I dont care about ABI.
- First I used register r2, the compiler copied it to r24. Ok, some
operations
can not be done on the lower register, so to help the compiler I
switched to the
prefered register r24, but now he is using r25. So it does not matter
which register is used, no chance for better results.
But you are right for the example r16 would be a better choice.
- If the keyword volatile is not used, the result is even more strange:
(or consistent with the assumption: r24 is equal to a ram location)
ldir25,lo8(100); tmp43,
sts tmp,r25 ; tmp, tmp43
.L2:
.stabn 68,0,14,.LM2-.LFBB1
.LM2:
sts tmp,r25 ; tmp, ivtmp.16
subir25,lo8(-(-1)); ivtmp.16,
.stabn 68,0,15,.LM3-.LFBB1
.LM3:
brne.L2 ; ,
ldir24,lo8(0); state,
Instead of using the suggested register r24, the compiler uses r25, and
will do an additonal load with zero to leave r24 with the correct value.
Why not use r24 directly ????
Am 30.04.2011 11:44, schrieb Georg-Johann Lay:
Christian Steer schrieb:
Hello list,
// just to avoid optimizig:
static volatile uint8_t tmp;
You explicit inhibit optimization and expect to get good results?
As your application is actually very small, I would propose to write
it completely in assembly.
valatile register is not supposed to work reliably.
Note that reserving r24 for global usage will make it impossible to
use any function that takes a parameter or call any function that
returns a value. gcc won't change the ABI for you.