-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimd_example.cpp
More file actions
29 lines (23 loc) · 874 Bytes
/
Copy pathsimd_example.cpp
File metadata and controls
29 lines (23 loc) · 874 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <simd>
#include "example_support.hpp"
#include <iostream>
int main() {
std::simd::vec<float, 4> left([](auto index) {
return static_cast<float>(decltype(index)::value + 1);
});
std::simd::vec<float, 4> right([](auto index) {
return static_cast<float>(4 - decltype(index)::value);
});
const auto sum = left + right;
const auto greater = left > right;
forge_example::require(sum[0] == 5.0f);
forge_example::require(sum[1] == 5.0f);
forge_example::require(sum[2] == 5.0f);
forge_example::require(sum[3] == 5.0f);
forge_example::require(std::simd::reduce_count(greater) == 2);
std::cout << "sum = {"
<< sum[0] << ", " << sum[1] << ", "
<< sum[2] << ", " << sum[3] << "}\n";
std::cout << "greater lanes = " << std::simd::reduce_count(greater) << '\n';
return 0;
}