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


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

Submitted by:  Joey Morin <joeymorin>
Submitted on:  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 <pitchumani>
Percent Complete:  0% Open/Closed:  Open
Release:  1.8.0 Fixed Release:  None

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Mon 28 Apr 2014 01:40:15 PM UTC, comment #2: 
Pitchumani <pitchumani>
Project MemberIn charge of this item.
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
       out 0x21, r24
       out 0x3f, r0
       out 0x21, r18

With the patch in place:
       ldi r25, 0x08
       ldi r24, 0x18
       in r0, 0x3f
       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 :)


Joey Morin <joeymorin>


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

Attach Files:

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.5