Skip to content

Commit 367e0a8

Browse files
authored
Revert "Alternate approach for HELPER_METHOD_FRAME removal for arithmetic div…" (#114308)
This reverts commit 7aa0868.
1 parent a2e1d21 commit 367e0a8

File tree

21 files changed

+496
-612
lines changed

21 files changed

+496
-612
lines changed

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/classlibnative/float/divmodint.cpp

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/coreclr/classlibnative/inc/divmodint.h

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/coreclr/inc/jithelpers.h

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,34 +29,24 @@
2929
#define DYNAMICJITHELPER_NOINDIRECT(code,fn,binderId) DYNAMICJITHELPER(code,fn,binderId)
3030
#endif
3131

32-
#if defined(TARGET_32BIT) && defined (TARGET_ARM)
33-
#define FEATURE_USE_HELPERS_FOR_32BIT_INT_DIV
34-
#endif
35-
3632
// pfnHelper is set to NULL if it is a stubbed helper.
3733
// It will be set in InitJITHelpers1
3834

3935
JITHELPER(CORINFO_HELP_UNDEF, NULL, METHOD__NIL)
4036

4137
// Arithmetic
42-
#ifdef FEATURE_USE_HELPERS_FOR_32BIT_INT_DIV
43-
DYNAMICJITHELPER(CORINFO_HELP_DIV, NULL, METHOD__MATH__DIV_INT32)
44-
DYNAMICJITHELPER(CORINFO_HELP_MOD, NULL, METHOD__MATH__MOD_INT32)
45-
DYNAMICJITHELPER(CORINFO_HELP_UDIV, NULL, METHOD__MATH__DIV_UINT32)
46-
DYNAMICJITHELPER(CORINFO_HELP_UMOD, NULL, METHOD__MATH__MOD_UINT32)
47-
#else
48-
JITHELPER(CORINFO_HELP_DIV, NULL, METHOD__NIL)
49-
JITHELPER(CORINFO_HELP_MOD, NULL, METHOD__NIL)
50-
JITHELPER(CORINFO_HELP_UDIV, NULL, METHOD__NIL)
51-
JITHELPER(CORINFO_HELP_UMOD, NULL, METHOD__NIL)
52-
#endif
38+
JITHELPER(CORINFO_HELP_DIV, JIT_Div, METHOD__NIL)
39+
JITHELPER(CORINFO_HELP_MOD, JIT_Mod, METHOD__NIL)
40+
JITHELPER(CORINFO_HELP_UDIV, JIT_UDiv, METHOD__NIL)
41+
JITHELPER(CORINFO_HELP_UMOD, JIT_UMod, METHOD__NIL)
5342

54-
#ifdef TARGET_32BIT
43+
// CORINFO_HELP_DBL2INT, CORINFO_HELP_DBL2UINT, and CORINFO_HELP_DBL2LONG get
44+
// patched for CPUs that support SSE2 (P4 and above).
45+
#ifndef TARGET_64BIT
5546
JITHELPER(CORINFO_HELP_LLSH, JIT_LLsh, METHOD__NIL)
5647
JITHELPER(CORINFO_HELP_LRSH, JIT_LRsh, METHOD__NIL)
5748
JITHELPER(CORINFO_HELP_LRSZ, JIT_LRsz, METHOD__NIL)
58-
#else // TARGET_32BIT
59-
49+
#else // !TARGET_64BIT
6050
JITHELPER(CORINFO_HELP_LLSH, NULL, METHOD__NIL)
6151
JITHELPER(CORINFO_HELP_LRSH, NULL, METHOD__NIL)
6252
JITHELPER(CORINFO_HELP_LRSZ, NULL, METHOD__NIL)
@@ -65,25 +55,14 @@
6555
#ifndef TARGET_64BIT
6656
DYNAMICJITHELPER(CORINFO_HELP_LMUL_OVF, NULL, METHOD__MATH__MULTIPLY_CHECKED_INT64)
6757
DYNAMICJITHELPER(CORINFO_HELP_ULMUL_OVF, NULL, METHOD__MATH__MULTIPLY_CHECKED_UINT64)
68-
#if defined(TARGET_X86) && defined(TARGET_WINDOWS)
58+
#else
59+
DYNAMICJITHELPER(CORINFO_HELP_LMUL_OVF, NULL, METHOD__NIL)
60+
DYNAMICJITHELPER(CORINFO_HELP_ULMUL_OVF, NULL, METHOD__NIL)
61+
#endif // TARGET_64BIT
6962
JITHELPER(CORINFO_HELP_LDIV, JIT_LDiv, METHOD__NIL)
7063
JITHELPER(CORINFO_HELP_LMOD, JIT_LMod, METHOD__NIL)
7164
JITHELPER(CORINFO_HELP_ULDIV, JIT_ULDiv, METHOD__NIL)
7265
JITHELPER(CORINFO_HELP_ULMOD, JIT_ULMod, METHOD__NIL)
73-
#else
74-
DYNAMICJITHELPER(CORINFO_HELP_LDIV, NULL, METHOD__MATH__DIV_INT64)
75-
DYNAMICJITHELPER(CORINFO_HELP_LMOD, NULL, METHOD__MATH__MOD_INT64)
76-
DYNAMICJITHELPER(CORINFO_HELP_ULDIV, NULL, METHOD__MATH__DIV_UINT64)
77-
DYNAMICJITHELPER(CORINFO_HELP_ULMOD, NULL, METHOD__MATH__MOD_UINT64)
78-
#endif // TARGET_X86 && TARGET_WINDOWS
79-
#else // TARGET_64BIT
80-
JITHELPER(CORINFO_HELP_LMUL_OVF, NULL, METHOD__NIL)
81-
JITHELPER(CORINFO_HELP_ULMUL_OVF, NULL, METHOD__NIL)
82-
JITHELPER(CORINFO_HELP_LDIV, NULL, METHOD__NIL)
83-
JITHELPER(CORINFO_HELP_LMOD, NULL, METHOD__NIL)
84-
JITHELPER(CORINFO_HELP_ULDIV, NULL, METHOD__NIL)
85-
JITHELPER(CORINFO_HELP_ULMOD, NULL, METHOD__NIL)
86-
#endif // TARGET_64BIT
8766
JITHELPER(CORINFO_HELP_LNG2DBL, JIT_Lng2Dbl, METHOD__NIL)
8867
JITHELPER(CORINFO_HELP_ULNG2DBL, JIT_ULng2Dbl, METHOD__NIL)
8968
JITHELPER(CORINFO_HELP_DBL2INT, JIT_Dbl2Int, METHOD__NIL)

src/coreclr/jit/valuenum.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14160,8 +14160,8 @@ bool Compiler::fgValueNumberHelperCall(GenTreeCall* call)
1416014160
vnpExc = fgValueNumberDivisionExceptions(GT_DIV, call->gtArgs.GetUserArgByIndex(0)->GetNode(),
1416114161
call->gtArgs.GetUserArgByIndex(1)->GetNode());
1416214162
break;
14163-
case CORINFO_HELP_LMOD:
1416414163
case CORINFO_HELP_MOD:
14164+
case CORINFO_HELP_LMOD:
1416514165
vnpExc = fgValueNumberDivisionExceptions(GT_MOD, call->gtArgs.GetUserArgByIndex(0)->GetNode(),
1416614166
call->gtArgs.GetUserArgByIndex(1)->GetNode());
1416714167
break;

src/coreclr/nativeaot/Runtime/CommonMacros.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ typedef uint8_t CODE_LOCATION;
207207
FCIMPL_RENAME_ARGSIZE(_rettype, _method, 16) \
208208
EXTERN_C _rettype F_CALL_CONV _method##_FCall (b, a) \
209209
{
210-
#define FCIMPL2_LL FCIMPL2_DD
211210
#define FCIMPL2_FI(_rettype, _method, a, b) \
212211
FCIMPL_RENAME_ARGSIZE(_rettype, _method, 8) \
213212
EXTERN_C _rettype F_CALL_CONV _method##_FCall (a, b) \
@@ -250,7 +249,6 @@ typedef uint8_t CODE_LOCATION;
250249
#define FCIMPL2_DD(_rettype, _method, a, b) \
251250
EXTERN_C _rettype F_CALL_CONV _method (a, b) \
252251
{
253-
#define FCIMPL2_LL FCIMPL2_DD
254252
#define FCIMPL2_FI(_rettype, _method, a, b) \
255253
EXTERN_C _rettype F_CALL_CONV _method (a, b) \
256254
{

src/coreclr/nativeaot/Runtime/MathHelpers.cpp

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

5858
#ifndef HOST_64BIT
59-
FCIMPL2_LL(int64_t, 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
}
64-
FCIMPLEND
6564

66-
FCIMPL2_LL(uint64_t, DivUInt64Internal, uint64_t i, uint64_t j)
65+
EXTERN_C uint64_t QCALLTYPE RhpULDiv(uint64_t i, uint64_t j)
6766
{
6867
ASSERT(j && "Divide by zero!");
6968
return i / j;
7069
}
71-
FCIMPLEND
7270

73-
FCIMPL2_LL(int64_t, ModInt64Internal, int64_t i, int64_t j)
71+
EXTERN_C int64_t QCALLTYPE RhpLMod(int64_t i, int64_t j)
7472
{
7573
ASSERT(j && "Divide by zero!");
7674
return i % j;
7775
}
78-
FCIMPLEND
7976

80-
FCIMPL2_LL(uint64_t, ModUInt64Internal, uint64_t i, uint64_t j)
77+
EXTERN_C uint64_t QCALLTYPE RhpULMod(uint64_t i, uint64_t j)
8178
{
8279
ASSERT(j && "Divide by zero!");
8380
return i % j;
8481
}
85-
FCIMPLEND
8682

8783
FCIMPL1_L(double, RhpLng2Dbl, int64_t val)
8884
{
@@ -99,25 +95,25 @@ FCIMPLEND
9995
#endif
10096

10197
#ifdef HOST_ARM
102-
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)
10399
{
104100
ASSERT(j && "Divide by zero!");
105101
return i / j;
106102
}
107103

108-
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)
109105
{
110106
ASSERT(j && "Divide by zero!");
111107
return i / j;
112108
}
113109

114-
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)
115111
{
116112
ASSERT(j && "Divide by zero!");
117113
return i % j;
118114
}
119115

120-
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)
121117
{
122118
ASSERT(j && "Divide by zero!");
123119
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\MethodNameAndSignature.cs" />

0 commit comments

Comments
 (0)