Changing AddNative to AddByteOffset
authorahsonkhan <ahson_ahmedk@yahoo.com>
Wed, 22 Feb 2017 23:56:04 +0000 (15:56 -0800)
committerahsonkhan <ahson_ahmedk@yahoo.com>
Wed, 22 Feb 2017 23:56:04 +0000 (15:56 -0800)
Commit migrated from https://github.com/dotnet/coreclr/commit/ec6fb88e7009457f54f31ba83da915af395f4bd6

src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/Unsafe.cs
src/coreclr/src/mscorlib/src/System/Span.cs
src/coreclr/src/vm/jitinterface.cpp
src/coreclr/src/vm/mscorlib.h

index 571d097..1268dac 100644 (file)
@@ -76,11 +76,10 @@ namespace System.Runtime.CompilerServices
         /// </summary>
         [NonVersionable]
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public static ref T AddNative<T>(ref T source, nuint elementOffset)
+        public static ref T AddByteOffset<T>(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();
         }
 
index c5e88c5..f2f7f8b 100644 (file)
@@ -849,12 +849,12 @@ namespace System
             {
                 if ((Unsafe.As<byte, int>(ref b) & 1) != 0)
                 {
-                    Unsafe.AddNative<byte>(ref b, i) = 0;
+                    Unsafe.AddByteOffset<byte>(ref b, i) = 0;
                     i += 1;
                     if ((Unsafe.As<byte, int>(ref b) & 2) != 0)
                         goto IntAligned;
                 }
-                Unsafe.As<byte, short>(ref Unsafe.AddNative<byte>(ref b, i)) = 0;
+                Unsafe.As<byte, short>(ref Unsafe.AddByteOffset<byte>(ref b, i)) = 0;
                 i += 2;
             }
 
@@ -870,7 +870,7 @@ namespace System
 
             if (((Unsafe.As<byte, int>(ref b) - 1) & 4) == 0)
             {
-                Unsafe.As<byte, int>(ref Unsafe.AddNative<byte>(ref b, i)) = 0;
+                Unsafe.As<byte, int>(ref Unsafe.AddByteOffset<byte>(ref b, i)) = 0;
                 i += 4;
             }
 
@@ -899,13 +899,13 @@ namespace System
                 // we save on writes to b.
 
 #if BIT64
-                Unsafe.As<byte, long>(ref Unsafe.AddNative<byte>(ref b, i)) = 0;
-                Unsafe.As<byte, long>(ref Unsafe.AddNative<byte>(ref b, i + 8)) = 0;
+                Unsafe.As<byte, long>(ref Unsafe.AddByteOffset<byte>(ref b, i)) = 0;
+                Unsafe.As<byte, long>(ref Unsafe.AddByteOffset<byte>(ref b, i + 8)) = 0;
 #else
-                Unsafe.As<byte, int>(ref Unsafe.AddNative<byte>(ref b, i)) = 0;
-                Unsafe.As<byte, int>(ref Unsafe.AddNative<byte>(ref b, i + 4)) = 0;
-                Unsafe.As<byte, int>(ref Unsafe.AddNative<byte>(ref b, i + 8)) = 0;
-                Unsafe.As<byte, int>(ref Unsafe.AddNative<byte>(ref b, i + 12)) = 0;
+                Unsafe.As<byte, int>(ref Unsafe.AddByteOffset<byte>(ref b, i)) = 0;
+                Unsafe.As<byte, int>(ref Unsafe.AddByteOffset<byte>(ref b, i + 4)) = 0;
+                Unsafe.As<byte, int>(ref Unsafe.AddByteOffset<byte>(ref b, i + 8)) = 0;
+                Unsafe.As<byte, int>(ref Unsafe.AddByteOffset<byte>(ref b, i + 12)) = 0;
 #endif
 
                 i = counter;
@@ -918,26 +918,26 @@ namespace System
             if ((byteLength & 8) != 0)
             {
 #if BIT64
-                Unsafe.As<byte, long>(ref Unsafe.AddNative<byte>(ref b, i)) = 0;
+                Unsafe.As<byte, long>(ref Unsafe.AddByteOffset<byte>(ref b, i)) = 0;
 #else
-                Unsafe.As<byte, int>(ref Unsafe.AddNative<byte>(ref b, i)) = 0;
-                Unsafe.As<byte, int>(ref Unsafe.AddNative<byte>(ref b, i + 4)) = 0;
+                Unsafe.As<byte, int>(ref Unsafe.AddByteOffset<byte>(ref b, i)) = 0;
+                Unsafe.As<byte, int>(ref Unsafe.AddByteOffset<byte>(ref b, i + 4)) = 0;
 #endif
                 i += 8;
             }
             if ((byteLength & 4) != 0)
             {
-                Unsafe.As<byte, int>(ref Unsafe.AddNative<byte>(ref b, i)) = 0;
+                Unsafe.As<byte, int>(ref Unsafe.AddByteOffset<byte>(ref b, i)) = 0;
                 i += 4;
             }
             if ((byteLength & 2) != 0)
             {
-                Unsafe.As<byte, short>(ref Unsafe.AddNative<byte>(ref b, i)) = 0;
+                Unsafe.As<byte, short>(ref Unsafe.AddByteOffset<byte>(ref b, i)) = 0;
                 i += 2;
             }
             if ((byteLength & 1) != 0)
             {
-                Unsafe.AddNative<byte>(ref b, i) = 0;
+                Unsafe.AddByteOffset<byte>(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<IntPtr>(ref ip, i + 0) = default(IntPtr);
-                Unsafe.AddNative<IntPtr>(ref ip, i + 1) = default(IntPtr);
-                Unsafe.AddNative<IntPtr>(ref ip, i + 2) = default(IntPtr);
-                Unsafe.AddNative<IntPtr>(ref ip, i + 3) = default(IntPtr);
-                Unsafe.AddNative<IntPtr>(ref ip, i + 4) = default(IntPtr);
-                Unsafe.AddNative<IntPtr>(ref ip, i + 5) = default(IntPtr);
-                Unsafe.AddNative<IntPtr>(ref ip, i + 6) = default(IntPtr);
-                Unsafe.AddNative<IntPtr>(ref ip, i + 7) = default(IntPtr);
+                Unsafe.AddByteOffset<IntPtr>(ref ip, (i + 0) * (nuint)sizeof(IntPtr)) = default(IntPtr);
+                Unsafe.AddByteOffset<IntPtr>(ref ip, (i + 1) * (nuint)sizeof(IntPtr)) = default(IntPtr);
+                Unsafe.AddByteOffset<IntPtr>(ref ip, (i + 2) * (nuint)sizeof(IntPtr)) = default(IntPtr);
+                Unsafe.AddByteOffset<IntPtr>(ref ip, (i + 3) * (nuint)sizeof(IntPtr)) = default(IntPtr);
+                Unsafe.AddByteOffset<IntPtr>(ref ip, (i + 4) * (nuint)sizeof(IntPtr)) = default(IntPtr);
+                Unsafe.AddByteOffset<IntPtr>(ref ip, (i + 5) * (nuint)sizeof(IntPtr)) = default(IntPtr);
+                Unsafe.AddByteOffset<IntPtr>(ref ip, (i + 6) * (nuint)sizeof(IntPtr)) = default(IntPtr);
+                Unsafe.AddByteOffset<IntPtr>(ref ip, (i + 7) * (nuint)sizeof(IntPtr)) = default(IntPtr);
                 i = n;
             }
             if ((n = i + 4) <= (pointerSizeLength))
             {
-                Unsafe.AddNative<IntPtr>(ref ip, i + 0) = default(IntPtr);
-                Unsafe.AddNative<IntPtr>(ref ip, i + 1) = default(IntPtr);
-                Unsafe.AddNative<IntPtr>(ref ip, i + 2) = default(IntPtr);
-                Unsafe.AddNative<IntPtr>(ref ip, i + 3) = default(IntPtr);
+                Unsafe.AddByteOffset<IntPtr>(ref ip, (i + 0) * (nuint)sizeof(IntPtr)) = default(IntPtr);
+                Unsafe.AddByteOffset<IntPtr>(ref ip, (i + 1) * (nuint)sizeof(IntPtr)) = default(IntPtr);
+                Unsafe.AddByteOffset<IntPtr>(ref ip, (i + 2) * (nuint)sizeof(IntPtr)) = default(IntPtr);
+                Unsafe.AddByteOffset<IntPtr>(ref ip, (i + 3) * (nuint)sizeof(IntPtr)) = default(IntPtr);
                 i = n;
             }
             if ((n = i + 2) <= (pointerSizeLength))
             {
-                Unsafe.AddNative<IntPtr>(ref ip, i + 0) = default(IntPtr);
-                Unsafe.AddNative<IntPtr>(ref ip, i + 1) = default(IntPtr);
+                Unsafe.AddByteOffset<IntPtr>(ref ip, (i + 0) * (nuint)sizeof(IntPtr)) = default(IntPtr);
+                Unsafe.AddByteOffset<IntPtr>(ref ip, (i + 1) * (nuint)sizeof(IntPtr)) = default(IntPtr);
                 i = n;
             }
             if ((i + 1) <= (pointerSizeLength))
             {
-                Unsafe.AddNative<IntPtr>(ref ip, i) = default(IntPtr);
+                Unsafe.AddByteOffset<IntPtr>(ref ip, (i + 0) * (nuint)sizeof(IntPtr)) = default(IntPtr);
             }
         }
     }
index 6f69003..2673a9f 100644 (file)
@@ -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<BYTE*>(ilcode);
         methInfo->ILCodeSize = sizeof(ilcode);
-        methInfo->maxStack = 3;
+        methInfo->maxStack = 2;
         methInfo->EHcount = 0;
         methInfo->options = (CorInfoOptions)0;
         return true;
index 023ecd9..c41723a 100644 (file)
@@ -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)