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

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

Re: [avr-gcc-list] Shorter code?


From: Ruud Vlaming
Subject: Re: [avr-gcc-list] Shorter code?
Date: Thu, 12 Jun 2008 22:23:31 +0200
User-agent: KMail/1.9.1

On Thursday 12 June 2008 15:59, Schwichtenberg, Knut wrote:
> it looks that you use a structure to define your high and low byte. Why
> don't you define a union covering high and low byte structure and a 16
> bit value? Gcc knows how to handle that and there is no need for
> shifting. I use this very often and if your CPU support 16 bit loads gcc
> uses them.
> 
> Cheers
> Knut

On Thursday 12 June 2008 16:20, Paulo Marques wrote:
> One trick I use to help the compiler is to define something like:
> 
> typedef struct { uint8_t l, h; } BYTES;
> 
> typedef union {
>    uint16_t w;
>    BYTES b;
> } WORD;

The structure solution was known to me, and then i forgot 
about it, so thanks for the hint, i will implement that. But 
my question was also of more general of nature.

1) Why is there no compiler optimization pass after code generation
that takes care of this? It seems so natural.
==> Wel Eric said why, simply because no one did write it yet. So hey, i can
be first! I assume however that such optimizations must be written in RTL,
which is quite new to me.

2) Is there some short way in C to convince ggc to do that trick, just like
gcc understands that 
  if (( val & 0x04) == 0x04) 
can be translated to a single instruction on the avr.
But is seems there is non for the situation i described (aside from
the union solution)

Thanks for your responses.
Ruud




reply via email to

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