Skip to content
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

Move arithmetic helpers to managed code #109087

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a6746b5
Move arithmetic helpers to managed code
am11 Oct 22, 2024
2a86f4d
Convert to FCall
am11 Oct 24, 2024
804e052
Update macros and keep comments
am11 Oct 24, 2024
3203c73
Address CR feedback
am11 Oct 24, 2024
be3a9b5
Merge dotnet/main into feature/fcalls-cleanups
am11 Oct 24, 2024
715b56c
Rename native calls to use Internal as suffix
am11 Oct 24, 2024
0e61d9d
Merge branch 'main' into feature/fcalls-cleanups
am11 Oct 24, 2024
3f47a34
Merge branch 'main' into feature/fcalls-cleanups
am11 Nov 28, 2024
31f56f6
Update Math.DivModInt.cs
EgorBo Nov 28, 2024
960dae1
Replace CreateTruncating
am11 Nov 29, 2024
2f980a2
Update src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/JitHelper.cs
am11 Nov 29, 2024
dfc151d
Merge branch 'main' into feature/fcalls-cleanups
am11 Nov 29, 2024
40dba4f
Revert "Replace CreateTruncating"
am11 Nov 30, 2024
d80d214
Use AggressiveOptimization as well
am11 Nov 30, 2024
e5dcf0b
Remove signed 32 bit helpers and inline conditions
am11 Nov 30, 2024
82aaa96
Temporarily add AggressiveOptimization on 64b meths
am11 Nov 30, 2024
83b7e85
Merge branch 'main' into feature/fcalls-cleanups
am11 Nov 30, 2024
8cb5d4d
Apply suggestions from code review
am11 Dec 1, 2024
a9624bb
Remove redundant casts and align style
am11 Dec 1, 2024
2784ba0
Use idiomatic long.MinValue
am11 Dec 1, 2024
1cdbf4d
Avoid redundant checks in 64bit helpers
am11 Dec 1, 2024
5674bc0
actually just remove them..
am11 Dec 1, 2024
228bb42
Remove AggressiveOptimization
am11 Dec 1, 2024
dda3da9
Revert "actually just remove them.."
am11 Dec 1, 2024
544f178
Experiment: Try replacing fcalls with software helpers
am11 Dec 2, 2024
520cb53
Merge dotnet/main into feature/fcalls-cleanups
am11 Dec 2, 2024
e51389e
Reduce a bit
am11 Dec 2, 2024
48f8f1b
Revert "Experiment: Try replacing fcalls with software helpers"
am11 Dec 2, 2024
36e7387
Merge branch 'main' into feature/fcalls-cleanups
am11 Dec 2, 2024
6ad8b12
Merge dotnet/main into feature/fcalls-cleanups
am11 Dec 5, 2024
9dbcf4e
Experiment: Change FCThrow to COMPlusThrowf
am11 Dec 5, 2024
f0cd111
Revert "Experiment: Change FCThrow to COMPlusThrowf"
am11 Dec 5, 2024
22fdedd
Remove COM prefix
am11 Dec 12, 2024
ae86d4a
Merge dotnet/main into feature/fcalls-cleanups
am11 Dec 12, 2024
ed9193e
Update header guard to preferred naming convention
am11 Dec 12, 2024
4f1f475
Update Math.DivModInt.cs
am11 Jan 17, 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, COMDivModInt::DivInt32, int32_t dividend, int32_t divisor)
FCALL_CONTRACT;

return dividend / divisor;
FCIMPLEND

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

return dividend / divisor;
FCIMPLEND

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

return dividend / divisor;
FCIMPLEND

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

return dividend / divisor;
FCIMPLEND

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

return dividend % divisor;
FCIMPLEND

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

return dividend % divisor;
FCIMPLEND

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

return dividend % divisor;
FCIMPLEND

FCIMPL2_VV(uint64_t, COMDivModInt::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 _DIVMODINT_H_
#define _DIVMODINT_H_

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

class COMDivModInt {
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 // _DIVMODINT_H_
39 changes: 24 additions & 15 deletions src/coreclr/inc/jithelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,44 @@

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)

// 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
// Arithmetic
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)

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
DYNAMICJITHELPER(CORINFO_HELP_DIV, NULL, METHOD__NIL)
DYNAMICJITHELPER(CORINFO_HELP_MOD, NULL, METHOD__NIL)
DYNAMICJITHELPER(CORINFO_HELP_UDIV, NULL, METHOD__NIL)
DYNAMICJITHELPER(CORINFO_HELP_UMOD, NULL, METHOD__NIL)

JITHELPER(CORINFO_HELP_LLSH, NULL, METHOD__NIL)
JITHELPER(CORINFO_HELP_LRSH, NULL, METHOD__NIL)
JITHELPER(CORINFO_HELP_LRSZ, NULL, METHOD__NIL)
#endif // TARGET_64BIT
#endif // TARGET_32BIT
JITHELPER(CORINFO_HELP_LMUL, JIT_LMul, METHOD__NIL)
#ifndef TARGET_64BIT
#ifdef TARGET_32BIT
DYNAMICJITHELPER(CORINFO_HELP_LMUL_OVF, NULL, METHOD__MATH__MULTIPLY_CHECKED_INT64)
DYNAMICJITHELPER(CORINFO_HELP_ULMUL_OVF, NULL, METHOD__MATH__MULTIPLY_CHECKED_UINT64)
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)
#else
DYNAMICJITHELPER(CORINFO_HELP_LMUL_OVF, NULL, METHOD__NIL)
DYNAMICJITHELPER(CORINFO_HELP_ULMUL_OVF, NULL, METHOD__NIL)
#endif // TARGET_64BIT
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)
DYNAMICJITHELPER(CORINFO_HELP_LDIV, NULL, METHOD__NIL)
DYNAMICJITHELPER(CORINFO_HELP_LMOD, NULL, METHOD__NIL)
DYNAMICJITHELPER(CORINFO_HELP_ULDIV, NULL, METHOD__NIL)
DYNAMICJITHELPER(CORINFO_HELP_ULMOD, NULL, METHOD__NIL)
#endif // TARGET_32BIT
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ public static int OffsetToStringData

[Intrinsic]
public static extern void InitializeArray(Array array, RuntimeFieldHandle fldHandle);

public const string QCall = "*";
}
}
16 changes: 8 additions & 8 deletions src/coreclr/nativeaot/Runtime/MathHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,25 @@ FCIMPL1_D(uint32_t, RhpDbl2UInt, double val)
FCIMPLEND

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

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

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

EXTERN_C uint64_t QCALLTYPE RhpULMod(uint64_t i, uint64_t j)
EXTERN_C uint64_t QCALLTYPE InternalModUInt64(uint64_t i, uint64_t j)
{
ASSERT(j && "Divide by zero!");
return i % j;
Expand All @@ -95,25 +95,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 InternalDivInt32(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 InternalDivUInt32(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 InternalModInt32(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 InternalModUInt32(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\RuntimeFieldHandleInfo.cs" />
Expand Down
Loading
Loading