Google Highway based FOSS FFT library

For MSVC, we recommend compiling with /Gv to allow non-inlined functions to pass vector arguments in registers. If intending to use the AVX2 target together with half-width vectors (e.g. for PromoteTo), it is also important to compile with /arch:AVX2. This seems to be the only way to reliably generate VEX-encoded SSE instructions on MSVC. Sometimes MSVC generates VEX-encoded SSE instructions, if they are mixed with AVX, but not always, see DevCom-10618264. Otherwise, mixing VEX-encoded AVX2 instructions and non-VEX SSE may cause severe performance degradation. Unfortunately, with /arch:AVX2 option, the resulting binary will then require AVX2. Note that no such flag is needed for clang and GCC because they support target-specific attributes, which we use to ensure proper VEX code generation for AVX2 targets.

Previously I directly quoted it, which is from Google Highway README.

So if I understand it correctly, if Highway & dynamic dispatch to SSE2/AVX2 & MSVC, lots of 128-bit operations will be emitted as non-VEX SSE instructions, mixed with AVX instructions. zldsp::fft, unfortunately, are using 128-bit operations in multiple functions (and I am not sure whether there are some 128-bit ops hidden in Highway implementations :innocent: )

A different dispatch method (I call it separate dispatch, i.e., two version are compiled with different flags independently, so it is actually static dispatch with a runtime selection) is added as an example.

Thanks to Github actions, I am able to run a benchmark experiment with different MSVC versions:

MSVC 19.44.35229.0; clang-cl 20.1.8

  • For MSVC, no practical difference between dynamic & separate dispatch
  • For clang-cl, no practical difference between dynamic & separate dispatch
  • MSVC version is approximately 10%~20% slower than clang-cl version

MSVC 19.51.36260.0; clang-cl 20.1.8

  • For MSVC, separate dispatch is up to 8x faster than dynamic dispatch
  • For clang-cl, still no practical difference between dynamic & separate dispatch
  • MSVC (separate version) is on par with clang-cl version

I would call it as a bug of MSVC.

Given the current results, I would suggest using clang-cl if possible. And if MSVC is a must, building separate versions for different targets.

Very interesting, so according to your results dynamic dispatch actually works fine MSVC 19.44 but is severely broken in 19.51.
They’re going to release 19.52 soon, which comes with a rather impressive list of optimizations, codegen and regression fixes: MSVC Build Tools Version 14.52 Release Candidate Now Available - C++ Team Blog

Hopefully this fixes the issues, if not it would be a good idea to post on their forum to alert them of the situation, as this is rather severe and probably affects a lot of other people’s code too.

MSVC is rather ubiqitous on Windows I’m afraid, one could always build with MSVC + clang but then I’m not sure all libraries support this (e.g. AAX etc)

Hopefully they could fix the issue, as I do find several AVX2 keywords there … I will keep an eye on that, but cannot give any promise. I would guess the bug also affect intrinsic instructions.

Anyway, for MSVC users, I would recommend the separate dispatch. It works just like dynamic dispatch but with a VERY ugly cmake to build SSE2/AVX2 separately.

I will update the website and README accordingly later.

We build all our recent releases with vanilla clang 20 installed via choco (so not clang-cl bundled with Visual Studio) on Windows, which just works out of the box. The primary reason for that was a massive performance boost that we noticed in some dsp code with hand rolled SIMD loops, another is that build times are sometimes twice as quick compared to MSVC which especially pays out for CI resource usage. The AAX libraries compile without issues using clang. We ran into some edge cases with copy protection systems we use that seem to rely on the MSVC linker so we compile with clang and link with the MSVC linker, which is not difficult to set up thanks to CMake.