Quick question: How do you tell a C compiler to use an instruction set extension only within specific code blocks, like:
if(processor_has_instruction)
//use instruction
else
//fallback code that won't be optimised to use instruction
Poke: @cmuratori
-
-
-
Replying to @cmuratori @NoHatCoder
[2/4] Put the code in a DLL, and have one version of the DLL for every architecture, then load the appropriate one at startup.
1 reply 0 retweets 4 likes -
Replying to @cmuratori @NoHatCoder
[3/4] Put the code in a separate file and compile that file n times, one for each arch, with a macro that changes the names of the function so you can pick which one you call.
1 reply 0 retweets 6 likes -
Replying to @cmuratori @NoHatCoder
[4/4] Compile the majority of the code with the minimum platform, but make separate versions of specific routines and decorate them with a compiler-specific prefix like "__attribute__ ((__target__("avx2")))" (CLANG).
1 reply 0 retweets 6 likes -
Replying to @cmuratori
Of course I'm asking because I wonder what we should do in Meow. Neither of the two first options seem particularly user-friendly for a library, third one should take care of GCC and Clang. Are there any good options in MSVC?
2 replies 0 retweets 1 like -
Replying to @NoHatCoder @cmuratori
the most cross-platform option is probably doing CPU detection during initialization and setting function pointers to the best version that the CPU supports. This prevents inlining, but that might not matter for your code https://attractivechaos.wordpress.com/2017/09/04/on-cpu-dispatch/ … https://gcc.gnu.org/wiki/FunctionMultiVersioning …
1 reply 0 retweets 0 likes
Again, the best thing here is to let the user decide. Inlining is important, so they may well want to compile their entire codebase n times, one per arch, and just use a loader where all it does is check the arch and then load the entire codebase compiler for that arch.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.