Skip to content

Commit dce0df2

Browse files
committed
cmd/compile/internal/gc: change bvfoo functions into bvec methods
plive.go (except for printeffects and livenessprintblock) and reflect.go changes were prepared mechanically with gofmt -r. Passes toolstash. name old alloc/op new alloc/op delta Template 44.3MB ± 0% 44.3MB ± 0% ~ (p=0.367 n=30+30) Unicode 37.4MB ± 0% 37.4MB ± 0% ~ (p=0.665 n=30+30) GoTypes 125MB ± 0% 125MB ± 0% ~ (p=0.067 n=30+30) Compiler 515MB ± 0% 515MB ± 0% ~ (p=0.542 n=30+28) name old allocs/op new allocs/op delta Template 434k ± 0% 434k ± 0% ~ (p=0.076 n=30+29) Unicode 367k ± 0% 367k ± 0% ~ (p=0.716 n=29+30) GoTypes 1.24M ± 0% 1.24M ± 0% ~ (p=0.428 n=29+29) Compiler 4.47M ± 0% 4.47M ± 0% ~ (p=0.225 n=28+30) Change-Id: Ibaf0668567b3f69fba06aa03b7997c8fb152113a Reviewed-on: https://go-review.googlesource.com/30356 Run-TryBot: Matthew Dempsky <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 7478ea5 commit dce0df2

File tree

3 files changed

+119
-119
lines changed

3 files changed

+119
-119
lines changed

src/cmd/compile/internal/gc/bv.go

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
package gc
66

7-
import "fmt"
8-
97
const (
108
WORDBITS = 32
119
WORDMASK = WORDBITS - 1
@@ -44,14 +42,7 @@ func (b *bulkBvec) next() bvec {
4442
return out
4543
}
4644

47-
// difference
48-
func bvandnot(dst bvec, src1 bvec, src2 bvec) {
49-
for i, x := range src1.b {
50-
dst.b[i] = x &^ src2.b[i]
51-
}
52-
}
53-
54-
func bveq(bv1 bvec, bv2 bvec) bool {
45+
func (bv1 bvec) Eq(bv2 bvec) bool {
5546
if bv1.n != bv2.n {
5647
Fatalf("bvequal: lengths %d and %d are not equal", bv1.n, bv2.n)
5748
}
@@ -63,22 +54,31 @@ func bveq(bv1 bvec, bv2 bvec) bool {
6354
return true
6455
}
6556

66-
func bvcopy(dst bvec, src bvec) {
57+
func (dst bvec) Copy(src bvec) {
6758
for i, x := range src.b {
6859
dst.b[i] = x
6960
}
7061
}
7162

72-
func bvget(bv bvec, i int32) int {
63+
func (bv bvec) Get(i int32) bool {
7364
if i < 0 || i >= bv.n {
7465
Fatalf("bvget: index %d is out of bounds with length %d\n", i, bv.n)
7566
}
76-
return int((bv.b[i>>WORDSHIFT] >> uint(i&WORDMASK)) & 1)
67+
mask := uint32(1 << uint(i%WORDBITS))
68+
return bv.b[i>>WORDSHIFT]&mask != 0
69+
}
70+
71+
func (bv bvec) Set(i int32) {
72+
if i < 0 || i >= bv.n {
73+
Fatalf("bvset: index %d is out of bounds with length %d\n", i, bv.n)
74+
}
75+
mask := uint32(1 << uint(i%WORDBITS))
76+
bv.b[i/WORDBITS] |= mask
7777
}
7878

7979
// bvnext returns the smallest index >= i for which bvget(bv, i) == 1.
8080
// If there is no such index, bvnext returns -1.
81-
func bvnext(bv bvec, i int32) int32 {
81+
func (bv bvec) Next(i int32) int32 {
8282
if i >= bv.n {
8383
return -1
8484
}
@@ -107,7 +107,7 @@ func bvnext(bv bvec, i int32) int32 {
107107
return i
108108
}
109109

110-
func bvisempty(bv bvec) bool {
110+
func (bv bvec) IsEmpty() bool {
111111
for i := int32(0); i < bv.n; i += WORDBITS {
112112
if bv.b[i>>WORDSHIFT] != 0 {
113113
return false
@@ -116,7 +116,7 @@ func bvisempty(bv bvec) bool {
116116
return true
117117
}
118118

119-
func bvnot(bv bvec) {
119+
func (bv bvec) Not() {
120120
i := int32(0)
121121
w := int32(0)
122122
for ; i < bv.n; i, w = i+WORDBITS, w+1 {
@@ -125,36 +125,41 @@ func bvnot(bv bvec) {
125125
}
126126

127127
// union
128-
func bvor(dst bvec, src1 bvec, src2 bvec) {
128+
func (dst bvec) Or(src1, src2 bvec) {
129129
for i, x := range src1.b {
130130
dst.b[i] = x | src2.b[i]
131131
}
132132
}
133133

134134
// intersection
135-
func bvand(dst bvec, src1 bvec, src2 bvec) {
135+
func (dst bvec) And(src1, src2 bvec) {
136136
for i, x := range src1.b {
137137
dst.b[i] = x & src2.b[i]
138138
}
139139
}
140140

141-
func bvprint(bv bvec) {
142-
fmt.Printf("#*")
143-
for i := int32(0); i < bv.n; i++ {
144-
fmt.Printf("%d", bvget(bv, i))
141+
// difference
142+
func (dst bvec) AndNot(src1, src2 bvec) {
143+
for i, x := range src1.b {
144+
dst.b[i] = x &^ src2.b[i]
145145
}
146146
}
147147

148-
func bvresetall(bv bvec) {
149-
for i := range bv.b {
150-
bv.b[i] = 0
148+
func (bv bvec) String() string {
149+
s := make([]byte, 2+bv.n)
150+
copy(s, "#*")
151+
for i := int32(0); i < bv.n; i++ {
152+
ch := byte('0')
153+
if bv.Get(i) {
154+
ch = '1'
155+
}
156+
s[2+i] = ch
151157
}
158+
return string(s)
152159
}
153160

154-
func bvset(bv bvec, i int32) {
155-
if i < 0 || i >= bv.n {
156-
Fatalf("bvset: index %d is out of bounds with length %d\n", i, bv.n)
161+
func (bv bvec) Clear() {
162+
for i := range bv.b {
163+
bv.b[i] = 0
157164
}
158-
mask := uint32(1 << uint(i%WORDBITS))
159-
bv.b[i/WORDBITS] |= mask
160165
}

0 commit comments

Comments
 (0)