[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Re: AVR byte swap optimization
From: |
Shaun Jackman |
Subject: |
Re: [avr-gcc-list] Re: AVR byte swap optimization |
Date: |
Mon, 18 Dec 2006 17:54:15 -0700 |
On 12/18/06, David VanHorn <address@hidden> wrote:
> * If the swap function is called on a constant, the compiler cannot
> remove the inline assembler. In general, any inline assembler tends to
> handcuff the optimizer to some degree.
I'm new to C, but why would you want to swap a constant?
CAN you swap a constant? Seems an inconstant constant :)
Quite! My usual case for this is when the constant is defined in host
order, but I'm comparing against a network order value. For example,
if (incoming == htons(EXPECTED))
Here, incoming is a 16-bit network order value and htons (a.k.a.
byteswap_16) is taking the 16-bit host order constant EXPECTED. If
htons is implemented as a mathematical expression, the compiler can
optimise it away to nothing.
Cheers,
Shaun