diff --git a/src/Compilers/Core/CodeAnalysisTest/Collections/SegmentedArrayHelperTests.cs b/src/Compilers/Core/CodeAnalysisTest/Collections/SegmentedArrayHelperTests.cs index 6580ae148a424..b9796628782d4 100644 --- a/src/Compilers/Core/CodeAnalysisTest/Collections/SegmentedArrayHelperTests.cs +++ b/src/Compilers/Core/CodeAnalysisTest/Collections/SegmentedArrayHelperTests.cs @@ -17,6 +17,9 @@ namespace Microsoft.CodeAnalysis.UnitTests.Collections { public class SegmentedArrayHelperTests { + [StructLayout(LayoutKind.Sequential, Size = 1)] + private struct Size1 { } + [StructLayout(LayoutKind.Sequential, Size = 2)] private struct Size2 { } @@ -44,10 +47,14 @@ private struct Size32 { } [StructLayout(LayoutKind.Sequential, Size = 40)] private struct Size40 { } + [StructLayout(LayoutKind.Sequential, Size = 64)] + private struct Size64 { } + public static IEnumerable ExplicitSizeTypes { get { + yield return new object[] { typeof(Size1) }; yield return new object[] { typeof(Size2) }; yield return new object[] { typeof(Size4) }; yield return new object[] { typeof(Size8) }; @@ -57,6 +64,7 @@ public static IEnumerable ExplicitSizeTypes yield return new object[] { typeof(Size28) }; yield return new object[] { typeof(Size32) }; yield return new object[] { typeof(Size40) }; + yield return new object[] { typeof(Size64) }; } } diff --git a/src/Dependencies/Collections/Internal/SegmentedArrayHelper.cs b/src/Dependencies/Collections/Internal/SegmentedArrayHelper.cs index c9ca2d2d31f19..87caa4c74b574 100644 --- a/src/Dependencies/Collections/Internal/SegmentedArrayHelper.cs +++ b/src/Dependencies/Collections/Internal/SegmentedArrayHelper.cs @@ -23,6 +23,8 @@ internal static int GetSegmentSize() // Hard code common values since not all versions of the .NET JIT support reducing this computation to a // constant value at runtime. Values are validated against the reference implementation in // CalculateSegmentSize in unit tests. + 1 => 65536, + 2 => 32768, 4 => 16384, 8 => 8192, 12 => 4096, @@ -31,6 +33,7 @@ internal static int GetSegmentSize() 28 => 2048, 32 => 2048, 40 => 2048, + 64 => 1024, #if NETCOREAPP3_0_OR_GREATER _ => InlineCalculateSegmentSize(Unsafe.SizeOf()), #else @@ -47,6 +50,8 @@ internal static int GetSegmentShift() // Hard code common values since not all versions of the .NET JIT support reducing this computation to a // constant value at runtime. Values are validated against the reference implementation in // CalculateSegmentSize in unit tests. + 1 => 16, + 2 => 15, 4 => 14, 8 => 13, 12 => 12, @@ -55,6 +60,7 @@ internal static int GetSegmentShift() 28 => 11, 32 => 11, 40 => 11, + 64 => 10, #if NETCOREAPP3_0_OR_GREATER _ => InlineCalculateSegmentShift(Unsafe.SizeOf()), #else @@ -71,6 +77,8 @@ internal static int GetOffsetMask() // Hard code common values since not all versions of the .NET JIT support reducing this computation to a // constant value at runtime. Values are validated against the reference implementation in // CalculateSegmentSize in unit tests. + 1 => 65535, + 2 => 32767, 4 => 16383, 8 => 8191, 12 => 4095, @@ -79,6 +87,7 @@ internal static int GetOffsetMask() 28 => 2047, 32 => 2047, 40 => 2047, + 64 => 1023, #if NETCOREAPP3_0_OR_GREATER _ => InlineCalculateOffsetMask(Unsafe.SizeOf()), #else