diff options
author | Levi Broderick <GrabYourPitchforks@users.noreply.github.com> | 2018-01-23 17:00:47 -0800 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2018-01-23 17:00:47 -0800 |
commit | 0bafdbc71e5a3efe6b6df0cbcf5aee5081a3e4c8 (patch) | |
tree | b5d5969008669d6e090a351729493c46bf47e44b /src | |
parent | 007fa5528ba3aee5bbb6c4397cc576a5cd88f8b0 (diff) | |
download | coreclr-0bafdbc71e5a3efe6b6df0cbcf5aee5081a3e4c8.tar.gz coreclr-0bafdbc71e5a3efe6b6df0cbcf5aee5081a3e4c8.tar.bz2 coreclr-0bafdbc71e5a3efe6b6df0cbcf5aee5081a3e4c8.zip |
Add Unsafe.IsAddressGreaterThan / IsAddressLessThan (#15988)
Diffstat (limited to 'src')
-rw-r--r-- | src/mscorlib/shared/Internal/Runtime/CompilerServices/Unsafe.cs | 40 | ||||
-rw-r--r-- | src/vm/jitinterface.cpp | 22 | ||||
-rw-r--r-- | src/vm/mscorlib.h | 2 |
3 files changed, 64 insertions, 0 deletions
diff --git a/src/mscorlib/shared/Internal/Runtime/CompilerServices/Unsafe.cs b/src/mscorlib/shared/Internal/Runtime/CompilerServices/Unsafe.cs index cd3dd052a2..aeff3ce2ca 100644 --- a/src/mscorlib/shared/Internal/Runtime/CompilerServices/Unsafe.cs +++ b/src/mscorlib/shared/Internal/Runtime/CompilerServices/Unsafe.cs @@ -169,6 +169,46 @@ namespace Internal.Runtime.CompilerServices } /// <summary> + /// Determines whether the memory address referenced by <paramref name="left"/> is greater than + /// the memory address referenced by <paramref name="right"/>. + /// </summary> + /// <remarks> + /// This check is conceptually similar to "(void*)(&left) > (void*)(&right)". + /// </remarks> + [Intrinsic] + [NonVersionable] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool IsAddressGreaterThan<T>(ref T left, ref T right) + { + throw new PlatformNotSupportedException(); + + // ldarg.0 + // ldarg.1 + // cgt.un + // ret + } + + /// <summary> + /// Determines whether the memory address referenced by <paramref name="left"/> is less than + /// the memory address referenced by <paramref name="right"/>. + /// </summary> + /// <remarks> + /// This check is conceptually similar to "(void*)(&left) < (void*)(&right)". + /// </remarks> + [Intrinsic] + [NonVersionable] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool IsAddressLessThan<T>(ref T left, ref T right) + { + throw new PlatformNotSupportedException(); + + // ldarg.0 + // ldarg.1 + // clt.un + // ret + } + + /// <summary> /// Initializes a block of memory at the given location with a given initial value /// without assuming architecture dependent alignment of the address. /// </summary> diff --git a/src/vm/jitinterface.cpp b/src/vm/jitinterface.cpp index b238de8cba..1cec0187e7 100644 --- a/src/vm/jitinterface.cpp +++ b/src/vm/jitinterface.cpp @@ -7192,6 +7192,28 @@ bool getILIntrinsicImplementationForUnsafe(MethodDesc * ftn, methInfo->options = (CorInfoOptions)0; return true; } + else if (tk == MscorlibBinder::GetMethod(METHOD__UNSAFE__BYREF_IS_ADDRESS_GREATER_THAN)->GetMemberDef()) + { + // Compare the two arguments + static const BYTE ilcode[] = { CEE_LDARG_0, CEE_LDARG_1, CEE_PREFIX1, (CEE_CGT_UN & 0xFF), CEE_RET }; + methInfo->ILCode = const_cast<BYTE*>(ilcode); + methInfo->ILCodeSize = sizeof(ilcode); + methInfo->maxStack = 2; + methInfo->EHcount = 0; + methInfo->options = (CorInfoOptions)0; + return true; + } + else if (tk == MscorlibBinder::GetMethod(METHOD__UNSAFE__BYREF_IS_ADDRESS_LESS_THAN)->GetMemberDef()) + { + // Compare the two arguments + static const BYTE ilcode[] = { CEE_LDARG_0, CEE_LDARG_1, CEE_PREFIX1, (CEE_CLT_UN & 0xFF), CEE_RET }; + methInfo->ILCode = const_cast<BYTE*>(ilcode); + methInfo->ILCodeSize = sizeof(ilcode); + methInfo->maxStack = 2; + methInfo->EHcount = 0; + methInfo->options = (CorInfoOptions)0; + return true; + } else if (tk == MscorlibBinder::GetMethod(METHOD__UNSAFE__BYREF_INIT_BLOCK_UNALIGNED)->GetMemberDef()) { static const BYTE ilcode[] = { CEE_LDARG_0, CEE_LDARG_1, CEE_LDARG_2, CEE_PREFIX1, (CEE_UNALIGNED & 0xFF), 0x01, CEE_PREFIX1, (CEE_INITBLK & 0xFF), CEE_RET }; diff --git a/src/vm/mscorlib.h b/src/vm/mscorlib.h index 511271d074..4d08c3cd37 100644 --- a/src/vm/mscorlib.h +++ b/src/vm/mscorlib.h @@ -780,6 +780,8 @@ DEFINE_METHOD(UNSAFE, PTR_ADD, Add, GM_PtrVoid_Int_ DEFINE_METHOD(UNSAFE, BYREF_BYTE_OFFSET, ByteOffset, NoSig) DEFINE_METHOD(UNSAFE, BYREF_ADD_BYTE_OFFSET, AddByteOffset, NoSig) 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) DEFINE_METHOD(UNSAFE, BYREF_INIT_BLOCK_UNALIGNED, InitBlockUnaligned, NoSig) DEFINE_METHOD(UNSAFE, BYREF_READ_UNALIGNED, ReadUnaligned, GM_RefByte_RetT) DEFINE_METHOD(UNSAFE, BYREF_WRITE_UNALIGNED, WriteUnaligned, GM_RefByte_T_RetVoid) |