diff options
| author | Alexander Musman <alexander.musman@gmail.com> | 2025-07-13 11:09:58 +0300 |
|---|---|---|
| committer | Keith Randall <khr@golang.org> | 2026-01-22 14:34:09 -0800 |
| commit | c7258178cda55e3903ad8e4b6cc51861fb689457 (patch) | |
| tree | 4ac6658be6f4896a3e019ce6e80a83febafd9542 /test/codegen | |
| parent | 26ffe78b8c34cea92a06690742b5d41b3397105f (diff) | |
| download | go-c7258178cda55e3903ad8e4b6cc51861fb689457.tar.xz | |
cmd/compile: optimize small constant-sized MemEq
Add optimization patterns for MemEq with small constant sizes
(3-32 bytes). These patterns help to avoid runtime calls for
small sizes.
For sizes 3-16, combine two chunks loading and comparison.
For sizes 17-32, combine a 16-byte comparison with the remaining bytes.
This change may increase binary size slightly due to inline expansion,
but improves performance for code with many small memequals,
e.g. DecodehealingTracker benchmark on arm64:
shortname: minio
pkg: github.com/minio/minio/cmd
│ Orig.res │ Uexp.res │
│ sec/op │ sec/op vs base │
DecodehealingTracker-4 842.5n ± 1% 794.0n ± 3% -5.75% (p=0.000 n=10)
AppendMsgResyncTargetsInfo-4 8.472n ± 0% 8.472n ± 0% ~ (p=0.582 n=10)
DataUpdateTracker-4 2.856µ ± 2% 2.804µ ± 3% ~ (p=0.210 n=10)
MarshalMsgdataUsageCacheInfo-4 131.2n ± 1% 131.6n ± 2% ~ (p=0.494 n=10)
geomean 227.4n 223.2n -1.86%
│ Orig.res │ Uexp.res │
│ B/s │ B/s vs base │
DecodehealingTracker-4 352.0Mi ± 1% 373.5Mi ± 3% +6.10% (p=0.000 n=10)
AppendMsgResyncTargetsInfo-4 1.099Gi ± 0% 1.099Gi ± 0% ~ (p=0.183 n=10)
DataUpdateTracker-4 341.8Ki ± 3% 351.6Ki ± 3% ~ (p=0.286 n=10)
geomean 50.95Mi 52.46Mi +2.96%
Change-Id: If3d7e7395656d5f36e3ab303a71044293d17bc3e
Reviewed-on: https://go-review.googlesource.com/c/go/+/688195
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Diffstat (limited to 'test/codegen')
| -rw-r--r-- | test/codegen/comparisons.go | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/test/codegen/comparisons.go b/test/codegen/comparisons.go index 0b550adc05..70852377f7 100644 --- a/test/codegen/comparisons.go +++ b/test/codegen/comparisons.go @@ -661,16 +661,22 @@ func equalVarString8(a string) bool { } func equalVarStringNoSpill(a, b string) bool { - s := string("ZZZZZZZZZ") + s := string("123456789012345678901234567890123") // arm64:".*memequal" - memeq1 := a[:9] == s + memeq1 := a[:33] == s // arm64:-".*" - memeq2 := s == a[:9] - // arm64:-"MOVB R0,.*SP",".*memequal" - memeq3 := s == b[:9] + memeq2 := s == a[:33] + // arm64:-"MOVB R0,.*SP" ".*memequal" + memeq3 := s == b[:33] return memeq1 && memeq2 && memeq3 } +func equalVarString17(a string) bool { + b := string("12345678901234567") + // arm64:-".*memequal" "CMPW [$]55," "MOVD [$]3906085646303834169," "MOVD [$]4050765991979987505," + return a[:17] == b +} + func cmpToCmn(a, b, c, d int) int { var c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11 int // arm64:`CMN`,-`CMP` |
