Subject:
|
floating point operation
|
Newsgroups:
|
lugnet.robotics.rcx.legos
|
Date:
|
Wed, 28 Nov 2001 16:33:48 GMT
|
Viewed:
|
1563 times
|
| |
| |
I did some experiments with floating point operations and I was surprised
when I tried this:
int main(){
long t1;
int i,j;
float t;
t1 = sys_time;
for(j=0; j<1000; j++){
t=0.06;
for(i=0; i<100; i++){
t=1.7*t;
}
}
lcd_int((sys_time - t1)/1000);
return 0;
}
this program terminated after 1 second, but the following program
took about 52 seconds:
int main(){
long t1;
int i,j;
float t;
t1 = sys_time;
for(j=0; j<1000; j++){
t=0.06;
for(i=0; i<100; i++){
if (t>0) t=1.7*t;
/* -------- */
}
}
lcd_int((sys_time - t1)/1000);
return 0;
}
What is the reason for this difference?
|
|
Message has 2 Replies: | | Re: floating point operation
|
| (...) I suspect that when you look at the assembler code produced by the compiler you will find in the first instance it was able to optimize the FP multiply out of the inner loop since it didn't depend on the loop induction variable. Ie, it simply (...) (23 years ago, 28-Nov-01, to lugnet.robotics.rcx.legos)
| | | Re: floating point operation
|
| (...) Compiler optimization? At least, a disassembly of similar code showed me that that seemed to be the case. The compiler can see that t is not used. Try returning t, or copying t to a global before you return from main. That will make things (...) (23 years ago, 28-Nov-01, to lugnet.robotics.rcx.legos)
|
4 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|