Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting floating point software emulation

I'm working on an application where runtime speed is more important than precision. The number crunching involves floating point arithmetic and I'm concerned about double and/or long double being handled in software instead of natively on the processor (this is always true on a 32-bit arch right?). I would like to conditionally compile using the highest precision with hardware support, but I haven't found a quick and easy way to detect software emulation. I'm using g++ on GNU/Linux and I'm not concerned about portability. It's running on x86 arch, so I'm assuming that float is always native.

like image 920
Oscar Korz Avatar asked Sep 26 '26 02:09

Oscar Korz


1 Answers

The Floating-point unit (FPU) on modern x86 is natively double (in fact, it's even bigger than double), not float (the "32" in 32-bit describes the integer register widths, not the floating-point width). This is not true, however, if your code is taking advantage of vectorized SSE instructions, which do either 4 single or 2 double operations in parallel.

If not, then your main speed hit by switching your app from float to double will be in the increased memory bandwidth.

like image 119
Oliver Charlesworth Avatar answered Sep 28 '26 15:09

Oliver Charlesworth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!