Remove real type

Mike Farnsworth mike.farnsworth at gmail.com
Fri Apr 23 14:50:50 PDT 2010


Walter Bright Wrote:

> Don wrote:
> > A simple rule of thumb: if it's an array, use float or double. If it's 
> > not, use real.
> 
> I agree. The only reason to use float or double is to save on storage.

There is another reason: performance, when combined with vectorized code.  If I use 4 32-bit floats to represent my vectors, points, etc. in my ray tracer, I can stuff them into an SSE register and use intrinsics to really, *really* speed it up.  Especially if I use the sum-of-products / structure-of-arrays form for packetizing the data.  Now, I realize this is not necessarily possible with D2 currently, but it's not inconceivable that some D2 compiler would get that capability in the relatively near future.

If I instead use 8-byte floats, I now have to double my operations and thus much of my processing time (due to only being able to put 2 items into each SSE register).  If I use reals, well, I get the x86 FPU, which seriously hampers performance.  And when it comes to rendering, performance is a very, very big deal (even in production/offline rendering).

-Mike




More information about the Digitalmars-d mailing list