utf8/valid_support_amd64.go
raw| 1 | //go:build !purego |
| 2 | // +build !purego |
| 3 | |
| 4 | package utf8 |
| 5 | |
| 6 | import ( |
| 7 | "github.com/segmentio/asm/cpu" |
| 8 | "github.com/segmentio/asm/cpu/x86" |
| 9 | ) |
| 10 | |
| 11 | var noAVX2 = !cpu.X86.Has(x86.AVX2) |
| 12 | |
| 13 | // Validate is a more precise version of Valid that also indicates whether the |
| 14 | // input was valid ASCII. |
| 15 | func Validate(p []byte) Validation { |
| 16 | if noAVX2 || len(p) < 32 { |
| 17 | return validate(p) |
| 18 | } |
| 19 | r := validateAvx(p) |
| 20 | return Validation(r) |
| 21 | } |