[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Re: sprintf
From: |
Georg-Johann Lay |
Subject: |
Re: [avr-gcc-list] Re: sprintf |
Date: |
Tue, 03 Mar 2009 23:43:29 +0100 |
User-agent: |
Mozilla Thunderbird 1.0.7 (Windows/20050923) |
David Brown schrieb:
However, the compiler has a much
better chance of doing bounds checking, alias checking, and other
optimisations on the array expression. It is even free to reorganise
the array, or keep it all in registers (I don't think any compilers do
that, but maybe one day...), whereas working with raw addresses will
often cause the compiler to lose the extra knowledge of the array.
Taking addresses of auto and params forces them into memory, because you
cannot take an address of a register. Even if it is possible in a
specific hardware (AVR is an example), addresses on regs cannot work as
intended. a=b[i] with i unknown at compiletime is the same: addresses
must be calculated at runtime.
If no addresses are taken and the array has some comfortable size, gcc
can hold it in register:
typedef union
{
uint8_t asByte[4];
uint16_t asWord[2];
int16_t asShort[2];
uint32_t asULong;
int32_t asLong;
} data32_t;
avr-gcc can hold that in a register, thus I am using such types for data
conversion and byte extraction/insertion.
Yust try this:
data32_t bswap (data32_t a)
{
data32_t b;
b.asByte[0] = a.asByte[3];
b.asByte[1] = a.asByte[2];
b.asByte[2] = a.asByte[1];
b.asByte[3] = a.asByte[0];
return b;
}
data32_t bswap2 (data32_t a)
{
return (data32_t) {.asByte = {a.asByte[3], a.asByte[2],
a.asByte[1], a.asByte[0]}};
}
Depending if you allow for wide types to split, the performance changes
slightly. The first version with -Os compiles to optimum.
Georg-Johann
- RE: [avr-gcc-list] Re: sprintf, (continued)
- RE: [avr-gcc-list] Re: sprintf, Weddington, Eric, 2009/03/02
- Re: [avr-gcc-list] Re: sprintf, David Kelly, 2009/03/02
- Re: [avr-gcc-list] Re: sprintf, Joerg Wunsch, 2009/03/03
- Re: [avr-gcc-list] Re: sprintf, Joerg Wunsch, 2009/03/03
- [avr-gcc-list] Re: sprintf, David Brown, 2009/03/03
- Re: [avr-gcc-list] Re: sprintf, Pertti Kellomäki, 2009/03/03
- Re: [avr-gcc-list] Re: sprintf,
Georg-Johann Lay <=
- Re: [avr-gcc-list] Re: sprintf, Joerg Wunsch, 2009/03/05
- [avr-gcc-list] Re: sprintf, David Brown, 2009/03/05
- Re: [avr-gcc-list] Re: sprintf, Joerg Wunsch, 2009/03/06
- [avr-gcc-list] Re: sprintf, David Brown, 2009/03/06
- RE: [avr-gcc-list] Re: sprintf, Weddington, Eric, 2009/03/06