From 6e11a0eb437bd082a884568f817fc814bb62d27c Mon Sep 17 00:00:00 2001 From: Egor Chesakov Date: Thu, 2 Dec 2021 18:16:52 -0800 Subject: [PATCH] Extend the byteCounts array to include sizes up to 128 bytes (the upper limit used on x86/x64) --- .../micro/runtime/StoreBlock/StoreBlock.cs | 152 ++++++++++++++++++ .../micro/runtime/StoreBlock/StoreBlock.tt | 2 +- 2 files changed, 153 insertions(+), 1 deletion(-) diff --git a/src/benchmarks/micro/runtime/StoreBlock/StoreBlock.cs b/src/benchmarks/micro/runtime/StoreBlock/StoreBlock.cs index 221d9d1b41d..22daccdb402 100644 --- a/src/benchmarks/micro/runtime/StoreBlock/StoreBlock.cs +++ b/src/benchmarks/micro/runtime/StoreBlock/StoreBlock.cs @@ -133,6 +133,60 @@ public void CopyBlock64() Unsafe.CopyBlock(ref _dstData[startOffset], ref _srcData[startOffset], 64); } } + + [Benchmark(OperationsPerInvoke = Size / 96)] + public void InitBlockAllZeros96() + { + for (int startOffset = 0; startOffset < Size; startOffset += 96) + { + Unsafe.InitBlock(ref _dstData[startOffset], 0, 96); + } + } + + [Benchmark(OperationsPerInvoke = Size / 96)] + public void InitBlockAllOnes96() + { + for (int startOffset = 0; startOffset < Size; startOffset += 96) + { + Unsafe.InitBlock(ref _dstData[startOffset], 255, 96); + } + } + + [Benchmark(OperationsPerInvoke = Size / 96)] + public void CopyBlock96() + { + for (int startOffset = 0; startOffset < Size; startOffset += 96) + { + Unsafe.CopyBlock(ref _dstData[startOffset], ref _srcData[startOffset], 96); + } + } + + [Benchmark(OperationsPerInvoke = Size / 128)] + public void InitBlockAllZeros128() + { + for (int startOffset = 0; startOffset < Size; startOffset += 128) + { + Unsafe.InitBlock(ref _dstData[startOffset], 0, 128); + } + } + + [Benchmark(OperationsPerInvoke = Size / 128)] + public void InitBlockAllOnes128() + { + for (int startOffset = 0; startOffset < Size; startOffset += 128) + { + Unsafe.InitBlock(ref _dstData[startOffset], 255, 128); + } + } + + [Benchmark(OperationsPerInvoke = Size / 128)] + public void CopyBlock128() + { + for (int startOffset = 0; startOffset < Size; startOffset += 128) + { + Unsafe.CopyBlock(ref _dstData[startOffset], ref _srcData[startOffset], 128); + } + } } [BenchmarkCategory(Categories.Runtime, Categories.JIT)] @@ -168,6 +222,20 @@ struct Struct64 Struct64 fld64; + [StructLayout(LayoutKind.Explicit, Size=96)] + struct Struct96 + { + } + + Struct96 fld96; + + [StructLayout(LayoutKind.Explicit, Size=128)] + struct Struct128 + { + } + + Struct128 fld128; + [Benchmark(OperationsPerInvoke = OperationsPerInvoke)] public unsafe void InitBlockAllZeros8() { @@ -335,5 +403,89 @@ public unsafe void CopyBlock64() fld64 = dstLcl; } + + [Benchmark(OperationsPerInvoke = OperationsPerInvoke)] + public unsafe void InitBlockAllZeros96() + { + Struct96 dstLcl; + + for (int i = 0; i < OperationsPerInvoke; i++) + { + Unsafe.InitBlock(&dstLcl, 0, 96); + } + + fld96 = dstLcl; + } + + [Benchmark(OperationsPerInvoke = OperationsPerInvoke)] + public unsafe void InitBlockAllOnes96() + { + Struct96 dstLcl; + + for (int i = 0; i < OperationsPerInvoke; i++) + { + Unsafe.InitBlock(&dstLcl, 255, 96); + } + + fld96 = dstLcl; + } + + [Benchmark(OperationsPerInvoke = OperationsPerInvoke)] + public unsafe void CopyBlock96() + { + Struct96 srcLcl; + Struct96 dstLcl; + + srcLcl = fld96; + + for (int i = 0; i < OperationsPerInvoke; i++) + { + Unsafe.CopyBlock(&dstLcl, &srcLcl, 96); + } + + fld96 = dstLcl; + } + + [Benchmark(OperationsPerInvoke = OperationsPerInvoke)] + public unsafe void InitBlockAllZeros128() + { + Struct128 dstLcl; + + for (int i = 0; i < OperationsPerInvoke; i++) + { + Unsafe.InitBlock(&dstLcl, 0, 128); + } + + fld128 = dstLcl; + } + + [Benchmark(OperationsPerInvoke = OperationsPerInvoke)] + public unsafe void InitBlockAllOnes128() + { + Struct128 dstLcl; + + for (int i = 0; i < OperationsPerInvoke; i++) + { + Unsafe.InitBlock(&dstLcl, 255, 128); + } + + fld128 = dstLcl; + } + + [Benchmark(OperationsPerInvoke = OperationsPerInvoke)] + public unsafe void CopyBlock128() + { + Struct128 srcLcl; + Struct128 dstLcl; + + srcLcl = fld128; + + for (int i = 0; i < OperationsPerInvoke; i++) + { + Unsafe.CopyBlock(&dstLcl, &srcLcl, 128); + } + + fld128 = dstLcl; + } } } diff --git a/src/benchmarks/micro/runtime/StoreBlock/StoreBlock.tt b/src/benchmarks/micro/runtime/StoreBlock/StoreBlock.tt index 6b700c9302e..3ec0716e03a 100644 --- a/src/benchmarks/micro/runtime/StoreBlock/StoreBlock.tt +++ b/src/benchmarks/micro/runtime/StoreBlock/StoreBlock.tt @@ -131,4 +131,4 @@ namespace StoreBlock #> } } -<#+ int[] byteCounts = new int[] { 8, 16, 32, 64 }; #> +<#+ int[] byteCounts = new int[] { 8, 16, 32, 64, 96, 128 }; #>