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

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

RE: [avr-gcc-list] mass stupidity with registers and longs


From: Ben Mann
Subject: RE: [avr-gcc-list] mass stupidity with registers and longs
Date: Fri, 14 Jan 2005 13:42:54 +0800

Hi Curtis,

I did a quick test and noticed that either a bitfield or union produces much
tighter code, ie

        typedef union {
                unsigned long as_long;
                struct {
                        unsigned char b[4];
                };
        } foo;

        extern char a[4];
        foo ul;

        ul.b[0] = a[1]; //lds rXX,a+1; sts ul
        ul.b[1] = a[0];   //lds rXX,a; sts ul+1

However there's the usual caveat that working with 4-byte integers on the
AVR gets a little dicey with limited registers etc... also you could modify
the code above so that ul is an unsigned long, and the a[] assignments are
done by casting ul to foo, however I fail to see the need...

Ben Mann


-----Original Message-----
From: address@hidden [mailto:address@hidden
On Behalf Of Curtis Maloney
Sent: Friday, 14 January 2005 12:52 PM
To: address@hidden
Subject: [avr-gcc-list] mass stupidity with registers and longs



I give up.  I've been trying to shift 4 chars into an unsigned long, but
can't 
stop GCC 3.4.1 (what's shipped with the latest WinAVR) from sign extending 
values, let alone producing sane code.

I've tried -Os, -O2, -O3, with and without -fnew-ra... the asm varies, but
is 
generaly crap.

now, if I have:
        extern char a[4];
        unsigned long ul;

        ul = ( (unsigned)a[0] << 8 ) | (unsigned)a[1];

why would it be sign extending a[0] and a[1] when they're cast to unsigneds?
And then why doesn't the code optimiser see to just mov rX, a[1]; mov
rX+1,a[0] ?

I tried casts on casts on casts... everything I could think of to get better

code, and it just did not improve.

Am I missing something, or do I just need to get gcc 3.4.3?  If so, is
anyone 
lurking here involved with WinAVR, and can tell me when the next update
might 
happen?

--
Curtis Maloney


_______________________________________________
avr-gcc-list mailing list
address@hidden http://www.avr1.org/mailman/listinfo/avr-gcc-list





reply via email to

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