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

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

Re: [avr-gcc-list] Compiler error


From: Dmitry K.
Subject: Re: [avr-gcc-list] Compiler error
Date: Mon, 30 May 2005 17:52:26 +1100
User-agent: KMail/1.5

On Monday 30 May 2005 14:14, Larry Barello wrote:
> Ok, I submitted this as a bug (#21811) and within an hour it was closed as
> a duplicate of #8788 which will be corrected in the 4.1.0 mainline.  #8788
> sounds similar, but I am still somewhat unsatisfied since a union of a
> three byte array and a word should be allowed in C.  Maybe I just didn't
> understand.

You may use 3-bytes unions with implicit loading to registers.

For example (I am not remember an original code):

   int foo (int i)
   {
       union {
           unsigned int word;
           unsigned char byte[3];
       } u;

       u.word = i;
       u.byte[2] = 0;
       asm (
           "subi   %0,-1   \n\t"
           "sbci   %1,-1   \n\t"
           "sbci   %2,-1   "
           : "+d" (u.byte[0]), "+d" (u.byte[1]), "+d" (u.byte[2]) );
       return u.byte[2];
   }

produce next code (avr-gcc 3.3.4 -Os):

        ...
   /* prologue end (size=10) */
        std Y+1,r24
        std Y+2,r25
        std Y+3,__zero_reg__
        ldd r18,Y+1
        ldd r25,Y+2
        ldd r24,Y+3
   /* #APP */
        subi    r18,-1
        sbci    r25,-1
        sbci    r24,-1
   /* #NOAPP */
        clr r25
   /* epilogue: frame size=3 */
        ...

Regards.





reply via email to

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