News for hackers. Stuff that matters.
Re:High Performance Correctly Rounded Math Libraries for 32-... by modeless on Thursday August 26, 2021 @03:06PM (#28319148)
32-bit floats are sufficient and desired for performance in many cases, like graphics or audio. 64-bit floats are not enough in some cases, like galaxy-scale coordinates or nanosecond precision over long time periods or some currency calculations. There's no single best answer, you have to know what your requirements are.
Re:High Performance Correctly Rounded Math Libraries for 32-... by retsibsi on Thursday August 26, 2021 @08:06PM (#28322663)
> 32-bit floats are sufficient and desired for performance in many cases, like graphics or audio

I was googling this recently, when deciding whether to use floats or doubles in a simple game I was writing. Some answers suggested that (32-bit) floats aren't necessarily any faster in real-world applications on modern hardware. If you or anyone else feels like elaborating on this I'd be interested.

Re:High Performance Correctly Rounded Math Libraries for 32-... by zamadatix on Thursday August 26, 2021 @08:33PM (#28322910)
For CPU cycle counts it's not that different, for GPU cycle counts it's something in the range of 50x FLOPS difference for consumer GPUs so avoid it in shaders and whatnot if you can. There is also the matter of SIMD on the CPU, you can generally get twice the SIMD rate by halving the bit width of the data which is quite the gain.

Outside raw computation rate though there is also the matter of cache and memory bandwidth. You'll use 2x with doubles which can really bog things down as even if the CPU can crunch the calculation quickly it could spend a lot of time waiting for the data to crunch to arrive.

All that being said if you know your game is going to be simple then it probably doesn't matter one way or the other even if it does come at a big performance cost.

Re:High Performance Correctly Rounded Math Libraries for 32-... by jiggawatts on Thursday August 26, 2021 @09:41PM (#28323380)
Games generally don't "accumulate" in floats for extended periods, unlike typical scientific applications where they might be using iterative solvers, simulating processes, or inverting huge matrices.

Instead, games tend to take some input parameters, use those to transform a read-only data set, render a frame, and then throw everything away. The next frame starts from scratch. There's no accumulation.

In my experience, typically only the "player camera angle" is kept around and accumulated into. The precision errors here are negligible. Nobody cares if the viewport is 0.00001 degrees to the left or right of where it "should" be.

Most other parameters that are kept frame-to-frame tend to be "world simulation" stuff. In that case, consistency is so important for network codes that most games use fixed point or integers only. This avoids any kind of discrepancies when using delta compression or multiplayer where people have different CPUs.

Re:High Performance Correctly Rounded Math Libraries for 32-... by modeless on Thursday August 26, 2021 @09:10PM (#28323174)
The big win is memory. Half the memory/cache usage and half the bandwidth. For SIMD you'll want 32 bit floats. But in many cases instead of reaching for SIMD you should go to compute shaders, which are definitely going to be 32 bit. And of course any graphics shaders will be using 32 bit floats.
Re:High Performance Correctly Rounded Math Libraries for 32-... by gpderetta on Thursday August 26, 2021 @08:22PM (#28322795)
For scalar computations 32 bit floats are not going to be faster except maybe divisions. There are second order effects due the reduced memory usage.

For anything that is vectorizable or otherwise amenable to SIMD optimizations you can get up to 2x speedup.

Re:High Performance Correctly Rounded Math Libraries for 32-... by adgjlsfhk1 on Thursday August 26, 2021 @10:37PM (#28323728)
All the transcendental functions are also an extra 2-4x slower for Float64 since you need higher order approximations, and the compensated arithmetic is slower.
Re:High Performance Correctly Rounded Math Libraries for 32-... by retsibsi on Thursday August 26, 2021 @11:52PM (#28324113)
It seems to be too late to edit, so I'll post here rather than clog up the thread with individual replies: thanks, I appreciate all the explanations. I will have to look up some details but it seems the basic takeaway is 'if in doubt, just use floats'.