Skip to content

cmd/compile: optimize float32/float64 conversions used with math package #75463

@dominikh

Description

@dominikh

Most functions in the math package operate on float64s. For users who work with float32s this leads to a lot of code like float32(math.Floor(float64(v)) where var v float32 (where Floor could be any one of the many math functions). On amd64 with GOAMD64=v2, that example compiles to

CVTSS2SD  X0, X1
ROUNDSD   $1, X1, X1
CVTSD2SS  X1, X1

which is the literal interpretation of the code. I suggest that this sequence gets optimized to a use of ROUNDSS instead. The example uses ROUNDSD, but of course I'd like this to work for all relevant instructions.

Metadata

Metadata

Assignees

Labels

ImplementationIssues describing a semantics-preserving change to the Go implementation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions