gpt4 book ai didi

c++ - 如何编写编译器可以优化到 SIMD 比较的代码?

转载 作者:太空狗 更新时间:2023-10-29 23:11:49 25 4
gpt4 key购买 nike

<分区>

std::array<int, 4> a = {1, 1, 1, 1};
std::array<int, 4> b = { 1, 2, 3, 4 };
std::array<int, 4> c;
bool res = false;
for (int i = 0; i < a.size(); i++) {
a[i] = rand() % 10;
}

for (int i = 0; i < 4; i++) {
c[i] = a[i] + b[i];
}

智能编译器可以很好地将以上编译成SIMD。但是像下面这样写比较的也可以很好地编译成SIMD;

res = a[0] <= b[0] && a[1] <= b[1] && a[2] <= b[2] && a[3] <= b[3]; // not compile to SIMD

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com