From 0cff219c1279cb76f042004bffcefba0a169cb67 Mon Sep 17 00:00:00 2001 From: Ilya Tocar Date: Thu, 28 Apr 2016 17:39:55 +0300 Subject: strings: use AVX2 for Index if available MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/bytes/bytes_amd64.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/bytes/bytes_amd64.go') 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 { -- cgit v1.3-5-g9baa