Skip to content

x/arch: incorrect disassembly for x86 FMA instruction #41043

Open
@zhangyoufu

Description

@zhangyoufu

What version of Go are you using (go version)?

$ go version
go version go1.15 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/zhangyoufu/Library/Caches/go-build"
GOENV="/Users/zhangyoufu/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/zhangyoufu/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/zhangyoufu/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.15/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.15/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/vf/10556_c97vj8qmvw000tgh5w0000gn/T/go-build228934958=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Sample:

package main

import (
	"log"
	"math"
)

func main() {
	log.Print(math.FMA(0, 0, 0))
}
$ go tool compile -S a.go | head -n 20
"".main STEXT size=183 args=0x0 locals=0x38
	0x0000 00000 (a.go:8)	TEXT	"".main(SB), ABIInternal, $56-0
	0x0000 00000 (a.go:8)	MOVQ	(TLS), CX
	0x0009 00009 (a.go:8)	CMPQ	SP, 16(CX)
	0x000d 00013 (a.go:8)	PCDATA	$0, $-2
	0x000d 00013 (a.go:8)	JLS	173
	0x0013 00019 (a.go:8)	PCDATA	$0, $-1
	0x0013 00019 (a.go:8)	SUBQ	$56, SP
	0x0017 00023 (a.go:8)	MOVQ	BP, 48(SP)
	0x001c 00028 (a.go:8)	LEAQ	48(SP), BP
	0x0021 00033 (a.go:8)	FUNCDATA	$0, gclocals·69c1753bd5f81501d95132d08af04464(SB)
	0x0021 00033 (a.go:8)	FUNCDATA	$1, gclocals·568470801006e5c0dc3947ea998fe279(SB)
	0x0021 00033 (a.go:8)	FUNCDATA	$3, "".main.stkobj(SB)
	0x0021 00033 (a.go:8)	MOVBQZX	runtime.x86HasFMA(SB), AX
	0x0029 00041 (a.go:8)	TESTQ	AX, AX
	0x002c 00044 (a.go:9)	JEQ	136
	0x002e 00046 (a.go:9)	XORPS	X0, X0
	0x0031 00049 (a.go:9)	VFMADD231SD	X0, X0, X0
	0x0036 00054 (a.go:9)	XORPS	X1, X1
	0x0039 00057 (a.go:9)	MOVUPS	X1, ""..autotmp_1+32(SP)
go tool compile: signal: broken pipe
$ go build a.go
$ go tool objdump -s main.main a | head -n13
TEXT main.main(SB) /Users/zhangyoufu/a.go
  a.go:8		0x10a8760		65488b0c2530000000	MOVQ GS:0x30, CX
  a.go:8		0x10a8769		483b6110		CMPQ 0x10(CX), SP
  a.go:8		0x10a876d		0f869a000000		JBE 0x10a880d
  a.go:8		0x10a8773		4883ec38		SUBQ $0x38, SP
  a.go:8		0x10a8777		48896c2430		MOVQ BP, 0x30(SP)
  a.go:8		0x10a877c		488d6c2430		LEAQ 0x30(SP), BP
  a.go:8		0x10a8781		480fb6054b710f00	MOVZX runtime.x86HasFMA(SB), AX
  a.go:8		0x10a8789		4885c0			TESTQ AX, AX
  a.go:9		0x10a878c		745a			JE 0x10a87e8
  a.go:9		0x10a878e		0f57c0			XORPS X0, X0
  a.go:9		0x10a8791		c4e2f9b9c00f57c9	MOVL $-0x36a8f040, CX
  a.go:9		0x10a8799		0f114c2420		MOVUPS X1, 0x20(SP)

What did you expect to see?

objdump shows FMA instruction VFMADD231SD X0, X0, X0.

What did you see instead?

objdump shows MOVL $-0x36a8f040, CX

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions