[Top][All Lists]

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

RE: [avr-gcc-list] Union as parameter

From: Larry Barello
Subject: RE: [avr-gcc-list] Union as parameter
Date: Wed, 24 Aug 2005 08:02:17 -0700

Passing by reference would work and produce decent code (GCC is amazing with
dereferenced data), but passing the bitfield in registers should result in
even tighter code.  Since this is lowest level EEPROM driver code I would
like it to be pretty tight.

I removed the struct and the resulting code was pretty good, if somewhat
more obscure (doing my own mask & shift operations).  I'll take Dean's
suggestion and declare the bit-field as uint32_t and see what happens; that
would be the cleanest way to do this.

In any case, GCC putting the union on the stack just because the bitfield
was not an exact unit long seems like broken behavior.  The first bit over
16 should have allocated the additional word to make it a dword variable.

Well, at least it produced correct, if somewhat sloppy, code.


-----Original Message-----
From: Dean Hall [mailto:address@hidden 
Sent: Wednesday, August 24, 2005 6:29 AM
To: address@hidden; address@hidden
Subject: Re: [avr-gcc-list] Union as parameter


Sounds like you're passing the union by value.  If you are, can you  
instead pass it by reference (which would occupy 2 bytes on the  
stack)?  If you're worried about modifying the data in the function,  
you can shield it with a const declaration.  More details here:  

I compiled to assembly a dummy program that used your union.  I  
didn't see anything out of the ordinary (but I'm not an expert in gcc  
prologue code, so take that statement with a modicum of sodium  
chloride).  One thing you might consider is to make the types in the  
bits struct all uint32_t.  This way you explicitly tell the compiler  
to pack them all into a 4 byte container.  I did this in my dummy  
program and didn't see a difference, but I didn't see a much of a  
"riot" in the first place.  Maybe my dummy program didn't exercise a  
certain case of bit manipulation that your program does.


On Aug 24, 2005, at 07:15, address@hidden wrote:

> ------------------------------
> Message: 8
> Date: Wed, 24 Aug 2005 00:19:08 -0700
> From: "Larry Barello" <address@hidden>
> Subject: [avr-gcc-list] Union as parameter
> To: "AVR GCC List" <address@hidden>
> Message-ID: <address@hidden>
> Content-Type: text/plain;    charset="us-ascii"
> I tried using this typedef, below, as a parameter to a function.   
> When I do,
> it gets stuck onto the stack frame.  The resulting code is a riot  
> since
> there is all sorts of set up and teardown, the value gets stuck  
> onto the
> stack, the routine called, the variable pulled off the stack into  
> registers
> where it is acted upon.

reply via email to

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