From 128a0785cd83490069dfb5c1d845bf3944323dd9 Mon Sep 17 00:00:00 2001 From: Yoan Picchi Date: Thu, 5 Jun 2025 11:13:39 +0000 Subject: [PATCH] Add regression test for double shufti It tests for false positive at vector edges. Signed-off-by: Yoan Picchi --- unit/internal/shufti.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/unit/internal/shufti.cpp b/unit/internal/shufti.cpp index 9adcac8b..e7d8532f 100644 --- a/unit/internal/shufti.cpp +++ b/unit/internal/shufti.cpp @@ -903,6 +903,34 @@ TEST(DoubleShufti, ExecMatchMixed3) { } } +// Double shufti used to report matches when the first char of a pair landed at +// the end of a vector. This test check for the regression. +TEST(DoubleShufti, ExecNoMatchVectorEdge) { + m128 lo1, hi1, lo2, hi2; + + flat_set> lits; + + lits.insert(make_pair('a','c')); + + bool ret = shuftiBuildDoubleMasks(CharReach(), lits, reinterpret_cast(&lo1), reinterpret_cast(&hi1), + reinterpret_cast(&lo2), reinterpret_cast(&hi2)); + ASSERT_TRUE(ret); + + const int len = 80; + char t1[len + 1]; + memset(t1, 'b', len); + + for (size_t i = 0; i < 70; i++) { + t1[len - i] = 'a'; + t1[len - i + 1] = 'b'; + DEBUG_PRINTF("i = %ld\n", i); + const u8 *rv = shuftiDoubleExec(lo1, hi1, lo2, hi2, + reinterpret_cast(t1), reinterpret_cast(t1) + len); + + ASSERT_EQ(reinterpret_cast(t1 + len), rv); + } +} + TEST(ReverseShufti, ExecNoMatch1) { m128 lo, hi;