#129 Floating point compare unnecessarily large

open
nobody
None
1
2006-04-26
2006-04-26
No

Please ignore this request (and any others I might
submit) before release, the floating point compare for
negative numbers and the test for equality is
unnecessarily large.
(code sizes are for mcs51 small model)

--------8<---------------------------------
float xf = 0.0;
long xl = 0xdeadbeef;

float request_1(void)
{
/* Have some register pressure as it would
be typical for code involving floating
point */
float a = xf;

/* 50 bytes plus a call to ___fslt.
This could have been as efficient as
the check for the highest bit below? */
if( xf < 0.0 )
xf = 2.0;

/* 6 bytes and no subroutine call */
if( xl & 0x80000000 )
xl = 0x12345678;

return a;
}

float request_2(void)
{
float a = xf;

/* 57 bytes plus a call to ___fseq.
This could have been as efficient as
the unsigned long compare below? */
if( xf == 1234.56)
xf = 3.0;

/* 20 bytes and no subroutine call */
if( xl == 0x12345678 )
xl = 4;

return a;
}

void main(void){}

-------->8---------------------------------

Discussion


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks