This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [avr-gcc-list] Re: AVR byte swap optimization
- From: "Shaun Jackman" <sjackman at gmail dot com>
- To: "Anton Erasmus" <antone at sentechsa dot com>
- Cc: avr-gcc-list at nongnu dot org, gcc at gcc dot gnu dot org
- Date: Mon, 18 Dec 2006 14:57:07 -0700
- Subject: Re: [avr-gcc-list] Re: AVR byte swap optimization
- References: <7f45d9390611171530g4c12f68dua3ade87a8b4147b0@mail.gmail.com> <200611270219.56427.vda.linux@googlemail.com> <7f45d9390612181028o21f8d1eo2fc3e01b5802c695@mail.gmail.com> <45871F64.11998.3280E3E@antone.sentechsa.com>
- Reply-to: "Shaun Jackman" <sjackman at gmail dot com>
On 12/18/06, Anton Erasmus <antone@sentechsa.com> wrote:
Hi,
Not a macro, but the following seems to generate reasonable code.
...
Thanks Anton,
I came to the same conclusion.
Cheers,
Shaun
static inline uint16_t bswap_16_inline(uint16_t x)
{
union {
uint16_t x;
struct {
uint8_t a;
uint8_t b;
} s;
} in, out;
in.x = x;
out.s.a = in.s.b;
out.s.b = in.s.a;
return out.x;
}
static inline uint32_t bswap_32_inline(uint32_t x)
{
union {
uint32_t x;
struct {
uint8_t a;
uint8_t b;
uint8_t c;
uint8_t d;
} s;
} in, out;
in.x = x;
out.s.a = in.s.d;
out.s.b = in.s.c;
out.s.c = in.s.b;
out.s.d = in.s.a;
return out.x;
}