Skip to content

Alternate approach for HELPER_METHOD_FRAME removal for arithmetic div… #113286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
aa53732
Alternate approach for HELPER_METHOD_FRAME removal for arithmetic div…
davidwrighton Mar 8, 2025
e2273af
Update alignment to be a bit better for the assembly routines
davidwrighton Mar 8, 2025
29364c3
Try to adjust jithelpers.cpp for better building on arm32
davidwrighton Mar 8, 2025
f7f6e3d
Fix more oops in the build
davidwrighton Mar 8, 2025
52e28a9
More attempts to fix build breaks... maybe I should actually set up a…
davidwrighton Mar 8, 2025
6796ab4
Get the types right for JIT_UDiv and JIT_UMod
davidwrighton Mar 8, 2025
7ed11fe
Swap the args around for the 64bit long/ulong divide helpers back to …
davidwrighton Mar 10, 2025
e76b3aa
Attempt to fix 32bit linux builds, and remove all use of FCThrow, and…
davidwrighton Mar 18, 2025
a5af1b4
Fix BCL build
davidwrighton Mar 18, 2025
19ec62a
Merge branch 'main' into alternate_approach_to_removingHMF_for_arithm…
davidwrighton Mar 18, 2025
3799b0d
Get this approach building on Linux X86 and Linux Arm ... turns out t…
davidwrighton Mar 19, 2025
f418940
Merge branch 'main' into alternate_approach_to_removingHMF_for_arithm…
davidwrighton Mar 21, 2025
8d6ba7e
Integrate am11's work into my branch
davidwrighton Mar 24, 2025
ee49f1c
Merge branch 'main' of https://github.com/dotnet/runtime into alterna…
davidwrighton Mar 24, 2025
a87b046
Fix x86 eh stuff
davidwrighton Mar 31, 2025
8cc6d52
Merge branch 'main' of https://github.com/dotnet/runtime into alterna…
davidwrighton Mar 31, 2025
37ae63f
Move the math helpers to be consistently FCalls
davidwrighton Mar 31, 2025
0722c32
Tweak macros
davidwrighton Mar 31, 2025
51db312
Merge branch 'main' of https://github.com/dotnet/runtime into alterna…
davidwrighton Apr 1, 2025
356f9ba
Code revewi from am11
davidwrighton Apr 1, 2025
eda6d06
Remove unused System namespace import
davidwrighton Apr 2, 2025
0eb3870
Merge branch 'main' of https://github.com/dotnet/runtime into alterna…
davidwrighton Apr 2, 2025
a21f51d
AAGGHH
davidwrighton Apr 4, 2025
5b7bfb6
Merge branch 'main' of github.com:dotnet/runtime into alternate_appro…
davidwrighton Apr 4, 2025
b3188c5
Code review comments
davidwrighton Apr 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/coreclr/classlibnative/float/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ include_directories("../inc")
set(FLOAT_SOURCES
floatdouble.cpp
floatsingle.cpp
divmodint.cpp
)

add_library_clr(comfloat_wks OBJECT ${FLOAT_SOURCES})
Expand Down
60 changes: 60 additions & 0 deletions src/coreclr/classlibnative/float/divmodint.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#ifdef TARGET_32BIT

#include <common.h>

#include "divmodint.h"

#include <optsmallperfcritical.h>

FCIMPL2(int32_t, DivModInt::DivInt32, int32_t dividend, int32_t divisor)
FCALL_CONTRACT;

return dividend / divisor;
FCIMPLEND

FCIMPL2(uint32_t, DivModInt::DivUInt32, uint32_t dividend, uint32_t divisor)
FCALL_CONTRACT;

return dividend / divisor;
FCIMPLEND

FCIMPL2_VV(int64_t, DivModInt::DivInt64, int64_t dividend, int64_t divisor)
FCALL_CONTRACT;

return dividend / divisor;
FCIMPLEND

FCIMPL2_VV(uint64_t, DivModInt::DivUInt64, uint64_t dividend, uint64_t divisor)
FCALL_CONTRACT;

return dividend / divisor;
FCIMPLEND

FCIMPL2(int32_t, DivModInt::ModInt32, int32_t dividend, int32_t divisor)
FCALL_CONTRACT;

return dividend % divisor;
FCIMPLEND

FCIMPL2(uint32_t, DivModInt::ModUInt32, uint32_t dividend, uint32_t divisor)
FCALL_CONTRACT;

return dividend % divisor;
FCIMPLEND

FCIMPL2_VV(int64_t, DivModInt::ModInt64, int64_t dividend, int64_t divisor)
FCALL_CONTRACT;

return dividend % divisor;
FCIMPLEND

FCIMPL2_VV(uint64_t, DivModInt::ModUInt64, uint64_t dividend, uint64_t divisor)
FCALL_CONTRACT;

return dividend % divisor;
FCIMPLEND

#endif // TARGET_32BIT
22 changes: 22 additions & 0 deletions src/coreclr/classlibnative/inc/divmodint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#ifndef HAVE_DIVMODINT_H
#define HAVE_DIVMODINT_H

#include <object.h>
#include <fcall.h>

class DivModInt {
public:
FCDECL2(static int32_t, DivInt32, int32_t dividend, int32_t divisor);
FCDECL2(static uint32_t, DivUInt32, uint32_t dividend, uint32_t divisor);
FCDECL2_VV(static int64_t, DivInt64, int64_t dividend, int64_t divisor);
FCDECL2_VV(static uint64_t, DivUInt64, uint64_t dividend, uint64_t divisor);
FCDECL2(static int32_t, ModInt32, int32_t dividend, int32_t divisor);
FCDECL2(static uint32_t, ModUInt32, uint32_t dividend, uint32_t divisor);
FCDECL2_VV(static int64_t, ModInt64, int64_t dividend, int64_t divisor);
FCDECL2_VV(static uint64_t, ModUInt64, uint64_t dividend, uint64_t divisor);
};

#endif // HAVE_DIVMODINT_H
45 changes: 33 additions & 12 deletions src/coreclr/inc/jithelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,34 @@
#define DYNAMICJITHELPER_NOINDIRECT(code,fn,binderId) DYNAMICJITHELPER(code,fn,binderId)
#endif

#if defined(TARGET_32BIT) && defined (TARGET_ARM)
#define FEATURE_USE_HELPERS_FOR_32BIT_INT_DIV
#endif

// pfnHelper is set to NULL if it is a stubbed helper.
// It will be set in InitJITHelpers1

JITHELPER(CORINFO_HELP_UNDEF, NULL, METHOD__NIL)

// Arithmetic
JITHELPER(CORINFO_HELP_DIV, JIT_Div, METHOD__NIL)
JITHELPER(CORINFO_HELP_MOD, JIT_Mod, METHOD__NIL)
JITHELPER(CORINFO_HELP_UDIV, JIT_UDiv, METHOD__NIL)
JITHELPER(CORINFO_HELP_UMOD, JIT_UMod, METHOD__NIL)
#ifdef FEATURE_USE_HELPERS_FOR_32BIT_INT_DIV
DYNAMICJITHELPER(CORINFO_HELP_DIV, NULL, METHOD__MATH__DIV_INT32)
DYNAMICJITHELPER(CORINFO_HELP_MOD, NULL, METHOD__MATH__MOD_INT32)
DYNAMICJITHELPER(CORINFO_HELP_UDIV, NULL, METHOD__MATH__DIV_UINT32)
DYNAMICJITHELPER(CORINFO_HELP_UMOD, NULL, METHOD__MATH__MOD_UINT32)
#else
JITHELPER(CORINFO_HELP_DIV, NULL, METHOD__NIL)
JITHELPER(CORINFO_HELP_MOD, NULL, METHOD__NIL)
JITHELPER(CORINFO_HELP_UDIV, NULL, METHOD__NIL)
JITHELPER(CORINFO_HELP_UMOD, NULL, METHOD__NIL)
#endif

// CORINFO_HELP_DBL2INT, CORINFO_HELP_DBL2UINT, and CORINFO_HELP_DBL2LONG get
// patched for CPUs that support SSE2 (P4 and above).
#ifndef TARGET_64BIT
#ifdef TARGET_32BIT
JITHELPER(CORINFO_HELP_LLSH, JIT_LLsh, METHOD__NIL)
JITHELPER(CORINFO_HELP_LRSH, JIT_LRsh, METHOD__NIL)
JITHELPER(CORINFO_HELP_LRSZ, JIT_LRsz, METHOD__NIL)
#else // !TARGET_64BIT
#else // TARGET_32BIT

JITHELPER(CORINFO_HELP_LLSH, NULL, METHOD__NIL)
JITHELPER(CORINFO_HELP_LRSH, NULL, METHOD__NIL)
JITHELPER(CORINFO_HELP_LRSZ, NULL, METHOD__NIL)
Expand All @@ -55,14 +65,25 @@
#ifndef TARGET_64BIT
DYNAMICJITHELPER(CORINFO_HELP_LMUL_OVF, NULL, METHOD__MATH__MULTIPLY_CHECKED_INT64)
DYNAMICJITHELPER(CORINFO_HELP_ULMUL_OVF, NULL, METHOD__MATH__MULTIPLY_CHECKED_UINT64)
#else
DYNAMICJITHELPER(CORINFO_HELP_LMUL_OVF, NULL, METHOD__NIL)
DYNAMICJITHELPER(CORINFO_HELP_ULMUL_OVF, NULL, METHOD__NIL)
#endif // TARGET_64BIT
#if defined(TARGET_X86) && defined(TARGET_WINDOWS)
JITHELPER(CORINFO_HELP_LDIV, JIT_LDiv, METHOD__NIL)
JITHELPER(CORINFO_HELP_LMOD, JIT_LMod, METHOD__NIL)
JITHELPER(CORINFO_HELP_ULDIV, JIT_ULDiv, METHOD__NIL)
JITHELPER(CORINFO_HELP_ULMOD, JIT_ULMod, METHOD__NIL)
#else
DYNAMICJITHELPER(CORINFO_HELP_LDIV, NULL, METHOD__MATH__DIV_INT64)
DYNAMICJITHELPER(CORINFO_HELP_LMOD, NULL, METHOD__MATH__MOD_INT64)
DYNAMICJITHELPER(CORINFO_HELP_ULDIV, NULL, METHOD__MATH__DIV_UINT64)
DYNAMICJITHELPER(CORINFO_HELP_ULMOD, NULL, METHOD__MATH__MOD_UINT64)
#endif // TARGET_X86 && TARGET_WINDOWS
#else // TARGET_64BIT
JITHELPER(CORINFO_HELP_LMUL_OVF, NULL, METHOD__NIL)
JITHELPER(CORINFO_HELP_ULMUL_OVF, NULL, METHOD__NIL)
JITHELPER(CORINFO_HELP_LDIV, NULL, METHOD__NIL)
JITHELPER(CORINFO_HELP_LMOD, NULL, METHOD__NIL)
JITHELPER(CORINFO_HELP_ULDIV, NULL, METHOD__NIL)
JITHELPER(CORINFO_HELP_ULMOD, NULL, METHOD__NIL)
#endif // TARGET_64BIT
JITHELPER(CORINFO_HELP_LNG2DBL, JIT_Lng2Dbl, METHOD__NIL)
JITHELPER(CORINFO_HELP_ULNG2DBL, JIT_ULng2Dbl, METHOD__NIL)
JITHELPER(CORINFO_HELP_DBL2INT, JIT_Dbl2Int, METHOD__NIL)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/valuenum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14160,8 +14160,8 @@ bool Compiler::fgValueNumberHelperCall(GenTreeCall* call)
vnpExc = fgValueNumberDivisionExceptions(GT_DIV, call->gtArgs.GetUserArgByIndex(0)->GetNode(),
call->gtArgs.GetUserArgByIndex(1)->GetNode());
break;
case CORINFO_HELP_MOD:
case CORINFO_HELP_LMOD:
case CORINFO_HELP_MOD:
vnpExc = fgValueNumberDivisionExceptions(GT_MOD, call->gtArgs.GetUserArgByIndex(0)->GetNode(),
call->gtArgs.GetUserArgByIndex(1)->GetNode());
break;
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/nativeaot/Runtime/CommonMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ typedef uint8_t CODE_LOCATION;
FCIMPL_RENAME_ARGSIZE(_rettype, _method, 16) \
EXTERN_C _rettype F_CALL_CONV _method##_FCall (b, a) \
{
#define FCIMPL2_LL FCIMPL2_DD
#define FCIMPL2_FI(_rettype, _method, a, b) \
FCIMPL_RENAME_ARGSIZE(_rettype, _method, 8) \
EXTERN_C _rettype F_CALL_CONV _method##_FCall (a, b) \
Expand Down Expand Up @@ -249,6 +250,7 @@ typedef uint8_t CODE_LOCATION;
#define FCIMPL2_DD(_rettype, _method, a, b) \
EXTERN_C _rettype F_CALL_CONV _method (a, b) \
{
#define FCIMPL2_LL FCIMPL2_DD
#define FCIMPL2_FI(_rettype, _method, a, b) \
EXTERN_C _rettype F_CALL_CONV _method (a, b) \
{
Expand Down
20 changes: 12 additions & 8 deletions src/coreclr/nativeaot/Runtime/MathHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,33 @@ FCIMPL1_D(uint32_t, RhpDbl2UInt, double val)
FCIMPLEND

#ifndef HOST_64BIT
EXTERN_C int64_t QCALLTYPE RhpLDiv(int64_t i, int64_t j)
FCIMPL2_LL(int64_t, DivInt64Internal, int64_t i, int64_t j)
{
ASSERT(j && "Divide by zero!");
return i / j;
}
FCIMPLEND

EXTERN_C uint64_t QCALLTYPE RhpULDiv(uint64_t i, uint64_t j)
FCIMPL2_LL(uint64_t, DivUInt64Internal, uint64_t i, uint64_t j)
{
ASSERT(j && "Divide by zero!");
return i / j;
}
FCIMPLEND

EXTERN_C int64_t QCALLTYPE RhpLMod(int64_t i, int64_t j)
FCIMPL2_LL(int64_t, ModInt64Internal, int64_t i, int64_t j)
{
ASSERT(j && "Divide by zero!");
return i % j;
}
FCIMPLEND

EXTERN_C uint64_t QCALLTYPE RhpULMod(uint64_t i, uint64_t j)
FCIMPL2_LL(uint64_t, ModUInt64Internal, uint64_t i, uint64_t j)
{
ASSERT(j && "Divide by zero!");
return i % j;
}
FCIMPLEND

FCIMPL1_L(double, RhpLng2Dbl, int64_t val)
{
Expand All @@ -95,25 +99,25 @@ FCIMPLEND
#endif

#ifdef HOST_ARM
EXTERN_C int32_t F_CALL_CONV RhpIDiv(int32_t i, int32_t j)
EXTERN_C int32_t F_CALL_CONV DivInt32Internal(int32_t i, int32_t j)
{
ASSERT(j && "Divide by zero!");
return i / j;
}

EXTERN_C uint32_t F_CALL_CONV RhpUDiv(uint32_t i, uint32_t j)
EXTERN_C uint32_t F_CALL_CONV DivUInt32Internal(uint32_t i, uint32_t j)
{
ASSERT(j && "Divide by zero!");
return i / j;
}

EXTERN_C int32_t F_CALL_CONV RhpIMod(int32_t i, int32_t j)
EXTERN_C int32_t F_CALL_CONV ModInt32Internal(int32_t i, int32_t j)
{
ASSERT(j && "Divide by zero!");
return i % j;
}

EXTERN_C uint32_t F_CALL_CONV RhpUMod(uint32_t i, uint32_t j)
EXTERN_C uint32_t F_CALL_CONV ModUInt32Internal(uint32_t i, uint32_t j)
{
ASSERT(j && "Divide by zero!");
return i % j;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@
<Compile Include="Internal\Runtime\IDynamicInterfaceCastableSupport.cs" />
<Compile Include="Internal\Runtime\MethodTable.Runtime.cs" />
<Compile Include="Internal\Runtime\CompilerHelpers\ThrowHelpers.cs" />
<Compile Include="Internal\Runtime\CompilerHelpers\MathHelpers.cs" />
<Compile Include="Internal\Runtime\CompilerServices\FunctionPointerOps.cs" />
<Compile Include="Internal\Runtime\CompilerServices\GenericMethodDescriptor.cs" />
<Compile Include="Internal\Runtime\CompilerServices\MethodNameAndSignature.cs" />
Expand Down
Loading
Loading