runtime: add benchmark for small-size memmory operation

On RISC-V and MIPS andarchitectures, misaligned load/store is not mandatory for implementations. Therefore, it's important to handle memory operations involving small sizes or data with a remainder when divided by 8 or 4.
This CL add some benchmark for small-size memmory operation, to ensure that SSA rules do not generate unaligned access traps on such architectures.

Change-Id: I6fcdfdb76e9552d5b10df140fa92568ac9468386
Reviewed-on: https://go-review.googlesource.com/c/go/+/682575
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Julian Zhu 2025-06-18 17:26:26 +08:00 committed by Gopher Robot
parent 18dbe5b941
commit e84ed38641

View file

@ -520,6 +520,42 @@ func BenchmarkMemclrRange(b *testing.B) {
} }
} }
func BenchmarkClearFat3(b *testing.B) {
p := new([3]byte)
Escape(p)
b.ResetTimer()
for i := 0; i < b.N; i++ {
*p = [3]byte{}
}
}
func BenchmarkClearFat4(b *testing.B) {
p := new([4 / 4]uint32)
Escape(p)
b.ResetTimer()
for i := 0; i < b.N; i++ {
*p = [4 / 4]uint32{}
}
}
func BenchmarkClearFat5(b *testing.B) {
p := new([5]byte)
Escape(p)
b.ResetTimer()
for i := 0; i < b.N; i++ {
*p = [5]byte{}
}
}
func BenchmarkClearFat6(b *testing.B) {
p := new([6]byte)
Escape(p)
b.ResetTimer()
for i := 0; i < b.N; i++ {
*p = [6]byte{}
}
}
func BenchmarkClearFat7(b *testing.B) { func BenchmarkClearFat7(b *testing.B) {
p := new([7]byte) p := new([7]byte)
Escape(p) Escape(p)
@ -538,6 +574,24 @@ func BenchmarkClearFat8(b *testing.B) {
} }
} }
func BenchmarkClearFat9(b *testing.B) {
p := new([9]byte)
Escape(p)
b.ResetTimer()
for i := 0; i < b.N; i++ {
*p = [9]byte{}
}
}
func BenchmarkClearFat10(b *testing.B) {
p := new([10]byte)
Escape(p)
b.ResetTimer()
for i := 0; i < b.N; i++ {
*p = [10]byte{}
}
}
func BenchmarkClearFat11(b *testing.B) { func BenchmarkClearFat11(b *testing.B) {
p := new([11]byte) p := new([11]byte)
Escape(p) Escape(p)
@ -592,6 +646,24 @@ func BenchmarkClearFat16(b *testing.B) {
} }
} }
func BenchmarkClearFat18(b *testing.B) {
p := new([18]byte)
Escape(p)
b.ResetTimer()
for i := 0; i < b.N; i++ {
*p = [18]byte{}
}
}
func BenchmarkClearFat20(b *testing.B) {
p := new([20 / 4]uint32)
Escape(p)
b.ResetTimer()
for i := 0; i < b.N; i++ {
*p = [20 / 4]uint32{}
}
}
func BenchmarkClearFat24(b *testing.B) { func BenchmarkClearFat24(b *testing.B) {
p := new([24 / 4]uint32) p := new([24 / 4]uint32)
Escape(p) Escape(p)
@ -709,6 +781,46 @@ func BenchmarkClearFat1040(b *testing.B) {
} }
} }
func BenchmarkCopyFat3(b *testing.B) {
var x [3]byte
p := new([3]byte)
Escape(p)
b.ResetTimer()
for i := 0; i < b.N; i++ {
*p = x
}
}
func BenchmarkCopyFat4(b *testing.B) {
var x [4 / 4]uint32
p := new([4 / 4]uint32)
Escape(p)
b.ResetTimer()
for i := 0; i < b.N; i++ {
*p = x
}
}
func BenchmarkCopyFat5(b *testing.B) {
var x [5]byte
p := new([5]byte)
Escape(p)
b.ResetTimer()
for i := 0; i < b.N; i++ {
*p = x
}
}
func BenchmarkCopyFat6(b *testing.B) {
var x [6]byte
p := new([6]byte)
Escape(p)
b.ResetTimer()
for i := 0; i < b.N; i++ {
*p = x
}
}
func BenchmarkCopyFat7(b *testing.B) { func BenchmarkCopyFat7(b *testing.B) {
var x [7]byte var x [7]byte
p := new([7]byte) p := new([7]byte)
@ -729,6 +841,26 @@ func BenchmarkCopyFat8(b *testing.B) {
} }
} }
func BenchmarkCopyFat9(b *testing.B) {
var x [9]byte
p := new([9]byte)
Escape(p)
b.ResetTimer()
for i := 0; i < b.N; i++ {
*p = x
}
}
func BenchmarkCopyFat10(b *testing.B) {
var x [10]byte
p := new([10]byte)
Escape(p)
b.ResetTimer()
for i := 0; i < b.N; i++ {
*p = x
}
}
func BenchmarkCopyFat11(b *testing.B) { func BenchmarkCopyFat11(b *testing.B) {
var x [11]byte var x [11]byte
p := new([11]byte) p := new([11]byte)
@ -789,6 +921,26 @@ func BenchmarkCopyFat16(b *testing.B) {
} }
} }
func BenchmarkCopyFat18(b *testing.B) {
var x [18]byte
p := new([18]byte)
Escape(p)
b.ResetTimer()
for i := 0; i < b.N; i++ {
*p = x
}
}
func BenchmarkCopyFat20(b *testing.B) {
var x [20 / 4]uint32
p := new([20 / 4]uint32)
Escape(p)
b.ResetTimer()
for i := 0; i < b.N; i++ {
*p = x
}
}
func BenchmarkCopyFat24(b *testing.B) { func BenchmarkCopyFat24(b *testing.B) {
var x [24 / 4]uint32 var x [24 / 4]uint32
p := new([24 / 4]uint32) p := new([24 / 4]uint32)