Auto vectorization not working

后端 未结 2 641
名媛妹妹
名媛妹妹 2020-12-20 18:39

I\'m trying to get my code to auto vectorize, but it isn\'t working.

int _tmain(int argc, _TCHAR* argv[])
{
    const int N = 4096;
    float x[N];
    float         


        
2条回答
  •  没有蜡笔的小新
    2020-12-20 19:35

    One problem could be that your stack allocation isn't necessarily aligned by your compiler. If your compiler supports c++11 you could use:

    float x[N] alignas(16);
    float y[N] alignas(16);
    

    To explicitly get 16 byte aligned memory, which is required by most SSE operations.


    EDIT:

    Even if alignment isn't the issue and your compiler is vectorizing unaligned code you should make this optimization as unaligned SSE operations are very slow compared to their aligned counterparts.

提交回复
热议问题