
Searching for fast complex numbers in C99 and C++ - ingve
https://medium.com/@smcallis_71148/complex-arithmetic-is-complicated-873ec0c69fc5
======
tgb
I've always wondered how much is wasted supporting the full IEEE floating
point standard. How rare is it for a program to actually care about rounding
behavior and NaN and inf and whatever that support for tiny numbers is called?
Obviously medical imaging devices and physics simulations will need to stop
and do this properly but they can get special hardware. How much silicon goes
towards supporting that stuff in an i7? In a 1080?

I have no idea, but it sounds like a lot to me.

~~~
kdkkfcg
So, if you read the article you will learn the float handling is done in
software.

~~~
flavio81
Yes... but note that the final machine language code does use the processor
opcodes that handle floats: MULSS, MOVSS

[http://www.felixcloutier.com/x86/MULSS.html](http://www.felixcloutier.com/x86/MULSS.html)
[http://www.felixcloutier.com/x86/MOVSS.html](http://www.felixcloutier.com/x86/MOVSS.html)

So the final float multiplication is done by the hardware. What the software
does, is to (a) handle the complex number and convert it to floats, and
probably (b) handle the double precision using single precision x86 opcodes.

------
s__mac
I submitted a bug report to GCC:

[https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81478](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81478)

Even though it's not a real bug, it's a missed optimization. My pitch is to
emit the code to do the multiplication, and only call a fixup function when
the results are NaN. If you short-circuit the NaN check, you only need 3
pretty cheap instructions to decide to call the standard library for help, and
you can avoid it in the vast vast majority of cases. This should make
multiplication and division much faster in the default case. Naturally the
checks would still be elided with -fcx-limited-range is on.

------
nwhitehead
> If you’re relying on c99 complex or std::complex and fast complex
> operations, and you don’t have -fcx-limited-range or -ffast-math turned on,
> you should probably consider this a bug in your project.

I would rephrase this as, "If you care about floating point performance and
have not investigated the compiler flags related to floating point
performance, consider this a bug in your project."

------
jwilk
Archived copy, which works with JS disabled:

[https://archive.is/n4r9C](https://archive.is/n4r9C)

------
flavio81
Nice to know that there is a big performance jump when using the latest g++
compiler!

