• Advertisement
Sign in to follow this  

Ints and floats

This topic is 2180 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

After reading that converting between ints and floats is a mortal sin,
I decided to rewrite my simple software rasterizer to use floats only.

No more 255, just plain 1.
No more i * a / 255, just plain f * a.
No more overflow checks, just treat 1.25 as white.

The result? It runs SLOWER now than before.
Maybe memory bandwidth is more of an issue.

Share this post


Link to post
Share on other sites
Advertisement
Conversion isn't a mortal sin for performance reasons (though it doesn't help); it's due to accuracy reasons.

Share this post


Link to post
Share on other sites
[quote name='meanwhile' timestamp='1328038202' post='4908124']
The result? It runs SLOWER now than before.
Maybe memory bandwidth is more of an issue.
[/quote]

Are you asking why, or are you just complaining about it?

Share this post


Link to post
Share on other sites
A CPU calculate integer faster.
A GPU calculate floats faster.

You use a SOFTWARE rasterizer, hence done on the CPU. Of course floats will be slower. Unless you use some GPGPU calculations...

Share this post


Link to post
Share on other sites
[quote name='Dunge' timestamp='1328045388' post='4908164']
A CPU calculate integer faster.[/quote]
Once upon a time, yes - these days it's not quite so cut-and-dried. The FPU may actually be faster than the ALU at many tasks, especially if you can make use of SIMD (SSE/altivec) instructions.

Share this post


Link to post
Share on other sites
As a rule of thumb, every time you see a statement to the effect that "X is a mortal sin", or "you should never do Y", or "if you're not doing Z you're doing it wrong", you should always look for the part of it beginning with the words "but..." or "except..."

If that's missing take it with an appropriately sized grain of salt.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement