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

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

Re: [avr-gcc-list] GCC does useless 16-bit operations


From: Dave Hylands
Subject: Re: [avr-gcc-list] GCC does useless 16-bit operations
Date: Thu, 10 May 2007 22:09:17 -0700

Hi Daniel,

But

  uint8_t temp = (tx_producer_index + (uint8_t) 1) % 64;

64 is an int, which is 16 bits, so the whole expression is promoted to int.

Using 4.1.1, the following source file:

#include <stdint.h>

uint8_t func( uint8_t x )
{
   return (uint8_t)( x + (uint8_t)1 ) % (uint8_t)64;
}

compiles to this:

func:
       subi r24,lo8(-(1))
       clr r25
       andi r24,lo8(63)
       andi r25,hi8(63)
       ret

which is about as optimal as it can be since the return value is still
promoted to an int (this was compiled with the -Os flag).

If you really want 8 bit ints, use the -mint8 and then it compiles down to:

func:
       subi r24,lo8(-(1))
       andi r24,lo8(63)
       ret

Aside: It seems that stdint.h is incompatible with the -mint8 flag.

--
Dave Hylands
Vancouver, BC, Canada
http://www.DaveHylands.com/




reply via email to

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