]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: optimize bvec routines
authorJosh Bleecher Snyder <josharian@gmail.com>
Mon, 30 Apr 2018 15:42:03 +0000 (08:42 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Tue, 1 May 2018 13:34:56 +0000 (13:34 +0000)
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 <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/bv.go

index 03c4b9d8297366a0e44e03d090a0ecc98de190a9..21f6f4f246311101dee2c6fc853d95d3b6ee882e 100644 (file)
@@ -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]
        }