From ddca13892b1265cea92e5c528e9b2f7c8216c432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Lema=C5=84czyk?= Date: Tue, 30 Sep 2025 19:24:46 +0200 Subject: [PATCH] New GPU benchmarks added --- .../MulMod64Benchmarks.cs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/EvenPerfectBitScanner.Benchmarks/MulMod64Benchmarks.cs b/EvenPerfectBitScanner.Benchmarks/MulMod64Benchmarks.cs index a0cddcc..0ac0722 100644 --- a/EvenPerfectBitScanner.Benchmarks/MulMod64Benchmarks.cs +++ b/EvenPerfectBitScanner.Benchmarks/MulMod64Benchmarks.cs @@ -3,6 +3,7 @@ using System.Runtime.CompilerServices; using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Jobs; using PerfectNumbers.Core; +using PerfectNumbers.Core.Gpu; namespace EvenPerfectBitScanner.Benchmarks; @@ -43,6 +44,40 @@ public class MulMod64Benchmarks return Input.Left.MulMod64(Input.Right, Input.Modulus); } + /// + /// Calls the UInt128-based helper, which stayed between + /// ?.?? ns and ?.?? ns for CrossWordBlend, MixedBitPattern, PrimeSizedModulus, SparseOperands, and ZeroOperands inputs, + /// and ?.?? ns for NearFullRange, making it the fastest option across every distribution. + /// + /// + /// Observed means: CrossWordBlend ?.??? ns (?.??×), MixedBitPattern ?.??? ns, NearFullRange ?.??? ns, PrimeSizedModulus + /// ?.??? ns, SparseOperands ?.??? ns, ZeroOperands ?.??? ns. + /// + [Benchmark] + public ulong GpuCompatibleMulModExtension() + { + GpuUInt128 gpuUInt128 = new(Input.Left); + gpuUInt128.MulMod(Input.Right, Input.Modulus); + return gpuUInt128.Low; + } + + /// + /// Calls the UInt128-based helper, which stayed between + /// ?.?? ns and ?.?? ns for CrossWordBlend, MixedBitPattern, PrimeSizedModulus, SparseOperands, and ZeroOperands inputs, + /// and ?.?? ns for NearFullRange, making it the fastest option across every distribution. + /// + /// + /// Observed means: CrossWordBlend ?.??? ns (?.??×), MixedBitPattern ?.??? ns, NearFullRange ?.??? ns, PrimeSizedModulus + /// ?.??? ns, SparseOperands ?.??? ns, ZeroOperands ?.??? ns. + /// + [Benchmark] + public ulong GpuCompatibleMulModSimplifiedExtension() + { + GpuUInt128 gpuUInt128 = new(Input.Left); + gpuUInt128.MulModSimplified(Input.Right, Input.Modulus); + return gpuUInt128.Low; + } + /// /// Uses manual UInt128 multiplication in the benchmark method; dense operands cost 23.6–33.6 ns (6.2–8.9× slower than /// baseline), while SparseOperands and ZeroOperands remain inexpensive at 3.58–3.87 ns.