From b269447d7309850f0bfd1d24b0b960a54a025b9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Petryka?= Date: Fri, 23 Feb 2024 16:21:06 +0100 Subject: [PATCH] Simplify floating point mod and round math jit helpers --- .../src/System/Math.CoreCLR.cs | 4 - .../src/System/MathF.CoreCLR.cs | 4 - .../classlibnative/float/floatdouble.cpp | 9 -- .../classlibnative/float/floatsingle.cpp | 9 -- src/coreclr/classlibnative/inc/floatdouble.h | 1 - src/coreclr/classlibnative/inc/floatsingle.h | 1 - src/coreclr/inc/corinfo.h | 4 +- src/coreclr/inc/jithelpers.h | 6 +- src/coreclr/jit/gentree.cpp | 4 - src/coreclr/jit/importercalls.cpp | 6 - src/coreclr/jit/namedintrinsiclist.h | 1 - src/coreclr/jit/valuenum.cpp | 20 --- src/coreclr/jit/valuenumfuncs.h | 1 - src/coreclr/nativeaot/Runtime/MathHelpers.cpp | 67 ++------- .../src/System/Math.NativeAot.cs | 6 - .../src/System/MathF.NativeAot.cs | 6 - .../ILCompiler.Compiler/Compiler/JitHelper.cs | 4 +- .../IL/ILImporter.Scanner.cs | 13 +- src/coreclr/vm/corelib.h | 6 + src/coreclr/vm/ecall.cpp | 8 ++ src/coreclr/vm/ecalllist.h | 2 - src/coreclr/vm/jithelpers.cpp | 127 +----------------- src/coreclr/vm/jitinterface.cpp | 14 +- .../src/System/Math.Mono.cs | 3 - .../src/System/MathF.Mono.cs | 3 - src/mono/mono/metadata/icall-decl.h | 2 - src/mono/mono/metadata/icall-def.h | 2 - src/mono/mono/metadata/sysmath.c | 12 -- 28 files changed, 56 insertions(+), 289 deletions(-) diff --git a/src/coreclr/System.Private.CoreLib/src/System/Math.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Math.CoreCLR.cs index a619dc4b1ca79..5dd46b02d4231 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Math.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Math.CoreCLR.cs @@ -115,10 +115,6 @@ public static unsafe (double Sin, double Cos) SinCos(double x) [MethodImpl(MethodImplOptions.InternalCall)] public static extern double Tanh(double value); - [Intrinsic] - [MethodImpl(MethodImplOptions.InternalCall)] - private static extern double FMod(double x, double y); - [MethodImpl(MethodImplOptions.InternalCall)] private static extern unsafe double ModF(double x, double* intptr); diff --git a/src/coreclr/System.Private.CoreLib/src/System/MathF.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/MathF.CoreCLR.cs index 855a1b1e7ef15..e9caae4c18a38 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/MathF.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/MathF.CoreCLR.cs @@ -112,10 +112,6 @@ public static unsafe (float Sin, float Cos) SinCos(float x) [MethodImpl(MethodImplOptions.InternalCall)] public static extern float Tanh(float x); - [Intrinsic] - [MethodImpl(MethodImplOptions.InternalCall)] - private static extern float FMod(float x, float y); - [MethodImpl(MethodImplOptions.InternalCall)] private static extern unsafe float ModF(float x, float* intptr); diff --git a/src/coreclr/classlibnative/float/floatdouble.cpp b/src/coreclr/classlibnative/float/floatdouble.cpp index 3124a4b64d3da..7ecd6e375d632 100644 --- a/src/coreclr/classlibnative/float/floatdouble.cpp +++ b/src/coreclr/classlibnative/float/floatdouble.cpp @@ -181,15 +181,6 @@ FCIMPLEND #pragma float_control(pop) #endif -/*=====================================FMod===================================== -** -==============================================================================*/ -FCIMPL2_VV(double, COMDouble::FMod, double x, double y) - FCALL_CONTRACT; - - return fmod(x, y); -FCIMPLEND - /*=====================================FusedMultiplyAdd========================== ** ==============================================================================*/ diff --git a/src/coreclr/classlibnative/float/floatsingle.cpp b/src/coreclr/classlibnative/float/floatsingle.cpp index 0109aa2407989..5b7bdaa7c6136 100644 --- a/src/coreclr/classlibnative/float/floatsingle.cpp +++ b/src/coreclr/classlibnative/float/floatsingle.cpp @@ -156,15 +156,6 @@ FCIMPL1_V(float, COMSingle::Floor, float x) return floorf(x); FCIMPLEND -/*=====================================FMod===================================== -** -==============================================================================*/ -FCIMPL2_VV(float, COMSingle::FMod, float x, float y) - FCALL_CONTRACT; - - return fmodf(x, y); -FCIMPLEND - /*=====================================FusedMultiplyAdd========================== ** ==============================================================================*/ diff --git a/src/coreclr/classlibnative/inc/floatdouble.h b/src/coreclr/classlibnative/inc/floatdouble.h index 43fecbd47431f..ee257bf0d39d6 100644 --- a/src/coreclr/classlibnative/inc/floatdouble.h +++ b/src/coreclr/classlibnative/inc/floatdouble.h @@ -22,7 +22,6 @@ class COMDouble { FCDECL1_V(static double, Cosh, double x); FCDECL1_V(static double, Exp, double x); FCDECL1_V(static double, Floor, double x); - FCDECL2_VV(static double, FMod, double x, double y); FCDECL3_VVV(static double, FusedMultiplyAdd, double x, double y, double z); FCDECL1_V(static double, Log, double x); FCDECL1_V(static double, Log2, double x); diff --git a/src/coreclr/classlibnative/inc/floatsingle.h b/src/coreclr/classlibnative/inc/floatsingle.h index 765032ce6371e..76e236704d11f 100644 --- a/src/coreclr/classlibnative/inc/floatsingle.h +++ b/src/coreclr/classlibnative/inc/floatsingle.h @@ -22,7 +22,6 @@ class COMSingle { FCDECL1_V(static float, Cosh, float x); FCDECL1_V(static float, Exp, float x); FCDECL1_V(static float, Floor, float x); - FCDECL2_VV(static float, FMod, float x, float y); FCDECL3_VVV(static float, FusedMultiplyAdd, float x, float y, float z); FCDECL1_V(static float, Log, float x); FCDECL1_V(static float, Log2, float x); diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index 95df5192d353e..346feed74f324 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -397,8 +397,8 @@ enum CorInfoHelpFunc CORINFO_HELP_DBL2ULNG_OVF, CORINFO_HELP_FLTREM, CORINFO_HELP_DBLREM, - CORINFO_HELP_FLTROUND, - CORINFO_HELP_DBLROUND, + CORINFO_HELP_FLTROUND, // unused, remove once MINIMUM_READYTORUN_MAJOR_VERSION > 9 + CORINFO_HELP_DBLROUND, // unused, remove once MINIMUM_READYTORUN_MAJOR_VERSION > 9 /* Allocating a new object. Always use ICorClassInfo::getNewHelper() to decide which is the right helper to use to allocate an object of a given type. */ diff --git a/src/coreclr/inc/jithelpers.h b/src/coreclr/inc/jithelpers.h index a0982f3ac6520..746f02367f936 100644 --- a/src/coreclr/inc/jithelpers.h +++ b/src/coreclr/inc/jithelpers.h @@ -65,8 +65,8 @@ JITHELPER(CORINFO_HELP_DBL2ULNG_OVF, JIT_Dbl2ULngOvf, CORINFO_HELP_SIG_8_STACK) JITHELPER(CORINFO_HELP_FLTREM, JIT_FltRem, CORINFO_HELP_SIG_8_STACK) JITHELPER(CORINFO_HELP_DBLREM, JIT_DblRem, CORINFO_HELP_SIG_16_STACK) - JITHELPER(CORINFO_HELP_FLTROUND, JIT_FloatRound, CORINFO_HELP_SIG_8_STACK) - JITHELPER(CORINFO_HELP_DBLROUND, JIT_DoubleRound, CORINFO_HELP_SIG_16_STACK) + DYNAMICJITHELPER(CORINFO_HELP_FLTROUND, NULL, CORINFO_HELP_SIG_8_STACK) + DYNAMICJITHELPER(CORINFO_HELP_DBLROUND, NULL, CORINFO_HELP_SIG_16_STACK) // Allocating a new object JITHELPER(CORINFO_HELP_NEWFAST, JIT_New, CORINFO_HELP_SIG_REG_ONLY) @@ -203,7 +203,7 @@ JITHELPER(CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE, JIT_GetSharedNonGCThreadStaticBase, CORINFO_HELP_SIG_REG_ONLY) JITHELPER(CORINFO_HELP_GETSHARED_GCTHREADSTATIC_BASE_NOCTOR, JIT_GetSharedGCThreadStaticBase, CORINFO_HELP_SIG_REG_ONLY) JITHELPER(CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_NOCTOR, JIT_GetSharedNonGCThreadStaticBase, CORINFO_HELP_SIG_REG_ONLY) - JITHELPER(CORINFO_HELP_GETSHARED_GCTHREADSTATIC_BASE_DYNAMICCLASS, JIT_GetSharedGCThreadStaticBaseDynamicClass, CORINFO_HELP_SIG_REG_ONLY) + JITHELPER(CORINFO_HELP_GETSHARED_GCTHREADSTATIC_BASE_DYNAMICCLASS, JIT_GetSharedGCThreadStaticBaseDynamicClass, CORINFO_HELP_SIG_REG_ONLY) JITHELPER(CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_DYNAMICCLASS, JIT_GetSharedNonGCThreadStaticBaseDynamicClass, CORINFO_HELP_SIG_REG_ONLY) JITHELPER(CORINFO_HELP_GETSHARED_GCTHREADSTATIC_BASE_NOCTOR_OPTIMIZED, JIT_GetSharedGCThreadStaticBaseOptimized, CORINFO_HELP_SIG_REG_ONLY) JITHELPER(CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_NOCTOR_OPTIMIZED, JIT_GetSharedNonGCThreadStaticBaseOptimized, CORINFO_HELP_SIG_REG_ONLY) diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index a8374adbe0a22..66cd99af4ee1d 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -5627,7 +5627,6 @@ unsigned Compiler::gtSetEvalOrder(GenTree* tree) case NI_System_Math_Cosh: case NI_System_Math_Exp: case NI_System_Math_Floor: - case NI_System_Math_FMod: case NI_System_Math_FusedMultiplyAdd: case NI_System_Math_ILogB: case NI_System_Math_Log: @@ -12771,9 +12770,6 @@ void Compiler::gtDispTree(GenTree* tree, case NI_System_Math_Floor: printf(" floor"); break; - case NI_System_Math_FMod: - printf(" fmod"); - break; case NI_System_Math_FusedMultiplyAdd: printf(" fma"); break; diff --git a/src/coreclr/jit/importercalls.cpp b/src/coreclr/jit/importercalls.cpp index df2ed84809ea7..53f33c45a98c7 100644 --- a/src/coreclr/jit/importercalls.cpp +++ b/src/coreclr/jit/importercalls.cpp @@ -4033,7 +4033,6 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, case NI_System_Math_Cosh: case NI_System_Math_Exp: case NI_System_Math_Floor: - case NI_System_Math_FMod: case NI_System_Math_ILogB: case NI_System_Math_Log: case NI_System_Math_Log2: @@ -7369,7 +7368,6 @@ bool Compiler::IsMathIntrinsic(NamedIntrinsic intrinsicName) case NI_System_Math_Cosh: case NI_System_Math_Exp: case NI_System_Math_Floor: - case NI_System_Math_FMod: case NI_System_Math_FusedMultiplyAdd: case NI_System_Math_ILogB: case NI_System_Math_Log: @@ -10084,10 +10082,6 @@ NamedIntrinsic Compiler::lookupPrimitiveFloatNamedIntrinsic(CORINFO_METHOD_HANDL { result = NI_System_Math_Floor; } - else if (strcmp(methodName, "FMod") == 0) - { - result = NI_System_Math_FMod; - } else if (strcmp(methodName, "FusedMultiplyAdd") == 0) { result = NI_System_Math_FusedMultiplyAdd; diff --git a/src/coreclr/jit/namedintrinsiclist.h b/src/coreclr/jit/namedintrinsiclist.h index 9fa128c38f74e..b3eb292677d80 100644 --- a/src/coreclr/jit/namedintrinsiclist.h +++ b/src/coreclr/jit/namedintrinsiclist.h @@ -37,7 +37,6 @@ enum NamedIntrinsic : unsigned short NI_System_Math_Cosh, NI_System_Math_Exp, NI_System_Math_Floor, - NI_System_Math_FMod, NI_System_Math_FusedMultiplyAdd, NI_System_Math_ILogB, NI_System_Math_Log, diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index 28abf35f37e82..aff07842f36c8 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -8743,14 +8743,6 @@ ValueNum ValueNumStore::EvalMathFuncBinary(var_types typ, NamedIntrinsic gtMathF break; } - case NI_System_Math_FMod: - { - assert(typ == TypeOfVN(arg1VN)); - double arg1Val = GetConstantDouble(arg1VN); - res = fmod(arg0Val, arg1Val); - break; - } - case NI_System_Math_Pow: { assert(typ == TypeOfVN(arg1VN)); @@ -8848,14 +8840,6 @@ ValueNum ValueNumStore::EvalMathFuncBinary(var_types typ, NamedIntrinsic gtMathF break; } - case NI_System_Math_FMod: - { - assert(typ == TypeOfVN(arg1VN)); - float arg1Val = GetConstantSingle(arg1VN); - res = fmodf(arg0Val, arg1Val); - break; - } - case NI_System_Math_Max: { assert(typ == TypeOfVN(arg1VN)); @@ -8946,10 +8930,6 @@ ValueNum ValueNumStore::EvalMathFuncBinary(var_types typ, NamedIntrinsic gtMathF vnf = VNF_Atan2; break; - case NI_System_Math_FMod: - vnf = VNF_FMod; - break; - case NI_System_Math_Max: vnf = VNF_Max; break; diff --git a/src/coreclr/jit/valuenumfuncs.h b/src/coreclr/jit/valuenumfuncs.h index c259212dfe35b..128935847defd 100644 --- a/src/coreclr/jit/valuenumfuncs.h +++ b/src/coreclr/jit/valuenumfuncs.h @@ -83,7 +83,6 @@ ValueNumFuncDef(Cos, 1, false, false, false, false) ValueNumFuncDef(Cosh, 1, false, false, false, false) ValueNumFuncDef(Exp, 1, false, false, false, false) ValueNumFuncDef(Floor, 1, false, false, false, false) -ValueNumFuncDef(FMod, 2, false, false, false, false) ValueNumFuncDef(ILogB, 1, false, false, false, false) ValueNumFuncDef(Log, 1, false, false, false, false) ValueNumFuncDef(Log2, 1, false, false, false, false) diff --git a/src/coreclr/nativeaot/Runtime/MathHelpers.cpp b/src/coreclr/nativeaot/Runtime/MathHelpers.cpp index 9c4220ef5a7ee..b5c4a251c82ba 100644 --- a/src/coreclr/nativeaot/Runtime/MathHelpers.cpp +++ b/src/coreclr/nativeaot/Runtime/MathHelpers.cpp @@ -26,61 +26,6 @@ FCIMPL1_D(uint64_t, RhpDbl2ULng, double val) } FCIMPLEND -#undef min -#undef max -#include - -FCIMPL2_FF(float, RhpFltRem, float dividend, float divisor) -{ - // - // From the ECMA standard: - // - // If [divisor] is zero or [dividend] is infinity - // the result is NaN. - // If [divisor] is infinity, - // the result is [dividend] (negated for -infinity***). - // - // ***"negated for -infinity" has been removed from the spec - // - - if (divisor==0 || !std::isfinite(dividend)) - { - return -nanf(""); - } - else if (!std::isfinite(divisor) && !std::isnan(divisor)) - { - return dividend; - } - // else... - return fmodf(dividend,divisor); -} -FCIMPLEND - -FCIMPL2_DD(double, RhpDblRem, double dividend, double divisor) -{ - // - // From the ECMA standard: - // - // If [divisor] is zero or [dividend] is infinity - // the result is NaN. - // If [divisor] is infinity, - // the result is [dividend] (negated for -infinity***). - // - // ***"negated for -infinity" has been removed from the spec - // - if (divisor==0 || !std::isfinite(dividend)) - { - return -nan(""); - } - else if (!std::isfinite(divisor) && !std::isnan(divisor)) - { - return dividend; - } - // else... - return(fmod(dividend,divisor)); -} -FCIMPLEND - #ifndef HOST_64BIT EXTERN_C int64_t QCALLTYPE RhpLDiv(int64_t i, int64_t j) { @@ -187,6 +132,10 @@ EXTERN_C int64_t F_CALL_CONV RhpLLsh(int64_t i, int32_t j) #ifdef HOST_X86 +#undef min +#undef max +#include + FCIMPL1_D(double, acos, double x) return std::acos(x); FCIMPLEND @@ -363,6 +312,14 @@ FCIMPL1_F(float, tanhf, float x) return std::tanhf(x); FCIMPLEND +FCIMPL2_DD(double, fmod, double x, double y) + return std::fmod(x, y); +FCIMPLEND + +FCIMPL2_FF(float, fmodf, float x, float y) + return std::fmodf(x, y); +FCIMPLEND + FCIMPL3_DDD(double, fma, double x, double y, double z) return std::fma(x, y, z); FCIMPLEND diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Math.NativeAot.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Math.NativeAot.cs index 15b629dbee219..f5e6b88fbf271 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Math.NativeAot.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Math.NativeAot.cs @@ -154,12 +154,6 @@ public static double Tanh(double value) return RuntimeImports.tanh(value); } - [Intrinsic] - private static double FMod(double x, double y) - { - return RuntimeImports.fmod(x, y); - } - [Intrinsic] private static unsafe double ModF(double x, double* intptr) { diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/MathF.NativeAot.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/MathF.NativeAot.cs index 2f42ad90e94c3..3f430fba63148 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/MathF.NativeAot.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/MathF.NativeAot.cs @@ -154,12 +154,6 @@ public static float Tanh(float x) return RuntimeImports.tanhf(x); } - [Intrinsic] - private static float FMod(float x, float y) - { - return RuntimeImports.fmodf(x, y); - } - [Intrinsic] private static unsafe float ModF(float x, float* intptr) { diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/JitHelper.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/JitHelper.cs index cf1d04ca666af..8faf4cf3fcfe7 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/JitHelper.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/JitHelper.cs @@ -198,10 +198,10 @@ public static void GetEntryPoint(TypeSystemContext context, ReadyToRunHelper id, break; case ReadyToRunHelper.DblRem: - mangledName = "RhpDblRem"; + mangledName = "fmod"; break; case ReadyToRunHelper.FltRem: - mangledName = "RhpFltRem"; + mangledName = "fmodf"; break; case ReadyToRunHelper.LMul: diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs index 7ae867370bdf4..e048adcf9f4bd 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs @@ -1224,7 +1224,7 @@ private void ImportBinaryOperation(ILOpcode opcode) break; case ILOpcode.mul_ovf: case ILOpcode.mul_ovf_un: - if (_compilation.TypeSystemContext.Target.Architecture == TargetArchitecture.ARM) + if (_compilation.TypeSystemContext.Target.PointerSize == 4) { _dependencies.Add(GetHelperEntrypoint(ReadyToRunHelper.LMulOfv), "_lmulovf"); _dependencies.Add(GetHelperEntrypoint(ReadyToRunHelper.ULMulOvf), "_ulmulovf"); @@ -1244,6 +1244,10 @@ private void ImportBinaryOperation(ILOpcode opcode) else if (_compilation.TypeSystemContext.Target.Architecture == TargetArchitecture.ARM64) { _dependencies.Add(GetHelperEntrypoint(ReadyToRunHelper.ThrowDivZero), "_divbyzero"); + if (opcode == ILOpcode.div) + { + _dependencies.Add(GetHelperEntrypoint(ReadyToRunHelper.Overflow), "_ovf"); + } } break; case ILOpcode.rem: @@ -1258,7 +1262,14 @@ private void ImportBinaryOperation(ILOpcode opcode) else if (_compilation.TypeSystemContext.Target.Architecture == TargetArchitecture.ARM64) { _dependencies.Add(GetHelperEntrypoint(ReadyToRunHelper.ThrowDivZero), "_divbyzero"); + if (opcode == ILOpcode.rem) + { + _dependencies.Add(GetHelperEntrypoint(ReadyToRunHelper.Overflow), "_ovf"); + } } + + _dependencies.Add(GetHelperEntrypoint(ReadyToRunHelper.DblRem), "rem"); + _dependencies.Add(GetHelperEntrypoint(ReadyToRunHelper.FltRem), "rem"); break; } } diff --git a/src/coreclr/vm/corelib.h b/src/coreclr/vm/corelib.h index da3b7b6bfe57a..a119814b0189d 100644 --- a/src/coreclr/vm/corelib.h +++ b/src/coreclr/vm/corelib.h @@ -262,6 +262,12 @@ DEFINE_METHOD(DELEGATE, GET_INVOKE_METHOD, GetInvokeMethod, DEFINE_CLASS(INT128, System, Int128) DEFINE_CLASS(UINT128, System, UInt128) +DEFINE_CLASS(MATH, System, Math) +DEFINE_METHOD(MATH, ROUND, Round, SM_Dbl_RetDbl) + +DEFINE_CLASS(MATHF, System, MathF) +DEFINE_METHOD(MATHF, ROUND, Round, SM_Flt_RetFlt) + DEFINE_CLASS(DYNAMICMETHOD, ReflectionEmit, DynamicMethod) DEFINE_CLASS(DYNAMICRESOLVER, ReflectionEmit, DynamicResolver) diff --git a/src/coreclr/vm/ecall.cpp b/src/coreclr/vm/ecall.cpp index 7a9538d8ea7dd..74cab901277c7 100644 --- a/src/coreclr/vm/ecall.cpp +++ b/src/coreclr/vm/ecall.cpp @@ -156,6 +156,14 @@ void ECall::PopulateManagedHelpers() pMD = CoreLibBinder::GetMethod((BinderMethodID)(METHOD__SPAN_HELPERS__MEMCOPY)); pDest = pMD->GetMultiCallableAddrOfCode(); SetJitHelperFunction(CORINFO_HELP_MEMCPY, pDest); + + pMD = CoreLibBinder::GetMethod((BinderMethodID)(METHOD__MATH__ROUND)); + pDest = pMD->GetMultiCallableAddrOfCode(); + SetJitHelperFunction(CORINFO_HELP_DBLROUND, pDest); + + pMD = CoreLibBinder::GetMethod((BinderMethodID)(METHOD__MATHF__ROUND)); + pDest = pMD->GetMultiCallableAddrOfCode(); + SetJitHelperFunction(CORINFO_HELP_FLTROUND, pDest); } static CrstStatic gFCallLock; diff --git a/src/coreclr/vm/ecalllist.h b/src/coreclr/vm/ecalllist.h index 0fe7f4b1479ca..fa4f8cb485687 100644 --- a/src/coreclr/vm/ecalllist.h +++ b/src/coreclr/vm/ecalllist.h @@ -278,7 +278,6 @@ FCFuncStart(gMathFuncs) FCFuncElement("Cosh", COMDouble::Cosh) FCFuncElement("Exp", COMDouble::Exp) FCFuncElement("Floor", COMDouble::Floor) - FCFuncElement("FMod", COMDouble::FMod) FCFuncElement("FusedMultiplyAdd", COMDouble::FusedMultiplyAdd) FCFuncElement("Log", COMDouble::Log) FCFuncElement("Log2", COMDouble::Log2) @@ -307,7 +306,6 @@ FCFuncStart(gMathFFuncs) FCFuncElement("Cosh", COMSingle::Cosh) FCFuncElement("Exp", COMSingle::Exp) FCFuncElement("Floor", COMSingle::Floor) - FCFuncElement("FMod", COMSingle::FMod) FCFuncElement("FusedMultiplyAdd", COMSingle::FusedMultiplyAdd) FCFuncElement("Log", COMSingle::Log) FCFuncElement("Log2", COMSingle::Log2) diff --git a/src/coreclr/vm/jithelpers.cpp b/src/coreclr/vm/jithelpers.cpp index 1da0211496029..2c77b3c4d0d34 100644 --- a/src/coreclr/vm/jithelpers.cpp +++ b/src/coreclr/vm/jithelpers.cpp @@ -510,57 +510,6 @@ HCIMPL1_V(double, JIT_Lng2Dbl, INT64 val) } HCIMPLEND -//-------------------------------------------------------------------------- -template -ftype modftype(ftype value, ftype *iptr); -template <> float modftype(float value, float *iptr) { return modff(value, iptr); } -template <> double modftype(double value, double *iptr) { return modf(value, iptr); } - -// round to nearest, round to even if tied -template -ftype BankersRound(ftype value) -{ - if (value < 0.0) return -BankersRound (-value); - - ftype integerPart; - modftype( value, &integerPart ); - - // if decimal part is exactly .5 - if ((value -(integerPart +0.5)) == 0.0) - { - // round to even - if (fmod(ftype(integerPart), ftype(2.0)) == 0.0) - return integerPart; - - // Else return the nearest even integer - return (ftype)copysign(ceil(fabs(value+0.5)), - value); - } - - // Otherwise round to closest - return (ftype)copysign(floor(fabs(value)+0.5), - value); -} - - -/*********************************************************************/ -// round double to nearest int (as double) -HCIMPL1_V(double, JIT_DoubleRound, double val) -{ - FCALL_CONTRACT; - return BankersRound(val); -} -HCIMPLEND - -/*********************************************************************/ -// round float to nearest int (as float) -HCIMPL1_V(float, JIT_FloatRound, float val) -{ - FCALL_CONTRACT; - return BankersRound(val); -} -HCIMPLEND - /*********************************************************************/ // Call fast Dbl2Lng conversion - used by functions below FORCEINLINE INT64 FastDbl2Lng(double val) @@ -674,63 +623,11 @@ HCIMPL1_V(INT64, JIT_Dbl2LngOvf, double val) } HCIMPLEND -#ifndef TARGET_WINDOWS -namespace -{ - bool isnan(float val) - { - UINT32 bits = *reinterpret_cast(&val); - return (bits & 0x7FFFFFFFU) > 0x7F800000U; - } - bool isnan(double val) - { - UINT64 bits = *reinterpret_cast(&val); - return (bits & 0x7FFFFFFFFFFFFFFFULL) > 0x7FF0000000000000ULL; - } - bool isfinite(float val) - { - UINT32 bits = *reinterpret_cast(&val); - return (~bits & 0x7F800000U) != 0; - } - bool isfinite(double val) - { - UINT64 bits = *reinterpret_cast(&val); - return (~bits & 0x7FF0000000000000ULL) != 0; - } -} -#endif - HCIMPL2_VV(float, JIT_FltRem, float dividend, float divisor) { FCALL_CONTRACT; - // - // From the ECMA standard: - // - // If [divisor] is zero or [dividend] is infinity - // the result is NaN. - // If [divisor] is infinity, - // the result is [dividend] (negated for -infinity***). - // - // ***"negated for -infinity" has been removed from the spec - // - - if (divisor==0 || !isfinite(dividend)) - { - UINT32 NaN = CLR_NAN_32; - return *(float *)(&NaN); - } - else if (!isfinite(divisor) && !isnan(divisor)) - { - return dividend; - } - // else... -#if 0 - // COMPILER BUG WITH FMODF() + /Oi, USE FMOD() INSTEAD - return fmodf(dividend,divisor); -#else - return (float)fmod((double)dividend,(double)divisor); -#endif + return fmodf(dividend, divisor); } HCIMPLEND @@ -738,27 +635,7 @@ HCIMPL2_VV(double, JIT_DblRem, double dividend, double divisor) { FCALL_CONTRACT; - // - // From the ECMA standard: - // - // If [divisor] is zero or [dividend] is infinity - // the result is NaN. - // If [divisor] is infinity, - // the result is [dividend] (negated for -infinity***). - // - // ***"negated for -infinity" has been removed from the spec - // - if (divisor==0 || !isfinite(dividend)) - { - UINT64 NaN = CLR_NAN_64; - return *(double *)(&NaN); - } - else if (!isfinite(divisor) && !isnan(divisor)) - { - return dividend; - } - // else... - return(fmod(dividend,divisor)); + return fmod(dividend, divisor); } HCIMPLEND diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index b5b8ec66d2d61..801fe4b614cd4 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -10677,7 +10677,8 @@ void* CEEJitInfo::getHelperFtn(CorInfoHelpFunc ftnNum, /* IN */ { _ASSERTE(ppIndirection != NULL); *ppIndirection = &hlpDynamicFuncTable[dynamicFtnNum].pfnHelper; - return NULL; + result = NULL; + goto exit; } #endif @@ -10686,7 +10687,8 @@ void* CEEJitInfo::getHelperFtn(CorInfoHelpFunc ftnNum, /* IN */ LPVOID finalTierAddr = hlpFinalTierAddrTable[dynamicFtnNum]; if (finalTierAddr != NULL) { - return finalTierAddr; + result = finalTierAddr; + goto exit; } if (dynamicFtnNum == DYNAMIC_CORINFO_HELP_ISINSTANCEOFINTERFACE || @@ -10737,13 +10739,15 @@ void* CEEJitInfo::getHelperFtn(CorInfoHelpFunc ftnNum, /* IN */ { // Cache it for future uses to avoid taking the lock again. hlpFinalTierAddrTable[dynamicFtnNum] = finalTierAddr; - return finalTierAddr; + result = finalTierAddr; + goto exit; } } } *ppIndirection = ((FixupPrecode*)pPrecode)->GetTargetSlot(); - return NULL; + result = NULL; + goto exit; } pfnHelper = hlpDynamicFuncTable[dynamicFtnNum].pfnHelper; @@ -10757,8 +10761,8 @@ void* CEEJitInfo::getHelperFtn(CorInfoHelpFunc ftnNum, /* IN */ result = (LPVOID)GetEEFuncEntryPoint(pfnHelper); +exit: ; EE_TO_JIT_TRANSITION_LEAF(); - return result; } diff --git a/src/mono/System.Private.CoreLib/src/System/Math.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Math.Mono.cs index eb0024f983e64..c7f86a48b9946 100644 --- a/src/mono/System.Private.CoreLib/src/System/Math.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Math.Mono.cs @@ -79,9 +79,6 @@ public partial class Math [MethodImpl(MethodImplOptions.InternalCall)] public static extern double Log2(double x); - [MethodImpl(MethodImplOptions.InternalCall)] - private static extern double FMod(double x, double y); - [MethodImpl(MethodImplOptions.InternalCall)] private static extern unsafe double ModF(double x, double* intptr); } diff --git a/src/mono/System.Private.CoreLib/src/System/MathF.Mono.cs b/src/mono/System.Private.CoreLib/src/System/MathF.Mono.cs index 4fd4dc614458b..6789856acae45 100644 --- a/src/mono/System.Private.CoreLib/src/System/MathF.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/MathF.Mono.cs @@ -79,9 +79,6 @@ public partial class MathF [MethodImpl(MethodImplOptions.InternalCall)] public static extern float Log2(float x); - [MethodImpl(MethodImplOptions.InternalCall)] - private static extern float FMod(float x, float y); - [MethodImpl(MethodImplOptions.InternalCall)] private static extern unsafe float ModF(float x, float* intptr); } diff --git a/src/mono/mono/metadata/icall-decl.h b/src/mono/mono/metadata/icall-decl.h index 240ff111af0a4..ebce337af7b1a 100644 --- a/src/mono/mono/metadata/icall-decl.h +++ b/src/mono/mono/metadata/icall-decl.h @@ -80,7 +80,6 @@ ICALL_EXPORT double ves_icall_System_Math_Ceiling (double); ICALL_EXPORT double ves_icall_System_Math_Cos (double); ICALL_EXPORT double ves_icall_System_Math_Cosh (double); ICALL_EXPORT double ves_icall_System_Math_Exp (double); -ICALL_EXPORT double ves_icall_System_Math_FMod (double, double); ICALL_EXPORT double ves_icall_System_Math_Floor (double); ICALL_EXPORT double ves_icall_System_Math_Log (double); ICALL_EXPORT double ves_icall_System_Math_Log10 (double); @@ -104,7 +103,6 @@ ICALL_EXPORT float ves_icall_System_MathF_Ceiling (float); ICALL_EXPORT float ves_icall_System_MathF_Cos (float); ICALL_EXPORT float ves_icall_System_MathF_Cosh (float); ICALL_EXPORT float ves_icall_System_MathF_Exp (float); -ICALL_EXPORT float ves_icall_System_MathF_FMod (float, float); ICALL_EXPORT float ves_icall_System_MathF_Floor (float); ICALL_EXPORT float ves_icall_System_MathF_Log (float); ICALL_EXPORT float ves_icall_System_MathF_Log10 (float); diff --git a/src/mono/mono/metadata/icall-def.h b/src/mono/mono/metadata/icall-def.h index ea62127f66b75..84bb3df63a8cd 100644 --- a/src/mono/mono/metadata/icall-def.h +++ b/src/mono/mono/metadata/icall-def.h @@ -243,7 +243,6 @@ NOHANDLES_FLAGS(ICALL(MATH_21, "Ceiling", ves_icall_System_Math_Ceiling), MONO_I NOHANDLES_FLAGS(ICALL(MATH_5, "Cos", ves_icall_System_Math_Cos), MONO_ICALL_FLAGS_NO_EXCEPTION) NOHANDLES_FLAGS(ICALL(MATH_6, "Cosh", ves_icall_System_Math_Cosh), MONO_ICALL_FLAGS_NO_EXCEPTION) NOHANDLES_FLAGS(ICALL(MATH_7, "Exp", ves_icall_System_Math_Exp), MONO_ICALL_FLAGS_NO_EXCEPTION) -NOHANDLES_FLAGS(ICALL(MATH_7a, "FMod", ves_icall_System_Math_FMod), MONO_ICALL_FLAGS_NO_EXCEPTION) NOHANDLES_FLAGS(ICALL(MATH_8, "Floor", ves_icall_System_Math_Floor), MONO_ICALL_FLAGS_NO_EXCEPTION) NOHANDLES_FLAGS(ICALL(MATH_22, "FusedMultiplyAdd", ves_icall_System_Math_FusedMultiplyAdd), MONO_ICALL_FLAGS_NO_EXCEPTION) NOHANDLES_FLAGS(ICALL(MATH_9, "Log", ves_icall_System_Math_Log), MONO_ICALL_FLAGS_NO_EXCEPTION) @@ -271,7 +270,6 @@ NOHANDLES_FLAGS(ICALL(MATHF_9, "Ceiling", ves_icall_System_MathF_Ceiling), MONO_ NOHANDLES_FLAGS(ICALL(MATHF_10, "Cos", ves_icall_System_MathF_Cos), MONO_ICALL_FLAGS_NO_EXCEPTION) NOHANDLES_FLAGS(ICALL(MATHF_11, "Cosh", ves_icall_System_MathF_Cosh), MONO_ICALL_FLAGS_NO_EXCEPTION) NOHANDLES_FLAGS(ICALL(MATHF_12, "Exp", ves_icall_System_MathF_Exp), MONO_ICALL_FLAGS_NO_EXCEPTION) -NOHANDLES_FLAGS(ICALL(MATHF_22, "FMod", ves_icall_System_MathF_FMod), MONO_ICALL_FLAGS_NO_EXCEPTION) NOHANDLES_FLAGS(ICALL(MATHF_13, "Floor", ves_icall_System_MathF_Floor), MONO_ICALL_FLAGS_NO_EXCEPTION) NOHANDLES_FLAGS(ICALL(MATHF_24, "FusedMultiplyAdd", ves_icall_System_MathF_FusedMultiplyAdd), MONO_ICALL_FLAGS_NO_EXCEPTION) NOHANDLES_FLAGS(ICALL(MATHF_14, "Log", ves_icall_System_MathF_Log), MONO_ICALL_FLAGS_NO_EXCEPTION) diff --git a/src/mono/mono/metadata/sysmath.c b/src/mono/mono/metadata/sysmath.c index b7c6006da692c..afcbf447ad721 100644 --- a/src/mono/mono/metadata/sysmath.c +++ b/src/mono/mono/metadata/sysmath.c @@ -43,12 +43,6 @@ ves_icall_System_Math_Round (gdouble x) return mono_round_to_even (x); } -gdouble -ves_icall_System_Math_FMod (gdouble x, gdouble y) -{ - return fmod (x, y); -} - gdouble ves_icall_System_Math_ModF (gdouble x, gdouble *d) { @@ -313,12 +307,6 @@ ves_icall_System_MathF_Tanh (float x) return tanhf (x); } -float -ves_icall_System_MathF_FMod (float x, float y) -{ - return fmodf (x, y); -} - float ves_icall_System_MathF_ModF (float x, float *d) {