avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] Re: AVR byte swap optimization


From: Shaun Jackman
Subject: [avr-gcc-list] Re: AVR byte swap optimization
Date: Mon, 18 Dec 2006 11:28:31 -0700

On 11/26/06, Denis Vlasenko <address@hidden> wrote:
On Saturday 18 November 2006 00:30, Shaun Jackman wrote:
> The following macro expands to some rather frightful code on the AVR:
>
> #define BSWAP_16(x) \
>      ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))

Sometimes gcc is generating better code if you cast
values instead of masking. Try:

      ( (uint8_t)((x) >> 8) | ((uint8_t)(x)) << 8 )

Your suggestion seemed like a good one and gave me some hope.
Unfortunately, it produces identical results to my BSWAP_16 macro. I
also tried the following:

        uint8_t a = x >> 8, b = x;
        return b << 8 | a;

Different register allocations this time, but identical instructions.

Cheers,
Shaun




reply via email to

[Prev in Thread] Current Thread [Next in Thread]