so recently my friend introduced me to intrinsics (AVX2 etc), and honestly, I've been busting my head nonstop how I could automate it at runtime. That is, to check if CPU has an instruction and if it does, it uses it, but if it doesn't it uses regular methods.
Ofc, since the point of it is optimization, I want to avoid ifs as much as possible.
My first idea was to write DLLs with and without intrinsics, and then in an init function I load appropriate DLL, which my friend said is a bad idea as it would be function pointers which would also have performance overhead.
Today I was talking to my friend and I asked him if it would be possible to at runtime replace a function with another function without the use of function pointers, and he mentioned self-modifyable code, but said he knows nothing about it.
So I was wondering, how would I do it?
eg. I have operator+ overload for __m256, and it calls _m256_add_ps, but in init function I want to replace it with a regular function that adds them sequentialy in case cpu doesn't support AVX2
ofc none of those info is know at compile time, which is the source of my problems