-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d37461
commit 3d85d28
Showing
5 changed files
with
156 additions
and
6 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
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
62 changes: 62 additions & 0 deletions
62
include/eve/module/core/regular/impl/simd/arm/sve/first_true.hpp
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,62 @@ | ||
//================================================================================================== | ||
/* | ||
EVE - Expressive Vector Engine | ||
Copyright : EVE Project Contributors | ||
SPDX-License-Identifier: BSL-1.0 | ||
*/ | ||
//================================================================================================== | ||
#pragma once | ||
|
||
namespace eve::detail | ||
{ | ||
|
||
// There are some explanations | ||
// Here: https://lemire.me/blog/2022/12/19/implementing-strlen-using-sve/ | ||
// Or: https://www.stonybrook.edu/commcms/ookami/support/_docs/5%20-%20Advanced%20SVE.pdf | ||
template<relative_conditional_expr C, logical_simd_value L> | ||
EVE_FORCEINLINE std::optional<std::ptrdiff_t> | ||
first_true_(EVE_SUPPORTS(sve_), C c, L m) noexcept | ||
{ | ||
if constexpr( C::is_complete && !C::is_inverted ) return std::nullopt; | ||
else if constexpr( has_aggregated_abi_v<L> ) | ||
{ | ||
if constexpr( !C::is_complete ) m = m && sve_true(c, as(m)); | ||
auto [lo, hi] = m.slice(); | ||
auto lo_res = first_true[ignore_none](lo); | ||
auto hi_res = first_true[ignore_none](hi); | ||
if( lo_res ) return lo_res; | ||
if( hi_res ) *hi_res += lo.size(); | ||
return hi_res; | ||
} | ||
else | ||
{ | ||
auto c_m = L {sve_true(c, eve::as(m))}; | ||
|
||
// We don't need this much but it makes the `no matches` case | ||
// faster | ||
if( !svptest_any(c_m, m) ) return std::nullopt; | ||
|
||
// we need to ignore as false | ||
if constexpr( !C::is_complete ) m = m && c_m; | ||
|
||
eve::as_wide_t<eve::element_type_t<L>> first_true_mask = | ||
svbrkb_z(sve_true<element_type_t<L>>(), m); | ||
return count_true(first_true_mask); | ||
} | ||
} | ||
|
||
template<logical_simd_value L> | ||
EVE_FORCEINLINE std::optional<std::ptrdiff_t> | ||
first_true_(EVE_SUPPORTS(sve_), L m) noexcept | ||
{ | ||
return first_true[ignore_none](m); | ||
} | ||
|
||
template<logical_simd_value L> | ||
EVE_FORCEINLINE std::optional<std::ptrdiff_t> | ||
first_true_(EVE_SUPPORTS(sve_), top_bits<L> m) noexcept | ||
{ | ||
return first_true(to_logical(m)); | ||
} | ||
|
||
} |
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,28 @@ | ||
#include <eve/module/core.hpp> | ||
#include <tts/tts.hpp> | ||
|
||
using w_t = eve::wide<int, eve::fixed<4>>; | ||
|
||
int main() | ||
{ | ||
w_t x = {1, 2, 3, 4}; | ||
|
||
// logicals | ||
|
||
TTS_EQUAL(std::nullopt, eve::first_true(x == 0)); | ||
TTS_EQUAL(0, eve::first_true(x == 1)); | ||
TTS_EQUAL(1, eve::first_true(x == 2)); | ||
|
||
TTS_EQUAL(std::nullopt, eve::first_true[eve::ignore_first(1)](x == 1)); | ||
TTS_EQUAL(2, eve::first_true[eve::ignore_first(2)](x < 5)); | ||
|
||
// top_bits | ||
|
||
eve::top_bits mmask{x >= 2}; | ||
TTS_EQUAL(1, eve::first_true(mmask)); | ||
|
||
// scalar | ||
|
||
TTS_EQUAL(std::nullopt, eve::first_true(false)); | ||
TTS_EQUAL(0, eve::first_true(true)); | ||
} |