SourceForge has been redesigned. Learn more.
Close

#538 General cast bug

closed-fixed
5
2013-05-25
2003-06-29
Anonymous
No

When the following code is compiled with memory model
large and stack auto, it creates a lot of register
variables. However, one casting produces the following
code:

; genCast
mov ar3, r2
mov ar4, r3 <---This should have been done first.

Using the peep-hole optimizer, I was able to fix it; I put
in six entries to reverse the order of the move if the
compiler did it in the wrong order and that fixed the
code.

robertr@hildalecity.com

Errant function:

#define uint unsigned int
#define uchar unsigned char
#define ulong unsigned long

ulong msTimer, SecTimer;
bit UpdateTimersInitialized;
#include "C:...\F310.h" // sfr definitions

void UpdateTimers() {

static xdata uint LastTimeValue, msTimer2;

auto uchar a,b,c;
auto uint TimeValue;
auto uint Increment; // Used in case values are
converted to long before subtraction
static xdata ulong MSTotalizer, SecTotalizer;

if (!UpdateTimersInitialized) {
UpdateTimersInitialized=1;
MSTotalizer=0;
SecTotalizer=0;
LastTimeValue=0;
msTimer2=0;

}

do {
b=TH0;
a=TL0;
c=TH0;
} while (b!=c);

TimeValue=((uint) b<<8)+a;

// TimeValue=LastTimeValue+3;
Increment=TimeValue-LastTimeValue; // <---Line
that gives the error
MSTotalizer=Increment+MSTotalizer;
LastTimeValue=TimeValue;

while (MSTotalizer> 58) { // Handle milliseconds
msTimer2=msTimer2+133; // Fudge factor
giving slightly slower clock because 117 doesn't come
out even.
MSTotalizer-=58;
if (msTimer2>256) {
++msTimer;
++SecTotalizer;
msTimer2-=256;
}
}

while (SecTotalizer>1000) {
++SecTimer;
SecTotalizer-=1000;
}
}

Discussion

  • Nobody/Anonymous

    Contains source code, assembly output, and peep-hole file to fix bug

     
  • Erik Petrich

    Erik Petrich - 2003-09-19
    • status: open --> closed-fixed
     
  • Erik Petrich

    Erik Petrich - 2003-09-19

    Logged In: YES
    user_id=635249

    Fixed in src/mcs51/ralloc.c 1.114

     
  • Erik Petrich

    Erik Petrich - 2003-09-19
    • labels: --> mcs51(8051) target
    • milestone: --> fixed
    • assigned_to: nobody --> epetrich
     

Log in to post a comment.