Although a bit wordy, the following produces good code under a lot of
different circumstances. It allows the compiler to shove things around &
optimize.
static inline uint16_t ByteSwap(uint16_t data)
{
union byteswap
{
uint16_t word;
struct
You could always equate the macro to some inline assembly like what is done
for a number of avr-libc macros.
Eric Weddington
> -Original Message-
> From:
> [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]
> org] On Behalf Of Shaun Jackman
> Sent: Friday, November 17, 2006 4:31 PM
> To: av
The following macro expands to some rather frightful code on the AVR:
#define BSWAP_16(x) \
x) >> 8) & 0xff) | (((x) & 0xff) << 8))
uint16_t bswap_16(uint16_t x)
{
0:9c 01 movwr18, r24
2:89 2f mov r24, r25
4:99 27 eor r25, r25