]>
Cypherpunks repositories - gostls13.git/commit
cmd/compile: make runtime calls last in eq algs
type T struct {
f float64
a [64]uint64
g float64
}
Prior to this change, the generated equality algorithm for T was:
func eqT(p, q *T) bool {
return p.f == q.f && runtime.memequal(p.a, q.a, 512) && p.g == q.g
}
In handwritten code, we would normally put the cheapest checks first.
This change takes a step in that direction. We now generate:
func eqT(p, q *T) bool {
return p.f == q.f && p.g == q.g && runtime.memequal(p.a, q.a, 512)
}
For most types, this also generates considerably shorter code. Examples:
runtime
.eq."".mstats 406 -> 391 (-3.69%)
.eq.""._func 114 -> 101 (-11.40%)
.eq."".itab 115 -> 102 (-11.30%)
.eq."".scase 125 -> 116 (-7.20%)
.eq."".traceStack 119 -> 102 (-14.29%)
.eq."".gcControllerState 169 -> 161 (-4.73%)
.eq."".sweepdata 121 -> 112 (-7.44%)
However, for types in which we make unwise choices about inlining
memory-only comparisons (#38494), this generates longer code.
Example:
cmd/internal/obj
.eq."".objWriter 211 -> 214 (+1.42%)
.eq."".Addr 185 -> 187 (+1.08%)
Fortunately, such cases are not common.
Change-Id: I47a27da93c1f88ec71fa350c192f36b29548a217
Reviewed-on: https://go-review.googlesource.com/c/go/+/230203
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>