Skip to content

fix: correct SVE accelerator bugs in shufti, truffle, and noodle#377

Open
byeonguk-jeong wants to merge 3 commits intoVectorCamp:developfrom
AhnLab-OSSG:sve-fix
Open

fix: correct SVE accelerator bugs in shufti, truffle, and noodle#377
byeonguk-jeong wants to merge 3 commits intoVectorCamp:developfrom
AhnLab-OSSG:sve-fix

Conversation

@byeonguk-jeong
Copy link

Summary

Fix three bugs affecting SVE/SVE2 accelerator code paths, with regression tests for truffle.

Bug Fixes

shufti-double: false positive on vector boundary

Use predicate mask to prevent false positives when scanning double shufti across vector boundaries.

truffle: off-by-one in rtruffleExecSVE tail

Fix off-by-one error in reverse truffle SVE tail processing. Includes comprehensive unit tests covering forward/reverse edge cases, varying lengths, alignment sweep, high-byte characters, and NUL matching.

noodle SVE: incorrect return types and scan length

  • Change return type from hwlmcb_rv_t to hwlm_error_t to match actual function signatures.
  • Fix scanDouble short-path condition to use (e - d) instead of scan_len, which could be stale after adjusting d for history.
  • Fix signedness mismatch in the pointer distance comparison.
  • Fix formatting: add space after if keyword.

Commits

  • f58f253 shufti-double: use predicate mask to prevent false positives
  • 6d8becc truffle: fix off-by-one in rtruffleExecSVE tail and add unit tests
  • 2414ae9 hwlm: correct return types and scan length in SVE noodle engine

Files Changed

  • src/nfa/shufti_sve.hpp
  • src/nfa/truffle_simd.hpp
  • src/hwlm/noodle_engine_sve.hpp
  • unit/internal/truffle.cpp
  • unit/internal/shufti.cpp

@AhnLab-OSS @AhnLab-OSSG

doubleMatched() in shufti_sve.hpp used svptrue_b8() for the final
comparison instead of the caller-provided predicate pg. When called
from dshuftiOnce() with a partial predicate (buffer shorter than SVE
vector length), inactive lanes loaded as zero could satisfy the match
condition, producing false positive matches.

Changed the return statement to use pg for both svnot_z and svcmpeq,
ensuring inactive lanes are excluded from match results.

Added 5 unit tests covering short/variable-length buffers with
null-byte pair patterns and mixed single/double-byte patterns to
catch regressions.

Fixes: 60b2112 ("Use SVE for double shufti")

Signed-off-by: Byeonguk Jeong <jungbu2855@gmail.com>
Fix a bug in rtruffleExecSVE where the tail processing for short
buffers used svwhilele_b8 instead of svwhilelt_b8. svwhilele_b8(0, N)
activates lanes 0..N (N+1 lanes), reading one byte past the buffer
end. The forward path (truffleExecSVE) already correctly uses
svwhilelt_b8, which activates lanes 0..N-1 (N lanes).

Add 26 new unit tests for the truffle accelerator covering:
- Compile roundtrip: character ranges, empty class, same-nibble chars
- Forward exec: single byte buffers, high byte (>=0x80) matching,
  same-nibble non-match, NUL char, dot (all chars), buffer-end match,
  varying lengths (1-130), alignment sweep, multi-char classes,
  all 256 single-char classes, 0x7F/0x80 boundary
- Reverse exec: single byte, high byte, NUL, buffer-start match,
  varying lengths, large buffer (4K), alignment sweep, all 256
  single-char classes, multiple matches, boundary chars

Fixes: c67076c ("Add truffle SVE implementation")

Signed-off-by: Byeonguk Jeong <jungbu2855@gmail.com>
- Change return type from hwlmcb_rv_t to hwlm_error_t to match the
  actual return type of checkMatched() and singleCheckMatched()
- Fix scanDouble short-path condition: use (e - d) instead of scan_len
  which could be stale after adjusting d for history
- Fix formatting: add space after 'if' keyword

Fixes: 0ba1cbb ("Add SVE2 support for noodle")
Fixes: b233221 ("Remove possibly undefined behaviour from Noodle.")

Signed-off-by: Byeonguk Jeong <jungbu2855@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant