aboutsummaryrefslogtreecommitdiff
path: root/src/bytes
diff options
context:
space:
mode:
authorIlya Tocar <ilya.tocar@intel.com>2016-04-28 17:39:55 +0300
committerIlya Tocar <ilya.tocar@intel.com>2016-09-07 10:43:13 +0000
commit0cff219c1279cb76f042004bffcefba0a169cb67 (patch)
treea929e6aaf14d9307523a72b278d053854676d7bb /src/bytes
parent83c73a85db84a04c8e60e52cfa348fc6b675fbf7 (diff)
downloadgo-0cff219c1279cb76f042004bffcefba0a169cb67.tar.xz
strings: use AVX2 for Index if available
IndexHard4-4 1.50ms ± 2% 0.71ms ± 0% -52.36% (p=0.000 n=20+19) This also fixes a bug, that caused a string of length 16 to use two 8-byte comparisons instead of one 16-byte. And adds a test for cases when partial_match fails. Change-Id: I1ee8fc4e068bb36c95c45de78f067c822c0d9df0 Reviewed-on: https://go-review.googlesource.com/22551 Run-TryBot: Ilya Tocar <ilya.tocar@intel.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/bytes')
-rw-r--r--src/bytes/bytes_amd64.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/bytes/bytes_amd64.go b/src/bytes/bytes_amd64.go
index b683e6721c..198962322a 100644
--- a/src/bytes/bytes_amd64.go
+++ b/src/bytes/bytes_amd64.go
@@ -9,7 +9,17 @@ package bytes
// indexShortStr returns the index of the first instance of c in s, or -1 if c is not present in s.
// indexShortStr requires 2 <= len(c) <= shortStringLen
func indexShortStr(s, c []byte) int // ../runtime/asm_$GOARCH.s
-const shortStringLen = 31
+func supportAVX2() bool // ../runtime/asm_$GOARCH.s
+
+var shortStringLen int
+
+func init() {
+ if supportAVX2() {
+ shortStringLen = 63
+ } else {
+ shortStringLen = 31
+ }
+}
// Index returns the index of the first instance of sep in s, or -1 if sep is not present in s.
func Index(s, sep []byte) int {