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)
#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.
#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);
}
/// <summary>
- /// Adds an element offset to the given reference.
+ /// Adds an byte offset to the given reference.
/// </summary>
[Intrinsic]
[NonVersionable]
}
}
- 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)
{
// 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;
while (lengthToExamine > 0)
{
- if (value == Add(ref searchSpace, offset))
+ if (value == Unsafe.Add(ref searchSpace, offset))
goto Found;
offset++;
}
[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)));