I want to design a function that uses SIMD(AVX2, AVX512, NEON) to speed up the calculation. And I want to make it cross-platform available. Thus it is necessary to detect which platform the user is on. Is there any possible way to implement it? I know that #ifdef
maybe useful to implement it, but I don't know what macro can be used. Please help.
Asked
Active
Viewed 62 times
0

233
- 77
- 4
-
It works the other way around. You are telling the *compiler* which architecture and instruction set you *want* it to compile for. How you decide this - is outside of the compiler paygrade. – Eugene Sh. Oct 13 '21 at 14:00
-
You may want to look at [DirectXMath](https://github.com/Microsoft/DirectXMath) which does some of this. For Visual C++ and MSVC-like clang/LLVM, ``__AVX2__``, ``__AVX__`` tell you if ``/arch:AVX2`` or ``/arch:AVX`` was specified. With ``/arch:AVX512`` (requires VS 2019 16.3 or later), you get ``__AVX512F__``, ``__AVX512CD__``, ``__AVX512BW__``, ``__AVX512DQ__`` and ``__AVX512VL__``. – Chuck Walbourn Oct 14 '21 at 20:24
-
For ARM, there's a lot of variability because a lot of detail is left up to each implementer. You can at least count on ARM-NEON being supported for ARM64 indicated by: ``_M_ARM64`` and ``_M_ARM64EC`` on Visual C++, ``__aarch64__`` for clang/LLVM and GNUC. – Chuck Walbourn Oct 14 '21 at 20:28