Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into orgpal-mesh
  • Loading branch information
actions-user committed Nov 10, 2023
2 parents adcb2c0 + 18c385b commit c1c2dad
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 102 deletions.
14 changes: 7 additions & 7 deletions src/CLR/CorLib/corlib_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,8 @@ static const CLR_RT_MethodHandler method_lookup[] =
NULL,
NULL,
Library_corlib_native_System_MathInternal::Abs___STATIC__I4__I4,
Library_corlib_native_System_MathInternal::Min___STATIC__I4__I4__I4,
Library_corlib_native_System_MathInternal::Max___STATIC__I4__I4__I4,
NULL,
NULL,
NULL,
NULL,
Library_corlib_native_System_MulticastDelegate::op_Equality___STATIC__BOOLEAN__SystemMulticastDelegate__SystemMulticastDelegate,
Expand Down Expand Up @@ -1320,8 +1320,8 @@ static const CLR_RT_MethodHandler method_lookup[] =
NULL,
NULL,
Library_corlib_native_System_MathInternal::Abs___STATIC__I4__I4,
Library_corlib_native_System_MathInternal::Min___STATIC__I4__I4__I4,
Library_corlib_native_System_MathInternal::Max___STATIC__I4__I4__I4,
NULL,
NULL,
NULL,
NULL,
Library_corlib_native_System_MulticastDelegate::op_Equality___STATIC__BOOLEAN__SystemMulticastDelegate__SystemMulticastDelegate,
Expand Down Expand Up @@ -1483,18 +1483,18 @@ const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_mscorlib =

#if (NANOCLR_REFLECTION == TRUE)

0xCCE8376E,
0x445C7AF9,

#elif (NANOCLR_REFLECTION == FALSE)

0xF60D1B13,
0xE3A4B52F,

#else
#error "NANOCLR_REFLECTION has to be define either TRUE or FALSE. Check the build options."
#endif

method_lookup,
{ 100, 5, 0, 18 }
{ 100, 5, 0, 19 }
};

// clang-format on
2 changes: 0 additions & 2 deletions src/CLR/CorLib/corlib_native.h
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,6 @@ struct Library_corlib_native_System_Guid
struct Library_corlib_native_System_MathInternal
{
NANOCLR_NATIVE_DECLARE(Abs___STATIC__I4__I4);
NANOCLR_NATIVE_DECLARE(Min___STATIC__I4__I4__I4);
NANOCLR_NATIVE_DECLARE(Max___STATIC__I4__I4__I4);

//--//
};
Expand Down
35 changes: 3 additions & 32 deletions src/CLR/CorLib/corlib_native_System_MathInternal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,15 @@
//
#include "CorLib.h"

HRESULT Library_corlib_native_System_MathInternal::Abs___STATIC__I4__I4( CLR_RT_StackFrame& stack )
HRESULT Library_corlib_native_System_MathInternal::Abs___STATIC__I4__I4(CLR_RT_StackFrame &stack)
{
NATIVE_PROFILE_CLR_CORE();
NANOCLR_HEADER();

CLR_INT32 d = stack.Arg0().NumericByRefConst().s4;
CLR_INT32 res = abs( d );
CLR_INT32 res = abs(d);

stack.SetResult_I4( res );
stack.SetResult_I4(res);

NANOCLR_NOCLEANUP_NOLABEL();
}

HRESULT Library_corlib_native_System_MathInternal::Max___STATIC__I4__I4__I4( CLR_RT_StackFrame& stack )
{
NATIVE_PROFILE_CLR_CORE();
NANOCLR_HEADER();

CLR_INT32 x = stack.Arg0().NumericByRefConst().s4;
CLR_INT32 y = stack.Arg1().NumericByRefConst().s4;
CLR_INT32 res = x >= y ? x : y;

stack.SetResult_I4( res );

NANOCLR_NOCLEANUP_NOLABEL();
}

HRESULT Library_corlib_native_System_MathInternal::Min___STATIC__I4__I4__I4( CLR_RT_StackFrame& stack )
{
NATIVE_PROFILE_CLR_CORE();
NANOCLR_HEADER();

CLR_INT32 x = stack.Arg0().NumericByRefConst().s4;
CLR_INT32 y = stack.Arg1().NumericByRefConst().s4;
CLR_INT32 res = x <= y ? x : y;

stack.SetResult_I4( res );

NANOCLR_NOCLEANUP_NOLABEL();
}

8 changes: 4 additions & 4 deletions src/CLR/System.Math/nf_native_system_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ static const CLR_RT_MethodHandler method_lookup[] =
Library_nf_native_system_math_System_Math::Log10___STATIC__R8__R8,
NULL,
Library_nf_native_system_math_System_Math::Max___STATIC__R8__R8__R8,
NULL,
Library_nf_native_system_math_System_Math::Max___STATIC__R4__R4__R4,
NULL,
Library_nf_native_system_math_System_Math::Min___STATIC__R8__R8__R8,
NULL,
Library_nf_native_system_math_System_Math::Min___STATIC__R4__R4__R4,
Library_nf_native_system_math_System_Math::Pow___STATIC__R8__R8__R8,
Library_nf_native_system_math_System_Math::Round___STATIC__R8__R8,
Library_nf_native_system_math_System_Math::Sign___STATIC__I4__R8,
Expand All @@ -50,9 +50,9 @@ static const CLR_RT_MethodHandler method_lookup[] =
const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_System_Math =
{
"System.Math",
0x46092CB1,
0x9F9E2A7E,
method_lookup,
{ 100, 0, 5, 4 }
{ 100, 0, 5, 5 }
};

// clang-format on
2 changes: 2 additions & 0 deletions src/CLR/System.Math/nf_native_system_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ struct Library_nf_native_system_math_System_Math
NANOCLR_NATIVE_DECLARE(Log___STATIC__R8__R8);
NANOCLR_NATIVE_DECLARE(Log10___STATIC__R8__R8);
NANOCLR_NATIVE_DECLARE(Max___STATIC__R8__R8__R8);
NANOCLR_NATIVE_DECLARE(Max___STATIC__R4__R4__R4);
NANOCLR_NATIVE_DECLARE(Min___STATIC__R8__R8__R8);
NANOCLR_NATIVE_DECLARE(Min___STATIC__R4__R4__R4);
NANOCLR_NATIVE_DECLARE(Pow___STATIC__R8__R8__R8);
NANOCLR_NATIVE_DECLARE(Round___STATIC__R8__R8);
NANOCLR_NATIVE_DECLARE(Sign___STATIC__I4__R8);
Expand Down
188 changes: 166 additions & 22 deletions src/CLR/System.Math/nf_native_system_math_System_Math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,55 @@ HRESULT Library_nf_native_system_math_System_Math::Max___STATIC__R8__R8__R8(CLR_
NATIVE_PROFILE_CLR_CORE();
NANOCLR_HEADER();

// This matches the IEEE 754:2019 `maximum` function
//
// It propagates NaN inputs back to the caller and
// otherwise returns the greater of the inputs. It
// treats +0 as greater than -0 as per the specification.

#if (DP_FLOATINGPOINT == TRUE)

double x = stack.Arg0().NumericByRefConst().r8;
double y = stack.Arg1().NumericByRefConst().r8;
double val1 = stack.Arg0().NumericByRefConst().r8;
double val2 = stack.Arg1().NumericByRefConst().r8;

// from .NET spec: If val1, val2, or both val1 and val2 are equal to NaN, NaN is returned.
if (System::Double::IsNaN(x) || System::Double::IsNaN(y))
if (val1 != val2)
{
stack.SetResult_R8(NAN);
if (!__isnand(val1))
{
double res = val2 < val1 ? val1 : val2;
stack.SetResult_R8(res);
}
else
{
stack.SetResult_R8(val1);
}
}
else
{
double res = x >= y ? x : y;

double res = (__signbitd(val2) != 0) ? val1 : val2;
stack.SetResult_R8(res);
}

#else

float x = (float)stack.Arg0().NumericByRefConst().r8;
float y = (float)stack.Arg1().NumericByRefConst().r8;
float val1 = (float)stack.Arg0().NumericByRefConst().r8;
float val2 = (float)stack.Arg1().NumericByRefConst().r8;

// from .NET spec: If val1, val2, or both val1 and val2 are equal to NaN, NaN is returned.
if (System::Double::IsNaN(x) || System::Double::IsNaN(y))
if (val1 != val2)
{
stack.SetResult_R8(NAN);
if (!__isnand(val1))
{
float res = val2 < val1 ? val1 : val2;
stack.SetResult_R8(res);
}
else
{
stack.SetResult_R8(val1);
}
}
else
{
float res = x >= y ? x : y;

float res = (__signbitd(val2) != 0) ? val1 : val2;
stack.SetResult_R8(res);
}

Expand All @@ -52,32 +70,138 @@ HRESULT Library_nf_native_system_math_System_Math::Max___STATIC__R8__R8__R8(CLR_
NANOCLR_NOCLEANUP_NOLABEL();
}

HRESULT Library_nf_native_system_math_System_Math::Max___STATIC__R4__R4__R4(CLR_RT_StackFrame &stack)
{
NATIVE_PROFILE_CLR_CORE();
NANOCLR_HEADER();

// This matches the IEEE 754:2019 `maximum` function
//
// It propagates NaN inputs back to the caller and
// otherwise returns the greater of the inputs. It
// treats +0 as greater than -0 as per the specification.

float val1 = (float)stack.Arg0().NumericByRefConst().r4;
float val2 = (float)stack.Arg1().NumericByRefConst().r4;

if (val1 != val2)
{
if (!__isnand(val1))
{
float res = val2 < val1 ? val1 : val2;
stack.SetResult_R4(res);
}
else
{
stack.SetResult_R4(val1);
}
}
else
{
float res = (__signbitd(val2) != 0) ? val1 : val2;
stack.SetResult_R4(res);
}

NANOCLR_NOCLEANUP_NOLABEL();
}

HRESULT Library_nf_native_system_math_System_Math::Min___STATIC__R8__R8__R8(CLR_RT_StackFrame &stack)
{
NATIVE_PROFILE_CLR_CORE();
NANOCLR_HEADER();

// This matches the IEEE 754:2019 `minimum` function
//
// It propagates NaN inputs back to the caller and
// otherwise returns the lesser of the inputs. It
// treats +0 as lesser than -0 as per the specification.

#if (DP_FLOATINGPOINT == TRUE)

double x = stack.Arg0().NumericByRefConst().r8;
double y = stack.Arg1().NumericByRefConst().r8;
double res = x <= y ? x : y;
double val1 = stack.Arg0().NumericByRefConst().r8;
double val2 = stack.Arg1().NumericByRefConst().r8;

stack.SetResult_R8(res);
if (val1 != val2)
{
if (!__isnand(val1))
{
double res = val1 < val2 ? val1 : val2;
stack.SetResult_R8(res);
}
else
{
stack.SetResult_R8(val1);
}
}
else
{
double res = (__signbitd(val2) != 0) ? val1 : val2;
stack.SetResult_R8(res);
}

#else

float x = (float)stack.Arg0().NumericByRefConst().r8;
float y = (float)stack.Arg1().NumericByRefConst().r8;
float res = x <= y ? x : y;
float val1 = (float)stack.Arg0().NumericByRefConst().r8;
float val2 = (float)stack.Arg1().NumericByRefConst().r8;

stack.SetResult_R8(res);
if (val1 != val2)
{
if (!__isnand(val1))
{
float res = val1 < val2 ? val1 : val2;
stack.SetResult_R8(res);
}
else
{
stack.SetResult_R8((float)val1);
}
}
else
{
float res = (__signbitd(val2) != 0) ? val1 : val2;
stack.SetResult_R8(res);
}

#endif

NANOCLR_NOCLEANUP_NOLABEL();
}

HRESULT Library_nf_native_system_math_System_Math::Min___STATIC__R4__R4__R4(CLR_RT_StackFrame &stack)
{
NATIVE_PROFILE_CLR_CORE();
NANOCLR_HEADER();

// This matches the IEEE 754:2019 `minimum` function
//
// It propagates NaN inputs back to the caller and
// otherwise returns the lesser of the inputs. It
// treats +0 as lesser than -0 as per the specification.

float val1 = (float)stack.Arg0().NumericByRefConst().r4;
float val2 = (float)stack.Arg1().NumericByRefConst().r4;

if (val1 != val2)
{
if (!__isnand(val1))
{
float res = val1 < val2 ? val1 : val2;
stack.SetResult_R4(res);
}
else
{
stack.SetResult_R4(val1);
}
}
else
{
float res = (__signbitd(val2) != 0) ? val1 : val2;
stack.SetResult_R8(res);
}

NANOCLR_NOCLEANUP_NOLABEL();
}

HRESULT Library_nf_native_system_math_System_Math::Abs___STATIC__R8__R8(CLR_RT_StackFrame &stack)
{
NATIVE_PROFILE_CLR_CORE();
Expand Down Expand Up @@ -820,6 +944,16 @@ HRESULT Library_nf_native_system_math_System_Math::Max___STATIC__R8__R8__R8(CLR_
NANOCLR_NOCLEANUP();
}

HRESULT Library_nf_native_system_math_System_Math::Max___STATIC__R4__R4__R4(CLR_RT_StackFrame &stack)
{
NATIVE_PROFILE_CLR_CORE();
NANOCLR_HEADER();

NANOCLR_SET_AND_LEAVE(stack.NotImplementedStub());

NANOCLR_NOCLEANUP();
}

HRESULT Library_nf_native_system_math_System_Math::Min___STATIC__R8__R8__R8(CLR_RT_StackFrame &stack)
{
NATIVE_PROFILE_CLR_CORE();
Expand All @@ -830,6 +964,16 @@ HRESULT Library_nf_native_system_math_System_Math::Min___STATIC__R8__R8__R8(CLR_
NANOCLR_NOCLEANUP();
}

HRESULT Library_nf_native_system_math_System_Math::Min___STATIC__R4__R4__R4(CLR_RT_StackFrame &stack)
{
NATIVE_PROFILE_CLR_CORE();
NANOCLR_HEADER();

NANOCLR_SET_AND_LEAVE(stack.NotImplementedStub());

NANOCLR_NOCLEANUP();
}

HRESULT Library_nf_native_system_math_System_Math::Abs___STATIC__R8__R8(CLR_RT_StackFrame &stack)
{
NATIVE_PROFILE_CLR_CORE();
Expand Down
Loading

0 comments on commit c1c2dad

Please sign in to comment.