| 1 |
// Adapted from the coregex project, https://github.com/coregx/coregex |
| 2 |
// (package simd), Copyright (c) 2025 Andrey Kolkov and contributors, |
| 3 |
// MIT License. See the LICENSE file in this directory for the full text. |
| 4 |
|
| 5 |
//go:build amd64 |
| 6 |
|
| 7 |
package simd |
| 8 |
|
| 9 |
// Assembly kernels implemented in memchr_class_amd64.s. Class membership |
| 10 |
// is computed with a pair of VPSHUFB nibble lookups instead of one |
| 11 |
// clamp-and-compare per range, and four 32-byte vectors are classified per |
| 12 |
// iteration. |
| 13 |
// |
| 14 |
//go:noescape |
| 15 |
func memchrWordAVX2(haystack []byte) int |
| 16 |
|
| 17 |
//go:noescape |
| 18 |
func memchrNotWordAVX2(haystack []byte) int |
| 19 |
|
| 20 |
// memchrWordImpl dispatches to the AVX2 kernel for inputs large enough to |
| 21 |
// amortize the vector setup. The caller guarantees a non-empty haystack. |
| 22 |
func memchrWordImpl(haystack []byte) int { |
| 23 |
if hasAVX2 && len(haystack) >= MinLen { |
| 24 |
return memchrWordAVX2(haystack) |
| 25 |
} |
| 26 |
return memchrWordGeneric(haystack) |
| 27 |
} |
| 28 |
|
| 29 |
// memchrNotWordImpl dispatches like memchrWordImpl. |
| 30 |
func memchrNotWordImpl(haystack []byte) int { |
| 31 |
if hasAVX2 && len(haystack) >= MinLen { |
| 32 |
return memchrNotWordAVX2(haystack) |
| 33 |
} |
| 34 |
return memchrNotWordGeneric(haystack) |
| 35 |
} |