Skip to content

Commit

Permalink
cmd/compile: optimize bvec routines
Browse files Browse the repository at this point in the history
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 <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Matthew Dempsky <[email protected]>
  • Loading branch information
josharian committed May 1, 2018
1 parent d91e970 commit 60c76f7
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/cmd/compile/internal/gc/bv.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,38 +118,51 @@ 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
}
}
return true
}

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]
}
}

// 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]
}
}

// 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]
}
Expand Down

0 comments on commit 60c76f7

Please sign in to comment.