github.com/primecitizens/pcz/std@v0.2.1/core/bytealg/index_s390x.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 4 //go:build pcz && s390x 5 6 package bytealg 7 8 import ( 9 "github.com/primecitizens/pcz/std/core/cpu" 10 ) 11 12 const ( 13 MaxBruteForce = 64 14 ) 15 16 var ( 17 hasVX bool 18 // indexArgBMaxLen is the maximum length of the string to be searched for (argument b) in Index. 19 // If indexArgBMaxLen is not 0, make sure indexArgBMaxLen >= 4. 20 indexArgBMaxLen int 21 ) 22 23 func init() { 24 // Note: we're kind of lucky that this flag is available at this point. 25 // The runtime sets HasVX when processing auxv records, and that happens 26 // to happen *before* running the init functions of packages that 27 // the runtime depends on. 28 // TODO: it would really be nicer for core/cpu to figure out this 29 // flag by itself. Then we wouldn't need to depend on quirks of 30 // early startup initialization order. 31 32 hasVX = cpu.S390X.HasAll(S390xFeature_vx) 33 if hasVX { 34 indexArgBMaxLen = 64 35 } 36 } 37 38 // cutover reports the number of failures of IndexByte we should tolerate 39 // before switching over to Index. 40 // n is the number of bytes processed so far. 41 // See the bytes.Index implementation for details. 42 func cutover(n int) int { 43 // 1 error per 8 characters, plus a few slop to start. 44 return (n + 16) / 8 45 }