aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/x86
diff options
context:
space:
mode:
authorBen Shi <powerman1st@163.com>2018-06-19 03:44:28 +0000
committerBen Shi <powerman1st@163.com>2018-08-20 14:05:37 +0000
commitbd483592a23c5c8964d1af5ca85792db031229ad (patch)
tree8371c805b56d3be12e7514109111b2c1efe136a6 /src/cmd/compile/internal/x86
parent5403b8ecebc37da227dae170f01b6004a66bf2e6 (diff)
downloadgo-bd483592a23c5c8964d1af5ca85792db031229ad.tar.gz
go-bd483592a23c5c8964d1af5ca85792db031229ad.zip
cmd/compile/internal/x86: simplify 387 with FLDZ and FLZ1
FLD1 pushes +1.0 to the 387 register stack, and FLDZ pushes +0.0 to the 387 regiser stack. They can be used to simplify MOVSSconst/MOVSDconst when the constant is +0.0, -0.0, +1.0, -1.0. The size of the go executable reduces about 62KB and the total size of pkg/linux_386 reduces about 7KB with this optimization. Change-Id: Icc8213b58262e0024a277cf1103812a17dd4b05e Reviewed-on: https://go-review.googlesource.com/119635 Run-TryBot: Ben Shi <powerman1st@163.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/x86')
-rw-r--r--src/cmd/compile/internal/x86/387.go23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/cmd/compile/internal/x86/387.go b/src/cmd/compile/internal/x86/387.go
index 7a3622405c..ab3d30e76c 100644
--- a/src/cmd/compile/internal/x86/387.go
+++ b/src/cmd/compile/internal/x86/387.go
@@ -22,11 +22,24 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) {
switch v.Op {
case ssa.Op386MOVSSconst, ssa.Op386MOVSDconst:
- p := s.Prog(loadPush(v.Type))
- p.From.Type = obj.TYPE_FCONST
- p.From.Val = math.Float64frombits(uint64(v.AuxInt))
- p.To.Type = obj.TYPE_REG
- p.To.Reg = x86.REG_F0
+ iv := uint64(v.AuxInt)
+ if iv == 0x0000000000000000 { // +0.0
+ s.Prog(x86.AFLDZ)
+ } else if iv == 0x3ff0000000000000 { // +1.0
+ s.Prog(x86.AFLD1)
+ } else if iv == 0x8000000000000000 { // -0.0
+ s.Prog(x86.AFLDZ)
+ s.Prog(x86.AFCHS)
+ } else if iv == 0xbff0000000000000 { // -1.0
+ s.Prog(x86.AFLD1)
+ s.Prog(x86.AFCHS)
+ } else { // others
+ p := s.Prog(loadPush(v.Type))
+ p.From.Type = obj.TYPE_FCONST
+ p.From.Val = math.Float64frombits(iv)
+ p.To.Type = obj.TYPE_REG
+ p.To.Reg = x86.REG_F0
+ }
popAndSave(s, v)
case ssa.Op386MOVSSconst2, ssa.Op386MOVSDconst2: