Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Moving parts of System.Math and System.MathF to be shared with Co…
Browse files Browse the repository at this point in the history
…reRT. (#14119)

* Moving parts of `System.MathF` to be shared with CoreRT.

* Moving parts of `System.Math` to be shared with CoreRT.

* Updating the new 'Round' named intrinsic to map to the legacy 'Round' intrinsic.

* Adding back the case statement for CORINFO_INTRINSIC_Round, since it is required for Desktop compat.
  • Loading branch information
tannergooding authored and jkotas committed Sep 23, 2017
1 parent ededd38 commit bfaad96
Show file tree
Hide file tree
Showing 14 changed files with 986 additions and 710 deletions.
37 changes: 11 additions & 26 deletions src/classlibnative/float/floatdouble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ FCIMPL1_V(double, COMDouble::Floor, double x)
return (double)floor(x);
FCIMPLEND

/*=====================================FMod=====================================
**
==============================================================================*/
FCIMPL2_VV(double, COMDouble::FMod, double x, double y)
FCALL_CONTRACT;

return (double)fmod(x, y);
FCIMPLEND

/*=====================================Log======================================
**
==============================================================================*/
Expand All @@ -153,10 +162,10 @@ FCIMPLEND
/*=====================================ModF=====================================
**
==============================================================================*/
FCIMPL1(double, COMDouble::ModF, double* iptr)
FCIMPL2_VV(double, COMDouble::ModF, double x, double* intptr)
FCALL_CONTRACT;

return (double)modf(*iptr, iptr);
return (double)modf(x, intptr);
FCIMPLEND

/*=====================================Pow======================================
Expand All @@ -168,30 +177,6 @@ FCIMPL2_VV(double, COMDouble::Pow, double x, double y)
return (double)pow(x, y);
FCIMPLEND

/*====================================Round=====================================
**
==============================================================================*/
FCIMPL1_V(double, COMDouble::Round, double x)
FCALL_CONTRACT;

// If the number has no fractional part do nothing
// This shortcut is necessary to workaround precision loss in borderline cases on some platforms
if (x == (double)((INT64)x)) {
return x;
}

// We had a number that was equally close to 2 integers.
// We need to return the even one.

double flrTempVal = floor(x + 0.5);

if ((x == (floor(x) + 0.5)) && (fmod(flrTempVal, 2.0) != 0)) {
flrTempVal -= 1.0;
}

return _copysign(flrTempVal, x);
FCIMPLEND

/*=====================================Sin======================================
**
==============================================================================*/
Expand Down
37 changes: 11 additions & 26 deletions src/classlibnative/float/floatsingle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ FCIMPL1_V(float, COMSingle::Floor, float x)
return (float)floorf(x);
FCIMPLEND

/*=====================================FMod=====================================
**
==============================================================================*/
FCIMPL2_VV(float, COMSingle::FMod, float x, float y)
FCALL_CONTRACT;

return (float)fmodf(x, y);
FCIMPLEND

/*=====================================Log======================================
**
==============================================================================*/
Expand All @@ -151,10 +160,10 @@ FCIMPLEND
/*=====================================ModF=====================================
**
==============================================================================*/
FCIMPL1(float, COMSingle::ModF, float* iptr)
FCIMPL2_VV(float, COMSingle::ModF, float x, float* intptr)
FCALL_CONTRACT;

return (float)modff(*iptr, iptr);
return (float)modff(x, intptr);
FCIMPLEND

/*=====================================Pow======================================
Expand All @@ -166,30 +175,6 @@ FCIMPL2_VV(float, COMSingle::Pow, float x, float y)
return (float)powf(x, y);
FCIMPLEND

/*====================================Round=====================================
**
==============================================================================*/
FCIMPL1_V(float, COMSingle::Round, float x)
FCALL_CONTRACT;

// If the number has no fractional part do nothing
// This shortcut is necessary to workaround precision loss in borderline cases on some platforms
if (x == (float)((INT32)x)) {
return x;
}

// We had a number that was equally close to 2 integers.
// We need to return the even one.

float flrTempVal = floorf(x + 0.5f);

if ((x == (floorf(x) + 0.5f)) && (fmod(flrTempVal, 2.0f) != 0)) {
flrTempVal -= 1.0f;
}

return _copysignf(flrTempVal, x);
FCIMPLEND

/*=====================================Sin======================================
**
==============================================================================*/
Expand Down
4 changes: 2 additions & 2 deletions src/classlibnative/inc/floatdouble.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ 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);
FCDECL1_V(static double, Log, double x);
FCDECL1_V(static double, Log10, double x);
FCDECL1(static double, ModF, double* iptr);
FCDECL2_VV(static double, ModF, double x, double* intptr);
FCDECL2_VV(static double, Pow, double x, double y);
FCDECL1_V(static double, Round, double x);
FCDECL1_V(static double, Sin, double x);
FCDECL1_V(static double, Sinh, double x);
FCDECL1_V(static double, Sqrt, double x);
Expand Down
4 changes: 2 additions & 2 deletions src/classlibnative/inc/floatsingle.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ 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);
FCDECL1_V(static float, Log, float x);
FCDECL1_V(static float, Log10, float x);
FCDECL1(static float, ModF, float* iptr);
FCDECL2_VV(static float, ModF, float x, float* intptr);
FCDECL2_VV(static float, Pow, float x, float y);
FCDECL1_V(static float, Round, float x);
FCDECL1_V(static float, Sin, float x);
FCDECL1_V(static float, Sinh, float x);
FCDECL1_V(static float, Sqrt, float x);
Expand Down
5 changes: 5 additions & 0 deletions src/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3007,6 +3007,11 @@ class Compiler
bool isJitIntrinsic,
CorInfoIntrinsics* pIntrinsicID,
bool* isSpecialIntrinsic = nullptr);
GenTree* impMathIntrinsic(CORINFO_METHOD_HANDLE method,
CORINFO_SIG_INFO* sig,
var_types callType,
CorInfoIntrinsics intrinsicID,
bool tailCall);
NamedIntrinsic lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method);
GenTreePtr impArrayAccessIntrinsic(CORINFO_CLASS_HANDLE clsHnd,
CORINFO_SIG_INFO* sig,
Expand Down
Loading

0 comments on commit bfaad96

Please sign in to comment.