From 386435e1031fdfb7e0824e5911b95013509f5d0a Mon Sep 17 00:00:00 2001 From: Adeel <3840695+am11@users.noreply.github.com> Date: Mon, 17 Jan 2022 05:46:57 +0200 Subject: [PATCH 1/4] Add managed implementation of Math/MathF.Abs --- .../src/System/Math.CoreCLR.cs | 8 ------ .../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/System/Math.CoreRT.cs | 12 -------- .../src/System/Runtime/RuntimeImports.cs | 12 -------- src/coreclr/vm/ecalllist.h | 2 -- .../System.Private.CoreLib/src/System/Math.cs | 28 +++++++++++++++++-- .../src/System/Math.Mono.cs | 6 ---- src/mono/mono/metadata/icall-decl.h | 2 -- src/mono/mono/metadata/icall-def-netcore.h | 4 +-- src/mono/mono/metadata/sysmath.c | 12 -------- src/mono/mono/mini/interp/interp.c | 2 -- src/mono/mono/mini/interp/mintops.def | 2 -- src/mono/mono/mini/interp/transform.c | 6 ++-- 16 files changed, 29 insertions(+), 87 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 c86aa1b2e62bfe..a619dc4b1ca795 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Math.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Math.CoreCLR.cs @@ -16,14 +16,6 @@ namespace System { public static partial class Math { - [Intrinsic] - [MethodImpl(MethodImplOptions.InternalCall)] - public static extern double Abs(double value); - - [Intrinsic] - [MethodImpl(MethodImplOptions.InternalCall)] - public static extern float Abs(float value); - [Intrinsic] [MethodImpl(MethodImplOptions.InternalCall)] public static extern double Acos(double d); diff --git a/src/coreclr/classlibnative/float/floatdouble.cpp b/src/coreclr/classlibnative/float/floatdouble.cpp index 67aceb60ea13e6..d20b772eb2207c 100644 --- a/src/coreclr/classlibnative/float/floatdouble.cpp +++ b/src/coreclr/classlibnative/float/floatdouble.cpp @@ -42,15 +42,6 @@ #pragma float_control(precise, off) #endif -/*=====================================Abs====================================== -** -==============================================================================*/ -FCIMPL1_V(double, COMDouble::Abs, double x) - FCALL_CONTRACT; - - return fabs(x); -FCIMPLEND - /*=====================================Acos===================================== ** ==============================================================================*/ diff --git a/src/coreclr/classlibnative/float/floatsingle.cpp b/src/coreclr/classlibnative/float/floatsingle.cpp index 965998fbaa2ba3..ae7fc2f8c0902e 100644 --- a/src/coreclr/classlibnative/float/floatsingle.cpp +++ b/src/coreclr/classlibnative/float/floatsingle.cpp @@ -40,15 +40,6 @@ #pragma float_control(precise, off) #endif -/*=====================================Abs===================================== -** -==============================================================================*/ -FCIMPL1_V(float, COMSingle::Abs, float x) - FCALL_CONTRACT; - - return fabsf(x); -FCIMPLEND - /*=====================================Acos===================================== ** ==============================================================================*/ diff --git a/src/coreclr/classlibnative/inc/floatdouble.h b/src/coreclr/classlibnative/inc/floatdouble.h index 9163349127ca14..43fecbd47431f3 100644 --- a/src/coreclr/classlibnative/inc/floatdouble.h +++ b/src/coreclr/classlibnative/inc/floatdouble.h @@ -9,7 +9,6 @@ class COMDouble { public: - FCDECL1_V(static double, Abs, double x); FCDECL1_V(static double, Acos, double x); FCDECL1_V(static double, Acosh, double x); FCDECL1_V(static double, Asin, double x); diff --git a/src/coreclr/classlibnative/inc/floatsingle.h b/src/coreclr/classlibnative/inc/floatsingle.h index 09a0512b230dbd..765032ce6371e4 100644 --- a/src/coreclr/classlibnative/inc/floatsingle.h +++ b/src/coreclr/classlibnative/inc/floatsingle.h @@ -9,7 +9,6 @@ class COMSingle { public: - FCDECL1_V(static float, Abs, float x); FCDECL1_V(static float, Acos, float x); FCDECL1_V(static float, Acosh, float x); FCDECL1_V(static float, Asin, float x); diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Math.CoreRT.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Math.CoreRT.cs index 8a53e1588b83d2..15b629dbee219f 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Math.CoreRT.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Math.CoreRT.cs @@ -16,18 +16,6 @@ namespace System { public static partial class Math { - [Intrinsic] - public static float Abs(float value) - { - return RuntimeImports.fabsf(value); - } - - [Intrinsic] - public static double Abs(double value) - { - return RuntimeImports.fabs(value); - } - [Intrinsic] public static double Acos(double d) { diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs index 304f7073e7ec3c..a7edbf10d819af 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs @@ -679,18 +679,6 @@ internal struct ConservativelyReportedRegionDesc [RuntimeImport(RuntimeLibrary, "RhpMemoryBarrier")] internal static extern void MemoryBarrier(); - [Intrinsic] - [MethodImplAttribute(MethodImplOptions.InternalCall)] - [RuntimeImport(RuntimeLibrary, "fabs")] - internal static extern double fabs(double x); - - [Intrinsic] - internal static float fabsf(float x) - { - // fabsf is not a real export for some architectures - return (float)fabs(x); - } - [Intrinsic] [MethodImplAttribute(MethodImplOptions.InternalCall)] [RuntimeImport(RuntimeLibrary, "acos")] diff --git a/src/coreclr/vm/ecalllist.h b/src/coreclr/vm/ecalllist.h index be7a6826854f0e..f3ada145b68395 100644 --- a/src/coreclr/vm/ecalllist.h +++ b/src/coreclr/vm/ecalllist.h @@ -322,8 +322,6 @@ FCFuncStart(gDelegateFuncs) FCFuncEnd() FCFuncStart(gMathFuncs) - FCFuncElementSig("Abs", &gsig_SM_Dbl_RetDbl, COMDouble::Abs) - FCFuncElementSig("Abs", &gsig_SM_Flt_RetFlt, COMSingle::Abs) FCFuncElement("Acos", COMDouble::Acos) FCFuncElement("Acosh", COMDouble::Acosh) FCFuncElement("Asin", COMDouble::Asin) diff --git a/src/libraries/System.Private.CoreLib/src/System/Math.cs b/src/libraries/System.Private.CoreLib/src/System/Math.cs index f242b825fb1708..2ef37d8e6eba9f 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Math.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Math.cs @@ -49,9 +49,9 @@ public static partial class Math private const double SCALEB_C3 = 9007199254740992; // 0x1p53 - private const int ILogB_NaN = 0x7fffffff; + private const int ILogB_NaN = 0x7FFFFFFF; - private const int ILogB_Zero = (-1 - 0x7fffffff); + private const int ILogB_Zero = (-1 - 0x7FFFFFFF); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static short Abs(short value) @@ -133,6 +133,30 @@ public static decimal Abs(decimal value) return decimal.Abs(value); } + [Intrinsic] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static double Abs(double value) + { + // Implementation based on https://git.musl-libc.org/cgit/musl/tree/src/math/fabs.c + + const ulong signMask = 0x7FFFFFFFFFFFFFFF; + ulong raw = BitConverter.DoubleToUInt64Bits(value); + + return BitConverter.UInt64BitsToDouble(raw & signMask); + } + + [Intrinsic] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static float Abs(float value) + { + // Implementation based on https://git.musl-libc.org/cgit/musl/tree/src/math/fabsf.c + + const uint signMask = 0x7FFFFFFF; + uint raw = BitConverter.SingleToUInt32Bits(value); + + return BitConverter.UInt32BitsToSingle(raw & signMask); + } + [DoesNotReturn] [StackTraceHidden] private static void ThrowAbsOverflow() 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 b2bf6baadd57c6..eb0024f983e64b 100644 --- a/src/mono/System.Private.CoreLib/src/System/Math.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Math.Mono.cs @@ -7,12 +7,6 @@ namespace System { public partial class Math { - [MethodImpl(MethodImplOptions.InternalCall)] - public static extern double Abs(double value); - - [MethodImpl(MethodImplOptions.InternalCall)] - public static extern float Abs(float value); - [MethodImpl(MethodImplOptions.InternalCall)] public static extern double Acos(double d); diff --git a/src/mono/mono/metadata/icall-decl.h b/src/mono/mono/metadata/icall-decl.h index d99cf1cee6c329..5b75710e6456ad 100644 --- a/src/mono/mono/metadata/icall-decl.h +++ b/src/mono/mono/metadata/icall-decl.h @@ -68,7 +68,6 @@ ICALL_EXPORT void ves_icall_System_ArgIterator_Setup (MonoArgIterator*, char*, c ICALL_EXPORT MonoType* ves_icall_System_ArgIterator_IntGetNextArgType (MonoArgIterator*); ICALL_EXPORT void ves_icall_System_ArgIterator_IntGetNextArg (MonoArgIterator*, MonoTypedRef*); ICALL_EXPORT void ves_icall_System_ArgIterator_IntGetNextArgWithType (MonoArgIterator*, MonoTypedRef*, MonoType*); -ICALL_EXPORT double ves_icall_System_Math_Abs_double (double); ICALL_EXPORT double ves_icall_System_Math_Acos (double); ICALL_EXPORT double ves_icall_System_Math_Acosh (double); ICALL_EXPORT double ves_icall_System_Math_Asin (double); @@ -116,7 +115,6 @@ ICALL_EXPORT float ves_icall_System_MathF_Sinh (float); ICALL_EXPORT float ves_icall_System_MathF_Sqrt (float); ICALL_EXPORT float ves_icall_System_MathF_Tan (float); ICALL_EXPORT float ves_icall_System_MathF_Tanh (float); -ICALL_EXPORT float ves_icall_System_Math_Abs_single (float); ICALL_EXPORT double ves_icall_System_Math_Log2 (double); ICALL_EXPORT double ves_icall_System_Math_FusedMultiplyAdd (double, double, double); ICALL_EXPORT float ves_icall_System_MathF_Log2 (float); diff --git a/src/mono/mono/metadata/icall-def-netcore.h b/src/mono/mono/metadata/icall-def-netcore.h index 3dde98a274d3d6..45c65207a08497 100644 --- a/src/mono/mono/metadata/icall-def-netcore.h +++ b/src/mono/mono/metadata/icall-def-netcore.h @@ -108,9 +108,7 @@ ICALL_TYPE(STREAM, "System.IO.Stream", STREAM_1) HANDLES(STREAM_1, "HasOverriddenBeginEndRead", ves_icall_System_IO_Stream_HasOverriddenBeginEndRead, MonoBoolean, 1, (MonoObject)) HANDLES(STREAM_2, "HasOverriddenBeginEndWrite", ves_icall_System_IO_Stream_HasOverriddenBeginEndWrite, MonoBoolean, 1, (MonoObject)) -ICALL_TYPE(MATH, "System.Math", MATH_19) -NOHANDLES(ICALL(MATH_19, "Abs(double)", ves_icall_System_Math_Abs_double)) -NOHANDLES(ICALL(MATH_20, "Abs(single)", ves_icall_System_Math_Abs_single)) +ICALL_TYPE(MATH, "System.Math", MATH_1) NOHANDLES(ICALL(MATH_1, "Acos", ves_icall_System_Math_Acos)) NOHANDLES(ICALL(MATH_1a, "Acosh", ves_icall_System_Math_Acosh)) NOHANDLES(ICALL(MATH_2, "Asin", ves_icall_System_Math_Asin)) diff --git a/src/mono/mono/metadata/sysmath.c b/src/mono/mono/metadata/sysmath.c index e8fef9f8e08e94..47a6c370c6b1d6 100644 --- a/src/mono/mono/metadata/sysmath.c +++ b/src/mono/mono/metadata/sysmath.c @@ -169,18 +169,6 @@ ves_icall_System_Math_Sqrt (gdouble x) return sqrt (x); } -gdouble -ves_icall_System_Math_Abs_double (gdouble v) -{ - return fabs (v); -} - -float -ves_icall_System_Math_Abs_single (float v) -{ - return fabsf (v); -} - gdouble ves_icall_System_Math_Ceiling (gdouble v) { diff --git a/src/mono/mono/mini/interp/interp.c b/src/mono/mono/mini/interp/interp.c index e5aef94c5c6ee1..4e978aabbe1979 100644 --- a/src/mono/mono/mini/interp/interp.c +++ b/src/mono/mono/mini/interp/interp.c @@ -6950,7 +6950,6 @@ MINT_IN_CASE(MINT_BRTRUE_I8_SP) ZEROP_SP(gint64, !=); MINT_IN_BREAK; LOCAL_VAR (ip [1], double) = mathfunc (LOCAL_VAR (ip [2], double), LOCAL_VAR (ip [3], double)); \ ip += 4; - MINT_IN_CASE(MINT_ABS) MATH_UNOP(fabs); MINT_IN_BREAK; MINT_IN_CASE(MINT_ASIN) MATH_UNOP(asin); MINT_IN_BREAK; MINT_IN_CASE(MINT_ASINH) MATH_UNOP(asinh); MINT_IN_BREAK; MINT_IN_CASE(MINT_ACOS) MATH_UNOP(acos); MINT_IN_BREAK; @@ -6990,7 +6989,6 @@ MINT_IN_CASE(MINT_BRTRUE_I8_SP) ZEROP_SP(gint64, !=); MINT_IN_BREAK; #define MATH_BINOPF(mathfunc) \ LOCAL_VAR (ip [1], float) = mathfunc (LOCAL_VAR (ip [2], float), LOCAL_VAR (ip [3], float)); \ ip += 4; - MINT_IN_CASE(MINT_ABSF) MATH_UNOPF(fabsf); MINT_IN_BREAK; MINT_IN_CASE(MINT_ASINF) MATH_UNOPF(asinf); MINT_IN_BREAK; MINT_IN_CASE(MINT_ASINHF) MATH_UNOPF(asinhf); MINT_IN_BREAK; MINT_IN_CASE(MINT_ACOSF) MATH_UNOPF(acosf); MINT_IN_BREAK; diff --git a/src/mono/mono/mini/interp/mintops.def b/src/mono/mono/mini/interp/mintops.def index 52b2c4bb1522cf..59f909b24b3659 100644 --- a/src/mono/mono/mini/interp/mintops.def +++ b/src/mono/mono/mini/interp/mintops.def @@ -708,7 +708,6 @@ OPDEF(MINT_LD_DELEGATE_METHOD_PTR, "ld_delegate_method_ptr", 3, 1, 1, MintOpNoAr // Math intrinsics // double -OPDEF(MINT_ABS, "abs", 3, 1, 1, MintOpNoArgs) OPDEF(MINT_ASIN, "asin", 3, 1, 1, MintOpNoArgs) OPDEF(MINT_ASINH, "asinh", 3, 1, 1, MintOpNoArgs) OPDEF(MINT_ACOS, "acos", 3, 1, 1, MintOpNoArgs) @@ -735,7 +734,6 @@ OPDEF(MINT_TAN, "tan", 3, 1, 1, MintOpNoArgs) OPDEF(MINT_TANH, "tanh", 3, 1, 1, MintOpNoArgs) // float. These must be kept in the same order as their double counterpart -OPDEF(MINT_ABSF, "absf", 3, 1, 1, MintOpNoArgs) OPDEF(MINT_ASINF, "asinf", 3, 1, 1, MintOpNoArgs) OPDEF(MINT_ASINHF, "asinhf", 3, 1, 1, MintOpNoArgs) OPDEF(MINT_ACOSF, "acosf", 3, 1, 1, MintOpNoArgs) diff --git a/src/mono/mono/mini/interp/transform.c b/src/mono/mono/mini/interp/transform.c index 8679774a338766..0fb4bb0f78e2b2 100644 --- a/src/mono/mono/mini/interp/transform.c +++ b/src/mono/mono/mini/interp/transform.c @@ -2180,9 +2180,7 @@ interp_handle_intrinsics (TransformData *td, MonoMethod *target_method, MonoClas if (csignature->param_count == 1 && csignature->params [0]->type == param_type) { // unops if (tm [0] == 'A') { - if (strcmp (tm, "Abs") == 0) { - *op = MINT_ABS; - } else if (strcmp (tm, "Asin") == 0){ + if (strcmp (tm, "Asin") == 0){ *op = MINT_ASIN; } else if (strcmp (tm, "Asinh") == 0){ *op = MINT_ASINH; @@ -2245,7 +2243,7 @@ interp_handle_intrinsics (TransformData *td, MonoMethod *target_method, MonoClas } if (*op != -1 && is_float) { - *op = *op + (MINT_ABSF - MINT_ABS); + *op = *op + (MINT_ASINF - MINT_ASIN); } } else if (in_corlib && !strcmp (klass_name_space, "System") && (!strcmp (klass_name, "Span`1") || !strcmp (klass_name, "ReadOnlySpan`1"))) { if (!strcmp (tm, "get_Item")) { From 97b4006add8e75a40b08703a02b13d8438b12dff Mon Sep 17 00:00:00 2001 From: Adeel <3840695+am11@users.noreply.github.com> Date: Mon, 17 Jan 2022 05:49:27 +0200 Subject: [PATCH 2/4] Cleanup trailing whitespaces in changeset --- src/mono/mono/metadata/sysmath.c | 38 ++++++++--------- src/mono/mono/mini/interp/interp.c | 22 +++++----- src/mono/mono/mini/interp/transform.c | 60 +++++++++++++-------------- 3 files changed, 60 insertions(+), 60 deletions(-) diff --git a/src/mono/mono/metadata/sysmath.c b/src/mono/mono/metadata/sysmath.c index 47a6c370c6b1d6..ec25a20fc0025f 100644 --- a/src/mono/mono/metadata/sysmath.c +++ b/src/mono/mono/metadata/sysmath.c @@ -1,6 +1,6 @@ /** * \file - * these are based on bob smith's csharp routines + * these are based on bob smith's csharp routines * * Author: * Mono Project (http://www.mono-project.com) @@ -55,49 +55,49 @@ ves_icall_System_Math_ModF (gdouble x, gdouble *d) return modf (x, d); } -gdouble +gdouble ves_icall_System_Math_Sin (gdouble x) { return sin (x); } -gdouble +gdouble ves_icall_System_Math_Cos (gdouble x) { return cos (x); } -gdouble +gdouble ves_icall_System_Math_Cbrt (gdouble x) { return cbrt (x); } -gdouble +gdouble ves_icall_System_Math_Tan (gdouble x) { return tan (x); } -gdouble +gdouble ves_icall_System_Math_Sinh (gdouble x) { return sinh (x); } -gdouble +gdouble ves_icall_System_Math_Cosh (gdouble x) { return cosh (x); } -gdouble +gdouble ves_icall_System_Math_Tanh (gdouble x) { return tanh (x); } -gdouble +gdouble ves_icall_System_Math_Acos (gdouble x) { return acos (x); @@ -109,61 +109,61 @@ ves_icall_System_Math_Acosh (gdouble x) return acosh (x); } -gdouble +gdouble ves_icall_System_Math_Asin (gdouble x) { return asin (x); } -gdouble +gdouble ves_icall_System_Math_Asinh (gdouble x) { return asinh (x); } -gdouble +gdouble ves_icall_System_Math_Atan (gdouble x) { return atan (x); } -gdouble +gdouble ves_icall_System_Math_Atan2 (gdouble y, gdouble x) { return atan2 (y, x); } -gdouble +gdouble ves_icall_System_Math_Atanh (gdouble x) { return atanh (x); } -gdouble +gdouble ves_icall_System_Math_Exp (gdouble x) { return exp (x); } -gdouble +gdouble ves_icall_System_Math_Log (gdouble x) { return log (x); } -gdouble +gdouble ves_icall_System_Math_Log10 (gdouble x) { return log10 (x); } -gdouble +gdouble ves_icall_System_Math_Pow (gdouble x, gdouble y) { return pow (x, y); } -gdouble +gdouble ves_icall_System_Math_Sqrt (gdouble x) { return sqrt (x); diff --git a/src/mono/mono/mini/interp/interp.c b/src/mono/mono/mini/interp/interp.c index 4e978aabbe1979..099c70695c1386 100644 --- a/src/mono/mono/mini/interp/interp.c +++ b/src/mono/mono/mini/interp/interp.c @@ -1930,7 +1930,7 @@ dump_args (InterpFrame *inv) GString *str = g_string_new (""); int i; MonoMethodSignature *signature = mono_method_signature_internal (inv->imethod->method); - + if (signature->param_count == 0 && !signature->hasthis) return g_string_free (str, FALSE); @@ -3232,7 +3232,7 @@ static long opcode_counts[MINT_LASTOP]; #define COUNT_OP(op) opcode_counts[op]++ #else -#define COUNT_OP(op) +#define COUNT_OP(op) #endif #if DEBUG_INTERP @@ -3478,7 +3478,7 @@ interp_exec_method (InterpFrame *frame, ThreadContext *context, FrameClauseArgs #endif main_loop: /* - * using while (ip < end) may result in a 15% performance drop, + * using while (ip < end) may result in a 15% performance drop, * but it may be useful for debug */ while (1) { @@ -3559,7 +3559,7 @@ interp_exec_method (InterpFrame *frame, ThreadContext *context, FrameClauseArgs MINT_IN_CASE(MINT_LDC_I4_8) LDC(8); MINT_IN_BREAK; - MINT_IN_CASE(MINT_LDC_I4_S) + MINT_IN_CASE(MINT_LDC_I4_S) LOCAL_VAR (ip [1], gint32) = (short)ip [2]; ip += 3; MINT_IN_BREAK; @@ -3584,7 +3584,7 @@ interp_exec_method (InterpFrame *frame, ThreadContext *context, FrameClauseArgs ip += 4; MINT_IN_BREAK; } - MINT_IN_CASE(MINT_LDC_R8) + MINT_IN_CASE(MINT_LDC_R8) LOCAL_VAR (ip [1], gint64) = READ64 (ip + 2); /* note union usage */ ip += 6; MINT_IN_BREAK; @@ -3720,7 +3720,7 @@ interp_exec_method (InterpFrame *frame, ThreadContext *context, FrameClauseArgs call_args_offset = ip [3]; if (need_unbox) { - MonoObject *this_arg = LOCAL_VAR (call_args_offset, MonoObject*); + MonoObject *this_arg = LOCAL_VAR (call_args_offset, MonoObject*); LOCAL_VAR (call_args_offset, gpointer) = mono_object_unbox_internal (this_arg); } ip += 4; @@ -6450,8 +6450,8 @@ MINT_IN_CASE(MINT_BRTRUE_I8_SP) ZEROP_SP(gint64, !=); MINT_IN_BREAK; ip += short_offset ? (gint16)*(ip + 1) : (gint32)READ32 (ip + 1); MINT_IN_BREAK; } - MINT_IN_CASE(MINT_ICALL_V_V) - MINT_IN_CASE(MINT_ICALL_P_V) + MINT_IN_CASE(MINT_ICALL_V_V) + MINT_IN_CASE(MINT_ICALL_P_V) MINT_IN_CASE(MINT_ICALL_PP_V) MINT_IN_CASE(MINT_ICALL_PPP_V) MINT_IN_CASE(MINT_ICALL_PPPP_V) @@ -6476,7 +6476,7 @@ MINT_IN_CASE(MINT_BRTRUE_I8_SP) ZEROP_SP(gint64, !=); MINT_IN_BREAK; CHECK_RESUME_STATE (context); ip += 4; MINT_IN_BREAK; - MINT_IN_CASE(MINT_MONO_LDPTR) + MINT_IN_CASE(MINT_MONO_LDPTR) LOCAL_VAR (ip [1], gpointer) = frame->imethod->data_items [ip [2]]; ip += 3; MINT_IN_BREAK; @@ -6912,12 +6912,12 @@ MINT_IN_CASE(MINT_BRTRUE_I8_SP) ZEROP_SP(gint64, !=); MINT_IN_BREAK; MINT_IN_BREAK; } MINT_IN_CASE(MINT_MONO_RETHROW) { - /* + /* * need to clarify what this should actually do: * * Takes an exception from the stack and rethrows it. * This is useful for wrappers that don't want to have to - * use CEE_THROW and lose the exception stacktrace. + * use CEE_THROW and lose the exception stacktrace. */ MonoException *exc = LOCAL_VAR (ip [1], MonoException*); diff --git a/src/mono/mono/mini/interp/transform.c b/src/mono/mono/mini/interp/transform.c index 0fb4bb0f78e2b2..a5d57007d885fb 100644 --- a/src/mono/mono/mini/interp/transform.c +++ b/src/mono/mono/mini/interp/transform.c @@ -778,7 +778,7 @@ init_bb_stack_state (TransformData *td, InterpBasicBlock *bb) } } -static void +static void handle_branch (TransformData *td, int long_op, int offset) { int target = td->ip + offset - td->il_code; @@ -806,7 +806,7 @@ handle_branch (TransformData *td, int long_op, int offset) td->last_ins->info.target_bb = target_bb; } -static void +static void one_arg_branch(TransformData *td, int mint_op, int offset, int inst_size) { int type = td->sp [-1].type == STACK_TYPE_O || td->sp [-1].type == STACK_TYPE_MP ? STACK_TYPE_I : td->sp [-1].type; @@ -835,7 +835,7 @@ interp_add_conv (TransformData *td, StackInfo *sp, InterpInst *prev_ins, int typ interp_ins_set_dreg (new_inst, sp->local); } -static void +static void two_arg_branch(TransformData *td, int mint_op, int offset, int inst_size) { int type1 = td->sp [-1].type == STACK_TYPE_O || td->sp [-1].type == STACK_TYPE_MP ? STACK_TYPE_I : td->sp [-1].type; @@ -854,7 +854,7 @@ two_arg_branch(TransformData *td, int mint_op, int offset, int inst_size) } else if (type1 == STACK_TYPE_R8 && type2 == STACK_TYPE_R4) { interp_add_conv (td, td->sp - 2, td->last_ins, STACK_TYPE_R8, MINT_CONV_R8_R4); } else if (type1 != type2) { - g_warning("%s.%s: branch type mismatch %d %d", + g_warning("%s.%s: branch type mismatch %d %d", m_class_get_name (td->method->klass), td->method->name, td->sp [-1].type, td->sp [-2].type); } @@ -910,7 +910,7 @@ binary_arith_op(TransformData *td, int mint_op) if (type2 == STACK_TYPE_MP) type2 = STACK_TYPE_I; if (type1 != type2) { - g_warning("%s.%s: %04x arith type mismatch %s %d %d", + g_warning("%s.%s: %04x arith type mismatch %s %d %d", m_class_get_name (td->method->klass), td->method->name, td->ip - td->il_code, mono_interp_opname (mint_op), type1, type2); } @@ -929,7 +929,7 @@ shift_op(TransformData *td, int mint_op) int op = mint_op + td->sp [-2].type - STACK_TYPE_I4; CHECK_STACK(td, 2); if (td->sp [-1].type != STACK_TYPE_I4) { - g_warning("%s.%s: shift type mismatch %d", + g_warning("%s.%s: shift type mismatch %d", m_class_get_name (td->method->klass), td->method->name, td->sp [-2].type); } @@ -940,7 +940,7 @@ shift_op(TransformData *td, int mint_op) interp_ins_set_dreg (td->last_ins, td->sp [-1].local); } -static int +static int can_store (int st_value, int vt_value) { if (st_value == STACK_TYPE_O || st_value == STACK_TYPE_MP) @@ -967,7 +967,7 @@ get_arg_type_exact (TransformData *td, int n, int *mt) return type; } -static void +static void load_arg(TransformData *td, int n) { gint32 size = 0; @@ -1006,12 +1006,12 @@ load_arg(TransformData *td, int n) } interp_add_ins (td, get_mov_for_type (mt, TRUE)); interp_ins_set_sreg (td->last_ins, n); - interp_ins_set_dreg (td->last_ins, td->sp [-1].local); + interp_ins_set_dreg (td->last_ins, td->sp [-1].local); if (mt == MINT_TYPE_VT) td->last_ins->data [0] = size; } -static void +static void store_arg(TransformData *td, int n) { gint32 size = 0; @@ -1060,7 +1060,7 @@ load_local (TransformData *td, int local) td->last_ins->data [0] = size; } -static void +static void store_local (TransformData *td, int local) { int mt = td->locals [local].mt; @@ -1070,7 +1070,7 @@ store_local (TransformData *td, int local) interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_I8, MINT_CONV_I8_I4); #endif if (!can_store(td->sp [-1].type, stack_type [mt])) { - g_warning("%s.%s: Store local stack type mismatch %d %d", + g_warning("%s.%s: Store local stack type mismatch %d %d", m_class_get_name (td->method->klass), td->method->name, stack_type [mt], td->sp [-1].type); } @@ -2828,7 +2828,7 @@ interp_inline_method (TransformData *td, MonoMethod *target_method, MonoMethodHe gboolean ret; unsigned int prev_max_stack_height, prev_locals_size; int prev_n_data_items; - int i; + int i; int prev_sp_offset; int prev_aggressive_inlining; MonoGenericContext *generic_context = NULL; @@ -3291,7 +3291,7 @@ interp_transform_call (TransformData *td, MonoMethod *method, MonoMethod *target CHECK_STACK (td, csignature->param_count + csignature->hasthis); if (tailcall && !td->gen_sdb_seq_points && !calli && op == -1 && - (target_method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) == 0 && + (target_method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) == 0 && (target_method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) == 0 && !(target_method->iflags & METHOD_IMPL_ATTRIBUTE_NOINLINING)) { (void)mono_class_vtable_checked (target_method->klass, error); @@ -3330,7 +3330,7 @@ interp_transform_call (TransformData *td, MonoMethod *method, MonoMethod *target int in_offset = td->ip - td->il_code; if (interp_ip_in_cbb (td, in_offset + 5)) - ++td->ip; /* gobble the CEE_RET if it isn't branched to */ + ++td->ip; /* gobble the CEE_RET if it isn't branched to */ td->ip += 5; return TRUE; } @@ -3436,7 +3436,7 @@ interp_transform_call (TransformData *td, MonoMethod *method, MonoMethod *target else g_error ("Unsupported opcode"); } - + if (op == MINT_LDLEN) { #ifdef MONO_BIG_ARRAYS SET_SIMPLE_TYPE (td->sp - 1, STACK_TYPE_I8); @@ -4656,7 +4656,7 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header, } switch (*td->ip) { - case CEE_NOP: + case CEE_NOP: /* lose it */ emitted_funccall_seq_point = FALSE; ++td->ip; @@ -4826,7 +4826,7 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header, interp_ins_set_dreg (td->last_ins, td->sp [-1].local); ++td->ip; break; - case CEE_LDC_I4_S: + case CEE_LDC_I4_S: interp_add_ins (td, MINT_LDC_I4_S); td->last_ins->data [0] = ((gint8 *) td->ip) [1]; push_simple_type (td, STACK_TYPE_I4); @@ -4931,7 +4931,7 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header, last_seq_point->flags |= INTERP_INST_FLAG_SEQ_POINT_NESTED_CALL; } else - emitted_funccall_seq_point = TRUE; + emitted_funccall_seq_point = TRUE; } last_seq_point = interp_add_ins (td, MINT_SDB_SEQ_POINT); // This seq point is actually associated with the instruction following the call @@ -5395,7 +5395,7 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header, } ++td->ip; break; - case CEE_CONV_I: + case CEE_CONV_I: CHECK_STACK (td, 1); switch (td->sp [-1].type) { case STACK_TYPE_R8: @@ -5869,7 +5869,7 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header, case CEE_UNBOX: CHECK_STACK (td, 1); token = read32 (td->ip + 1); - + if (method->wrapper_type != MONO_WRAPPER_NONE) klass = (MonoClass *)mono_method_get_wrapper_data (method, token); else { @@ -6946,7 +6946,7 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header, interp_add_ins (td, MINT_LD_DELEGATE_METHOD_PTR); interp_ins_set_sreg (td->last_ins, td->sp [0].local); push_simple_type (td, STACK_TYPE_I); - interp_ins_set_dreg (td->last_ins, td->sp [-1].local); + interp_ins_set_dreg (td->last_ins, td->sp [-1].local); break; case CEE_MONO_CALLI_EXTRA_ARG: { int saved_local = td->sp [-1].local; @@ -7079,7 +7079,7 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header, td->sp--; interp_ins_set_sreg (td->last_ins, td->sp [0].local); klass = (MonoClass *)mono_method_get_wrapper_data (method, token); - + /*stackval_from_data (signature->ret, frame->retval, sp->data.vt, signature->pinvoke);*/ if (td->sp > td->stack) @@ -7182,7 +7182,7 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header, * to take into account the number of prefix bytes (usually the * throw point is just (ip - n_prefix_bytes). */ - case CEE_PREFIX1: + case CEE_PREFIX1: ++td->ip; switch (*td->ip) { case CEE_ARGLIST: @@ -7331,7 +7331,7 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header, td->ip += 5; break; } - + int index = get_data_item_index (td, mono_interp_get_imethod (m, error)); goto_if_nok (error, exit); if (*td->ip == CEE_LDVIRTFTN) { @@ -7424,7 +7424,7 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header, #if SIZEOF_VOID_P == 8 if (td->sp [-1].type == STACK_TYPE_I8) interp_add_conv (td, td->sp - 1, NULL, STACK_TYPE_I4, MINT_MOV_8); -#endif +#endif interp_add_ins (td, MINT_LOCALLOC); if (td->sp != td->stack + 1) g_warning("CEE_LOCALLOC: stack not empty"); @@ -7540,7 +7540,7 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header, THROW_EX (mono_exception_from_name (mono_defaults.corlib, "System", "InvalidProgramException"), ip - 5); #endif size = mono_type_size (m_class_get_byval_arg (szclass), &align); - } + } interp_add_ins (td, MINT_LDC_I4); WRITE32_INS (td->last_ins, 0, &size); push_simple_type (td, STACK_TYPE_I4); @@ -9131,7 +9131,7 @@ static void initialize_global_var_cb (TransformData *td, int var, gpointer data) { initialize_global_var (td, var, (int)(gsize)data); -} +} static void initialize_global_vars (TransformData *td) @@ -9550,7 +9550,7 @@ interp_fix_localloc_ret (TransformData *td) g_assert (td->has_localloc); for (InterpBasicBlock *bb = td->entry_bb; bb != NULL; bb = bb->next_bb) { InterpInst *ins = bb->first_ins; - while (ins) { + while (ins) { if (ins->opcode >= MINT_RET && ins->opcode <= MINT_RET_VT) ins->opcode += MINT_RET_LOCALLOC - MINT_RET; ins = ins->next; @@ -9804,7 +9804,7 @@ tiered_patcher (MiniTieredPatchPointContext *ctx, gpointer patchsite) #endif -void +void mono_interp_transform_init (void) { mono_os_mutex_init_recursive(&calc_section); From cb293adcf4a4c377fdd787d071d5f5979c1e55e2 Mon Sep 17 00:00:00 2001 From: Adeel <3840695+am11@users.noreply.github.com> Date: Mon, 17 Jan 2022 18:45:51 +0200 Subject: [PATCH 3/4] Address CR feedback --- .../System.Private.CoreLib/src/System/Math.cs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Math.cs b/src/libraries/System.Private.CoreLib/src/System/Math.cs index 2ef37d8e6eba9f..a929322173585c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Math.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Math.cs @@ -137,24 +137,20 @@ public static decimal Abs(decimal value) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Abs(double value) { - // Implementation based on https://git.musl-libc.org/cgit/musl/tree/src/math/fabs.c - - const ulong signMask = 0x7FFFFFFFFFFFFFFF; + const ulong mask = 0x7FFFFFFFFFFFFFFF; ulong raw = BitConverter.DoubleToUInt64Bits(value); - return BitConverter.UInt64BitsToDouble(raw & signMask); + return BitConverter.UInt64BitsToDouble(raw & mask); } [Intrinsic] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Abs(float value) { - // Implementation based on https://git.musl-libc.org/cgit/musl/tree/src/math/fabsf.c - - const uint signMask = 0x7FFFFFFF; + const uint mask = 0x7FFFFFFF; uint raw = BitConverter.SingleToUInt32Bits(value); - return BitConverter.UInt32BitsToSingle(raw & signMask); + return BitConverter.UInt32BitsToSingle(raw & mask); } [DoesNotReturn] From a083829b7ea97a64544df1e936ad2f8fc88601e0 Mon Sep 17 00:00:00 2001 From: Adeel <3840695+am11@users.noreply.github.com> Date: Tue, 18 Jan 2022 04:56:22 +0200 Subject: [PATCH 4/4] Delete unused _copysignf macro --- src/coreclr/classlibnative/float/floatsingle.cpp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/coreclr/classlibnative/float/floatsingle.cpp b/src/coreclr/classlibnative/float/floatsingle.cpp index ae7fc2f8c0902e..1694fd78cb8467 100644 --- a/src/coreclr/classlibnative/float/floatsingle.cpp +++ b/src/coreclr/classlibnative/float/floatsingle.cpp @@ -8,18 +8,6 @@ #include "floatsingle.h" -// Windows x86 and Windows ARM/ARM64 may not define _isnanf() or _copysignf() but they do -// define _isnan() and _copysign(). We will redirect the macros to these other functions if -// the macro is not defined for the platform. This has the side effect of a possible implicit -// upcasting for arguments passed in and an explicit downcasting for the _copysign() call. -#if (defined(TARGET_X86) || defined(TARGET_ARM) || defined(TARGET_ARM64)) && !defined(TARGET_UNIX) - -#if !defined(_copysignf) -#define _copysignf (float)_copysign -#endif - -#endif - // The default compilation mode is /fp:precise, which disables floating-point intrinsics. This // default compilation mode has previously caused performance regressions in floating-point code. // We enable /fp:fast semantics for the majority of the math functions, as it will speed up performance