home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / L-M / Maximizing Quadra FloatingPoint / ReadMe < prev   
Encoding:
Text File  |  1992-12-03  |  4.7 KB  |  65 lines  |  [TEXT/ttxt]

  1. The Truth About Floating Point on the Quadra
  2.  
  3. Wonder why you don't seem to be getting the performance improvement on the Quadra with floating-point that you should?
  4.  
  5. Do you do your work exclusively in the floating-point domain, or do you frequently need to convert to integer for outputting graphics, sound, or text?
  6.  
  7. While the Quadra is maybe an order of magnitude faster in floating-point addition, subtraction, multiplication, and division, it does not implement the 6888x FINTRZ instruction, so conversions from float to int take 4 times longer on the Quadra than the FX.  FINTRZ means "float-to-int, rounding toward zero", and is the rounding method that is specified by C. One the 68040, the FINTRZ instruction is not implemented, and is implemented through a trap.
  8.  
  9. Below, we can see the relative timings:
  10.  
  11. *Timing*
  12.                                   FX        Quadra900        Quadra950
  13. Instruction                time           time                  time
  14. l=x; /*FINTRZ*/          241          1624                 1232  
  15. l=TruncXToLong(x);     631             118                     71
  16. x*=x;                            90               22                     20
  17.  
  18. *Relative speed between processors with the same instruction (compare across)*
  19.                                     FX        Quadra900        Quadra950
  20. Instruction               speed         speed                 speed
  21. l=x; /*FINTRZ*/            7X             1X                    1.3X  
  22. l=TruncXToLong(x);       1X             5X                       9X
  23. x*=x;                            1X              4X                   4.5X
  24.  
  25. This shows that while pure floating point operations are 4X as fast on the Quadra as an FX, conversion to integer is 7X slower.
  26.  
  27. Another way of looking at this is to compare relative instruction timings on the same processor. Below, we show relative speeds of floating-point and conversion operations on the same processor.
  28.  
  29. *Relative Speed  on the same processor (compare down)*
  30.                                     FX        Quadra900        Quadra950
  31. Instruction               speed         speed                 speed
  32. l=x; /*FINTRZ*/         2.6X             1X                       1X  
  33. l=TruncXToLong(x);       1X            14X                    17X
  34. x*=x;                            7X            73X                    61X
  35.  
  36. This says that 70 floating point operations on the Quadra 900 takes less time than one float-to-int conversion! You could probably invert a 3x3 matrix in that time!
  37. Can you imagine????
  38.  
  39. The accompanying code (TruncXToLong, found in FloatToLong.a) will speed up float-to-int conversions on the Quadra by over an order of magnitude, making them only 5X slower than multiplies, rather than over 60X!
  40.  
  41. Unfortunately, though, this slows down the FX's conversion by a factor of 2.6, so you can't optimize for both the FX and the Quadra with the same code. The best solution, of course, would be to implement the FINTRZ instruction in hardware in the '040, but until that time the enclosed code will improve your demos.
  42.  
  43. Note that there are three procedures implemented in FloatToLong.a:
  44.  
  45.      long RoundXToLong(long double x);
  46.      long TruncXToLong(long double x);
  47.      long FloorXToLong(long double x);
  48.  
  49. These correspond to the 68881/2 rounding modes of
  50. • round to nearest
  51. • round to zero
  52. • round to -∞
  53. The only rounding mode not used is "round to +∞", which would implement a CeilXToLong() function. If you need it, I'm sure you can figure out how to modify the enclosed code.
  54.  
  55. The enclosed code was written for MPW. It is trivial to convert it to Think C.
  56.  
  57. Additionally, in THINK C, you can optimize it even further by using a "fmove.s" if your data is single precision "float" instead of a "fmove.x" for extended precision "long double", because THINK C passes float and double arguments without conversion (as provided for by ANSI), whereas MPW converts all floating-point arguments to extended. You can optimize it even more by putting it inline. Beware of pulling the change-of-rounding-mode out of the inner loop, because it affects all floating-point computations (multiplication, square root, etc.), not just float-to-int conversion.
  58.  
  59. None of the timing numbers have been gathered in an unbiased way. You'll probably get the same numbers if you do a tight loop executing the same instruction over 100,000 times, but who does that on a regular basis? Your mileage may vary. All I know is that when it is plugged into some of our 2D and 3D rendering code in ATG, it feels like its rendering 3 times faster. It's hard to come by that kind of speed improvement with careful code and algorithm optimization. This one's a no-brainer.
  60.  
  61. -Ken Turkowski-
  62.   +Computer Graphics+
  63.      *Advanced Technololgy Group*
  64.              /Apple Computer, Inc./
  65.