Skip to content

Commit 9dbcf4e

Browse files
committed
Experiment: Change FCThrow to COMPlusThrowf
1 parent 6ad8b12 commit 9dbcf4e

File tree

15 files changed

+569
-44
lines changed

15 files changed

+569
-44
lines changed

src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
<Compile Include="$(BclSourcesRoot)\System\IO\Stream.CoreCLR.cs" />
144144
<Compile Include="$(BclSourcesRoot)\System\Math.CoreCLR.cs" />
145145
<Compile Include="$(BclSourcesRoot)\System\MathF.CoreCLR.cs" />
146+
<Compile Include="$(BclSourcesRoot)\System\Math.DivMod.cs" Condition="'$(Is64Bit)' != 'true'" />
146147
<Compile Include="$(BclSourcesRoot)\System\MulticastDelegate.CoreCLR.cs" />
147148
<Compile Include="$(BclSourcesRoot)\System\Object.CoreCLR.cs" />
148149
<Compile Include="$(BclSourcesRoot)\System\Reflection\Assembly.CoreCLR.cs" />
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Diagnostics;
5+
using System.Runtime.CompilerServices;
6+
using System.Runtime.InteropServices;
7+
8+
namespace System
9+
{
10+
/// <summary>
11+
/// Provides constants and static methods for trigonometric, logarithmic, and other common mathematical functions.
12+
/// </summary>
13+
public static partial class Math
14+
{
15+
[StackTraceHidden]
16+
internal static int DivInt32(int dividend, int divisor) => DivInt32Internal(dividend, divisor);
17+
18+
[StackTraceHidden]
19+
internal static uint DivUInt32(uint dividend, uint divisor) => DivUInt32Internal(dividend, divisor);
20+
21+
[StackTraceHidden]
22+
internal static long DivInt64(long dividend, long divisor) => DivInt64Internal(dividend, divisor);
23+
24+
[StackTraceHidden]
25+
internal static ulong DivUInt64(ulong dividend, ulong divisor) => DivUInt64Internal(dividend, divisor);
26+
27+
[StackTraceHidden]
28+
internal static int ModInt32(int dividend, int divisor) => ModInt32Internal(dividend, divisor);
29+
30+
[StackTraceHidden]
31+
internal static uint ModUInt32(uint dividend, uint divisor) => ModUInt32Internal(dividend, divisor);
32+
33+
[StackTraceHidden]
34+
internal static long ModInt64(long dividend, long divisor) => ModInt64Internal(dividend, divisor);
35+
36+
[StackTraceHidden]
37+
internal static ulong ModUInt64(ulong dividend, ulong divisor) => ModUInt64Internal(dividend, divisor);
38+
39+
[LibraryImport(RuntimeHelpers.QCall), SuppressGCTransition]
40+
private static partial int DivInt32Internal(int dividend, int divisor);
41+
42+
[LibraryImport(RuntimeHelpers.QCall), SuppressGCTransition]
43+
private static partial uint DivUInt32Internal(uint dividend, uint divisor);
44+
45+
[LibraryImport(RuntimeHelpers.QCall), SuppressGCTransition]
46+
private static partial long DivInt64Internal(long dividend, long divisor);
47+
48+
[LibraryImport(RuntimeHelpers.QCall), SuppressGCTransition]
49+
private static partial ulong DivUInt64Internal(ulong dividend, ulong divisor);
50+
51+
[LibraryImport(RuntimeHelpers.QCall), SuppressGCTransition]
52+
private static partial int ModInt32Internal(int dividend, int divisor);
53+
54+
[LibraryImport(RuntimeHelpers.QCall), SuppressGCTransition]
55+
private static partial uint ModUInt32Internal(uint dividend, uint divisor);
56+
57+
[LibraryImport(RuntimeHelpers.QCall), SuppressGCTransition]
58+
private static partial long ModInt64Internal(long dividend, long divisor);
59+
60+
[LibraryImport(RuntimeHelpers.QCall), SuppressGCTransition]
61+
private static partial ulong ModUInt64Internal(ulong dividend, ulong divisor);
62+
}
63+
}

src/coreclr/classlibnative/float/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ include_directories("../inc")
33
set(FLOAT_SOURCES
44
floatdouble.cpp
55
floatsingle.cpp
6-
divmodint.cpp
76
)
87

98
add_library_clr(comfloat_wks OBJECT ${FLOAT_SOURCES})

src/coreclr/inc/jithelpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
DYNAMICJITHELPER(CORINFO_HELP_LMOD, NULL, METHOD__MATH__MOD_INT64)
6565
DYNAMICJITHELPER(CORINFO_HELP_ULDIV, NULL, METHOD__MATH__DIV_UINT64)
6666
DYNAMICJITHELPER(CORINFO_HELP_ULMOD, NULL, METHOD__MATH__MOD_UINT64)
67-
#else
67+
#else // TARGET_32BIT
6868
DYNAMICJITHELPER(CORINFO_HELP_LMUL_OVF, NULL, METHOD__NIL)
6969
DYNAMICJITHELPER(CORINFO_HELP_ULMUL_OVF, NULL, METHOD__NIL)
7070
DYNAMICJITHELPER(CORINFO_HELP_LDIV, NULL, METHOD__NIL)

src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/CompilerServices/RuntimeHelpers.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,5 @@ public static int OffsetToStringData
1818

1919
[Intrinsic]
2020
public static extern void InitializeArray(Array array, RuntimeFieldHandle fldHandle);
21-
22-
public const string QCall = "*";
2321
}
2422
}

src/coreclr/nativeaot/Runtime/MathHelpers.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,25 @@ FCIMPL1_D(uint32_t, RhpDbl2UInt, double val)
5656
FCIMPLEND
5757

5858
#ifndef HOST_64BIT
59-
EXTERN_C int64_t QCALLTYPE DivInt64Internal(int64_t i, int64_t j)
59+
EXTERN_C int64_t QCALLTYPE RhpLDiv(int64_t i, int64_t j)
6060
{
6161
ASSERT(j && "Divide by zero!");
6262
return i / j;
6363
}
6464

65-
EXTERN_C uint64_t QCALLTYPE DivUInt64Internal(uint64_t i, uint64_t j)
65+
EXTERN_C uint64_t QCALLTYPE RhpULDiv(uint64_t i, uint64_t j)
6666
{
6767
ASSERT(j && "Divide by zero!");
6868
return i / j;
6969
}
7070

71-
EXTERN_C int64_t QCALLTYPE ModInt64Internal(int64_t i, int64_t j)
71+
EXTERN_C int64_t QCALLTYPE RhpLMod(int64_t i, int64_t j)
7272
{
7373
ASSERT(j && "Divide by zero!");
7474
return i % j;
7575
}
7676

77-
EXTERN_C uint64_t QCALLTYPE ModUInt64Internal(uint64_t i, uint64_t j)
77+
EXTERN_C uint64_t QCALLTYPE RhpULMod(uint64_t i, uint64_t j)
7878
{
7979
ASSERT(j && "Divide by zero!");
8080
return i % j;
@@ -95,25 +95,25 @@ FCIMPLEND
9595
#endif
9696

9797
#ifdef HOST_ARM
98-
EXTERN_C int32_t F_CALL_CONV DivInt32Internal(int32_t i, int32_t j)
98+
EXTERN_C int32_t F_CALL_CONV RhpIDiv(int32_t i, int32_t j)
9999
{
100100
ASSERT(j && "Divide by zero!");
101101
return i / j;
102102
}
103103

104-
EXTERN_C uint32_t F_CALL_CONV DivUInt32Internal(uint32_t i, uint32_t j)
104+
EXTERN_C uint32_t F_CALL_CONV RhpUDiv(uint32_t i, uint32_t j)
105105
{
106106
ASSERT(j && "Divide by zero!");
107107
return i / j;
108108
}
109109

110-
EXTERN_C int32_t F_CALL_CONV ModInt32Internal(int32_t i, int32_t j)
110+
EXTERN_C int32_t F_CALL_CONV RhpIMod(int32_t i, int32_t j)
111111
{
112112
ASSERT(j && "Divide by zero!");
113113
return i % j;
114114
}
115115

116-
EXTERN_C uint32_t F_CALL_CONV ModUInt32Internal(uint32_t i, uint32_t j)
116+
EXTERN_C uint32_t F_CALL_CONV RhpUMod(uint32_t i, uint32_t j)
117117
{
118118
ASSERT(j && "Divide by zero!");
119119
return i % j;
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Diagnostics;
6+
using System.Runtime;
7+
using System.Runtime.CompilerServices;
8+
using System.Runtime.InteropServices;
9+
10+
namespace Internal.Runtime.CompilerHelpers
11+
{
12+
/// <summary>
13+
/// Math helpers for generated code. The helpers here are referenced by the runtime.
14+
/// </summary>
15+
[StackTraceHidden]
16+
internal static partial class MathHelpers
17+
{
18+
#if !TARGET_64BIT
19+
private const string RuntimeLibrary = "*";
20+
21+
[LibraryImport(RuntimeLibrary)]
22+
[SuppressGCTransition]
23+
private static partial ulong RhpULMod(ulong dividend, ulong divisor);
24+
25+
public static ulong ULMod(ulong dividend, ulong divisor)
26+
{
27+
if (divisor == 0)
28+
ThrowHelper.ThrowDivideByZeroException();
29+
30+
return RhpULMod(dividend, divisor);
31+
}
32+
33+
[LibraryImport(RuntimeLibrary)]
34+
[SuppressGCTransition]
35+
private static partial long RhpLMod(long dividend, long divisor);
36+
37+
public static long LMod(long dividend, long divisor)
38+
{
39+
if (divisor == 0)
40+
ThrowHelper.ThrowDivideByZeroException();
41+
if (divisor == -1 && dividend == long.MinValue)
42+
ThrowHelper.ThrowOverflowException();
43+
44+
return RhpLMod(dividend, divisor);
45+
}
46+
47+
[LibraryImport(RuntimeLibrary)]
48+
[SuppressGCTransition]
49+
private static partial ulong RhpULDiv(ulong dividend, ulong divisor);
50+
51+
public static ulong ULDiv(ulong dividend, ulong divisor)
52+
{
53+
if (divisor == 0)
54+
ThrowHelper.ThrowDivideByZeroException();
55+
56+
return RhpULDiv(dividend, divisor);
57+
}
58+
59+
[LibraryImport(RuntimeLibrary)]
60+
[SuppressGCTransition]
61+
private static partial long RhpLDiv(long dividend, long divisor);
62+
63+
public static long LDiv(long dividend, long divisor)
64+
{
65+
if (divisor == 0)
66+
ThrowHelper.ThrowDivideByZeroException();
67+
if (divisor == -1 && dividend == long.MinValue)
68+
ThrowHelper.ThrowOverflowException();
69+
70+
return RhpLDiv(dividend, divisor);
71+
}
72+
73+
#if TARGET_ARM
74+
[RuntimeImport(RuntimeLibrary, "RhpIDiv")]
75+
[MethodImpl(MethodImplOptions.InternalCall)]
76+
private static extern int RhpIDiv(int dividend, int divisor);
77+
78+
public static int IDiv(int dividend, int divisor)
79+
{
80+
if (divisor == 0)
81+
ThrowHelper.ThrowDivideByZeroException();
82+
if (divisor == -1 && dividend == int.MinValue)
83+
ThrowHelper.ThrowOverflowException();
84+
85+
return RhpIDiv(dividend, divisor);
86+
}
87+
88+
[RuntimeImport(RuntimeLibrary, "RhpUDiv")]
89+
[MethodImpl(MethodImplOptions.InternalCall)]
90+
private static extern uint RhpUDiv(uint dividend, uint divisor);
91+
92+
public static long UDiv(uint dividend, uint divisor)
93+
{
94+
if (divisor == 0)
95+
ThrowHelper.ThrowDivideByZeroException();
96+
97+
return RhpUDiv(dividend, divisor);
98+
}
99+
100+
[RuntimeImport(RuntimeLibrary, "RhpIMod")]
101+
[MethodImpl(MethodImplOptions.InternalCall)]
102+
private static extern int RhpIMod(int dividend, int divisor);
103+
104+
public static int IMod(int dividend, int divisor)
105+
{
106+
if (divisor == 0)
107+
ThrowHelper.ThrowDivideByZeroException();
108+
if (divisor == -1 && dividend == int.MinValue)
109+
ThrowHelper.ThrowOverflowException();
110+
111+
return RhpIMod(dividend, divisor);
112+
}
113+
114+
[RuntimeImport(RuntimeLibrary, "RhpUMod")]
115+
[MethodImpl(MethodImplOptions.InternalCall)]
116+
private static extern uint RhpUMod(uint dividend, uint divisor);
117+
118+
public static long UMod(uint dividend, uint divisor)
119+
{
120+
if (divisor == 0)
121+
ThrowHelper.ThrowDivideByZeroException();
122+
123+
return RhpUMod(dividend, divisor);
124+
}
125+
#endif // TARGET_ARM
126+
#endif // TARGET_64BIT
127+
}
128+
}

src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
<Compile Include="Internal\Runtime\IDynamicInterfaceCastableSupport.cs" />
117117
<Compile Include="Internal\Runtime\MethodTable.Runtime.cs" />
118118
<Compile Include="Internal\Runtime\CompilerHelpers\ThrowHelpers.cs" />
119+
<Compile Include="Internal\Runtime\CompilerHelpers\MathHelpers.cs" />
119120
<Compile Include="Internal\Runtime\CompilerServices\FunctionPointerOps.cs" />
120121
<Compile Include="Internal\Runtime\CompilerServices\GenericMethodDescriptor.cs" />
121122
<Compile Include="Internal\Runtime\CompilerServices\RuntimeFieldHandleInfo.cs" />

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/JitHelper.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -233,30 +233,30 @@ public static void GetEntryPoint(TypeSystemContext context, ReadyToRunHelper id,
233233
}
234234
break;
235235

236-
case ReadyToRunHelper.Div:
237-
methodDesc = context.SystemModule.GetKnownType("System", "Math").GetKnownMethod("DivInt32", null);
236+
case ReadyToRunHelper.Mod:
237+
methodDesc = context.GetHelperEntryPoint("MathHelpers", "IMod");
238238
break;
239-
case ReadyToRunHelper.UDiv:
240-
methodDesc = context.SystemModule.GetKnownType("System", "Math").GetKnownMethod("DivUInt32", null);
239+
case ReadyToRunHelper.UMod:
240+
methodDesc = context.GetHelperEntryPoint("MathHelpers", "UMod");
241241
break;
242-
case ReadyToRunHelper.LDiv:
243-
methodDesc = context.SystemModule.GetKnownType("System", "Math").GetKnownMethod("DivInt64", null);
242+
case ReadyToRunHelper.ULMod:
243+
methodDesc = context.GetHelperEntryPoint("MathHelpers", "ULMod");
244244
break;
245-
case ReadyToRunHelper.ULDiv:
246-
methodDesc = context.SystemModule.GetKnownType("System", "Math").GetKnownMethod("DivUInt64", null);
245+
case ReadyToRunHelper.LMod:
246+
methodDesc = context.GetHelperEntryPoint("MathHelpers", "LMod");
247247
break;
248248

249-
case ReadyToRunHelper.Mod:
250-
methodDesc = context.SystemModule.GetKnownType("System", "Math").GetKnownMethod("ModInt32", null);
249+
case ReadyToRunHelper.Div:
250+
methodDesc = context.GetHelperEntryPoint("MathHelpers", "IDiv");
251251
break;
252-
case ReadyToRunHelper.UMod:
253-
methodDesc = context.SystemModule.GetKnownType("System", "Math").GetKnownMethod("ModUInt32", null);
252+
case ReadyToRunHelper.UDiv:
253+
methodDesc = context.GetHelperEntryPoint("MathHelpers", "UDiv");
254254
break;
255-
case ReadyToRunHelper.LMod:
256-
methodDesc = context.SystemModule.GetKnownType("System", "Math").GetKnownMethod("ModInt64", null);
255+
case ReadyToRunHelper.ULDiv:
256+
methodDesc = context.GetHelperEntryPoint("MathHelpers", "ULDiv");
257257
break;
258-
case ReadyToRunHelper.ULMod:
259-
methodDesc = context.SystemModule.GetKnownType("System", "Math").GetKnownMethod("ModUInt64", null);
258+
case ReadyToRunHelper.LDiv:
259+
methodDesc = context.GetHelperEntryPoint("MathHelpers", "LDiv");
260260
break;
261261

262262
case ReadyToRunHelper.LRsz:

src/coreclr/vm/JitQCallHelpers.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,15 @@ extern "C" void QCALLTYPE ThrowInvalidCastException(CORINFO_CLASS_HANDLE pTarget
2525
extern "C" void QCALLTYPE GetThreadStaticsByMethodTable(QCall::ByteRefOnStack refHandle, MethodTable* pMT, bool gcStatic);
2626
extern "C" void QCALLTYPE GetThreadStaticsByIndex(QCall::ByteRefOnStack refHandle, uint32_t staticBlockIndex, bool gcStatic);
2727

28-
#endif //_JITQCALLHELPERS_H
28+
#if defined(TARGET_32BIT)
29+
extern "C" INT32 QCALLTYPE DivInt32Internal(INT32 dividend, INT32 divisor);
30+
extern "C" UINT32 QCALLTYPE DivUInt32Internal(UINT32 dividend, UINT32 divisor);
31+
extern "C" INT64 QCALLTYPE DivInt64Internal(INT64 dividend, INT64 divisor);
32+
extern "C" UINT64 QCALLTYPE DivUInt64Internal(UINT64 dividend, UINT64 divisor);
33+
extern "C" INT32 QCALLTYPE ModInt32Internal(INT32 dividend, INT32 divisor);
34+
extern "C" UINT32 QCALLTYPE ModUInt32Internal(UINT32 dividend, UINT32 divisor);
35+
extern "C" INT64 QCALLTYPE ModInt64Internal(INT64 dividend, INT64 divisor);
36+
extern "C" UINT64 QCALLTYPE ModUInt64Internal(UINT64 dividend, UINT64 divisor);
37+
#endif // TARGET_32BIT
38+
39+
#endif // _JITQCALLHELPERS_H

0 commit comments

Comments
 (0)