-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
374 - Did you know about C++26 simd proposal (2/N)?
- Loading branch information
1 parent
80f4f0a
commit 23a8940
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<details open><summary>Info</summary><p> | ||
|
||
* **Did you know about C++26 simd proposal (2/N)?** | ||
|
||
* https://wg21.link/P1928 | ||
|
||
</p></details><details open><summary>Example</summary><p> | ||
|
||
```cpp | ||
int main() { | ||
std::array<char, 8> storage{1, 2, 3, 4, 5, 6, 7, 8}; | ||
std::experimental::fixed_size_simd<char, 8> data{storage.begin(), std::experimental::element_aligned}; | ||
std::experimental::fixed_size_simd_mask<char, 8> values = (data == 7); | ||
std::cout << std::experimental::any_of(values) << std::endl; | ||
} | ||
``` | ||
|
||
> https://godbolt.org/z/3389qGWh6 | ||
</p></details><details open><summary>Puzzle</summary><p> | ||
|
||
* **Can you implement function find which returns { true: if given element is found; false: otherwise }?** | ||
|
||
```cpp | ||
template<class T, auto Size> | ||
auto find(const std::array<T, Size>& data, const T value); // TODO | ||
|
||
int main() { | ||
using namespace ut; | ||
|
||
"simd.find"_test = []() mutable { | ||
expect(true_b == find(std::array{1, 2, 3, 4}, 1)); | ||
expect(true_b == find(std::array{1, 2, 3, 4}, 2)); | ||
expect(true_b == find(std::array{1, 2, 3, 4}, 3)); | ||
expect(true_b == find(std::array{1, 2, 3, 4}, 4)); | ||
expect(false_b == find(std::array{1, 2, 3, 4}, 0)); | ||
expect(false_b == find(std::array{1, 2, 3, 4}, 6)); | ||
}; | ||
} | ||
``` | ||
> https://godbolt.org/z/9hqq1nq6z | ||
</p></details> | ||
</p></details><details><summary>Solutions</summary><p> | ||
```cpp | ||
template<class T, auto Size> | ||
auto find(const std::array<T, Size>& data, const T value) { | ||
const std::experimental::fixed_size_simd<T, Size> lhs{data.begin(), std::experimental::element_aligned}; | ||
return std::experimental::any_of(lhs == value); | ||
} | ||
``` | ||
|
||
> https://godbolt.org/z/KGPhvM3bY | ||
|
||
</p></details> |