Skip to content

Commit

Permalink
Use actual nint/nuint in Latin1Utility (#44162)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub committed Nov 3, 2020
1 parent 2eb63c2 commit 7a6ee5f
Showing 1 changed file with 2 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,10 @@
using System.Runtime.Intrinsics.X86;
using Internal.Runtime.CompilerServices;

#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
#if TARGET_64BIT
using nint = System.Int64;
using nuint = System.UInt64;
#else // TARGET_64BIT
using nint = System.Int32;
using nuint = System.UInt32;
#endif // TARGET_64BIT

namespace System.Text
{
internal static partial class Latin1Utility
{
#if DEBUG
static Latin1Utility()
{
Debug.Assert(sizeof(nint) == IntPtr.Size && nint.MinValue < 0, "nint is defined incorrectly.");
Debug.Assert(sizeof(nuint) == IntPtr.Size && nuint.MinValue == 0, "nuint is defined incorrectly.");
}
#endif // DEBUG

/// <summary>
/// Returns the index in <paramref name="pBuffer"/> where the first non-Latin1 char is found.
/// Returns <paramref name="bufferLength"/> if the buffer is empty or all-Latin1.
Expand Down Expand Up @@ -776,7 +759,7 @@ private static unsafe nuint NarrowUtf16ToLatin1_Sse2(char* pUtf16Buffer, byte* p
// JIT turns the below into constants

uint SizeOfVector128 = (uint)Unsafe.SizeOf<Vector128<byte>>();
nuint MaskOfAllBitsInVector128 = (nuint)(SizeOfVector128 - 1);
nuint MaskOfAllBitsInVector128 = SizeOfVector128 - 1;

// This method is written such that control generally flows top-to-bottom, avoiding
// jumps as much as possible in the optimistic case of "all Latin-1". If we see non-Latin-1
Expand Down Expand Up @@ -963,7 +946,7 @@ private static unsafe void WidenLatin1ToUtf16_Sse2(byte* pLatin1Buffer, char* pU
// JIT turns the below into constants

uint SizeOfVector128 = (uint)Unsafe.SizeOf<Vector128<byte>>();
nuint MaskOfAllBitsInVector128 = (nuint)(SizeOfVector128 - 1);
nuint MaskOfAllBitsInVector128 = SizeOfVector128 - 1;

Debug.Assert(Sse2.IsSupported);
Debug.Assert(BitConverter.IsLittleEndian);
Expand Down

0 comments on commit 7a6ee5f

Please sign in to comment.