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

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

Re: [avr-gcc-list] Bug with -Os with constant multiplier of 3?


From: David Kopf
Subject: Re: [avr-gcc-list] Bug with -Os with constant multiplier of 3?
Date: Fri, 24 Dec 2010 09:57:24 -0500

While creating the bug report I realized this is the known effect of promotion to 16 bits. Before I was forcing the calculation by transfering the result to a volatile location, which obscured the handling of the zeroed upper byte registers.

There is no bug, Os is indeed shorter. It becomes clear when volatile is used 
directly.

-Os
volatile uint8_t rssi;
rssi=3*rssi;
 44: 89 81        ldd r24, Y+1 ; 0x01
 46: 90 e0        ldi r25, 0x00 ; 0
 48: 63 e0        ldi r22, 0x03 ; 3
 4a: 70 e0        ldi r23, 0x00 ; 0
 4c: 5f d0        rcall .+190     ; 0x10c <__mulhi3>
 4e: 89 83        std Y+1, r24 ; 0x01

-O3
volatile uint8_t rssi;
rssi=3*rssi;
 44: 29 81        ldd r18, Y+1 ; 0x01
 46: 30 e0        ldi r19, 0x00 ; 0
 48: c9 01        movw r24, r18
 4a: 88 0f        add r24, r24
 4c: 99 1f        adc r25, r25
 4e: 82 0f        add r24, r18
 50: 93 1f        adc r25, r19
 52: 89 83        std Y+1, r24 ; 0x01

-O3 would be the same size if the unneeded r19 and r25 were to be dropped. But -Os could be shorter too, by dropping r23 and r25 and calling mulqi3.


With -mint8 the upper byte is not calculated but -Os is still shorter:

-Os -mint8
volatile uint8_t rssi;
rssi=3*rssi;
 40: 89 81        ldd r24, Y+1 ; 0x01
 42: 63 e0        ldi r22, 0x03 ; 3
 44: 43 d0        rcall .+134     ; 0xcc <__mulqi3>
 46: 89 83        std Y+1, r24 ; 0x01

-O3 -mint8
volatile uint8_t rssi;
rssi=3*rssi;
 40: 99 81        ldd r25, Y+1 ; 0x01
 42: 89 2f        mov r24, r25
 44: 88 0f        add r24, r24
 46: 89 0f        add r24, r25
 48: 89 83        std Y+1, r24 ; 0x01



----- Original Message ----- From: "Weddington, Eric" <address@hidden>
To: "David Kopf" <address@hidden>; <address@hidden>
Sent: Friday, December 24, 2010 12:03 AM
Subject: RE: [avr-gcc-list] Bug with -Os with constant multiplier of 3?


Hi David,

Have you had a chance to take a look at the avr target bugs in the GCC Bugzilla database? This might have already been submitted, but if not, could you submit a bug to the GCC project? If you do this, please put my email address in the CC list.

Thanks,
Eric Weddington

-----Original Message-----
From: address@hidden
[mailto:address@hidden On
Behalf Of David Kopf
Sent: Tuesday, December 21, 2010 8:02 AM
To: address@hidden
Subject: [avr-gcc-list] Bug with -Os with constant multiplier of 3?

Hi,

Using WinAVR avr-gcc 4.3.0 and 4.3.3, compiling 3*<uint8_t> with -Os calls
__mulhi3 instead of the optimized *2+1 when no hardware
multiply is present.  O1,O2,O3 does it right:

Target: ATTiny85

> uint8_t rssi;  //r24
> -O1 -O2 -O3
> rssi=3*rssi;
>    aa: 28 2f        mov r18, r24
>    ac: 22 0f        add r18, r18
>    ae: 28 0f        add r18, r24
>

> -Os
> rssi=3*rssi;
>    ae: 90 e0        ldi r25, 0x00 ; 0
>    b0: 63 e0        ldi r22, 0x03 ; 3
>    b2: 70 e0        ldi r23, 0x00 ; 0
>    b4: 40 d0        rcall .+128     ; 0x136<__mulhi3>
>



_______________________________________________
AVR-GCC-list mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list




reply via email to

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