From: Josh Bleecher Snyder Date: Thu, 23 Apr 2015 03:08:03 +0000 (-0700) Subject: cmd/5g, etc: prepare to unexport gc.Mp* X-Git-Tag: go1.5beta1~576 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=0112f6f6b605b17194175aa7cfe15b4054f862fc;p=gostls13.git 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 --- diff --git a/src/cmd/5g/cgen64.go b/src/cmd/5g/cgen64.go index 699e555f71..c55e000adc 100644 --- a/src/cmd/5g/cgen64.go +++ b/src/cmd/5g/cgen64.go @@ -237,7 +237,7 @@ func cgen64(n *gc.Node, res *gc.Node) { // 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 @@ func cgen64(n *gc.Node, res *gc.Node) { 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 @@ func cgen64(n *gc.Node, res *gc.Node) { 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 c2bd6dda0a..e4612362a2 100644 --- a/src/cmd/5g/ggen.go +++ b/src/cmd/5g/ggen.go @@ -183,7 +183,7 @@ func cgen_shift(op int, bounded bool, nl *gc.Node, nr *gc.Node, res *gc.Node) { 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 @@ func cgen_shift(op int, bounded bool, nl *gc.Node, nr *gc.Node, res *gc.Node) { 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 ginscon(as int, c int64, n *gc.Node) { } 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 @@ func ginscmp(op int, t *gc.Type, n1, n2 *gc.Node, likely int) *obj.Prog { 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 57d511e6f6..db46d6e9ee 100644 --- a/src/cmd/5g/gsubr.go +++ b/src/cmd/5g/gsubr.go @@ -53,7 +53,7 @@ func ncon(i uint32) *gc.Node { 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 @@ func split64(n *gc.Node, lo *gc.Node, hi *gc.Node) { 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 @@ func sudoaddable(as int, n *gc.Node, a *obj.Addr) bool { 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 6e5e6bc4ca..12198d7187 100644 --- a/src/cmd/6g/ggen.go +++ b/src/cmd/6g/ggen.go @@ -190,9 +190,9 @@ func dodiv(op int, nl *gc.Node, nr *gc.Node, res *gc.Node) { check := 0 if gc.Issigned[t.Etype] { check = 1 - if gc.Isconst(nl, gc.CTINT) && gc.Mpgetfix(nl.Val.U.Xval) != -(1<= 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 14e1a57cbd..4e54bc8de5 100644 --- a/src/cmd/6g/gsubr.go +++ b/src/cmd/6g/gsubr.go @@ -32,6 +32,7 @@ package main import ( "cmd/internal/gc" + "cmd/internal/gc/big" "cmd/internal/obj" "cmd/internal/obj/x86" "fmt" @@ -139,29 +140,27 @@ func ginsboolval(a int, n *gc.Node) { 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 + + var i big.Int + i.SetInt64(1) + i.Lsh(&i, 63) - gc.Nodconst(&bigi, gc.Types[gc.TUINT64], 1) - gc.Mpshiftfix(bigi.Val.U.Xval, 63) + gc.Nodconst(&bigi, gc.Types[gc.TUINT64], 0) + bigi.SetBigInt(&i) - 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.Convconst(&bigf, gc.Types[gc.TFLOAT64], &bigi.Val) } /* @@ -206,10 +205,7 @@ func gmove(f *gc.Node, t *gc.Node) { // 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 @@ func sudoaddable(as int, n *gc.Node, a *obj.Addr) bool { 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 b824a3a18c..af51c31648 100644 --- a/src/cmd/7g/ggen.go +++ b/src/cmd/7g/ggen.go @@ -147,9 +147,9 @@ func dodiv(op int, nl *gc.Node, nr *gc.Node, res *gc.Node) { check := 0 if gc.Issigned[t.Etype] { check = 1 - if gc.Isconst(nl, gc.CTINT) && gc.Mpgetfix(nl.Val.U.Xval) != -(1<= 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 60c3a7ad44..2f03b121b4 100644 --- a/src/cmd/7g/gsubr.go +++ b/src/cmd/7g/gsubr.go @@ -115,7 +115,7 @@ func ginscmp(op int, t *gc.Type, n1, n2 *gc.Node, likely int) *obj.Prog { 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 @@ func intLiteral(n *gc.Node) (x int64, ok bool) { } 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 a682e2fb44..80a9642f75 100644 --- a/src/cmd/8g/cgen64.go +++ b/src/cmd/8g/cgen64.go @@ -162,7 +162,7 @@ func cgen64(n *gc.Node, res *gc.Node) { // 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 @@ func cgen64(n *gc.Node, res *gc.Node) { 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 @@ func cgen64(n *gc.Node, res *gc.Node) { 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 @@ func cgen64(n *gc.Node, res *gc.Node) { 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 59025525fa..baa1b64d1e 100644 --- a/src/cmd/8g/ggen.go +++ b/src/cmd/8g/ggen.go @@ -216,9 +216,9 @@ func dodiv(op int, nl *gc.Node, nr *gc.Node, res *gc.Node, ax *gc.Node, dx *gc.N check := 0 if gc.Issigned[t.Etype] { check = 1 - if gc.Isconst(nl, gc.CTINT) && gc.Mpgetfix(nl.Val.U.Xval) != -1<= 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 d1134d2c74..6878883b28 100644 --- a/src/cmd/8g/gsubr.go +++ b/src/cmd/8g/gsubr.go @@ -32,6 +32,7 @@ package main import ( "cmd/internal/gc" + "cmd/internal/gc/big" "cmd/internal/obj" "cmd/internal/obj/x86" "fmt" @@ -641,7 +642,7 @@ func ncon(i uint32) *gc.Node { 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 @@ func split64(n *gc.Node, lo *gc.Node, hi *gc.Node) { 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 @@ func splitclean() { } } -/* - * 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 + + gc.Nodconst(&zerof, gc.Types[gc.TINT64], 0) + gc.Convconst(&zerof, gc.Types[gc.TFLOAT64], &zerof.Val) - 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.) + var i big.Int + i.SetInt64(1) + i.Lsh(&i, 63) + var bigi gc.Node - two63f = two64f - two63f.Val.U.Fval = new(gc.Mpflt) - gc.Mpmovecflt(two63f.Val.U.Fval, 9223372036854775808.) + gc.Nodconst(&bigi, gc.Types[gc.TUINT64], 0) + bigi.SetBigInt(&i) + gc.Convconst(&two63f, gc.Types[gc.TFLOAT64], &bigi.Val) - zerof = two64f - zerof.Val.U.Fval = new(gc.Mpflt) - gc.Mpmovecflt(zerof.Val.U.Fval, 0) + 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 28ebd9cc01..265536921a 100644 --- a/src/cmd/9g/ggen.go +++ b/src/cmd/9g/ggen.go @@ -141,9 +141,9 @@ func dodiv(op int, nl *gc.Node, nr *gc.Node, res *gc.Node) { check := 0 if gc.Issigned[t.Etype] { check = 1 - if gc.Isconst(nl, gc.CTINT) && gc.Mpgetfix(nl.Val.U.Xval) != -(1<= 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 61ba87ee3e..f14f93734c 100644 --- a/src/cmd/9g/gsubr.go +++ b/src/cmd/9g/gsubr.go @@ -32,6 +32,7 @@ package main import ( "cmd/internal/gc" + "cmd/internal/gc/big" "cmd/internal/obj" "cmd/internal/obj/ppc64" "fmt" @@ -129,7 +130,7 @@ func ginscmp(op int, t *gc.Type, n1, n2 *gc.Node, likely int) *obj.Prog { 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 @@ func ginscmp(op int, t *gc.Type, n1, n2 *gc.Node, likely int) *obj.Prog { 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 + + var i big.Int + i.SetInt64(1) + i.Lsh(&i, 63) - gc.Nodconst(&bigi, gc.Types[gc.TUINT64], 1) - gc.Mpshiftfix(bigi.Val.U.Xval, 63) + gc.Nodconst(&bigi, gc.Types[gc.TUINT64], 0) + bigi.SetBigInt(&i) - 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.Convconst(&bigf, gc.Types[gc.TFLOAT64], &bigi.Val) } /* @@ -552,7 +551,7 @@ func intLiteral(n *gc.Node) (x int64, ok bool) { } 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 84b133769c..748752679b 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.