Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio VC2013 enabling SSE4.1 without AVX

Tags:

visual-c++

I have a rather simple question, but after searching quite some time I found no real answer yet. Microsoft suggests to enable AVX enhanced instruction set in order to also make use of SSE4 optimized code. Unfortunately, despite some readings, this enforces also use of an AVX capable CPU. Is there a way known to enable SSE4 without enforcing AVX in VC2013? Background of this question is obvious I think, SSE4 is longer supported and only requires older CPU's (first from 2006 I think), while AVX requires CPU's from 2011. The dll in question only uses optimizations for SSE4, but for now I have to stick with SSE2 sacrificing performance in order to keep it working.

like image 216
Gnampf Avatar asked Sep 27 '22 22:09

Gnampf


1 Answers

It seems that /arch:SSE2 flag adds support for SSE2 and later intrinsics. I don't have Visual Studio installed but this example works(_mm_floor_ps is SSE4 specific) :

#include <smmintrin.h>
#include <iostream>
using namespace std;

int main()
{
    __declspec(align(16)) float values[4] = {1.3f, 2.1f, 4.3f, 5.1f};
    for(int i = 0; i < 4; i++)
        cout << values[i] << ' ';
    cout << endl;

    __m128 x = _mm_load_ps(values);
    x = _mm_floor_ps(x);
    _mm_store_ps(values, x);

   for(int i = 0; i < 4; i++)
        cout << values[i] << ' ';
    cout << endl;
}

You can try it online here.Compile result

like image 98
Nazar554 Avatar answered Sep 30 '22 08:09

Nazar554