Skip to content

Commit

Permalink
cmd/compile: don't use FMA on plan9
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
smasher164 authored and bradfitz committed Oct 22, 2019
1 parent 48eb79e commit 03fb1f6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
10 changes: 10 additions & 0 deletions src/cmd/compile/internal/gc/ssa.go
Original file line number Diff line number Diff line change
Expand Up @@ -3330,6 +3330,11 @@ func init() {
sys.ARM64, sys.PPC64, sys.S390X)
addF("math", "Fma",
func(s *state, n *Node, args []*ssa.Value) *ssa.Value {
if !s.config.UseFMA {
a := s.call(n, callNormal)
s.vars[n] = s.load(types.Types[TFLOAT64], a)
return s.variable(n, types.Types[TFLOAT64])
}
addr := s.entryNewValue1A(ssa.OpAddr, types.Types[TBOOL].PtrTo(), x86HasFMA, s.sb)
v := s.load(types.Types[TBOOL], addr)
b := s.endBlock()
Expand Down Expand Up @@ -3360,6 +3365,11 @@ func init() {
sys.AMD64)
addF("math", "Fma",
func(s *state, n *Node, args []*ssa.Value) *ssa.Value {
if !s.config.UseFMA {
a := s.call(n, callNormal)
s.vars[n] = s.load(types.Types[TFLOAT64], a)
return s.variable(n, types.Types[TFLOAT64])
}
addr := s.entryNewValue1A(ssa.OpAddr, types.Types[TBOOL].PtrTo(), armHasVFPv4, s.sb)
v := s.load(types.Types[TBOOL], addr)
b := s.endBlock()
Expand Down
17 changes: 12 additions & 5 deletions src/cmd/compile/internal/ssa/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type Config struct {
Race bool // race detector enabled
NeedsFpScratch bool // No direct move between GP and FP register sets
BigEndian bool //
UseFMA bool // Use hardware FMA operation
}

type (
Expand Down Expand Up @@ -326,12 +327,18 @@ func NewConfig(arch string, types Types, ctxt *obj.Link, optimize bool) *Config
c.ctxt = ctxt
c.optimize = optimize
c.useSSE = true
c.UseFMA = true

// Don't use Duff's device nor SSE on Plan 9 AMD64, because
// floating point operations are not allowed in note handler.
if objabi.GOOS == "plan9" && arch == "amd64" {
c.noDuffDevice = true
c.useSSE = false
// On Plan 9, floating point operations are not allowed in note handler.
if objabi.GOOS == "plan9" {
// Don't use FMA on Plan 9
c.UseFMA = false

// Don't use Duff's device and SSE on Plan 9 AMD64.
if arch == "amd64" {
c.noDuffDevice = true
c.useSSE = false
}
}

if ctxt.Flag_shared {
Expand Down

0 comments on commit 03fb1f6

Please sign in to comment.