bugAVR C Runtime Library - Bugs: bug #40003, Integer type promotion leads to...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #40003: Integer type promotion leads to inefficent code in wdt.h

Submitter:  Joey Morin <joeymorin>
Submitted:  Wed 11 Sep 2013 03:15:33 PM UTC
   
 
Category:  Library Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Header files
Status:  Fixed Assigned to:  pitchumani
Percent Complete:  0% Open/Closed:  Open
Release:  1.8.0 Fixed Release:  None

Mon 28 Apr 2014 01:40:15 PM UTC, comment #2: 
Pitchumani <pitchumani>
Group Member
Wed 11 Sep 2013 03:23:28 PM UTC, comment #1: 

Forgot to add an example:

In the case of wdt_enable(WDTO_15MS), the assembled output for targets such as the ATtiny85:
       ldi r18, 0x08
       ldi r24, 0x18
       ldi r25, 0x00
       in r0, 0x3f
       cli
       wdr
       out 0x21, r24
       out 0x3f, r0
       out 0x21, r18

With the patch in place:
       ldi r25, 0x08
       ldi r24, 0x18
       in r0, 0x3f
       cli
       wdr
       out 0x21, r24
       out 0x3f, r0
       out 0x21, r25


Joey Morin <joeymorin>
Wed 11 Sep 2013 03:15:33 PM UTC, original submission:  

Operands constructed in this fashion:
        "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)),

...result in the use of two registers, one of which is loaded with 0x00 and never used.

Seems as though integer type promotion is responsible.  A fix is as simple as casting to an 8-bit type:
        "r" ((uint8_t)(_BV(_WD_CHANGE_BIT) | _BV(WDE))),

Indeed, most _asm_ statements in wdt.h are already taking this approach, but a couple are not.

Attached is a patch to resolve the issue.

I'm aware this is a minor issue, but as it is easy to resolve, I hope it will be accepted :)

Cheers,
JJ


Joey Morin <joeymorin>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #29105:  wdt.h.patch added by joeymorin (802B - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by pitchumani (Updated the item)
  • -email is unavailable- added by joeymorin (Submitted the item)
  •  

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-04-28 pitchumani StatusConfirmed Fixed
    2014-04-28 pitchumani StatusNone Confirmed
        Assigned toNone pitchumani
    2013-09-11 joeymorin Attached File- Added wdt.h.patch, #29105

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code