Commit a329e21c authored by Keith Randall's avatar Keith Randall

[dev.ssa] cmd/compile/internal/ssa: implement OSQRT

Change-Id: Iec61ca1bdc064c29ceca6d47f600d5643d0a64dd
Reviewed-on: https://go-review.googlesource.com/14533Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 0726931c
...@@ -988,6 +988,8 @@ var opToSSA = map[opAndType]ssa.Op{ ...@@ -988,6 +988,8 @@ var opToSSA = map[opAndType]ssa.Op{
opAndType{OLROT, TUINT16}: ssa.OpLrot16, opAndType{OLROT, TUINT16}: ssa.OpLrot16,
opAndType{OLROT, TUINT32}: ssa.OpLrot32, opAndType{OLROT, TUINT32}: ssa.OpLrot32,
opAndType{OLROT, TUINT64}: ssa.OpLrot64, opAndType{OLROT, TUINT64}: ssa.OpLrot64,
opAndType{OSQRT, TFLOAT64}: ssa.OpSqrt,
} }
func (s *state) concreteEtype(t *Type) uint8 { func (s *state) concreteEtype(t *Type) uint8 {
...@@ -1643,7 +1645,7 @@ func (s *state) expr(n *Node) *ssa.Value { ...@@ -1643,7 +1645,7 @@ func (s *state) expr(n *Node) *ssa.Value {
s.newValue1(negop, tp, s.newValue1(ssa.OpComplexImag, tp, a))) s.newValue1(negop, tp, s.newValue1(ssa.OpComplexImag, tp, a)))
} }
return s.newValue1(s.ssaOp(n.Op, n.Type), a.Type, a) return s.newValue1(s.ssaOp(n.Op, n.Type), a.Type, a)
case ONOT, OCOM: case ONOT, OCOM, OSQRT:
a := s.expr(n.Left) a := s.expr(n.Left)
return s.newValue1(s.ssaOp(n.Op, n.Type), a.Type, a) return s.newValue1(s.ssaOp(n.Op, n.Type), a.Type, a)
case OIMAG, OREAL: case OIMAG, OREAL:
...@@ -3325,6 +3327,12 @@ func (s *genState) genValue(v *ssa.Value) { ...@@ -3325,6 +3327,12 @@ func (s *genState) genValue(v *ssa.Value) {
p := Prog(v.Op.Asm()) p := Prog(v.Op.Asm())
p.To.Type = obj.TYPE_REG p.To.Type = obj.TYPE_REG
p.To.Reg = r p.To.Reg = r
case ssa.OpAMD64SQRTSD:
p := Prog(v.Op.Asm())
p.From.Type = obj.TYPE_REG
p.From.Reg = regnum(v.Args[0])
p.To.Type = obj.TYPE_REG
p.To.Reg = regnum(v)
case ssa.OpSP, ssa.OpSB: case ssa.OpSP, ssa.OpSB:
// nothing to do // nothing to do
case ssa.OpAMD64SETEQ, ssa.OpAMD64SETNE, case ssa.OpAMD64SETEQ, ssa.OpAMD64SETNE,
......
...@@ -89,6 +89,8 @@ ...@@ -89,6 +89,8 @@
(Com16 x) -> (NOTW x) (Com16 x) -> (NOTW x)
(Com8 x) -> (NOTB x) (Com8 x) -> (NOTB x)
(Sqrt x) -> (SQRTSD x)
// Note: we always extend to 64 bits even though some ops don't need that many result bits. // Note: we always extend to 64 bits even though some ops don't need that many result bits.
(SignExt8to16 x) -> (MOVBQSX x) (SignExt8to16 x) -> (MOVBQSX x)
(SignExt8to32 x) -> (MOVBQSX x) (SignExt8to32 x) -> (MOVBQSX x)
......
...@@ -307,6 +307,8 @@ func init() { ...@@ -307,6 +307,8 @@ func init() {
{name: "NOTW", reg: gp11, asm: "NOTW"}, // ^arg0 {name: "NOTW", reg: gp11, asm: "NOTW"}, // ^arg0
{name: "NOTB", reg: gp11, asm: "NOTB"}, // ^arg0 {name: "NOTB", reg: gp11, asm: "NOTB"}, // ^arg0
{name: "SQRTSD", reg: fp11, asm: "SQRTSD"}, // sqrt(arg0)
{name: "SBBQcarrymask", reg: flagsgp, asm: "SBBQ"}, // (int64)(-1) if carry is set, 0 if carry is clear. {name: "SBBQcarrymask", reg: flagsgp, asm: "SBBQ"}, // (int64)(-1) if carry is set, 0 if carry is clear.
{name: "SBBLcarrymask", reg: flagsgp, asm: "SBBL"}, // (int32)(-1) if carry is set, 0 if carry is clear. {name: "SBBLcarrymask", reg: flagsgp, asm: "SBBL"}, // (int32)(-1) if carry is set, 0 if carry is clear.
// Note: SBBW and SBBB are subsumed by SBBL // Note: SBBW and SBBB are subsumed by SBBL
......
...@@ -232,6 +232,8 @@ var genericOps = []opData{ ...@@ -232,6 +232,8 @@ var genericOps = []opData{
{name: "Com32"}, {name: "Com32"},
{name: "Com64"}, {name: "Com64"},
{name: "Sqrt"}, // sqrt(arg0), float64 only
// Data movement // Data movement
{name: "Phi"}, // select an argument based on which predecessor block we came from {name: "Phi"}, // select an argument based on which predecessor block we came from
{name: "Copy"}, // output = arg0 {name: "Copy"}, // output = arg0
......
...@@ -203,6 +203,7 @@ const ( ...@@ -203,6 +203,7 @@ const (
OpAMD64NOTL OpAMD64NOTL
OpAMD64NOTW OpAMD64NOTW
OpAMD64NOTB OpAMD64NOTB
OpAMD64SQRTSD
OpAMD64SBBQcarrymask OpAMD64SBBQcarrymask
OpAMD64SBBLcarrymask OpAMD64SBBLcarrymask
OpAMD64SETEQ OpAMD64SETEQ
...@@ -448,6 +449,7 @@ const ( ...@@ -448,6 +449,7 @@ const (
OpCom16 OpCom16
OpCom32 OpCom32
OpCom64 OpCom64
OpSqrt
OpPhi OpPhi
OpCopy OpCopy
OpConstBool OpConstBool
...@@ -2361,6 +2363,18 @@ var opcodeTable = [...]opInfo{ ...@@ -2361,6 +2363,18 @@ var opcodeTable = [...]opInfo{
}, },
}, },
}, },
{
name: "SQRTSD",
asm: x86.ASQRTSD,
reg: regInfo{
inputs: []inputInfo{
{0, 4294901760}, // .X0 .X1 .X2 .X3 .X4 .X5 .X6 .X7 .X8 .X9 .X10 .X11 .X12 .X13 .X14 .X15
},
outputs: []regMask{
4294901760, // .X0 .X1 .X2 .X3 .X4 .X5 .X6 .X7 .X8 .X9 .X10 .X11 .X12 .X13 .X14 .X15
},
},
},
{ {
name: "SBBQcarrymask", name: "SBBQcarrymask",
asm: x86.ASBBQ, asm: x86.ASBBQ,
...@@ -3809,6 +3823,10 @@ var opcodeTable = [...]opInfo{ ...@@ -3809,6 +3823,10 @@ var opcodeTable = [...]opInfo{
name: "Com64", name: "Com64",
generic: true, generic: true,
}, },
{
name: "Sqrt",
generic: true,
},
{ {
name: "Phi", name: "Phi",
generic: true, generic: true,
......
...@@ -9391,6 +9391,22 @@ func rewriteValueAMD64(v *Value, config *Config) bool { ...@@ -9391,6 +9391,22 @@ func rewriteValueAMD64(v *Value, config *Config) bool {
goto endcef6d6001d3f25cf5dacee11a46e5c8c goto endcef6d6001d3f25cf5dacee11a46e5c8c
endcef6d6001d3f25cf5dacee11a46e5c8c: endcef6d6001d3f25cf5dacee11a46e5c8c:
; ;
case OpSqrt:
// match: (Sqrt x)
// cond:
// result: (SQRTSD x)
{
x := v.Args[0]
v.Op = OpAMD64SQRTSD
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.AddArg(x)
return true
}
goto end72f79ca9ec139e15856aaa03338cf543
end72f79ca9ec139e15856aaa03338cf543:
;
case OpStaticCall: case OpStaticCall:
// match: (StaticCall [argwid] {target} mem) // match: (StaticCall [argwid] {target} mem)
// cond: // cond:
......
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