Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 1 deletion src/coreclr/classlibnative/float/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ include_directories("../inc")
set(FLOAT_SOURCES
floatdouble.cpp
floatsingle.cpp
divmodint.cpp
)

add_library_clr(comfloat_wks OBJECT ${FLOAT_SOURCES})
Expand Down
60 changes: 0 additions & 60 deletions src/coreclr/classlibnative/float/divmodint.cpp

This file was deleted.

22 changes: 0 additions & 22 deletions src/coreclr/classlibnative/inc/divmodint.h

This file was deleted.

45 changes: 12 additions & 33 deletions src/coreclr/inc/jithelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,24 @@
#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
#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
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 TARGET_32BIT
// CORINFO_HELP_DBL2INT, CORINFO_HELP_DBL2UINT, and CORINFO_HELP_DBL2LONG get
// patched for CPUs that support SSE2 (P4 and above).
#ifndef TARGET_64BIT
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_32BIT

#else // !TARGET_64BIT
JITHELPER(CORINFO_HELP_LLSH, NULL, METHOD__NIL)
JITHELPER(CORINFO_HELP_LRSH, NULL, METHOD__NIL)
JITHELPER(CORINFO_HELP_LRSZ, NULL, METHOD__NIL)
Expand All @@ -65,25 +55,14 @@
#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)
#if defined(TARGET_X86) && defined(TARGET_WINDOWS)
#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)
#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_LMOD:
case CORINFO_HELP_MOD:
case CORINFO_HELP_LMOD:
vnpExc = fgValueNumberDivisionExceptions(GT_MOD, call->gtArgs.GetUserArgByIndex(0)->GetNode(),
call->gtArgs.GetUserArgByIndex(1)->GetNode());
break;
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/nativeaot/Runtime/CommonMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ 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 @@ -250,7 +249,6 @@ 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: 8 additions & 12 deletions src/coreclr/nativeaot/Runtime/MathHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,29 @@ FCIMPL1_D(uint32_t, RhpDbl2UInt, double val)
FCIMPLEND

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

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

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

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

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

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

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

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

EXTERN_C uint32_t F_CALL_CONV ModUInt32Internal(uint32_t i, uint32_t j)
EXTERN_C uint32_t F_CALL_CONV RhpUMod(uint32_t i, uint32_t j)
{
ASSERT(j && "Divide by zero!");
return i % j;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics;
using System.Runtime;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace Internal.Runtime.CompilerHelpers
{
/// <summary>
/// Math helpers for generated code. The helpers here are referenced by the runtime.
/// </summary>
[StackTraceHidden]
internal static partial class MathHelpers
{
#if !TARGET_64BIT
private const string RuntimeLibrary = "*";

[LibraryImport(RuntimeLibrary)]
[SuppressGCTransition]
private static partial ulong RhpULMod(ulong dividend, ulong divisor);

public static ulong ULMod(ulong dividend, ulong divisor)
{
if (divisor == 0)
ThrowHelper.ThrowDivideByZeroException();

return RhpULMod(dividend, divisor);
}

[LibraryImport(RuntimeLibrary)]
[SuppressGCTransition]
private static partial long RhpLMod(long dividend, long divisor);

public static long LMod(long dividend, long divisor)
{
if (divisor == 0)
ThrowHelper.ThrowDivideByZeroException();
if (divisor == -1 && dividend == long.MinValue)
ThrowHelper.ThrowOverflowException();

return RhpLMod(dividend, divisor);
}

[LibraryImport(RuntimeLibrary)]
[SuppressGCTransition]
private static partial ulong RhpULDiv(ulong dividend, ulong divisor);

public static ulong ULDiv(ulong dividend, ulong divisor)
{
if (divisor == 0)
ThrowHelper.ThrowDivideByZeroException();

return RhpULDiv(dividend, divisor);
}

[LibraryImport(RuntimeLibrary)]
[SuppressGCTransition]
private static partial long RhpLDiv(long dividend, long divisor);

public static long LDiv(long dividend, long divisor)
{
if (divisor == 0)
ThrowHelper.ThrowDivideByZeroException();
if (divisor == -1 && dividend == long.MinValue)
ThrowHelper.ThrowOverflowException();

return RhpLDiv(dividend, divisor);
}

#if TARGET_ARM
[RuntimeImport(RuntimeLibrary, "RhpIDiv")]
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern int RhpIDiv(int dividend, int divisor);

public static int IDiv(int dividend, int divisor)
{
if (divisor == 0)
ThrowHelper.ThrowDivideByZeroException();
if (divisor == -1 && dividend == int.MinValue)
ThrowHelper.ThrowOverflowException();

return RhpIDiv(dividend, divisor);
}

[RuntimeImport(RuntimeLibrary, "RhpUDiv")]
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern uint RhpUDiv(uint dividend, uint divisor);

public static long UDiv(uint dividend, uint divisor)
{
if (divisor == 0)
ThrowHelper.ThrowDivideByZeroException();

return RhpUDiv(dividend, divisor);
}

[RuntimeImport(RuntimeLibrary, "RhpIMod")]
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern int RhpIMod(int dividend, int divisor);

public static int IMod(int dividend, int divisor)
{
if (divisor == 0)
ThrowHelper.ThrowDivideByZeroException();
if (divisor == -1 && dividend == int.MinValue)
ThrowHelper.ThrowOverflowException();

return RhpIMod(dividend, divisor);
}

[RuntimeImport(RuntimeLibrary, "RhpUMod")]
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern uint RhpUMod(uint dividend, uint divisor);

public static long UMod(uint dividend, uint divisor)
{
if (divisor == 0)
ThrowHelper.ThrowDivideByZeroException();

return RhpUMod(dividend, divisor);
}
#endif // TARGET_ARM
#endif // TARGET_64BIT
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
<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