简体   繁体   中英

Visual Studio VC2013 enabling SSE4.1 without AVX

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.

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 . 编译结果

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM