From 959d2c9979f5acf8d33f7a2e294631f50c0f0f01 Mon Sep 17 00:00:00 2001 From: ahsonkhan Date: Wed, 22 Feb 2017 15:56:04 -0800 Subject: [PATCH] Changing AddNative to AddByteOffset Commit migrated from https://github.com/dotnet/coreclr/commit/ec6fb88e7009457f54f31ba83da915af395f4bd6 --- .../src/System/Runtime/CompilerServices/Unsafe.cs | 3 +- src/coreclr/src/mscorlib/src/System/Span.cs | 60 +++++++++++----------- src/coreclr/src/vm/jitinterface.cpp | 17 ++---- src/coreclr/src/vm/mscorlib.h | 2 +- 4 files changed, 35 insertions(+), 47 deletions(-) diff --git a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/Unsafe.cs b/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/Unsafe.cs index 571d097..1268dac 100644 --- a/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/Unsafe.cs +++ b/src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/Unsafe.cs @@ -76,11 +76,10 @@ namespace System.Runtime.CompilerServices /// [NonVersionable] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ref T AddNative(ref T source, nuint elementOffset) + public static ref T AddByteOffset(ref T source, nuint byteOffset) { // The body of this function will be replaced by the EE with unsafe code!!! // See getILIntrinsicImplementationForUnsafe for how this happens. - typeof(T).ToString(); // Type used by the actual method body throw new InvalidOperationException(); } diff --git a/src/coreclr/src/mscorlib/src/System/Span.cs b/src/coreclr/src/mscorlib/src/System/Span.cs index c5e88c5..f2f7f8b 100644 --- a/src/coreclr/src/mscorlib/src/System/Span.cs +++ b/src/coreclr/src/mscorlib/src/System/Span.cs @@ -849,12 +849,12 @@ namespace System { if ((Unsafe.As(ref b) & 1) != 0) { - Unsafe.AddNative(ref b, i) = 0; + Unsafe.AddByteOffset(ref b, i) = 0; i += 1; if ((Unsafe.As(ref b) & 2) != 0) goto IntAligned; } - Unsafe.As(ref Unsafe.AddNative(ref b, i)) = 0; + Unsafe.As(ref Unsafe.AddByteOffset(ref b, i)) = 0; i += 2; } @@ -870,7 +870,7 @@ namespace System if (((Unsafe.As(ref b) - 1) & 4) == 0) { - Unsafe.As(ref Unsafe.AddNative(ref b, i)) = 0; + Unsafe.As(ref Unsafe.AddByteOffset(ref b, i)) = 0; i += 4; } @@ -899,13 +899,13 @@ namespace System // we save on writes to b. #if BIT64 - Unsafe.As(ref Unsafe.AddNative(ref b, i)) = 0; - Unsafe.As(ref Unsafe.AddNative(ref b, i + 8)) = 0; + Unsafe.As(ref Unsafe.AddByteOffset(ref b, i)) = 0; + Unsafe.As(ref Unsafe.AddByteOffset(ref b, i + 8)) = 0; #else - Unsafe.As(ref Unsafe.AddNative(ref b, i)) = 0; - Unsafe.As(ref Unsafe.AddNative(ref b, i + 4)) = 0; - Unsafe.As(ref Unsafe.AddNative(ref b, i + 8)) = 0; - Unsafe.As(ref Unsafe.AddNative(ref b, i + 12)) = 0; + Unsafe.As(ref Unsafe.AddByteOffset(ref b, i)) = 0; + Unsafe.As(ref Unsafe.AddByteOffset(ref b, i + 4)) = 0; + Unsafe.As(ref Unsafe.AddByteOffset(ref b, i + 8)) = 0; + Unsafe.As(ref Unsafe.AddByteOffset(ref b, i + 12)) = 0; #endif i = counter; @@ -918,26 +918,26 @@ namespace System if ((byteLength & 8) != 0) { #if BIT64 - Unsafe.As(ref Unsafe.AddNative(ref b, i)) = 0; + Unsafe.As(ref Unsafe.AddByteOffset(ref b, i)) = 0; #else - Unsafe.As(ref Unsafe.AddNative(ref b, i)) = 0; - Unsafe.As(ref Unsafe.AddNative(ref b, i + 4)) = 0; + Unsafe.As(ref Unsafe.AddByteOffset(ref b, i)) = 0; + Unsafe.As(ref Unsafe.AddByteOffset(ref b, i + 4)) = 0; #endif i += 8; } if ((byteLength & 4) != 0) { - Unsafe.As(ref Unsafe.AddNative(ref b, i)) = 0; + Unsafe.As(ref Unsafe.AddByteOffset(ref b, i)) = 0; i += 4; } if ((byteLength & 2) != 0) { - Unsafe.As(ref Unsafe.AddNative(ref b, i)) = 0; + Unsafe.As(ref Unsafe.AddByteOffset(ref b, i)) = 0; i += 2; } if ((byteLength & 1) != 0) { - Unsafe.AddNative(ref b, i) = 0; + Unsafe.AddByteOffset(ref b, i) = 0; // We're not using i after this, so not needed // i += 1; } @@ -959,33 +959,33 @@ namespace System nuint n = 0; while ((n = i + 8) <= (pointerSizeLength)) { - Unsafe.AddNative(ref ip, i + 0) = default(IntPtr); - Unsafe.AddNative(ref ip, i + 1) = default(IntPtr); - Unsafe.AddNative(ref ip, i + 2) = default(IntPtr); - Unsafe.AddNative(ref ip, i + 3) = default(IntPtr); - Unsafe.AddNative(ref ip, i + 4) = default(IntPtr); - Unsafe.AddNative(ref ip, i + 5) = default(IntPtr); - Unsafe.AddNative(ref ip, i + 6) = default(IntPtr); - Unsafe.AddNative(ref ip, i + 7) = default(IntPtr); + Unsafe.AddByteOffset(ref ip, (i + 0) * (nuint)sizeof(IntPtr)) = default(IntPtr); + Unsafe.AddByteOffset(ref ip, (i + 1) * (nuint)sizeof(IntPtr)) = default(IntPtr); + Unsafe.AddByteOffset(ref ip, (i + 2) * (nuint)sizeof(IntPtr)) = default(IntPtr); + Unsafe.AddByteOffset(ref ip, (i + 3) * (nuint)sizeof(IntPtr)) = default(IntPtr); + Unsafe.AddByteOffset(ref ip, (i + 4) * (nuint)sizeof(IntPtr)) = default(IntPtr); + Unsafe.AddByteOffset(ref ip, (i + 5) * (nuint)sizeof(IntPtr)) = default(IntPtr); + Unsafe.AddByteOffset(ref ip, (i + 6) * (nuint)sizeof(IntPtr)) = default(IntPtr); + Unsafe.AddByteOffset(ref ip, (i + 7) * (nuint)sizeof(IntPtr)) = default(IntPtr); i = n; } if ((n = i + 4) <= (pointerSizeLength)) { - Unsafe.AddNative(ref ip, i + 0) = default(IntPtr); - Unsafe.AddNative(ref ip, i + 1) = default(IntPtr); - Unsafe.AddNative(ref ip, i + 2) = default(IntPtr); - Unsafe.AddNative(ref ip, i + 3) = default(IntPtr); + Unsafe.AddByteOffset(ref ip, (i + 0) * (nuint)sizeof(IntPtr)) = default(IntPtr); + Unsafe.AddByteOffset(ref ip, (i + 1) * (nuint)sizeof(IntPtr)) = default(IntPtr); + Unsafe.AddByteOffset(ref ip, (i + 2) * (nuint)sizeof(IntPtr)) = default(IntPtr); + Unsafe.AddByteOffset(ref ip, (i + 3) * (nuint)sizeof(IntPtr)) = default(IntPtr); i = n; } if ((n = i + 2) <= (pointerSizeLength)) { - Unsafe.AddNative(ref ip, i + 0) = default(IntPtr); - Unsafe.AddNative(ref ip, i + 1) = default(IntPtr); + Unsafe.AddByteOffset(ref ip, (i + 0) * (nuint)sizeof(IntPtr)) = default(IntPtr); + Unsafe.AddByteOffset(ref ip, (i + 1) * (nuint)sizeof(IntPtr)) = default(IntPtr); i = n; } if ((i + 1) <= (pointerSizeLength)) { - Unsafe.AddNative(ref ip, i) = default(IntPtr); + Unsafe.AddByteOffset(ref ip, (i + 0) * (nuint)sizeof(IntPtr)) = default(IntPtr); } } } diff --git a/src/coreclr/src/vm/jitinterface.cpp b/src/coreclr/src/vm/jitinterface.cpp index 6f69003..2673a9f 100644 --- a/src/coreclr/src/vm/jitinterface.cpp +++ b/src/coreclr/src/vm/jitinterface.cpp @@ -7060,24 +7060,13 @@ bool getILIntrinsicImplementationForUnsafe(MethodDesc * ftn, methInfo->options = (CorInfoOptions)0; return true; } - else if (tk == MscorlibBinder::GetMethod(METHOD__UNSAFE__BYREF_ADD_NATIVE)->GetMemberDef()) + else if (tk == MscorlibBinder::GetMethod(METHOD__UNSAFE__BYREF_ADD_BYTE_OFFSET)->GetMemberDef()) { - mdToken tokGenericArg = FindGenericMethodArgTypeSpec(MscorlibBinder::GetModule()->GetMDImport()); - - static BYTE ilcode[] = { CEE_LDARG_0, CEE_LDARG_1, - CEE_PREFIX1, (CEE_SIZEOF & 0xFF), 0,0,0,0, - CEE_MUL, - CEE_ADD, - CEE_RET }; - - ilcode[4] = (BYTE)(tokGenericArg); - ilcode[5] = (BYTE)(tokGenericArg >> 8); - ilcode[6] = (BYTE)(tokGenericArg >> 16); - ilcode[7] = (BYTE)(tokGenericArg >> 24); + static BYTE ilcode[] = { CEE_LDARG_0, CEE_LDARG_1, CEE_ADD, CEE_RET }; methInfo->ILCode = const_cast(ilcode); methInfo->ILCodeSize = sizeof(ilcode); - methInfo->maxStack = 3; + methInfo->maxStack = 2; methInfo->EHcount = 0; methInfo->options = (CorInfoOptions)0; return true; diff --git a/src/coreclr/src/vm/mscorlib.h b/src/coreclr/src/vm/mscorlib.h index 023ecd9..c41723a 100644 --- a/src/coreclr/src/vm/mscorlib.h +++ b/src/coreclr/src/vm/mscorlib.h @@ -1109,7 +1109,7 @@ DEFINE_METHOD(UNSAFE, AS_POINTER, AsPointer, NoSig) DEFINE_METHOD(UNSAFE, SIZEOF, SizeOf, NoSig) DEFINE_METHOD(UNSAFE, BYREF_AS, As, NoSig) DEFINE_METHOD(UNSAFE, BYREF_ADD, Add, NoSig) -DEFINE_METHOD(UNSAFE, BYREF_ADD_NATIVE, AddNative, NoSig) +DEFINE_METHOD(UNSAFE, BYREF_ADD_BYTE_OFFSET, AddByteOffset, NoSig) DEFINE_METHOD(UNSAFE, BYREF_ARE_SAME, AreSame, NoSig) DEFINE_METHOD(UNSAFE, BYREF_INIT_BLOCK_UNALIGNED, InitBlockUnaligned, NoSig) -- 2.7.4