]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: add benchmark for small-size memmory operation
authorJulian Zhu <julian.oerv@isrc.iscas.ac.cn>
Wed, 18 Jun 2025 09:26:26 +0000 (17:26 +0800)
committerGopher Robot <gobot@golang.org>
Thu, 24 Jul 2025 17:49:11 +0000 (10:49 -0700)
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>
src/runtime/memmove_test.go

index 5649a20c5f4676dafc0a5fb6996fe714708c6226..22905504d45e3a28b085d155d7a0fd89c67900c8 100644 (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) {
        p := new([7]byte)
        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) {
        p := new([11]byte)
        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) {
        p := new([24 / 4]uint32)
        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) {
        var x [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) {
        var x [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) {
        var x [24 / 4]uint32
        p := new([24 / 4]uint32)