I want to write math function with SSE instructions in the VS2017. I could try it:
__m128 addWithIntrinsics(__m128 a, __m128 b)
{
__m128 r = _mm_add_ps(a, b);
return r;
}
__m128 addWithAssembly(__m128 a, __m128 b)
{
__m128 r;
__asm
{
movaps xmm0, xmmword ptr[a]
movaps xmm1, xmmword ptr[b]
addps xmm0, xmm1
movaps xmmword ptr[r], xmm0
}
return r.
}
But I’m not sure ... If I write mathematical operations like this, will this code be cross-platform (in terms of working only on Windows, but on different processors and those that do not support SSE), or will I need to determine at the compilation stage whether Processor these instructions and if not then use the usual? What is the best way for me to do this, and which of my two variants is preferable?