Skip to content

Commit

Permalink
implement has_tabs_or_newline in Arm SVE
Browse files Browse the repository at this point in the history
  • Loading branch information
wx257osn2 committed Jun 4, 2023
1 parent a0fee5e commit 13e790b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 4 additions & 0 deletions include/ada/common_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ namespace ada {
#define ADA_SSE2 1
#endif

#if defined(__ARM_FEATURE_SVE)
#define ADA_SVE 1
#endif

#if defined(__aarch64__) || defined(_M_ARM64)
#define ADA_NEON 1
#endif
Expand Down
25 changes: 23 additions & 2 deletions src/unicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ ADA_PUSH_DISABLE_ALL_WARNINGS
ADA_POP_DISABLE_WARNINGS

#include <algorithm>
#if ADA_NEON
#if ADA_SVE
#include <arm_sve.h>
#elif ADA_NEON
#include <arm_neon.h>
#elif ADA_SSE2
#include <emmintrin.h>
Expand Down Expand Up @@ -44,7 +46,26 @@ constexpr bool to_lower_ascii(char* input, size_t length) noexcept {
}
return non_ascii == 0;
}
#if ADA_NEON
#if ADA_SVE
ada_really_inline bool has_tabs_or_newline(
std::string_view user_input) noexcept {
const svuint8_t mask1 = svdup_n_u8('\r');
const svuint8_t mask2 = svdup_n_u8('\n');
const svuint8_t mask3 = svdup_n_u8('\t');
svbool_t running = svdup_n_b8(false);
const size_t lanes = svcntb();
for (size_t i = 0; i < user_input.size(); i += lanes) {
const svbool_t mask = svwhilelt_b8_u64(i, user_input.size());
svuint8_t word = svld1_u8(mask, (const uint8_t*)user_input.data() + i);
running = svorr_b_z(mask,
svorr_b_z(mask, running,
svorr_b_z(mask, svcmpeq_u8(mask, word, mask1),
svcmpeq_u8(mask, word, mask2))),
svcmpeq_u8(mask, word, mask3));
}
return svptest_any(running);
}
#elif ADA_NEON
ada_really_inline bool has_tabs_or_newline(
std::string_view user_input) noexcept {
size_t i = 0;
Expand Down

0 comments on commit 13e790b

Please sign in to comment.