diff options
| author | Alberto Donizetti <alb.donizetti@gmail.com> | 2021-03-05 11:22:13 +0100 |
|---|---|---|
| committer | Alberto Donizetti <alb.donizetti@gmail.com> | 2021-03-09 08:19:14 +0000 |
| commit | b70a2bc9c612de35b765712bd689865f6a1716b6 (patch) | |
| tree | 7e538fba518ca7a8a706601214c5e700d7979979 /src/cmd/compile/internal/ssa/op.go | |
| parent | 437d229e2ac4cda4265090375b94d74ca218a846 (diff) | |
| download | go-git-b70a2bc9c612de35b765712bd689865f6a1716b6.tar.gz | |
cmd/compile: make ValAndOff.{Val,Off} return an int32
The ValAndOff type is a 64bit integer holding a 32bit value and a
32bit offset in each half, but for historical reasons its Val and Off
methods returned an int64. This was convenient when AuxInt was always
an int64, but now that AuxInts are typed we can return int32 from Val
and Off and get rid of a several casts and now unnecessary range
checks.
This change:
- changes the Val and Off methods to return an int32 (from int64);
- adds Val64 and Off64 methods for convenience in the few remaining
places (in the ssa.go files) where Val and Off are stored in int64
fields;
- deletes makeValAndOff64, renames makeValAndOff32 to makeValAndOff
- deletes a few ValAndOff methods that are now unused;
- removes several validOff/validValAndOff check that will always
return true.
Passes:
GOARCH=amd64 gotip build -toolexec 'toolstash -cmp' -a std
GOARCH=386 gotip build -toolexec 'toolstash -cmp' -a std
GOARCH=s390x gotip build -toolexec 'toolstash -cmp' -a std
(the three GOARCHs with SSA rules files impacted by the change).
Change-Id: I2abbbf42188c798631b94d3a55ca44256f140be7
Reviewed-on: https://go-review.googlesource.com/c/go/+/299149
Trust: Alberto Donizetti <alb.donizetti@gmail.com>
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/ssa/op.go')
| -rw-r--r-- | src/cmd/compile/internal/ssa/op.go | 42 |
1 files changed, 9 insertions, 33 deletions
diff --git a/src/cmd/compile/internal/ssa/op.go b/src/cmd/compile/internal/ssa/op.go index 574377a33d..342df73d02 100644 --- a/src/cmd/compile/internal/ssa/op.go +++ b/src/cmd/compile/internal/ssa/op.go @@ -382,13 +382,13 @@ type Sym interface { // The low 32 bits hold a pointer offset. type ValAndOff int64 -func (x ValAndOff) Val() int64 { return int64(x) >> 32 } -func (x ValAndOff) Val32() int32 { return int32(int64(x) >> 32) } +func (x ValAndOff) Val() int32 { return int32(int64(x) >> 32) } +func (x ValAndOff) Val64() int64 { return int64(x) >> 32 } func (x ValAndOff) Val16() int16 { return int16(int64(x) >> 32) } func (x ValAndOff) Val8() int8 { return int8(int64(x) >> 32) } -func (x ValAndOff) Off() int64 { return int64(int32(x)) } -func (x ValAndOff) Off32() int32 { return int32(x) } +func (x ValAndOff) Off64() int64 { return int64(int32(x)) } +func (x ValAndOff) Off() int32 { return int32(x) } func (x ValAndOff) String() string { return fmt.Sprintf("val=%d,off=%d", x.Val(), x.Off()) @@ -400,40 +400,16 @@ func validVal(val int64) bool { return val == int64(int32(val)) } -// validOff reports whether the offset can be used -// as an argument to makeValAndOff. -func validOff(off int64) bool { - return off == int64(int32(off)) -} - -// validValAndOff reports whether we can fit the value and offset into -// a ValAndOff value. -func validValAndOff(val, off int64) bool { - if !validVal(val) { - return false - } - if !validOff(off) { - return false - } - return true -} - -func makeValAndOff32(val, off int32) ValAndOff { +func makeValAndOff(val, off int32) ValAndOff { return ValAndOff(int64(val)<<32 + int64(uint32(off))) } -func makeValAndOff64(val, off int64) ValAndOff { - if !validValAndOff(val, off) { - panic("invalid makeValAndOff64") - } - return ValAndOff(val<<32 + int64(uint32(off))) -} func (x ValAndOff) canAdd32(off int32) bool { - newoff := x.Off() + int64(off) + newoff := x.Off64() + int64(off) return newoff == int64(int32(newoff)) } func (x ValAndOff) canAdd64(off int64) bool { - newoff := x.Off() + off + newoff := x.Off64() + off return newoff == int64(int32(newoff)) } @@ -441,13 +417,13 @@ func (x ValAndOff) addOffset32(off int32) ValAndOff { if !x.canAdd32(off) { panic("invalid ValAndOff.addOffset32") } - return makeValAndOff64(x.Val(), x.Off()+int64(off)) + return makeValAndOff(x.Val(), x.Off()+off) } func (x ValAndOff) addOffset64(off int64) ValAndOff { if !x.canAdd64(off) { panic("invalid ValAndOff.addOffset64") } - return makeValAndOff64(x.Val(), x.Off()+off) + return makeValAndOff(x.Val(), x.Off()+int32(off)) } // int128 is a type that stores a 128-bit constant. |
