Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » AVR-GCC
  • » [avr-gcc-list] Bug with -Os with constant multiplier of 3? [RSS Feed]

#1 Dec. 23, 2010 15:00:50

David K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[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 hardwaremultiply is present. O1,O2,O3 does it right:Target: ATTiny85uint8_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
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#2 Dec. 24, 2010 05:03:10

Weddington, E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[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: avr-gcc-list-bounces+eric.weddington=atmel.***@*ongnu.org
> On
> Behalf Of David Kopf
> Sent: Tuesday, December 21, 2010 8:02 AM
> To: avr-gcc-l***@*ongnu.org
> Subject: 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
> AVR-GCC-l***@*ongnu.org
>http://lists.nongnu.org/mailman/listinfo/avr-gcc-list_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#3 Dec. 24, 2010 14:57:57

David K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

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


While creating the bug report I realized this is the known effect of promotion to 16 bits. Before I was forcing the calculation bytransfering 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 r25and 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" <eric.wedding***@*tmel.com>To: "David Kopf" <dak***@*mbarqmail.com>; <avr-gcc-l***@*ongnu.org>
Sent: Friday, December 24, 2010 12:03 AM
Subject: RE: 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: avr-gcc-list-bounces+eric.weddington=atmel.***@*ongnu.org
On
Behalf Of David Kopf
Sent: Tuesday, December 21, 2010 8:02 AM
To: avr-gcc-l***@*ongnu.org
Subject: 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
AVR-GCC-l***@*ongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

  • Root
  • » AVR-GCC
  • » [avr-gcc-list] Bug with -Os with constant multiplier of 3? [RSS Feed]

Board footer

Moderator control

Enjoy the 16th of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support