Skip to content

Commit 03fb1f6

Browse files
smasher164bradfitz
authored andcommitted
cmd/compile: don't use FMA on plan9
CL 137156 introduces an intrinsic on AMD64 that executes vfmadd231sd when feature detection is successful. However, because floating-point isn't allowed in note handler, the builder disables SSE instructions, and fails when attempting to execute this instruction. This change disables FMA on plan9 to immediately use the software fallback. Fixes #35063. Change-Id: I87d8f0995bd2f15013d203e618938f5079c9eed2 Reviewed-on: https://go-review.googlesource.com/c/go/+/202617 Reviewed-by: Keith Randall <khr@golang.org>
1 parent 48eb79e commit 03fb1f6

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/cmd/compile/internal/gc/ssa.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3330,6 +3330,11 @@ func init() {
33303330
sys.ARM64, sys.PPC64, sys.S390X)
33313331
addF("math", "Fma",
33323332
func(s *state, n *Node, args []*ssa.Value) *ssa.Value {
3333+
if !s.config.UseFMA {
3334+
a := s.call(n, callNormal)
3335+
s.vars[n] = s.load(types.Types[TFLOAT64], a)
3336+
return s.variable(n, types.Types[TFLOAT64])
3337+
}
33333338
addr := s.entryNewValue1A(ssa.OpAddr, types.Types[TBOOL].PtrTo(), x86HasFMA, s.sb)
33343339
v := s.load(types.Types[TBOOL], addr)
33353340
b := s.endBlock()
@@ -3360,6 +3365,11 @@ func init() {
33603365
sys.AMD64)
33613366
addF("math", "Fma",
33623367
func(s *state, n *Node, args []*ssa.Value) *ssa.Value {
3368+
if !s.config.UseFMA {
3369+
a := s.call(n, callNormal)
3370+
s.vars[n] = s.load(types.Types[TFLOAT64], a)
3371+
return s.variable(n, types.Types[TFLOAT64])
3372+
}
33633373
addr := s.entryNewValue1A(ssa.OpAddr, types.Types[TBOOL].PtrTo(), armHasVFPv4, s.sb)
33643374
v := s.load(types.Types[TBOOL], addr)
33653375
b := s.endBlock()

src/cmd/compile/internal/ssa/config.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type Config struct {
4343
Race bool // race detector enabled
4444
NeedsFpScratch bool // No direct move between GP and FP register sets
4545
BigEndian bool //
46+
UseFMA bool // Use hardware FMA operation
4647
}
4748

4849
type (
@@ -326,12 +327,18 @@ func NewConfig(arch string, types Types, ctxt *obj.Link, optimize bool) *Config
326327
c.ctxt = ctxt
327328
c.optimize = optimize
328329
c.useSSE = true
330+
c.UseFMA = true
329331

330-
// Don't use Duff's device nor SSE on Plan 9 AMD64, because
331-
// floating point operations are not allowed in note handler.
332-
if objabi.GOOS == "plan9" && arch == "amd64" {
333-
c.noDuffDevice = true
334-
c.useSSE = false
332+
// On Plan 9, floating point operations are not allowed in note handler.
333+
if objabi.GOOS == "plan9" {
334+
// Don't use FMA on Plan 9
335+
c.UseFMA = false
336+
337+
// Don't use Duff's device and SSE on Plan 9 AMD64.
338+
if arch == "amd64" {
339+
c.noDuffDevice = true
340+
c.useSSE = false
341+
}
335342
}
336343

337344
if ctxt.Flag_shared {

0 commit comments

Comments
 (0)