Performance of Double Vs Float

Started by
6 comments, last by oggialli 18 years, 1 month ago
I have a silly question to ask. Please, no making fun of the newbie. If floats and double both use the FPU stack, is there a difference in performance when doing math operations. Thanks for any replies.
Advertisement
Depends, to a certain extent, on your architecture, I would imagine.

For example, PowerPC internally does fp operations w/doubles, even if your C code has floats. I don't know offhand what Intel does.

What might be more significant is memory bandwidth when you are dealing with a large number of them (say, for example, in vertex buffers). Copying a bunch of floats will be about half the work as copying the same number of doubles.
As far as execution time, there shouldn't be a real difference between double and float... However, because double is bigger, I'd suspect that copying a double would take longer then it would a float.

I guess the easiest way to find out for sure is to profile some code...
AFAIK, Intel FPU's do all calculations internally using long (80-bit) doubles. So there shouldn't be much (if any) performance difference besides potential cache effects caused by the size difference.
Thanks for the replies.
Doubles take up twice as much space, so only half as many fit in the cache at the same time. That might have no impact in one application or make it run an order of magnitude slower in another application.
The real issue that people have kind of mentioned but no one has hit is that doubles are twice as big, which means you can only move half as many of them in and out of memory. This can be a problem if you have a lot of data. And if you're doing a graphics application, GPU's use 32 bit floats anyway so using doubles is a waste.
Moreover, sending doubles to the GPU in any way is going to impose a conversion in the driver which makes using doubles even slower.
Olli Salli

This topic is closed to new replies.

Advertisement