Skip to content

Commit f66db49

Browse files
committed
cmd/compile: store constant floats using integer constants
x86 is better at storing constant ints than constant floats. (It uses a constant directly in the instruction stream, instead of loading it from a constant global memory.) Noticed as part of #67957 Change-Id: I9b7b586ad8e0fe9ce245324f020e9526f82b209d Reviewed-on: https://go-review.googlesource.com/c/go/+/592596 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: David Chase <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent d15525d commit f66db49

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

src/cmd/compile/internal/ssa/_gen/AMD64.rules

+3
Original file line numberDiff line numberDiff line change
@@ -1583,6 +1583,9 @@
15831583
(MOVSDstore [off] {sym} ptr (MOVQi2f val) mem) => (MOVQstore [off] {sym} ptr val mem)
15841584
(MOVSSstore [off] {sym} ptr (MOVLi2f val) mem) => (MOVLstore [off] {sym} ptr val mem)
15851585

1586+
(MOVSDstore [off] {sym} ptr (MOVSDconst [f]) mem) && f == f => (MOVQstore [off] {sym} ptr (MOVQconst [int64(math.Float64bits(f))]) mem)
1587+
(MOVSSstore [off] {sym} ptr (MOVSSconst [f]) mem) && f == f => (MOVLstore [off] {sym} ptr (MOVLconst [int32(math.Float32bits(f))]) mem)
1588+
15861589
// Load args directly into the register class where it will be used.
15871590
// We do this by just modifying the type of the Arg.
15881591
(MOVQf2i <t> (Arg <u> [off] {sym})) && t.Size() == u.Size() => @b.Func.Entry (Arg <t> [off] {sym})

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

+50
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/codegen/floats.go

+9
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,12 @@ func Float64DenormalFloat32Constant() float64 {
227227
// ppc64x:"FMOVD\t[$]f64\\.3800000000000000\\(SB\\)"
228228
return 0x1p-127
229229
}
230+
231+
func Float64ConstantStore(p *float64) {
232+
// amd64: "MOVQ\t[$]4617801906721357038"
233+
*p = 5.432
234+
}
235+
func Float32ConstantStore(p *float32) {
236+
// amd64: "MOVL\t[$]1085133554"
237+
*p = 5.432
238+
}

0 commit comments

Comments
 (0)