Skip to content

Commit

Permalink
Add tests and small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaraslaut committed Nov 10, 2024
1 parent aadecbb commit bae48fc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/libunicode/scan_simd_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ size_t scan_for_text_ascii_simd(std::string_view text, size_t maxColumnCount) no
auto const is_control_mask = intrinsics::less(batch, vec_control);
auto const is_complex_mask = intrinsics::equal(intrinsics::and_vec(batch, vec_complex), vec_complex);
auto const ctrl_or_complex_mask = intrinsics::or_mask(is_control_mask, is_complex_mask);
if (is_control_mask)
if (ctrl_or_complex_mask)
{
int const advance = trailing_zero_count(intrinsics::to_unsigned(ctrl_or_complex_mask));
input += advance;
Expand Down
33 changes: 29 additions & 4 deletions src/libunicode/scan_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,26 @@ TEST_CASE("scan.ascii.empty")
}

TEST_CASE("scan.ascii.32")
{
auto const text = "0123456789ABCDEF0123456789ABCDEF"sv;
CHECK(scan_for_text_ascii(text, 32) == 32);
CHECK(scan_for_text_ascii(text, 16) == 16);
CHECK(scan_for_text_ascii(text, 8) == 8);
CHECK(scan_for_text_ascii(text, 1) == 1);
}

TEST_CASE("scan.ascii.64")
{
auto const text = "0123456789ABCDEF0123456789ABCDEF"
"0123456789ABCDEF0123456789ABCDEF"sv;
CHECK(scan_for_text_ascii(text, 64) == 64);
CHECK(scan_for_text_ascii(text, 32) == 32);
CHECK(scan_for_text_ascii(text, 16) == 16);
CHECK(scan_for_text_ascii(text, 8) == 8);
CHECK(scan_for_text_ascii(text, 1) == 1);
}

TEST_CASE("scan.ascii.128")
{
auto const text = "0123456789ABCDEF0123456789ABCDEF"
"0123456789ABCDEF0123456789ABCDEF"
Expand All @@ -128,11 +148,16 @@ TEST_CASE("scan.ascii.mixed_with_controls")
CHECK(scan_for_text_ascii("12345678\033", 80) == 8);
CHECK(scan_for_text_ascii("0123456789ABCDEF\033", 80) == 16);
CHECK(scan_for_text_ascii("0123456789ABCDEF1\033", 80) == 17);
constexpr auto text = "0123456789ABCDEF0\033123456789ABCDEF"
"0123456789ABCDEF0123456789ABCDEF"
"0123456789ABCDEF0123456789ABCDEF"
"0123456789ABCDEF0123456789ABCDEF"sv;
auto text = "0123456789ABCDEF0\033123456789ABCDEF"
"0123456789ABCDEF0123456789ABCDEF"
"0123456789ABCDEF0123456789ABCDEF"
"0123456789ABCDEF0123456789ABCDEF"sv;
CHECK(scan_for_text_ascii(text, 80) == 17);
text = "0123456789ABCDEF0123456789ABCDEF"
"0123456789ABCDEF0123456789ABCDEF"
"0123456789ABCDEF0123456789ABCDEF"
"0123456789ABCDEF\0330123456789ABCDEF"sv;
CHECK(scan_for_text_ascii(text, 128) == 112);
}

TEST_CASE("scan.ascii.until_complex")
Expand Down

0 comments on commit bae48fc

Please sign in to comment.