4 ms·
Say hello to Function Multi-versioning [0]. You tell the compiler to build a version for each march defined in the attribute. When that function is called a qui
by giantrobot 6y ago
Say hello to Function Multi-versioning [0]. You tell the compiler to build a version for each march defined in the attribute. When that function is called a quick CPU check (via CPUID) is performed and if there's a version specific to the current CPU that will run instead of the more general implementation. ICC has supported this for a long time and it's widely used in Intel's MKL.
LLVM also supports FMV but uses a slightly different method to define it in code. IIRC there was an LLVM issue tracking work to support GCC's way of declaring FMV but I don't know if that landed yet.
Since the function's signature is the same between the multiple implementations the caller doesn't need to change of their code to get a free boost from features like AVX2 or these M1 instructions. When an M2 comes out with better vector instructions or something and a new Accelerate framework is released, anyone using the framework get a free performance increase without recompiling anything.
[0] https://lwn.net/Articles/691932/ https://lwn.net/Articles/691932/
- floatboth 6y agoAt least __attribute__((ifunc(..))) is common between clang and gcc. (E.g. no compiler conditionals are used in https://cgit.freebsd.org/src/tree/sys/arm64/include/ifunc.h https://cgit.freebsd.org/src/tree/sys/arm64/include/ifunc.h) The fancier high level stuff that automatically compiles multiple versions of a function, I'm not sure.
- saagarjha 6y agoNote that on ARM it is more annoying to get CPU capabilities as there is no straight cpuid equivalent.
- stephencanon 6y agoOn Apple platforms, CPU capabilities are cached on the commpage, so system libraries don’t even need to use cpuid on x86.