问题
I've read this LWN article with great interest. Executive summary: GCC 6.x supports something called function multi-versioning which builds multiple versions of the same function, optimized for different instruction sets. Let's say you have a machine with AVX2 support and one without. It's possible to run the same binary on both, with function foo() existing in two versions, one of which uses AVX2 instructions. The function with the AVX2 instructions are, however, only called if the CPU supports it.
My question is: does clang support something similar? It doesn't seem like the most advanced feature in the world.
回答1:
LLVM 7 supports function multiversioning using the 'target' attribute for ELF-based x86/x86_64 targets.
'target_clones' has yet to land though.
来源:https://stackoverflow.com/questions/39958935/does-clang-offer-anything-similar-to-gcc-6-xs-function-multi-versioning-target