Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
028b1c2
Move math PAL that redefined functions to handle boundary conditions …
jkoritzinsky Feb 6, 2024
e5b1ae6
Use netintrinsics in mono codegen/interp backends
jkoritzinsky Feb 6, 2024
3fc672d
Update NativeAOT to use the netintrinsics APIs as well
jkoritzinsky Feb 6, 2024
c3afdce
Remove unused defines
jkoritzinsky Feb 6, 2024
ab98412
Remove now-duplicate configure steps
jkoritzinsky Feb 6, 2024
a501838
Add back default debug channel
jkoritzinsky Feb 6, 2024
9d45460
Fix macro name
jkoritzinsky Feb 6, 2024
f2b0cad
Add sincos to PAL headers on Apple platforms
jkoritzinsky Feb 6, 2024
cf4b2d3
Move ilogb intrinsic handling into RyuJIT (as we still need this one …
jkoritzinsky Feb 6, 2024
f519041
Remove _isnan
jkoritzinsky Feb 6, 2024
2c842df
Remove _copysign from the PAL
jkoritzinsky Feb 7, 2024
267e6e1
Remove _finite from the PAL and delete the now-empty math.cpp
jkoritzinsky Feb 7, 2024
c7a561f
Fix isfinite implementation
jkoritzinsky Feb 7, 2024
cc7ab05
Merge branch 'main' of github.com:dotnet/runtime into math-pal
jkoritzinsky Feb 7, 2024
6f5f524
Revert changes to Mono
jkoritzinsky Feb 7, 2024
6ffc62b
Change the native isFinite implementation to use the same implementat…
jkoritzinsky Feb 8, 2024
34adfb1
Apparently we don't have the PAL/standard overloads available here. D…
jkoritzinsky Feb 9, 2024
92bb263
Fix formatting
jkoritzinsky Feb 9, 2024
874ff56
Merge branch 'math-pal' of github.com:jkoritzinsky/runtime into math-pal
jkoritzinsky Feb 10, 2024
1b39abb
Remove now-unneceesary tryrun.cmake statements
jkoritzinsky Feb 10, 2024
8f7e09a
Merge branch 'main' of github.com:dotnet/runtime into math-pal
jkoritzinsky Feb 10, 2024
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
31 changes: 0 additions & 31 deletions eng/native/tryrun.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,6 @@ if(DARWIN)
set_cache_value(HAVE_CLOCK_REALTIME_EXITCODE 0)
set_cache_value(HAVE_CLOCK_THREAD_CPUTIME_EXITCODE 0)
set_cache_value(HAVE_CLOCK_GETTIME_NSEC_NP_EXITCODE 0)
set_cache_value(HAVE_COMPATIBLE_ACOS_EXITCODE 0)
set_cache_value(HAVE_COMPATIBLE_ASIN_EXITCODE 0)
set_cache_value(HAVE_COMPATIBLE_ATAN2_EXITCODE 0)
set_cache_value(HAVE_COMPATIBLE_EXP_EXITCODE 1)
set_cache_value(HAVE_COMPATIBLE_ILOGB0_EXITCODE 0)
set_cache_value(HAVE_COMPATIBLE_ILOGBNAN_EXITCODE 1)
set_cache_value(HAVE_COMPATIBLE_LOG10_EXITCODE 0)
set_cache_value(HAVE_COMPATIBLE_LOG_EXITCODE 0)
set_cache_value(HAVE_COMPATIBLE_POW_EXITCODE 0)
set_cache_value(HAVE_FUNCTIONAL_PTHREAD_ROBUST_MUTEXES_EXITCODE 1)
set_cache_value(HAVE_LARGE_SNPRINTF_SUPPORT_EXITCODE 0)
set_cache_value(HAVE_MMAP_DEV_ZERO_EXITCODE 1)
Expand All @@ -75,8 +66,6 @@ if(DARWIN)
set_cache_value(HAVE_PROCFS_STATM_EXITCODE 1)
set_cache_value(HAVE_SCHED_GETCPU_EXITCODE 1)
set_cache_value(HAVE_SCHED_GET_PRIORITY_EXITCODE 0)
set_cache_value(HAVE_VALID_NEGATIVE_INF_POW_EXITCODE 0)
set_cache_value(HAVE_VALID_POSITIVE_INF_POW_EXITCODE 0)
set_cache_value(HAVE_WORKING_CLOCK_GETTIME_EXITCODE 0)
set_cache_value(HAVE_WORKING_GETTIMEOFDAY_EXITCODE 0)
set_cache_value(MMAP_ANON_IGNORES_PROTECTION_EXITCODE 1)
Expand All @@ -97,23 +86,13 @@ elseif(TARGET_ARCH_NAME MATCHES "^(armel|arm|armv6|arm64|loongarch64|riscv64|s39
set_cache_value(HAVE_CLOCK_MONOTONIC_EXITCODE 0)
set_cache_value(HAVE_CLOCK_REALTIME_EXITCODE 0)
set_cache_value(HAVE_CLOCK_THREAD_CPUTIME_EXITCODE 0)
set_cache_value(HAVE_COMPATIBLE_ACOS_EXITCODE 0)
set_cache_value(HAVE_COMPATIBLE_ASIN_EXITCODE 0)
set_cache_value(HAVE_COMPATIBLE_ATAN2_EXITCODE 0)
set_cache_value(HAVE_COMPATIBLE_ILOGB0_EXITCODE 1)
set_cache_value(HAVE_COMPATIBLE_ILOGBNAN_EXITCODE 1)
set_cache_value(HAVE_COMPATIBLE_LOG10_EXITCODE 0)
set_cache_value(HAVE_COMPATIBLE_LOG_EXITCODE 0)
set_cache_value(HAVE_COMPATIBLE_POW_EXITCODE 0)
set_cache_value(HAVE_LARGE_SNPRINTF_SUPPORT_EXITCODE 0)
set_cache_value(HAVE_MMAP_DEV_ZERO_EXITCODE 0)
set_cache_value(HAVE_PROCFS_CTL_EXITCODE 1)
set_cache_value(HAVE_PROCFS_STAT_EXITCODE 0)
set_cache_value(HAVE_PROCFS_STATM_EXITCODE 0)
set_cache_value(HAVE_SCHED_GETCPU_EXITCODE 0)
set_cache_value(HAVE_SCHED_GET_PRIORITY_EXITCODE 0)
set_cache_value(HAVE_VALID_NEGATIVE_INF_POW_EXITCODE 0)
set_cache_value(HAVE_VALID_POSITIVE_INF_POW_EXITCODE 0)
set_cache_value(HAVE_WORKING_CLOCK_GETTIME_EXITCODE 0)
set_cache_value(HAVE_WORKING_GETTIMEOFDAY_EXITCODE 0)
set_cache_value(ONE_SHARED_MAPPING_PER_FILEREGION_PER_PROCESS_EXITCODE 1)
Expand All @@ -140,16 +119,8 @@ elseif(TARGET_ARCH_NAME MATCHES "^(armel|arm|armv6|arm64|loongarch64|riscv64|s39
set_cache_value(HAVE_PROCFS_STAT 0)
set_cache_value(HAVE_PROCFS_STATM 0)
set_cache_value(UNGETC_NOT_RETURN_EOF 0)
set_cache_value(HAVE_COMPATIBLE_ILOGBNAN 1)
set_cache_value(HAVE_FUNCTIONAL_PTHREAD_ROBUST_MUTEXES_EXITCODE 0)
elseif(ILLUMOS)
set_cache_value(HAVE_COMPATIBLE_ACOS_EXITCODE 1)
set_cache_value(HAVE_COMPATIBLE_ASIN_EXITCODE 1)
set_cache_value(HAVE_COMPATIBLE_ATAN2_EXITCODE 1)
set_cache_value(HAVE_COMPATIBLE_POW_EXITCODE 1)
set_cache_value(HAVE_COMPATIBLE_ILOGBNAN_EXITCODE 0)
set_cache_value(HAVE_COMPATIBLE_LOG10_EXITCODE 1)
set_cache_value(HAVE_COMPATIBLE_LOG_EXITCODE 1)
set_cache_value(HAVE_LARGE_SNPRINTF_SUPPORT_EXITCODE 1)
set_cache_value(HAVE_PROCFS_CTL_EXITCODE 0)
set_cache_value(SSCANF_SUPPORT_ll_EXITCODE 1)
Expand All @@ -162,8 +133,6 @@ elseif(TARGET_ARCH_NAME MATCHES "^(armel|arm|armv6|arm64|loongarch64|riscv64|s39
set_cache_value(HAVE_FUNCTIONAL_PTHREAD_ROBUST_MUTEXES_EXITCODE 0)
elseif(HAIKU)
set_cache_value(HAVE_CLOCK_MONOTONIC_COARSE_EXITCODE 1)
set_cache_value(HAVE_COMPATIBLE_EXP_EXITCODE 0)
set_cache_value(HAVE_COMPATIBLE_ILOGBNAN_EXITCODE 0)
set_cache_value(HAVE_PROCFS_STAT_EXITCODE 1)
set_cache_value(HAVE_PROCFS_STATM_EXITCODE 1)
endif()
Expand Down
11 changes: 0 additions & 11 deletions eng/native/tryrun_ios_tvos.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,13 @@ set_cache_value(HAVE_BROKEN_FIFO_SELECT_EXITCODE 1)
set_cache_value(HAVE_CLOCK_REALTIME_EXITCODE 0)
set_cache_value(HAVE_CLOCK_THREAD_CPUTIME_EXITCODE 0)
set_cache_value(HAVE_CLOCK_GETTIME_NSEC_NP_EXITCODE 0)
set_cache_value(HAVE_COMPATIBLE_ACOS_EXITCODE 0)
set_cache_value(HAVE_COMPATIBLE_ASIN_EXITCODE 0)
set_cache_value(HAVE_COMPATIBLE_ATAN2_EXITCODE 0)
set_cache_value(HAVE_COMPATIBLE_EXP_EXITCODE 1)
set_cache_value(HAVE_COMPATIBLE_ILOGB0_EXITCODE 0)
set_cache_value(HAVE_COMPATIBLE_ILOGBNAN_EXITCODE 1)
set_cache_value(HAVE_COMPATIBLE_LOG10_EXITCODE 0)
set_cache_value(HAVE_COMPATIBLE_LOG_EXITCODE 0)
set_cache_value(HAVE_COMPATIBLE_POW_EXITCODE 0)
set_cache_value(HAVE_FUNCTIONAL_PTHREAD_ROBUST_MUTEXES_EXITCODE 1)
set_cache_value(HAVE_LARGE_SNPRINTF_SUPPORT_EXITCODE 0)
set_cache_value(HAVE_MMAP_DEV_ZERO_EXITCODE 1)
set_cache_value(HAVE_PROCFS_CTL_EXITCODE 1)
set_cache_value(HAVE_PROCFS_STAT_EXITCODE 1)
set_cache_value(HAVE_PROCFS_STATM_EXITCODE 1)
set_cache_value(HAVE_SCHED_GET_PRIORITY_EXITCODE 0)
set_cache_value(HAVE_VALID_NEGATIVE_INF_POW_EXITCODE 0)
set_cache_value(HAVE_VALID_POSITIVE_INF_POW_EXITCODE 0)
set_cache_value(HAVE_WORKING_CLOCK_GETTIME_EXITCODE 0)
set_cache_value(HAVE_WORKING_GETTIMEOFDAY_EXITCODE 0)
set_cache_value(MMAP_ANON_IGNORES_PROTECTION_EXITCODE 1)
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/classlibnative/float/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
set(CMAKE_INCLUDE_CURRENT_DIR ON)

include_directories("../inc")

set(FLOAT_SOURCES
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/classlibnative/float/floatdouble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ FCIMPL3_VII(void, COMDouble::SinCos, double x, double* pSin, double* pCos)
#ifdef _MSC_VER
*pSin = sin(x);
*pCos = cos(x);
#elif defined(__APPLE__)
__sincos(x, pSin, pCos);
#else
sincos(x, pSin, pCos);
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/classlibnative/float/floatsingle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ FCIMPL3_VII(void, COMSingle::SinCos, float x, float* pSin, float* pCos)
#ifdef _MSC_VER
*pSin = sinf(x);
*pCos = cosf(x);
#elif defined(__APPLE__)
__sincosf(x, pSin, pCos);
#else
sincosf(x, pSin, pCos);
#endif
Expand Down
10 changes: 5 additions & 5 deletions src/coreclr/jit/assertionprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,7 @@ AssertionIndex Compiler::optCreateAssertion(GenTree* op1,
{
noway_assert(op2->gtOper == GT_CNS_DBL);
/* If we have an NaN value then don't record it */
if (_isnan(op2->AsDblCon()->DconValue()))
if (FloatingPointUtils::isNaN(op2->AsDblCon()->DconValue()))
{
goto DONE_ASSERTION; // Don't make an assertion
}
Expand Down Expand Up @@ -1691,8 +1691,8 @@ bool Compiler::optAssertionVnInvolvesNan(AssertionDsc* assertion)
if (vnStore->IsVNConstant(vns[i]))
{
var_types type = vnStore->TypeOfVN(vns[i]);
if ((type == TYP_FLOAT && _isnan(vnStore->ConstantValue<float>(vns[i])) != 0) ||
(type == TYP_DOUBLE && _isnan(vnStore->ConstantValue<double>(vns[i])) != 0))
if ((type == TYP_FLOAT && FloatingPointUtils::isNaN(vnStore->ConstantValue<float>(vns[i])) != 0) ||
(type == TYP_DOUBLE && FloatingPointUtils::isNaN(vnStore->ConstantValue<double>(vns[i])) != 0))
{
return true;
}
Expand Down Expand Up @@ -4351,15 +4351,15 @@ GenTree* Compiler::optAssertionPropGlobal_RelOp(ASSERT_VALARG_TP assertions, Gen
// which will yield a false correctly. Instead if IL had "op1 != NaN", then we already
// made op1 NaN which will yield a true correctly. Note that this is irrespective of the
// assertion we have made.
allowReverse = (_isnan(constant) == 0);
allowReverse = !FloatingPointUtils::isNaN(constant);
}
else if (op1->TypeGet() == TYP_FLOAT)
{
float constant = vnStore->ConstantValue<float>(vnCns);
op1->BashToConst(constant);

// See comments for TYP_DOUBLE.
allowReverse = (_isnan(constant) == 0);
allowReverse = !FloatingPointUtils::isNaN(constant);
}
else if (op1->TypeGet() == TYP_REF)
{
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16091,7 +16091,7 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)
// For unordered operations (i.e. the GTF_RELOP_NAN_UN flag is set)
// the result is always true - return 1.

if (_isnan(d1) || _isnan(d2))
if (FloatingPointUtils::isNaN(d1) || FloatingPointUtils::isNaN(d2))
{
JITDUMP("Double operator(s) is NaN\n");

Expand Down
78 changes: 62 additions & 16 deletions src/coreclr/jit/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2399,22 +2399,10 @@ double FloatingPointUtils::round(double x)
// noting that we also need to copy back the original sign to
// correctly handle -0.0

double temp = _copysign(IntegerBoundary, x);
return _copysign((x + temp) - temp, x);
double temp = copysign(IntegerBoundary, x);
return copysign((x + temp) - temp, x);
}

// Windows x86 and Windows ARM/ARM64 may not define _copysignf() but they do define _copysign().
// We will redirect the macro to this 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

// Rounds a single-precision floating-point value to the nearest integer,
// and rounds midpoint values to the nearest even number.
float FloatingPointUtils::round(float x)
Expand Down Expand Up @@ -2456,8 +2444,8 @@ float FloatingPointUtils::round(float x)
// noting that we also need to copy back the original sign to
// correctly handle -0.0

float temp = _copysignf(IntegerBoundary, x);
return _copysignf((x + temp) - temp, x);
float temp = copysignf(IntegerBoundary, x);
return copysignf((x + temp) - temp, x);
}

bool FloatingPointUtils::isNormal(double x)
Expand Down Expand Up @@ -2584,6 +2572,38 @@ bool FloatingPointUtils::isAllBitsSet(double val)
return bits == 0xFFFFFFFFFFFFFFFFULL;
}

//------------------------------------------------------------------------
// isFinite: Determines whether the specified value is finite
//
// Arguments:
// val - value to check is not NaN or infinity
//
// Return Value:
// True if val is finite
//

bool FloatingPointUtils::isFinite(float val)
{
UINT32 bits = *reinterpret_cast<UINT32*>(&val);
return (~bits & 0x7F800000U) != 0;
}

//------------------------------------------------------------------------
// isFinite: Determines whether the specified value is finite
//
// Arguments:
// val - value to check is not NaN or infinity
//
// Return Value:
// True if val is finite
//

bool FloatingPointUtils::isFinite(double val)
{
UINT64 bits = *reinterpret_cast<UINT64*>(&val);
return (~bits & 0x7FF0000000000000ULL) != 0;
}

//------------------------------------------------------------------------
// isNegative: Determines whether the specified value is negative
//
Expand Down Expand Up @@ -3202,6 +3222,32 @@ double FloatingPointUtils::normalize(double value)
#endif
}

int FloatingPointUtils::ilogb(double value)
{
if (value == 0.0)
{
return -2147483648;
}
else if (isNaN(value))
{
return 2147483647;
}
return ilogb(value);
}

int FloatingPointUtils::ilogb(float value)
{
if (value == 0.0f)
{
return -2147483648;
}
else if (isNaN(value))
{
return 2147483647;
}
return ilogbf(value);
}

//------------------------------------------------------------------------
// BitOperations::BitScanReverse: Search the mask data from most significant bit (MSB) to least significant bit
// (LSB) for a set bit (1).
Expand Down
8 changes: 8 additions & 0 deletions src/coreclr/jit/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,10 @@ class FloatingPointUtils

static bool isAllBitsSet(double val);

static bool isFinite(float val);

static bool isFinite(double val);

static bool isNegative(float val);

static bool isNegative(double val);
Expand Down Expand Up @@ -858,6 +862,10 @@ class FloatingPointUtils
static float minimumNumber(float val1, float val2);

static double normalize(double x);

static int ilogb(double x);

static int ilogb(float f);
};

class BitOperations
Expand Down
Loading