Add an IndexByte implementation useful for benchmarking against stdlib SIMD implementation

This commit is contained in:
Kovid Goyal
2024-03-07 09:36:40 +05:30
parent 9ea0dde469
commit 47fea26b62
4 changed files with 71 additions and 0 deletions

View File

@@ -219,6 +219,26 @@ func TestSIMDStringOps(t *testing.T) {
c0tests("afsgdfg\x7f")
c0tests("afgd\x1bfgd\t")
c0tests("a\x00")
index_test := func(haystack []byte, needle byte) {
var actual int
expected := index_byte_scalar(haystack, needle)
for _, sz := range sizes {
switch sz {
case 16:
actual = index_byte_asm_128(haystack, needle)
case 32:
actual = index_byte_asm_256(haystack, needle)
}
if actual != expected {
t.Fatalf("index failed in: %#v (%d != %d) at size: %d with needle: %#v", string(haystack), expected, actual, sz, needle)
}
}
}
index_test([]byte("abc"), 'x')
index_test([]byte("abc"), 'b')
}
func TestIntrinsics(t *testing.T) {