Source file src/internal/bytealg/index_loong64.go
1 // Copyright 2025 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package bytealg 6 7 import "internal/cpu" 8 9 // Empirical data shows that using Index can get better 10 // performance when len(s) <= 16. 11 const MaxBruteForce = 16 12 13 func init() { 14 // If SIMD is supported, optimize the cases where the substring length is less than 64 bytes, 15 // otherwise, cases the length less than 32 bytes is optimized. 16 if cpu.Loong64.HasLASX || cpu.Loong64.HasLSX { 17 MaxLen = 64 18 } else { 19 MaxLen = 32 20 } 21 } 22 23 // Cutover reports the number of failures of IndexByte we should tolerate 24 // before switching over to Index. 25 // n is the number of bytes processed so far. 26 // See the bytes.Index implementation for details. 27 func Cutover(n int) int { 28 // 1 error per 8 characters, plus a few slop to start. 29 return (n + 16) / 8 30 } 31