Skip to content

Commit

Permalink
A small jit changes for Arm64 apple. (#45461)
Browse files Browse the repository at this point in the history
* Expand the test.

* The jit change that slipped in branches and merges.
  • Loading branch information
Sergey Andreenko authored Dec 2, 2020
1 parent 76b52a5 commit 44cf945
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/coreclr/src/jit/ee_il_dll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,14 @@ unsigned Compiler::eeGetArgSize(CORINFO_ARG_LIST_HANDLE list, CORINFO_SIG_INFO*
}
else
{
#if !defined(OSX_ARM64_ABI)
unsigned argSize = sizeof(int) * genTypeStSz(argType);
argSize = roundUp(argSize, TARGET_POINTER_SIZE);
#else
unsigned argSize = genTypeSize(argType);
#endif
assert(0 < argSize && argSize <= sizeof(__int64));
return roundUp(argSize, TARGET_POINTER_SIZE);
return argSize;
}
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/jit/lclvars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ void Compiler::lvaInitUserArgs(InitVarDscInfo* varDscInfo)
assert((argSize % TARGET_POINTER_SIZE) == 0);
assert((varDscInfo->stackArgSize % TARGET_POINTER_SIZE) == 0);
#endif // !OSX_ARM64_ABI

JITDUMP("set user arg V%02u offset to %u\n", varDscInfo->stackArgSize);
varDsc->SetStackOffset(varDscInfo->stackArgSize);
varDscInfo->stackArgSize += argSize;
#endif // FEATURE_FASTTAILCALL
Expand Down
19 changes: 16 additions & 3 deletions src/coreclr/src/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2719,7 +2719,7 @@ void Compiler::fgInitArgInfo(GenTreeCall* call)
*insertionPoint = gtNewCallArgs(arg);
#else // !defined(TARGET_X86)
// All other architectures pass the cookie in a register.
call->gtCallArgs = gtPrependNewCallArg(arg, call->gtCallArgs);
call->gtCallArgs = gtPrependNewCallArg(arg, call->gtCallArgs);
#endif // defined(TARGET_X86)

nonStandardArgs.Add(arg, REG_PINVOKE_COOKIE_PARAM);
Expand Down Expand Up @@ -2958,8 +2958,6 @@ void Compiler::fgInitArgInfo(GenTreeCall* call)
bool passUsingFloatRegs;
#if !defined(OSX_ARM64_ABI)
unsigned argAlignBytes = TARGET_POINTER_SIZE;
#else
unsigned argAlignBytes = TARGET_POINTER_SIZE; // TODO-OSX-ARM64: change it after other changes are merged.
#endif
unsigned size = 0;
unsigned byteSize = 0;
Expand Down Expand Up @@ -3211,6 +3209,21 @@ void Compiler::fgInitArgInfo(GenTreeCall* call)
assert(size != 0);
assert(byteSize != 0);

#if defined(OSX_ARM64_ABI)
// Arm64 Apple has a special ABI for passing small size arguments on stack,
// bytes are aligned to 1-byte, shorts to 2-byte, int/float to 4-byte, etc.
// It means passing 8 1-byte arguments on stack can take as small as 8 bytes.
unsigned argAlignBytes;
if (isStructArg)
{
argAlignBytes = TARGET_POINTER_SIZE;
}
else
{
argAlignBytes = byteSize;
}
#endif

//
// Figure out if the argument will be passed in a register.
//
Expand Down
22 changes: 22 additions & 0 deletions src/tests/Interop/PInvoke/Primitives/Int/PInvokeIntNative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,28 @@ extern "C" DLL_EXPORT int STDMETHODCALLTYPE Marshal_InMany(/*[in]*/short i1, sho
return i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + i10 + i11 + i12 + i13 + i14 + i15;
}

extern "C" DLL_EXPORT int STDMETHODCALLTYPE Marshal_InMany_InOutPointer(/*[in]*/short i1, short i2, short i3, short i4, short i5, short i6, short i7, short i8, short i9, short i10, short i11, unsigned char i12, unsigned char i13, int i14, short i15, /*[in,out]*/int *pintValue)
{
//Check the input
if(i1 != 1 || i2 != 2 || i3 != 3 || i4 != 4 || i5 != 5 || i6 != 6 || i7 != 7 || i8 != 8 || i9 != 9 || i10 != 10 || i11 != 11 || i12 != 12 || i13 != 13 || i14 != 14 || i15 != 15 || (*pintValue != 1000))
{
printf("Error in Function Marshal_InMany_InOutPointer(Native Client)\n");

//Expected
printf("Expected: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1000\n");

//Actual
printf("Actual: %hi, %hi, %hi, %hi, %hi, %hi, %hi, %hi, %hi, %hi, %hi, %i, %i, %i, %hi, %i\n", i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, (int)i12, (int)i13, i14, i15, *pintValue);

//Return the error value instead if verification failed
return intErrReturn;
}

*pintValue = 2000;

return i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + i10 + i11 + i12 + i13 + i14 + i15;
}

extern "C" DLL_EXPORT int STDMETHODCALLTYPE Marshal_InOut(/*[In,Out]*/int intValue)
{
//Check the input
Expand Down
15 changes: 15 additions & 0 deletions src/tests/Interop/PInvoke/Primitives/Int/PInvokeIntTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class ClientPInvokeIntNativeTest

[DllImport("PInvokeIntNative")]
private static extern int Marshal_InMany([In]short i1, [In]short i2, [In]short i3, [In]short i4, [In]short i5, [In]short i6, [In]short i7, [In]short i8, [In]short i9, [In]short i10, [In]short i11, [In]byte i12, [In]byte i13, [In]int i14, [In]short i15);

[DllImport("PInvokeIntNative")]
private static extern int Marshal_InMany_InOutPointer([In]short i1, [In]short i2, [In]short i3, [In]short i4, [In]short i5, [In]short i6, [In]short i7, [In]short i8, [In]short i9, [In]short i10, [In]short i11, [In]byte i12, [In]byte i13, [In]int i14, [In]short i15, ref int pintValue);


public static int Main(string[] args)
Expand Down Expand Up @@ -107,6 +110,18 @@ public static int Main(string[] args)
failures++;
Console.WriteLine("InMany return value is wrong");
}

int int7 = intManaged;
if(120 != Marshal_InMany_InOutPointer(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, ref int7))
{
failures++;
Console.WriteLine("InMany_InOutPointer return value is wrong");
}
if (intNative != int7)
{
failures++;
Console.WriteLine("InMany_InOutPointer byref value is wrong.");
}

return 100 + failures;
}
Expand Down

0 comments on commit 44cf945

Please sign in to comment.