To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 2141
2140  |  2142
Subject: 
floating point operation
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Wed, 28 Nov 2001 16:33:48 GMT
Viewed: 
1472 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
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR