From 60c76f7656f24074b7708369c1628835c89118da Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Mon, 30 Apr 2018 08:42:03 -0700 Subject: [PATCH] cmd/compile: optimize bvec routines MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The recent improvements to the prove pass make it possible to provide bounds hints to the compiler in some bvec routines. This speeds up the compilation of the code in name old time/op new time/op delta Pkg 7.93s ± 4% 7.69s ± 3% -2.98% (p=0.000 n=29+26) While we're here, clean up some C-isms. Updates #13554 Updates #20393 Change-Id: I47a0ec68543a9fc95c5359c3f37813fb529cb4f0 Reviewed-on: https://go-review.googlesource.com/110560 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/gc/bv.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/cmd/compile/internal/gc/bv.go b/src/cmd/compile/internal/gc/bv.go index 03c4b9d829..21f6f4f246 100644 --- a/src/cmd/compile/internal/gc/bv.go +++ b/src/cmd/compile/internal/gc/bv.go @@ -118,8 +118,8 @@ func (bv bvec) Next(i int32) int32 { } func (bv bvec) IsEmpty() bool { - for i := int32(0); i < bv.n; i += wordBits { - if bv.b[i>>wordShift] != 0 { + for _, x := range bv.b { + if x != 0 { return false } } @@ -127,15 +127,18 @@ func (bv bvec) IsEmpty() bool { } func (bv bvec) Not() { - i := int32(0) - w := int32(0) - for ; i < bv.n; i, w = i+wordBits, w+1 { - bv.b[w] = ^bv.b[w] + for i, x := range bv.b { + bv.b[i] = ^x } } // union func (dst bvec) Or(src1, src2 bvec) { + if len(src1.b) == 0 { + return + } + _, _ = dst.b[len(src1.b)-1], src2.b[len(src1.b)-1] // hoist bounds checks out of the loop + for i, x := range src1.b { dst.b[i] = x | src2.b[i] } @@ -143,6 +146,11 @@ func (dst bvec) Or(src1, src2 bvec) { // intersection func (dst bvec) And(src1, src2 bvec) { + if len(src1.b) == 0 { + return + } + _, _ = dst.b[len(src1.b)-1], src2.b[len(src1.b)-1] // hoist bounds checks out of the loop + for i, x := range src1.b { dst.b[i] = x & src2.b[i] } @@ -150,6 +158,11 @@ func (dst bvec) And(src1, src2 bvec) { // difference func (dst bvec) AndNot(src1, src2 bvec) { + if len(src1.b) == 0 { + return + } + _, _ = dst.b[len(src1.b)-1], src2.b[len(src1.b)-1] // hoist bounds checks out of the loop + for i, x := range src1.b { dst.b[i] = x &^ src2.b[i] } -- 2.50.0