cmd/5g, etc: prepare to unexport gc.Mp*
Remove all uses of Mp* outside of the gc package.
A subsequent, automated commit in the Go 1.6
cycle will unexport all Mp* functions and types.
No functional changes. Passes toolstash -cmp.
Change-Id: Ie1604cb5b84ffb30b47f4777d4235570f2c62709
Reviewed-on: https://go-review.googlesource.com/9263
Reviewed-by: Russ Cox <rsc@golang.org>
diff --git a/src/cmd/5g/cgen64.go b/src/cmd/5g/cgen64.go
index 699e555..c55e000 100644
--- a/src/cmd/5g/cgen64.go
+++ b/src/cmd/5g/cgen64.go
@@ -237,7 +237,7 @@
// shld hi:lo, c
// shld lo:t, c
case gc.OLROT:
- v := uint64(gc.Mpgetfix(r.Val.U.Xval))
+ v := uint64(r.Int())
var bl gc.Node
gc.Regalloc(&bl, lo1.Type, nil)
@@ -291,7 +291,7 @@
var p4 *obj.Prog
var p5 *obj.Prog
if r.Op == gc.OLITERAL {
- v := uint64(gc.Mpgetfix(r.Val.U.Xval))
+ v := uint64(r.Int())
if v >= 64 {
// TODO(kaib): replace with gins(AMOVW, nodintconst(0), &al)
// here and below (verify it optimizes to EOR)
@@ -452,7 +452,7 @@
var creg gc.Node
var p3 *obj.Prog
if r.Op == gc.OLITERAL {
- v := uint64(gc.Mpgetfix(r.Val.U.Xval))
+ v := uint64(r.Int())
if v >= 64 {
if bh.Type.Etype == gc.TINT32 {
// MOVW bh->31, al
diff --git a/src/cmd/5g/ggen.go b/src/cmd/5g/ggen.go
index c2bd6dd..e461236 100644
--- a/src/cmd/5g/ggen.go
+++ b/src/cmd/5g/ggen.go
@@ -183,7 +183,7 @@
w := int(nl.Type.Width * 8)
if op == gc.OLROT {
- v := int(gc.Mpgetfix(nr.Val.U.Xval))
+ v := nr.Int()
var n1 gc.Node
gc.Regalloc(&n1, nl.Type, res)
if w == 32 {
@@ -210,7 +210,7 @@
var n1 gc.Node
gc.Regalloc(&n1, nl.Type, res)
gc.Cgen(nl, &n1)
- sc := uint64(gc.Mpgetfix(nr.Val.U.Xval))
+ sc := uint64(nr.Int())
if sc == 0 {
} else // nothing to do
if sc >= uint64(nl.Type.Width*8) {
@@ -480,7 +480,7 @@
}
func ginscmp(op int, t *gc.Type, n1, n2 *gc.Node, likely int) *obj.Prog {
- if gc.Isint[t.Etype] && n1.Op == gc.OLITERAL && gc.Mpgetfix(n1.Val.U.Xval) == 0 && n2.Op != gc.OLITERAL {
+ if gc.Isint[t.Etype] && n1.Op == gc.OLITERAL && n1.Int() == 0 && n2.Op != gc.OLITERAL {
op = gc.Brrev(op)
n1, n2 = n2, n1
}
@@ -489,7 +489,7 @@
gc.Regalloc(&g1, n1.Type, &r1)
gc.Cgen(n1, &g1)
gmove(&g1, &r1)
- if gc.Isint[t.Etype] && n2.Op == gc.OLITERAL && gc.Mpgetfix(n2.Val.U.Xval) == 0 {
+ if gc.Isint[t.Etype] && n2.Op == gc.OLITERAL && n2.Int() == 0 {
gins(arm.ACMP, &r1, n2)
} else {
gc.Regalloc(&r2, t, n2)
diff --git a/src/cmd/5g/gsubr.go b/src/cmd/5g/gsubr.go
index 57d511e..db46d6e 100644
--- a/src/cmd/5g/gsubr.go
+++ b/src/cmd/5g/gsubr.go
@@ -53,7 +53,7 @@
if ncon_n.Type == nil {
gc.Nodconst(&ncon_n, gc.Types[gc.TUINT32], 0)
}
- gc.Mpmovecfix(ncon_n.Val.U.Xval, int64(i))
+ ncon_n.SetInt(int64(i))
return &ncon_n
}
@@ -112,7 +112,7 @@
case gc.OLITERAL:
var n1 gc.Node
gc.Convconst(&n1, n.Type, &n.Val)
- i := gc.Mpgetfix(n1.Val.U.Xval)
+ i := n1.Int()
gc.Nodconst(lo, gc.Types[gc.TUINT32], int64(uint32(i)))
i >>= 32
if n.Type.Etype == gc.TINT64 {
@@ -1118,7 +1118,7 @@
if !gc.Isconst(n, gc.CTINT) {
break
}
- v := gc.Mpgetfix(n.Val.U.Xval)
+ v := n.Int()
if v >= 32000 || v <= -32000 {
break
}
diff --git a/src/cmd/6g/ggen.go b/src/cmd/6g/ggen.go
index 6e5e6bc..12198d7 100644
--- a/src/cmd/6g/ggen.go
+++ b/src/cmd/6g/ggen.go
@@ -190,9 +190,9 @@
check := 0
if gc.Issigned[t.Etype] {
check = 1
- if gc.Isconst(nl, gc.CTINT) && gc.Mpgetfix(nl.Val.U.Xval) != -(1<<uint64(t.Width*8-1)) {
+ if gc.Isconst(nl, gc.CTINT) && nl.Int() != -(1<<uint64(t.Width*8-1)) {
check = 0
- } else if gc.Isconst(nr, gc.CTINT) && gc.Mpgetfix(nr.Val.U.Xval) != -1 {
+ } else if gc.Isconst(nr, gc.CTINT) && nr.Int() != -1 {
check = 0
}
}
@@ -381,7 +381,7 @@
var n1 gc.Node
gc.Regalloc(&n1, nl.Type, res)
gc.Cgen(nl, &n1)
- sc := uint64(gc.Mpgetfix(nr.Val.U.Xval))
+ sc := uint64(nr.Int())
if sc >= uint64(nl.Type.Width*8) {
// large shift gets 2 shifts by width-1
var n3 gc.Node
diff --git a/src/cmd/6g/gsubr.go b/src/cmd/6g/gsubr.go
index 14e1a57..4e54bc8 100644
--- a/src/cmd/6g/gsubr.go
+++ b/src/cmd/6g/gsubr.go
@@ -32,6 +32,7 @@
import (
"cmd/internal/gc"
+ "cmd/internal/gc/big"
"cmd/internal/obj"
"cmd/internal/obj/x86"
"fmt"
@@ -139,29 +140,27 @@
gins(jmptoset(a), nil, n)
}
-/*
- * set up nodes representing 2^63
- */
-var bigi gc.Node
-
-var bigf gc.Node
-
-var bignodes_did int
+// set up nodes representing 2^63
+var (
+ bigi gc.Node
+ bigf gc.Node
+ bignodes_did bool
+)
func bignodes() {
- if bignodes_did != 0 {
+ if bignodes_did {
return
}
- bignodes_did = 1
+ bignodes_did = true
- gc.Nodconst(&bigi, gc.Types[gc.TUINT64], 1)
- gc.Mpshiftfix(bigi.Val.U.Xval, 63)
+ var i big.Int
+ i.SetInt64(1)
+ i.Lsh(&i, 63)
- bigf = bigi
- bigf.Type = gc.Types[gc.TFLOAT64]
- bigf.Val.Ctype = gc.CTFLT
- bigf.Val.U.Fval = new(gc.Mpflt)
- gc.Mpmovefixflt(bigf.Val.U.Fval, bigi.Val.U.Xval)
+ gc.Nodconst(&bigi, gc.Types[gc.TUINT64], 0)
+ bigi.SetBigInt(&i)
+
+ gc.Convconst(&bigf, gc.Types[gc.TFLOAT64], &bigi.Val)
}
/*
@@ -206,10 +205,7 @@
// 64-bit immediates are really 32-bit sign-extended
// unless moving into a register.
if gc.Isint[tt] {
- if gc.Mpcmpfixfix(con.Val.U.Xval, gc.Minintval[gc.TINT32]) < 0 {
- goto hard
- }
- if gc.Mpcmpfixfix(con.Val.U.Xval, gc.Maxintval[gc.TINT32]) > 0 {
+ if i := con.Int(); int64(int32(i)) != i {
goto hard
}
}
@@ -1273,7 +1269,7 @@
if !gc.Isconst(n, gc.CTINT) {
break
}
- v := gc.Mpgetfix(n.Val.U.Xval)
+ v := n.Int()
if v >= 32000 || v <= -32000 {
break
}
diff --git a/src/cmd/7g/ggen.go b/src/cmd/7g/ggen.go
index b824a3a..af51c31 100644
--- a/src/cmd/7g/ggen.go
+++ b/src/cmd/7g/ggen.go
@@ -147,9 +147,9 @@
check := 0
if gc.Issigned[t.Etype] {
check = 1
- if gc.Isconst(nl, gc.CTINT) && gc.Mpgetfix(nl.Val.U.Xval) != -(1<<uint64(t.Width*8-1)) {
+ if gc.Isconst(nl, gc.CTINT) && nl.Int() != -(1<<uint64(t.Width*8-1)) {
check = 0
- } else if gc.Isconst(nr, gc.CTINT) && gc.Mpgetfix(nr.Val.U.Xval) != -1 {
+ } else if gc.Isconst(nr, gc.CTINT) && nr.Int() != -1 {
check = 0
}
}
@@ -312,7 +312,7 @@
var n1 gc.Node
gc.Regalloc(&n1, nl.Type, res)
gc.Cgen(nl, &n1)
- sc := uint64(uint64(gc.Mpgetfix(nr.Val.U.Xval)))
+ sc := uint64(nr.Int())
if sc >= uint64(nl.Type.Width*8) {
// large shift gets 2 shifts by width-1
var n3 gc.Node
diff --git a/src/cmd/7g/gsubr.go b/src/cmd/7g/gsubr.go
index 60c3a7a..2f03b12 100644
--- a/src/cmd/7g/gsubr.go
+++ b/src/cmd/7g/gsubr.go
@@ -115,7 +115,7 @@
gc.Cgen(n1, &g1)
gmove(&g1, &r1)
if gc.Isint[t.Etype] && gc.Isconst(n2, gc.CTINT) {
- ginscon2(optoas(gc.OCMP, t), &r1, gc.Mpgetfix(n2.Val.U.Xval))
+ ginscon2(optoas(gc.OCMP, t), &r1, n2.Int())
} else {
gc.Regalloc(&r2, t, n2)
gc.Regalloc(&g2, n1.Type, &r2)
@@ -473,7 +473,7 @@
}
switch n.Val.Ctype {
case gc.CTINT, gc.CTRUNE:
- return gc.Mpgetfix(n.Val.U.Xval), true
+ return n.Int(), true
case gc.CTBOOL:
return int64(obj.Bool2int(n.Val.U.Bval)), true
}
diff --git a/src/cmd/8g/cgen64.go b/src/cmd/8g/cgen64.go
index a682e2f..80a9642 100644
--- a/src/cmd/8g/cgen64.go
+++ b/src/cmd/8g/cgen64.go
@@ -162,7 +162,7 @@
// shld hi:lo, c
// shld lo:t, c
case gc.OLROT:
- v := uint64(gc.Mpgetfix(r.Val.U.Xval))
+ v := uint64(r.Int())
if v >= 32 {
// reverse during load to do the first 32 bits of rotate
@@ -189,7 +189,7 @@
case gc.OLSH:
if r.Op == gc.OLITERAL {
- v := uint64(gc.Mpgetfix(r.Val.U.Xval))
+ v := uint64(r.Int())
if v >= 64 {
if gc.Is64(r.Type) {
splitclean()
@@ -278,7 +278,7 @@
case gc.ORSH:
if r.Op == gc.OLITERAL {
- v := uint64(gc.Mpgetfix(r.Val.U.Xval))
+ v := uint64(r.Int())
if v >= 64 {
if gc.Is64(r.Type) {
splitclean()
@@ -400,9 +400,8 @@
if lo2.Op == gc.OLITERAL {
// special cases for constants.
- lv := uint32(gc.Mpgetfix(lo2.Val.U.Xval))
-
- hv := uint32(gc.Mpgetfix(hi2.Val.U.Xval))
+ lv := uint32(lo2.Int())
+ hv := uint32(hi2.Int())
splitclean() // right side
split64(res, &lo2, &hi2)
switch n.Op {
diff --git a/src/cmd/8g/ggen.go b/src/cmd/8g/ggen.go
index 5902552..baa1b64 100644
--- a/src/cmd/8g/ggen.go
+++ b/src/cmd/8g/ggen.go
@@ -216,9 +216,9 @@
check := 0
if gc.Issigned[t.Etype] {
check = 1
- if gc.Isconst(nl, gc.CTINT) && gc.Mpgetfix(nl.Val.U.Xval) != -1<<uint64(t.Width*8-1) {
+ if gc.Isconst(nl, gc.CTINT) && nl.Int() != -1<<uint64(t.Width*8-1) {
check = 0
- } else if gc.Isconst(nr, gc.CTINT) && gc.Mpgetfix(nr.Val.U.Xval) != -1 {
+ } else if gc.Isconst(nr, gc.CTINT) && nr.Int() != -1 {
check = 0
}
}
@@ -391,7 +391,7 @@
var n1 gc.Node
gc.Regalloc(&n1, nl.Type, res)
gmove(&n2, &n1)
- sc := uint64(gc.Mpgetfix(nr.Val.U.Xval))
+ sc := uint64(nr.Int())
if sc >= uint64(nl.Type.Width*8) {
// large shift gets 2 shifts by width-1
gins(a, ncon(uint32(w)-1), &n1)
diff --git a/src/cmd/8g/gsubr.go b/src/cmd/8g/gsubr.go
index d1134d2..6878883 100644
--- a/src/cmd/8g/gsubr.go
+++ b/src/cmd/8g/gsubr.go
@@ -32,6 +32,7 @@
import (
"cmd/internal/gc"
+ "cmd/internal/gc/big"
"cmd/internal/obj"
"cmd/internal/obj/x86"
"fmt"
@@ -641,7 +642,7 @@
if ncon_n.Type == nil {
gc.Nodconst(&ncon_n, gc.Types[gc.TUINT32], 0)
}
- gc.Mpmovecfix(ncon_n.Val.U.Xval, int64(i))
+ ncon_n.SetInt(int64(i))
return &ncon_n
}
@@ -700,7 +701,7 @@
case gc.OLITERAL:
var n1 gc.Node
gc.Convconst(&n1, n.Type, &n.Val)
- i := gc.Mpgetfix(n1.Val.U.Xval)
+ i := n1.Int()
gc.Nodconst(lo, gc.Types[gc.TUINT32], int64(uint32(i)))
i >>= 32
if n.Type.Etype == gc.TINT64 {
@@ -721,36 +722,36 @@
}
}
-/*
- * set up nodes representing fp constants
- */
-var zerof gc.Node
-
-var two64f gc.Node
-
-var two63f gc.Node
-
-var bignodes_did int
+// set up nodes representing fp constants
+var (
+ zerof gc.Node
+ two63f gc.Node
+ two64f gc.Node
+ bignodes_did bool
+)
func bignodes() {
- if bignodes_did != 0 {
+ if bignodes_did {
return
}
- bignodes_did = 1
+ bignodes_did = true
- two64f = *ncon(0)
- two64f.Type = gc.Types[gc.TFLOAT64]
- two64f.Val.Ctype = gc.CTFLT
- two64f.Val.U.Fval = new(gc.Mpflt)
- gc.Mpmovecflt(two64f.Val.U.Fval, 18446744073709551616.)
+ gc.Nodconst(&zerof, gc.Types[gc.TINT64], 0)
+ gc.Convconst(&zerof, gc.Types[gc.TFLOAT64], &zerof.Val)
- two63f = two64f
- two63f.Val.U.Fval = new(gc.Mpflt)
- gc.Mpmovecflt(two63f.Val.U.Fval, 9223372036854775808.)
+ var i big.Int
+ i.SetInt64(1)
+ i.Lsh(&i, 63)
+ var bigi gc.Node
- zerof = two64f
- zerof.Val.U.Fval = new(gc.Mpflt)
- gc.Mpmovecflt(zerof.Val.U.Fval, 0)
+ gc.Nodconst(&bigi, gc.Types[gc.TUINT64], 0)
+ bigi.SetBigInt(&i)
+ gc.Convconst(&two63f, gc.Types[gc.TFLOAT64], &bigi.Val)
+
+ gc.Nodconst(&bigi, gc.Types[gc.TUINT64], 0)
+ i.Lsh(&i, 1)
+ bigi.SetBigInt(&i)
+ gc.Convconst(&two64f, gc.Types[gc.TFLOAT64], &bigi.Val)
}
func memname(n *gc.Node, t *gc.Type) {
diff --git a/src/cmd/9g/ggen.go b/src/cmd/9g/ggen.go
index 28ebd9c..2655369 100644
--- a/src/cmd/9g/ggen.go
+++ b/src/cmd/9g/ggen.go
@@ -141,9 +141,9 @@
check := 0
if gc.Issigned[t.Etype] {
check = 1
- if gc.Isconst(nl, gc.CTINT) && gc.Mpgetfix(nl.Val.U.Xval) != -(1<<uint64(t.Width*8-1)) {
+ if gc.Isconst(nl, gc.CTINT) && nl.Int() != -(1<<uint64(t.Width*8-1)) {
check = 0
- } else if gc.Isconst(nr, gc.CTINT) && gc.Mpgetfix(nr.Val.U.Xval) != -1 {
+ } else if gc.Isconst(nr, gc.CTINT) && nr.Int() != -1 {
check = 0
}
}
@@ -308,7 +308,7 @@
var n1 gc.Node
gc.Regalloc(&n1, nl.Type, res)
gc.Cgen(nl, &n1)
- sc := uint64(uint64(gc.Mpgetfix(nr.Val.U.Xval)))
+ sc := uint64(nr.Int())
if sc >= uint64(nl.Type.Width*8) {
// large shift gets 2 shifts by width-1
var n3 gc.Node
diff --git a/src/cmd/9g/gsubr.go b/src/cmd/9g/gsubr.go
index 61ba87e..f14f937 100644
--- a/src/cmd/9g/gsubr.go
+++ b/src/cmd/9g/gsubr.go
@@ -32,6 +32,7 @@
import (
"cmd/internal/gc"
+ "cmd/internal/gc/big"
"cmd/internal/obj"
"cmd/internal/obj/ppc64"
"fmt"
@@ -129,7 +130,7 @@
gc.Cgen(n1, &g1)
gmove(&g1, &r1)
if gc.Isint[t.Etype] && gc.Isconst(n2, gc.CTINT) {
- ginscon2(optoas(gc.OCMP, t), &r1, gc.Mpgetfix(n2.Val.U.Xval))
+ ginscon2(optoas(gc.OCMP, t), &r1, n2.Int())
} else {
gc.Regalloc(&r2, t, n2)
gc.Regalloc(&g2, n1.Type, &r2)
@@ -144,29 +145,27 @@
return gc.Gbranch(optoas(op, t), nil, likely)
}
-/*
- * set up nodes representing 2^63
- */
-var bigi gc.Node
-
-var bigf gc.Node
-
-var bignodes_did int
+// set up nodes representing 2^63
+var (
+ bigi gc.Node
+ bigf gc.Node
+ bignodes_did bool
+)
func bignodes() {
- if bignodes_did != 0 {
+ if bignodes_did {
return
}
- bignodes_did = 1
+ bignodes_did = true
- gc.Nodconst(&bigi, gc.Types[gc.TUINT64], 1)
- gc.Mpshiftfix(bigi.Val.U.Xval, 63)
+ var i big.Int
+ i.SetInt64(1)
+ i.Lsh(&i, 63)
- bigf = bigi
- bigf.Type = gc.Types[gc.TFLOAT64]
- bigf.Val.Ctype = gc.CTFLT
- bigf.Val.U.Fval = new(gc.Mpflt)
- gc.Mpmovefixflt(bigf.Val.U.Fval, bigi.Val.U.Xval)
+ gc.Nodconst(&bigi, gc.Types[gc.TUINT64], 0)
+ bigi.SetBigInt(&i)
+
+ gc.Convconst(&bigf, gc.Types[gc.TFLOAT64], &bigi.Val)
}
/*
@@ -552,7 +551,7 @@
}
switch n.Val.Ctype {
case gc.CTINT, gc.CTRUNE:
- return gc.Mpgetfix(n.Val.U.Xval), true
+ return n.Int(), true
case gc.CTBOOL:
return int64(obj.Bool2int(n.Val.U.Bval)), true
}
diff --git a/src/cmd/internal/gc/const.go b/src/cmd/internal/gc/const.go
index 84b1337..7487526 100644
--- a/src/cmd/internal/gc/const.go
+++ b/src/cmd/internal/gc/const.go
@@ -5,10 +5,38 @@
package gc
import (
+ "cmd/internal/gc/big"
"cmd/internal/obj"
"strings"
)
+// Int returns n as an int.
+// n must be an integer constant.
+func (n *Node) Int() int64 {
+ if !Isconst(n, CTINT) {
+ Fatal("Int(%v)", n)
+ }
+ return Mpgetfix(n.Val.U.Xval)
+}
+
+// SetInt sets n's value to i.
+// n must be an integer constant.
+func (n *Node) SetInt(i int64) {
+ if !Isconst(n, CTINT) {
+ Fatal("SetInt(%v)", n)
+ }
+ Mpmovecfix(n.Val.U.Xval, i)
+}
+
+// SetBigInt sets n's value to x.
+// n must be an integer constant.
+func (n *Node) SetBigInt(x *big.Int) {
+ if !Isconst(n, CTINT) {
+ Fatal("SetBigInt(%v)", n)
+ }
+ n.Val.U.Xval.Val.Set(x)
+}
+
/*
* truncate float literal fv to 32-bit or 64-bit precision
* according to type; return truncated value.