Auto-Vectorize comparison

前端 未结 1 1646
刺人心
刺人心 2020-12-21 10:51

I\'ve problems getting my g++ 5.4 use vectorization for comparison. Basically I want to compare 4 unsigned ints using vectorization. My first approach was straight forward:<

相关标签:
1条回答
  • 2020-12-21 11:15

    Okay, apparently the compiler does not like "unrolled loops". This works for me:

    bool compare(signed int const pX[8]) {
        signed int const w[] __attribute__((aligned(32))) = {1,2,3,4,5,6,7,8};
        signed int out[8] __attribute__((aligned(32)));
    
        for (unsigned int i = 0; i < 8; ++i) {
            out[i] = (pX[i] <= w[i]);
        }
    
        bool temp = true;
        for (unsigned int i = 0; i < 8; ++i) {
            temp = temp && out[i];
            if (!temp) {
                return false;
            }
        }
        return true;
    }
    

    Please note, that out is also a signed int. Now I'll just need a fast way to combine the result saved in out

    0 讨论(0)
提交回复
热议问题