Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/coreclr/src/vm/mscorlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ DEFINE_METHOD(UNSAFE, BYREF_ADD, Add, GM_RefT_Int_Ret
DEFINE_METHOD(UNSAFE, BYREF_INTPTR_ADD, Add, GM_RefT_IntPtr_RetRefT)
DEFINE_METHOD(UNSAFE, PTR_ADD, Add, GM_PtrVoid_Int_RetPtrVoid)
DEFINE_METHOD(UNSAFE, BYREF_BYTE_OFFSET, ByteOffset, NoSig)
DEFINE_METHOD(UNSAFE, BYREF_ADD_BYTE_OFFSET, AddByteOffset, NoSig)
DEFINE_METHOD(UNSAFE, BYREF_ADD_BYTE_OFFSET, AddByteOffset, GM_RefT_IntPtr_RetRefT)
DEFINE_METHOD(UNSAFE, BYREF_ARE_SAME, AreSame, NoSig)
DEFINE_METHOD(UNSAFE, BYREF_IS_ADDRESS_GREATER_THAN, IsAddressGreaterThan, NoSig)
DEFINE_METHOD(UNSAFE, BYREF_IS_ADDRESS_LESS_THAN, IsAddressLessThan, NoSig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,11 @@
#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
#if BIT64
using nuint = System.UInt64;
#else
using nuint = System.UInt32;
#endif
#if !CORECLR
#if BIT64
using nint = System.Int64;
#else
using nuint = System.UInt32;
using nint = System.Int32;
#endif
#endif

//
// The implementations of most the methods in this file are provided as intrinsics.
Expand Down Expand Up @@ -150,12 +145,25 @@ public static ref T Add<T>(ref T source, IntPtr elementOffset)
#endif
}

#if BIT64
/// <summary>
/// Adds an element offset to the given reference.
/// </summary>
[Intrinsic]
[NonVersionable]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static ref T Add<T>(ref T source, nint elementOffset)
{
return ref Unsafe.Add(ref source, (IntPtr)(void*)elementOffset);
}
#endif

/// <summary>
/// Adds an byte offset to the given reference.
/// </summary>
[Intrinsic]
[NonVersionable]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static ref T AddByteOffset<T>(ref T source, nuint byteOffset)
{
return ref AddByteOffset(ref source, (IntPtr)(void*)byteOffset);
Expand Down Expand Up @@ -295,7 +303,7 @@ public static void WriteUnaligned<T>(ref byte destination, T value)
}

/// <summary>
/// Adds an element offset to the given reference.
/// Adds an byte offset to the given reference.
/// </summary>
[Intrinsic]
[NonVersionable]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,16 @@ public static unsafe int SequenceCompareTo(ref char first, int firstLength, ref
}
}

if (sizeof(UIntPtr) > sizeof(int) && (byte*)minLength >= (byte*)(i + sizeof(int) / sizeof(char)))
#if BIT64
if ((byte*)minLength >= (byte*)(i + sizeof(int) / sizeof(char)))
{
if (Unsafe.ReadUnaligned<int>(ref Unsafe.As<char, byte>(ref Unsafe.Add(ref first, i))) ==
Unsafe.ReadUnaligned<int>(ref Unsafe.As<char, byte>(ref Unsafe.Add(ref second, i))))
{
i += sizeof(int) / sizeof(char);
}
}
#endif

while ((byte*)i < (byte*)minLength)
{
Expand Down Expand Up @@ -254,15 +256,15 @@ public static unsafe int IndexOf(ref char searchSpace, char value, int length)
// remaining data that is shorter than a Vector length.
while (lengthToExamine >= 4)
{
ref char current = ref Add(ref searchSpace, offset);
ref char current = ref Unsafe.Add(ref searchSpace, offset);

if (value == current)
goto Found;
if (value == Add(ref current, 1))
if (value == Unsafe.Add(ref current, 1))
goto Found1;
if (value == Add(ref current, 2))
if (value == Unsafe.Add(ref current, 2))
goto Found2;
if (value == Add(ref current, 3))
if (value == Unsafe.Add(ref current, 3))
goto Found3;

offset += 4;
Expand All @@ -271,7 +273,7 @@ public static unsafe int IndexOf(ref char searchSpace, char value, int length)

while (lengthToExamine > 0)
{
if (value == Add(ref searchSpace, offset))
if (value == Unsafe.Add(ref searchSpace, offset))
goto Found;

offset++;
Expand Down Expand Up @@ -1031,10 +1033,6 @@ private static int LocateLastFoundChar(ulong match)
return 3 - (BitOperations.LeadingZeroCount(match) >> 4);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref char Add(ref char source, nint elementOffset)
=> ref Unsafe.Add(ref source, (IntPtr)elementOffset);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static unsafe Vector<ushort> LoadVector(ref char start, nint offset)
=> Unsafe.ReadUnaligned<Vector<ushort>>(ref Unsafe.As<char, byte>(ref Unsafe.Add(ref start, (IntPtr)offset)));
Expand Down