Commit a866df26 authored by Cherry Zhang's avatar Cherry Zhang

cmd/internal/obj/arm64: materialize float constant 0 from zero register

Materialize float constant 0 from integer zero register, instead
of loading from constant pool.

Also fix assembling FMOV from zero register to FP register.

Change-Id: Ie413dd342cedebdb95ba8cfc220e23ed2a39e885
Reviewed-on: https://go-review.googlesource.com/32250
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarDavid Chase <drchase@google.com>
parent 9d1efba2
...@@ -2380,13 +2380,15 @@ func asmout(ctxt *obj.Link, p *obj.Prog, o *Optab, out []uint32) { ...@@ -2380,13 +2380,15 @@ func asmout(ctxt *obj.Link, p *obj.Prog, o *Optab, out []uint32) {
o2 |= uint32(p.To.Reg & 31) o2 |= uint32(p.To.Reg & 31)
case 29: /* op Rn, Rd */ case 29: /* op Rn, Rd */
if (p.As == AFMOVD || p.As == AFMOVS) && (aclass(ctxt, &p.From) == C_REG || aclass(ctxt, &p.To) == C_REG) { fc := aclass(ctxt, &p.From)
tc := aclass(ctxt, &p.To)
if (p.As == AFMOVD || p.As == AFMOVS) && (fc == C_REG || fc == C_ZCON || tc == C_REG || tc == C_ZCON) {
// FMOV Rx, Fy or FMOV Fy, Rx // FMOV Rx, Fy or FMOV Fy, Rx
o1 = FPCVTI(0, 0, 0, 0, 6) o1 = FPCVTI(0, 0, 0, 0, 6)
if p.As == AFMOVD { if p.As == AFMOVD {
o1 |= 1<<31 | 1<<22 // 64-bit o1 |= 1<<31 | 1<<22 // 64-bit
} }
if aclass(ctxt, &p.From) == C_REG { if fc == C_REG || fc == C_ZCON {
o1 |= 1 << 16 // FMOV Rx, Fy o1 |= 1 << 16 // FMOV Rx, Fy
} }
} else { } else {
......
...@@ -262,6 +262,11 @@ func progedit(ctxt *obj.Link, p *obj.Prog) { ...@@ -262,6 +262,11 @@ func progedit(ctxt *obj.Link, p *obj.Prog) {
if p.From.Type == obj.TYPE_FCONST { if p.From.Type == obj.TYPE_FCONST {
f32 := float32(p.From.Val.(float64)) f32 := float32(p.From.Val.(float64))
i32 := math.Float32bits(f32) i32 := math.Float32bits(f32)
if i32 == 0 {
p.From.Type = obj.TYPE_REG
p.From.Reg = REGZERO
break
}
literal := fmt.Sprintf("$f32.%08x", i32) literal := fmt.Sprintf("$f32.%08x", i32)
s := obj.Linklookup(ctxt, literal, 0) s := obj.Linklookup(ctxt, literal, 0)
s.Size = 4 s.Size = 4
...@@ -275,6 +280,11 @@ func progedit(ctxt *obj.Link, p *obj.Prog) { ...@@ -275,6 +280,11 @@ func progedit(ctxt *obj.Link, p *obj.Prog) {
case AFMOVD: case AFMOVD:
if p.From.Type == obj.TYPE_FCONST { if p.From.Type == obj.TYPE_FCONST {
i64 := math.Float64bits(p.From.Val.(float64)) i64 := math.Float64bits(p.From.Val.(float64))
if i64 == 0 {
p.From.Type = obj.TYPE_REG
p.From.Reg = REGZERO
break
}
literal := fmt.Sprintf("$f64.%016x", i64) literal := fmt.Sprintf("$f64.%016x", i64)
s := obj.Linklookup(ctxt, literal, 0) s := obj.Linklookup(ctxt, literal, 0)
s.Size = 8 s.Size = 8
......
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