Skip to content

Commit 44cf945

Browse files
author
Sergey Andreenko
authored
A small jit changes for Arm64 apple. (#45461)
* Expand the test. * The jit change that slipped in branches and merges.
1 parent 76b52a5 commit 44cf945

File tree

5 files changed

+60
-5
lines changed

5 files changed

+60
-5
lines changed

src/coreclr/src/jit/ee_il_dll.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,14 @@ unsigned Compiler::eeGetArgSize(CORINFO_ARG_LIST_HANDLE list, CORINFO_SIG_INFO*
426426
}
427427
else
428428
{
429+
#if !defined(OSX_ARM64_ABI)
429430
unsigned argSize = sizeof(int) * genTypeStSz(argType);
431+
argSize = roundUp(argSize, TARGET_POINTER_SIZE);
432+
#else
433+
unsigned argSize = genTypeSize(argType);
434+
#endif
430435
assert(0 < argSize && argSize <= sizeof(__int64));
431-
return roundUp(argSize, TARGET_POINTER_SIZE);
436+
return argSize;
432437
}
433438
#endif
434439
}

src/coreclr/src/jit/lclvars.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ void Compiler::lvaInitUserArgs(InitVarDscInfo* varDscInfo)
10291029
assert((argSize % TARGET_POINTER_SIZE) == 0);
10301030
assert((varDscInfo->stackArgSize % TARGET_POINTER_SIZE) == 0);
10311031
#endif // !OSX_ARM64_ABI
1032-
1032+
JITDUMP("set user arg V%02u offset to %u\n", varDscInfo->stackArgSize);
10331033
varDsc->SetStackOffset(varDscInfo->stackArgSize);
10341034
varDscInfo->stackArgSize += argSize;
10351035
#endif // FEATURE_FASTTAILCALL

src/coreclr/src/jit/morph.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2719,7 +2719,7 @@ void Compiler::fgInitArgInfo(GenTreeCall* call)
27192719
*insertionPoint = gtNewCallArgs(arg);
27202720
#else // !defined(TARGET_X86)
27212721
// All other architectures pass the cookie in a register.
2722-
call->gtCallArgs = gtPrependNewCallArg(arg, call->gtCallArgs);
2722+
call->gtCallArgs = gtPrependNewCallArg(arg, call->gtCallArgs);
27232723
#endif // defined(TARGET_X86)
27242724

27252725
nonStandardArgs.Add(arg, REG_PINVOKE_COOKIE_PARAM);
@@ -2958,8 +2958,6 @@ void Compiler::fgInitArgInfo(GenTreeCall* call)
29582958
bool passUsingFloatRegs;
29592959
#if !defined(OSX_ARM64_ABI)
29602960
unsigned argAlignBytes = TARGET_POINTER_SIZE;
2961-
#else
2962-
unsigned argAlignBytes = TARGET_POINTER_SIZE; // TODO-OSX-ARM64: change it after other changes are merged.
29632961
#endif
29642962
unsigned size = 0;
29652963
unsigned byteSize = 0;
@@ -3211,6 +3209,21 @@ void Compiler::fgInitArgInfo(GenTreeCall* call)
32113209
assert(size != 0);
32123210
assert(byteSize != 0);
32133211

3212+
#if defined(OSX_ARM64_ABI)
3213+
// Arm64 Apple has a special ABI for passing small size arguments on stack,
3214+
// bytes are aligned to 1-byte, shorts to 2-byte, int/float to 4-byte, etc.
3215+
// It means passing 8 1-byte arguments on stack can take as small as 8 bytes.
3216+
unsigned argAlignBytes;
3217+
if (isStructArg)
3218+
{
3219+
argAlignBytes = TARGET_POINTER_SIZE;
3220+
}
3221+
else
3222+
{
3223+
argAlignBytes = byteSize;
3224+
}
3225+
#endif
3226+
32143227
//
32153228
// Figure out if the argument will be passed in a register.
32163229
//

src/tests/Interop/PInvoke/Primitives/Int/PInvokeIntNative.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,28 @@ extern "C" DLL_EXPORT int STDMETHODCALLTYPE Marshal_InMany(/*[in]*/short i1, sho
5050
return i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + i10 + i11 + i12 + i13 + i14 + i15;
5151
}
5252

53+
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)
54+
{
55+
//Check the input
56+
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))
57+
{
58+
printf("Error in Function Marshal_InMany_InOutPointer(Native Client)\n");
59+
60+
//Expected
61+
printf("Expected: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1000\n");
62+
63+
//Actual
64+
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);
65+
66+
//Return the error value instead if verification failed
67+
return intErrReturn;
68+
}
69+
70+
*pintValue = 2000;
71+
72+
return i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + i10 + i11 + i12 + i13 + i14 + i15;
73+
}
74+
5375
extern "C" DLL_EXPORT int STDMETHODCALLTYPE Marshal_InOut(/*[In,Out]*/int intValue)
5476
{
5577
//Check the input

src/tests/Interop/PInvoke/Primitives/Int/PInvokeIntTest.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class ClientPInvokeIntNativeTest
2626

2727
[DllImport("PInvokeIntNative")]
2828
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);
29+
30+
[DllImport("PInvokeIntNative")]
31+
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);
2932

3033

3134
public static int Main(string[] args)
@@ -107,6 +110,18 @@ public static int Main(string[] args)
107110
failures++;
108111
Console.WriteLine("InMany return value is wrong");
109112
}
113+
114+
int int7 = intManaged;
115+
if(120 != Marshal_InMany_InOutPointer(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, ref int7))
116+
{
117+
failures++;
118+
Console.WriteLine("InMany_InOutPointer return value is wrong");
119+
}
120+
if (intNative != int7)
121+
{
122+
failures++;
123+
Console.WriteLine("InMany_InOutPointer byref value is wrong.");
124+
}
110125

111126
return 100 + failures;
112127
}

0 commit comments

Comments
 (0)