diff --git a/Snappier.Benchmarks/Configuration/FrameworkCompareConfig.cs b/Snappier.Benchmarks/Configuration/FrameworkCompareConfig.cs index 939070d..67952c5 100644 --- a/Snappier.Benchmarks/Configuration/FrameworkCompareConfig.cs +++ b/Snappier.Benchmarks/Configuration/FrameworkCompareConfig.cs @@ -13,14 +13,15 @@ public FrameworkCompareConfig(Job baseJob) .WithRuntime(ClrRuntime.Net48)); AddJob(baseJob .WithRuntime(CoreRuntime.Core60)); - - var job80 = baseJob.WithRuntime(CoreRuntime.Core80); - AddJob(job80.WithPgo(false)); - AddJob(job80.WithPgo(true)); + AddJob(baseJob + .WithRuntime(CoreRuntime.Core80) + .WithPgo(true)); + AddJob(baseJob + .WithRuntime(CoreRuntime.Core90) + .WithPgo(true)); AddLogicalGroupRules(BenchmarkLogicalGroupRule.ByJob); - AddColumn(PgoColumn.Default); HideColumns(Column.EnvironmentVariables); } } diff --git a/Snappier.Benchmarks/Configuration/VersionComparisonConfig.cs b/Snappier.Benchmarks/Configuration/VersionComparisonConfig.cs index 89b6cf9..84c912a 100644 --- a/Snappier.Benchmarks/Configuration/VersionComparisonConfig.cs +++ b/Snappier.Benchmarks/Configuration/VersionComparisonConfig.cs @@ -20,27 +20,26 @@ public VersionComparisonConfig(Job baseJob) var jobBefore48 = jobBefore.WithRuntime(ClrRuntime.Net48).AsBaseline(); var jobBefore60 = jobBefore.WithRuntime(CoreRuntime.Core60).AsBaseline(); - var jobBefore80 = jobBefore.WithRuntime(CoreRuntime.Core80).AsBaseline(); - var jobBefore80Pgo = jobBefore80.WithPgo(); + var jobBefore80 = jobBefore.WithRuntime(CoreRuntime.Core80).WithPgo().AsBaseline(); + var jobBefore90 = jobBefore.WithRuntime(CoreRuntime.Core90).WithPgo().AsBaseline(); var jobAfter48 = baseJob.WithRuntime(ClrRuntime.Net48); var jobAfter60 = baseJob.WithRuntime(CoreRuntime.Core60); - var jobAfter80 = baseJob.WithRuntime(CoreRuntime.Core80); - var jobAfter80Pgo = jobAfter80.WithPgo(); + var jobAfter80 = baseJob.WithRuntime(CoreRuntime.Core80).WithPgo(); + var jobAfter90 = baseJob.WithRuntime(CoreRuntime.Core90).WithPgo(); AddJob(jobBefore48); AddJob(jobBefore60); AddJob(jobBefore80); - AddJob(jobBefore80Pgo); + AddJob(jobBefore90); AddJob(jobAfter48); AddJob(jobAfter60); AddJob(jobAfter80); - AddJob(jobAfter80Pgo); + AddJob(jobAfter90); WithOrderer(VersionComparisonOrderer.Default); - AddColumn(PgoColumn.Default); HideColumns(Column.EnvironmentVariables, Column.Job); } diff --git a/Snappier.Tests/HelpersTests.cs b/Snappier.Tests/HelpersTests.cs index d11ed5b..e45b7c1 100644 --- a/Snappier.Tests/HelpersTests.cs +++ b/Snappier.Tests/HelpersTests.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; using Snappier.Internal; using Xunit; @@ -39,26 +37,36 @@ public void LeftShiftOverflows_False(byte value, int shift) Assert.False(result); } - #endregion - - #region Log2FloorNonZero - - public static IEnumerable Log2FloorNonZeroValues() => - Enumerable.Range(1, 31).Select(p => new object[] {p}); + public static TheoryData Log2FloorValues() => + [ + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 + ]; [Theory] - [MemberData(nameof(Log2FloorNonZeroValues))] - public void Log2FloorNonZero(uint value) + [MemberData(nameof(Log2FloorValues))] + public void Log2Floor(uint value) { // Act - var result = Helpers.Log2FloorNonZero(value); + var result = Helpers.Log2Floor(value); // Assert Assert.Equal((int) Math.Floor(Math.Log(value, 2)), result); } + [Fact] + public void Log2Floor_Zero() + { + // Act + + var result = Helpers.Log2Floor(0); + + // Assert + + Assert.Equal(0, result); + } + #endregion } } diff --git a/Snappier/Internal/Helpers.cs b/Snappier/Internal/Helpers.cs index c3a58d8..9163cc7 100644 --- a/Snappier/Internal/Helpers.cs +++ b/Snappier/Internal/Helpers.cs @@ -165,21 +165,11 @@ ref MemoryMarshal.GetReference(Log2DeBruijn), #endif /// - /// Return floor(log2(n)) for positive integer n. Returns -1 if n == 0. + /// Return floor(log2(n)) for positive integer n. Returns 0 for the special case n = 0. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Log2Floor(uint n) => - n == 0 ? -1 : Log2FloorNonZero(n); - - - /// - /// Return floor(log2(n)) for positive integer n. - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Log2FloorNonZero(uint n) + public static int Log2Floor(uint n) { - Debug.Assert(n != 0); - #if NET6_0_OR_GREATER return BitOperations.Log2(n); #else