[Top][All Lists]

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

Re: [avr-gcc-list] How to get the GCC to use the swap instruction?

From: Marek Michalkiewicz
Subject: Re: [avr-gcc-list] How to get the GCC to use the swap instruction?
Date: Wed, 30 Oct 2002 08:26:15 +0100 (CET)

> I suspect the answer is that gcc doesn't do this because it doesn't
> consider a nibble to be a complete data type.  If there was a halfchar
> datatype, then you could expect gcc to do it for you.

It shouldn't be that hard to add a rotlqi3 insn to GCC, as swapping
nibbles is the same as rotate left by 4 bits.  But probably not now,
as we are too close to the GCC 3.3 release (bug fixes only).

Other than that, the swap instruction appears in a few hand-optimized
assembler patterns for bit shifts.

> #define swap_nibble(a) { asm("swap %0": "=r" (a) : "r" (a)); }

When rotlqi3 is implemented, simple ((a << 4) | (a >> 4)) would be
equivalent.  Rotation in general (even by unknown number of bits)
could be optimized as well, by making use of the carry flag - like
this (for rotate left by 1, repeat in a loop as needed):

        lsl %0
        adc %0,__zero_reg__     ; set bit 0 to C flag


avr-gcc-list at http://avr1.org

reply via email to

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