Commit 99683483 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/internal/obj: unify creation of numeric literal syms

This is a straightforward refactoring,
to reduce the scope of upcoming changes.

The symbol size and AttrLocal=true was not
set universally, but it appears not to matter,
since toolstash -cmp is happy.

Passes toolstash-check -all.

Change-Id: I7f8392f939592d3a1bc6f61dec992f5661f42fca
Reviewed-on: https://go-review.googlesource.com/39791
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent c3114882
...@@ -703,10 +703,8 @@ var knownFormats = map[string]string{ ...@@ -703,10 +703,8 @@ var knownFormats = map[string]string{
"uint16 %d": "", "uint16 %d": "",
"uint16 %v": "", "uint16 %v": "",
"uint16 %x": "", "uint16 %x": "",
"uint32 %08x": "",
"uint32 %d": "", "uint32 %d": "",
"uint32 %x": "", "uint32 %x": "",
"uint64 %016x": "",
"uint64 %08x": "", "uint64 %08x": "",
"uint64 %d": "", "uint64 %d": "",
"uint64 %x": "", "uint64 %x": "",
......
...@@ -443,17 +443,15 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { ...@@ -443,17 +443,15 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
p.To.Type = obj.TYPE_REG p.To.Type = obj.TYPE_REG
p.To.Reg = x p.To.Reg = x
case ssa.Op386MOVSSconst1, ssa.Op386MOVSDconst1: case ssa.Op386MOVSSconst1, ssa.Op386MOVSDconst1:
var literal string
if v.Op == ssa.Op386MOVSDconst1 {
literal = fmt.Sprintf("$f64.%016x", uint64(v.AuxInt))
} else {
literal = fmt.Sprintf("$f32.%08x", math.Float32bits(float32(math.Float64frombits(uint64(v.AuxInt)))))
}
p := s.Prog(x86.ALEAL) p := s.Prog(x86.ALEAL)
p.From.Type = obj.TYPE_MEM p.From.Type = obj.TYPE_MEM
p.From.Name = obj.NAME_EXTERN p.From.Name = obj.NAME_EXTERN
p.From.Sym = gc.Ctxt.Lookup(literal, 0) f := math.Float64frombits(uint64(v.AuxInt))
p.From.Sym.Set(obj.AttrLocal, true) if v.Op == ssa.Op386MOVSDconst1 {
p.From.Sym = gc.Ctxt.Float64Sym(f)
} else {
p.From.Sym = gc.Ctxt.Float32Sym(float32(f))
}
p.To.Type = obj.TYPE_REG p.To.Type = obj.TYPE_REG
p.To.Reg = v.Reg() p.To.Reg = v.Reg()
case ssa.Op386MOVSSconst2, ssa.Op386MOVSDconst2: case ssa.Op386MOVSSconst2, ssa.Op386MOVSDconst2:
......
...@@ -33,8 +33,6 @@ package arm ...@@ -33,8 +33,6 @@ package arm
import ( import (
"cmd/internal/obj" "cmd/internal/obj"
"cmd/internal/sys" "cmd/internal/sys"
"fmt"
"math"
) )
var progedit_tlsfallback *obj.LSym var progedit_tlsfallback *obj.LSym
...@@ -108,22 +106,16 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) { ...@@ -108,22 +106,16 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) {
case AMOVF: case AMOVF:
if p.From.Type == obj.TYPE_FCONST && chipfloat5(ctxt, p.From.Val.(float64)) < 0 && (chipzero5(ctxt, p.From.Val.(float64)) < 0 || p.Scond&C_SCOND != C_SCOND_NONE) { if p.From.Type == obj.TYPE_FCONST && chipfloat5(ctxt, p.From.Val.(float64)) < 0 && (chipzero5(ctxt, p.From.Val.(float64)) < 0 || p.Scond&C_SCOND != C_SCOND_NONE) {
f32 := float32(p.From.Val.(float64)) f32 := float32(p.From.Val.(float64))
i32 := math.Float32bits(f32)
literal := fmt.Sprintf("$f32.%08x", i32)
s := ctxt.Lookup(literal, 0)
p.From.Type = obj.TYPE_MEM p.From.Type = obj.TYPE_MEM
p.From.Sym = s p.From.Sym = ctxt.Float32Sym(f32)
p.From.Name = obj.NAME_EXTERN p.From.Name = obj.NAME_EXTERN
p.From.Offset = 0 p.From.Offset = 0
} }
case AMOVD: case AMOVD:
if p.From.Type == obj.TYPE_FCONST && chipfloat5(ctxt, p.From.Val.(float64)) < 0 && (chipzero5(ctxt, p.From.Val.(float64)) < 0 || p.Scond&C_SCOND != C_SCOND_NONE) { if p.From.Type == obj.TYPE_FCONST && chipfloat5(ctxt, p.From.Val.(float64)) < 0 && (chipzero5(ctxt, p.From.Val.(float64)) < 0 || p.Scond&C_SCOND != C_SCOND_NONE) {
i64 := math.Float64bits(p.From.Val.(float64))
literal := fmt.Sprintf("$f64.%016x", i64)
s := ctxt.Lookup(literal, 0)
p.From.Type = obj.TYPE_MEM p.From.Type = obj.TYPE_MEM
p.From.Sym = s p.From.Sym = ctxt.Float64Sym(p.From.Val.(float64))
p.From.Name = obj.NAME_EXTERN p.From.Name = obj.NAME_EXTERN
p.From.Offset = 0 p.From.Offset = 0
} }
......
...@@ -33,7 +33,6 @@ package arm64 ...@@ -33,7 +33,6 @@ package arm64
import ( import (
"cmd/internal/obj" "cmd/internal/obj"
"cmd/internal/sys" "cmd/internal/sys"
"fmt"
"math" "math"
) )
...@@ -259,36 +258,27 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) { ...@@ -259,36 +258,27 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) {
case AFMOVS: case AFMOVS:
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) if math.Float32bits(f32) == 0 {
if i32 == 0 {
p.From.Type = obj.TYPE_REG p.From.Type = obj.TYPE_REG
p.From.Reg = REGZERO p.From.Reg = REGZERO
break break
} }
literal := fmt.Sprintf("$f32.%08x", i32)
s := ctxt.Lookup(literal, 0)
s.Size = 4
p.From.Type = obj.TYPE_MEM p.From.Type = obj.TYPE_MEM
p.From.Sym = s p.From.Sym = ctxt.Float32Sym(f32)
p.From.Sym.Set(obj.AttrLocal, true)
p.From.Name = obj.NAME_EXTERN p.From.Name = obj.NAME_EXTERN
p.From.Offset = 0 p.From.Offset = 0
} }
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)) f64 := p.From.Val.(float64)
if i64 == 0 { if math.Float64bits(f64) == 0 {
p.From.Type = obj.TYPE_REG p.From.Type = obj.TYPE_REG
p.From.Reg = REGZERO p.From.Reg = REGZERO
break break
} }
literal := fmt.Sprintf("$f64.%016x", i64)
s := ctxt.Lookup(literal, 0)
s.Size = 8
p.From.Type = obj.TYPE_MEM p.From.Type = obj.TYPE_MEM
p.From.Sym = s p.From.Sym = ctxt.Float64Sym(f64)
p.From.Sym.Set(obj.AttrLocal, true)
p.From.Name = obj.NAME_EXTERN p.From.Name = obj.NAME_EXTERN
p.From.Offset = 0 p.From.Offset = 0
} }
......
...@@ -58,36 +58,29 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) { ...@@ -58,36 +58,29 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) {
case AMOVF: case AMOVF:
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) if math.Float32bits(f32) == 0 {
if i32 == 0 {
p.As = AMOVW p.As = AMOVW
p.From.Type = obj.TYPE_REG p.From.Type = obj.TYPE_REG
p.From.Reg = REGZERO p.From.Reg = REGZERO
break break
} }
literal := fmt.Sprintf("$f32.%08x", i32)
s := ctxt.Lookup(literal, 0)
s.Size = 4
p.From.Type = obj.TYPE_MEM p.From.Type = obj.TYPE_MEM
p.From.Sym = s p.From.Sym = ctxt.Float32Sym(f32)
p.From.Name = obj.NAME_EXTERN p.From.Name = obj.NAME_EXTERN
p.From.Offset = 0 p.From.Offset = 0
} }
case AMOVD: case AMOVD:
if p.From.Type == obj.TYPE_FCONST { if p.From.Type == obj.TYPE_FCONST {
i64 := math.Float64bits(p.From.Val.(float64)) f64 := p.From.Val.(float64)
if i64 == 0 && ctxt.Arch.Family == sys.MIPS64 { if math.Float64bits(f64) == 0 && ctxt.Arch.Family == sys.MIPS64 {
p.As = AMOVV p.As = AMOVV
p.From.Type = obj.TYPE_REG p.From.Type = obj.TYPE_REG
p.From.Reg = REGZERO p.From.Reg = REGZERO
break break
} }
literal := fmt.Sprintf("$f64.%016x", i64)
s := ctxt.Lookup(literal, 0)
s.Size = 8
p.From.Type = obj.TYPE_MEM p.From.Type = obj.TYPE_MEM
p.From.Sym = s p.From.Sym = ctxt.Float64Sym(f64)
p.From.Name = obj.NAME_EXTERN p.From.Name = obj.NAME_EXTERN
p.From.Offset = 0 p.From.Offset = 0
} }
...@@ -95,11 +88,8 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) { ...@@ -95,11 +88,8 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) {
// Put >32-bit constants in memory and load them // Put >32-bit constants in memory and load them
case AMOVV: case AMOVV:
if p.From.Type == obj.TYPE_CONST && p.From.Name == obj.NAME_NONE && p.From.Reg == 0 && int64(int32(p.From.Offset)) != p.From.Offset { if p.From.Type == obj.TYPE_CONST && p.From.Name == obj.NAME_NONE && p.From.Reg == 0 && int64(int32(p.From.Offset)) != p.From.Offset {
literal := fmt.Sprintf("$i64.%016x", uint64(p.From.Offset))
s := ctxt.Lookup(literal, 0)
s.Size = 8
p.From.Type = obj.TYPE_MEM p.From.Type = obj.TYPE_MEM
p.From.Sym = s p.From.Sym = ctxt.Int64Sym(p.From.Offset)
p.From.Name = obj.NAME_EXTERN p.From.Name = obj.NAME_EXTERN
p.From.Offset = 0 p.From.Offset = 0
} }
......
...@@ -32,8 +32,6 @@ package ppc64 ...@@ -32,8 +32,6 @@ package ppc64
import ( import (
"cmd/internal/obj" "cmd/internal/obj"
"cmd/internal/sys" "cmd/internal/sys"
"fmt"
"math"
) )
func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) { func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) {
...@@ -57,26 +55,17 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) { ...@@ -57,26 +55,17 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) {
case AFMOVS: case AFMOVS:
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)
literal := fmt.Sprintf("$f32.%08x", i32)
s := ctxt.Lookup(literal, 0)
s.Size = 4
p.From.Type = obj.TYPE_MEM p.From.Type = obj.TYPE_MEM
p.From.Sym = s p.From.Sym = ctxt.Float32Sym(f32)
p.From.Sym.Set(obj.AttrLocal, true)
p.From.Name = obj.NAME_EXTERN p.From.Name = obj.NAME_EXTERN
p.From.Offset = 0 p.From.Offset = 0
} }
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)) f64 := p.From.Val.(float64)
literal := fmt.Sprintf("$f64.%016x", i64)
s := ctxt.Lookup(literal, 0)
s.Size = 8
p.From.Type = obj.TYPE_MEM p.From.Type = obj.TYPE_MEM
p.From.Sym = s p.From.Sym = ctxt.Float64Sym(f64)
p.From.Sym.Set(obj.AttrLocal, true)
p.From.Name = obj.NAME_EXTERN p.From.Name = obj.NAME_EXTERN
p.From.Offset = 0 p.From.Offset = 0
} }
...@@ -84,12 +73,8 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) { ...@@ -84,12 +73,8 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) {
// Put >32-bit constants in memory and load them // Put >32-bit constants in memory and load them
case AMOVD: case AMOVD:
if p.From.Type == obj.TYPE_CONST && p.From.Name == obj.NAME_NONE && p.From.Reg == 0 && int64(int32(p.From.Offset)) != p.From.Offset { if p.From.Type == obj.TYPE_CONST && p.From.Name == obj.NAME_NONE && p.From.Reg == 0 && int64(int32(p.From.Offset)) != p.From.Offset {
literal := fmt.Sprintf("$i64.%016x", uint64(p.From.Offset))
s := ctxt.Lookup(literal, 0)
s.Size = 8
p.From.Type = obj.TYPE_MEM p.From.Type = obj.TYPE_MEM
p.From.Sym = s p.From.Sym = ctxt.Int64Sym(p.From.Offset)
p.From.Sym.Set(obj.AttrLocal, true)
p.From.Name = obj.NAME_EXTERN p.From.Name = obj.NAME_EXTERN
p.From.Offset = 0 p.From.Offset = 0
} }
......
...@@ -32,7 +32,6 @@ package s390x ...@@ -32,7 +32,6 @@ package s390x
import ( import (
"cmd/internal/obj" "cmd/internal/obj"
"cmd/internal/sys" "cmd/internal/sys"
"fmt"
"math" "math"
) )
...@@ -57,32 +56,23 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) { ...@@ -57,32 +56,23 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) {
case AFMOVS: case AFMOVS:
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) if math.Float32bits(f32) == 0 { // +0
if i32 == 0 { // +0
break break
} }
literal := fmt.Sprintf("$f32.%08x", i32)
s := ctxt.Lookup(literal, 0)
s.Size = 4
p.From.Type = obj.TYPE_MEM p.From.Type = obj.TYPE_MEM
p.From.Sym = s p.From.Sym = ctxt.Float32Sym(f32)
p.From.Sym.Set(obj.AttrLocal, true)
p.From.Name = obj.NAME_EXTERN p.From.Name = obj.NAME_EXTERN
p.From.Offset = 0 p.From.Offset = 0
} }
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)) f64 := p.From.Val.(float64)
if i64 == 0 { // +0 if math.Float64bits(f64) == 0 { // +0
break break
} }
literal := fmt.Sprintf("$f64.%016x", i64)
s := ctxt.Lookup(literal, 0)
s.Size = 8
p.From.Type = obj.TYPE_MEM p.From.Type = obj.TYPE_MEM
p.From.Sym = s p.From.Sym = ctxt.Float64Sym(f64)
p.From.Sym.Set(obj.AttrLocal, true)
p.From.Name = obj.NAME_EXTERN p.From.Name = obj.NAME_EXTERN
p.From.Offset = 0 p.From.Offset = 0
} }
...@@ -94,12 +84,8 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) { ...@@ -94,12 +84,8 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) {
if int64(int32(val)) != val && if int64(int32(val)) != val &&
int64(uint32(val)) != val && int64(uint32(val)) != val &&
int64(uint64(val)&(0xffffffff<<32)) != val { int64(uint64(val)&(0xffffffff<<32)) != val {
literal := fmt.Sprintf("$i64.%016x", uint64(p.From.Offset))
s := ctxt.Lookup(literal, 0)
s.Size = 8
p.From.Type = obj.TYPE_MEM p.From.Type = obj.TYPE_MEM
p.From.Sym = s p.From.Sym = ctxt.Int64Sym(p.From.Offset)
p.From.Sym.Set(obj.AttrLocal, true)
p.From.Name = obj.NAME_EXTERN p.From.Name = obj.NAME_EXTERN
p.From.Offset = 0 p.From.Offset = 0
} }
......
...@@ -32,7 +32,9 @@ ...@@ -32,7 +32,9 @@
package obj package obj
import ( import (
"fmt"
"log" "log"
"math"
"os" "os"
"path/filepath" "path/filepath"
) )
...@@ -82,6 +84,32 @@ func (ctxt *Link) Lookup(name string, v int) *LSym { ...@@ -82,6 +84,32 @@ func (ctxt *Link) Lookup(name string, v int) *LSym {
return s return s
} }
func (ctxt *Link) Float32Sym(f float32) *LSym {
i := math.Float32bits(f)
name := fmt.Sprintf("$f32.%08x", i)
s := ctxt.Lookup(name, 0)
s.Size = 4
s.Set(AttrLocal, true)
return s
}
func (ctxt *Link) Float64Sym(f float64) *LSym {
i := math.Float64bits(f)
name := fmt.Sprintf("$f64.%016x", i)
s := ctxt.Lookup(name, 0)
s.Size = 8
s.Set(AttrLocal, true)
return s
}
func (ctxt *Link) Int64Sym(i int64) *LSym {
name := fmt.Sprintf("$i64.%016x", uint64(i))
s := ctxt.Lookup(name, 0)
s.Size = 8
s.Set(AttrLocal, true)
return s
}
func Linksymfmt(s *LSym) string { func Linksymfmt(s *LSym) string {
if s == nil { if s == nil {
return "<nil>" return "<nil>"
......
...@@ -33,7 +33,6 @@ package x86 ...@@ -33,7 +33,6 @@ package x86
import ( import (
"cmd/internal/obj" "cmd/internal/obj"
"cmd/internal/sys" "cmd/internal/sys"
"fmt"
"math" "math"
"strings" "strings"
) )
...@@ -241,13 +240,9 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) { ...@@ -241,13 +240,9 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) {
AUCOMISS: AUCOMISS:
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)
literal := fmt.Sprintf("$f32.%08x", i32)
s := ctxt.Lookup(literal, 0)
p.From.Type = obj.TYPE_MEM p.From.Type = obj.TYPE_MEM
p.From.Name = obj.NAME_EXTERN p.From.Name = obj.NAME_EXTERN
p.From.Sym = s p.From.Sym = ctxt.Float32Sym(f32)
p.From.Sym.Set(obj.AttrLocal, true)
p.From.Offset = 0 p.From.Offset = 0
} }
...@@ -281,13 +276,10 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) { ...@@ -281,13 +276,10 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) {
ACOMISD, ACOMISD,
AUCOMISD: AUCOMISD:
if p.From.Type == obj.TYPE_FCONST { if p.From.Type == obj.TYPE_FCONST {
i64 := math.Float64bits(p.From.Val.(float64)) f64 := p.From.Val.(float64)
literal := fmt.Sprintf("$f64.%016x", i64)
s := ctxt.Lookup(literal, 0)
p.From.Type = obj.TYPE_MEM p.From.Type = obj.TYPE_MEM
p.From.Name = obj.NAME_EXTERN p.From.Name = obj.NAME_EXTERN
p.From.Sym = s p.From.Sym = ctxt.Float64Sym(f64)
p.From.Sym.Set(obj.AttrLocal, true)
p.From.Offset = 0 p.From.Offset = 0
} }
} }
......
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