Commit 0659cf69 authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile: small Mpint method simplifications

Get rid of (*Mpint).Add's "quiet" parameter: it's always set to 0.

Inline (*Mpint).shift into (*Mpint).Lsh and (*Mpint).Rsh. There's no
need for a common shift method that can handle both left or right
shifts based on sign when the higher level abstractions only ever do
one or the other.

Change-Id: Icd3b082413f9193961b6835279e0bd4b6a6a6621
Reviewed-on: https://go-review.googlesource.com/21050
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarRobert Griesemer <gri@golang.org>
parent 4c9a470d
......@@ -833,7 +833,7 @@ func evconst(n *Node) {
case OADD_ | CTINT_,
OADD_ | CTRUNE_:
v.U.(*Mpint).Add(rv.U.(*Mpint), 0)
v.U.(*Mpint).Add(rv.U.(*Mpint))
case OSUB_ | CTINT_,
OSUB_ | CTRUNE_:
......
......@@ -68,7 +68,7 @@ func (a *Mpint) SetFloat(b *Mpflt) int {
return -1
}
func (a *Mpint) Add(b *Mpint, quiet int) {
func (a *Mpint) Add(b *Mpint) {
if a.Ovf || b.Ovf {
if nsavederrors+nerrors == 0 {
Yyerror("ovf in mpaddfixfix")
......@@ -79,7 +79,7 @@ func (a *Mpint) Add(b *Mpint, quiet int) {
a.Val.Add(&a.Val, &b.Val)
if a.checkOverflow(0) && quiet == 0 {
if a.checkOverflow(0) {
Yyerror("constant addition overflow")
}
}
......@@ -198,20 +198,6 @@ func (a *Mpint) Xor(b *Mpint) {
a.Val.Xor(&a.Val, &b.Val)
}
// shift left by s (or right by -s)
func (a *Mpint) shift(s int) {
switch {
case s > 0:
if a.checkOverflow(s) {
Yyerror("constant shift overflow")
return
}
a.Val.Lsh(&a.Val, uint(s))
case s < 0:
a.Val.Rsh(&a.Val, uint(-s))
}
}
func (a *Mpint) Lsh(b *Mpint) {
if a.Ovf || b.Ovf {
if nsavederrors+nerrors == 0 {
......@@ -232,7 +218,11 @@ func (a *Mpint) Lsh(b *Mpint) {
return
}
a.shift(int(s))
if a.checkOverflow(int(s)) {
Yyerror("constant shift overflow")
return
}
a.Val.Lsh(&a.Val, uint(s))
}
func (a *Mpint) Rsh(b *Mpint) {
......@@ -255,7 +245,7 @@ func (a *Mpint) Rsh(b *Mpint) {
return
}
a.shift(int(-s))
a.Val.Rsh(&a.Val, uint(s))
}
func (a *Mpint) Cmp(b *Mpint) int {
......
......@@ -3318,7 +3318,7 @@ func (p *parser) hidden_constant() *Node {
if s2.Val().Ctype() == CTRUNE && s4.Val().Ctype() == CTINT {
ss := s2
s2.Val().U.(*Mpint).Add(s4.Val().U.(*Mpint), 0)
s2.Val().U.(*Mpint).Add(s4.Val().U.(*Mpint))
return ss
}
s4.Val().U.(*Mpcplx).Real = s4.Val().U.(*Mpcplx).Imag
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment