Skip to content

Commit

Permalink
PAL math and memory API clean up
Browse files Browse the repository at this point in the history
Remove externally visible redifinitions of math and memory management
functions. Delete corresponding math function implementations, as they
pretty much call their system counterparts. Hide memory management
functions, since they are still used from inside of PAL.

CC chakra-core#6404
  • Loading branch information
ppenzin committed Feb 12, 2021
1 parent acaa38c commit 1fc39e8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 254 deletions.
2 changes: 2 additions & 0 deletions lib/Runtime/Base/jitprofiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

#include "ittnotify_config.h"

#ifdef ITT_PLATFORM
#if ITT_PLATFORM==ITT_PLATFORM_WIN
#include <windows.h>
#endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
#if ITT_PLATFORM != ITT_PLATFORM_MAC && ITT_PLATFORM != ITT_PLATFORM_FREEBSD
#include <malloc.h>
#endif
#endif
#include <stdlib.h>

#include "jitprofiling.h"
Expand Down
55 changes: 8 additions & 47 deletions pal/inc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -6089,7 +6089,6 @@ CoCreateGuid(OUT GUID * pguid);
#define towupper PAL_towupper
#define vsprintf PAL_vsprintf
#define vswprintf PAL_vswprintf
#define realloc PAL_realloc
#define fopen PAL_fopen
#define strtok PAL_strtok
#define strtoul PAL_strtoul
Expand Down Expand Up @@ -6122,16 +6121,7 @@ CoCreateGuid(OUT GUID * pguid);
#define ungetc PAL_ungetc
#define setvbuf PAL_setvbuf
#define atol PAL_atol
#define acos PAL_acos
#define asin PAL_asin
#define atan2 PAL_atan2
#define exp PAL_exp
#define labs PAL_labs
#define log PAL_log
#define log10 PAL_log10
#define malloc PAL_malloc
#define memmove memmove_xplat
#define free PAL_free
#define mkstemp PAL_mkstemp
#define rename PAL_rename
#define unlink PAL_unlink
Expand Down Expand Up @@ -6195,7 +6185,7 @@ PALIMPORT int __cdecl vsprintf(char *, const char *, va_list);
PALIMPORT int __cdecl sscanf(const char *, const char *, ...);
PALIMPORT int __cdecl atoi(const char *);
PALIMPORT LONG __cdecl atol(const char *);
PALIMPORT long long int __cdecl atoll(const char *);
//PALIMPORT long long int __cdecl atoll(const char *) __THROW;
PALIMPORT ULONG __cdecl strtoul(const char *, char **, int);
PALIMPORT double __cdecl atof(const char *);
PALIMPORT double __cdecl strtod(const char *, char **);
Expand Down Expand Up @@ -6372,39 +6362,6 @@ unsigned long long __cdecl _rotr64(unsigned long long value, int shift)
}
#endif

PALIMPORT int __cdecl abs(int);
PALIMPORT double __cdecl fabs(double);
#ifndef PAL_STDCPP_COMPAT
PALIMPORT LONG __cdecl labs(LONG);
PALIMPORT double __cdecl fabs(double);
#endif // !PAL_STDCPP_COMPAT
// clang complains if this is declared with __int64
PALIMPORT long long __cdecl llabs(long long);

PALIMPORT double __cdecl sqrt(double);
PALIMPORT double __cdecl log(double);
PALIMPORT double __cdecl log10(double);
PALIMPORT double __cdecl exp(double);
PALIMPORT double __cdecl acos(double);
PALIMPORT double __cdecl asin(double);
PALIMPORT double __cdecl atan(double);
PALIMPORT double __cdecl atan2(double,double);
PALIMPORT double __cdecl cos(double);
PALIMPORT double __cdecl sin(double);
PALIMPORT double __cdecl tan(double);
PALIMPORT double __cdecl cosh(double);
PALIMPORT double __cdecl sinh(double);
PALIMPORT double __cdecl tanh(double);
PALIMPORT double __cdecl fmod(double, double);
PALIMPORT float __cdecl fmodf(float, float);
PALIMPORT double __cdecl floor(double);
PALIMPORT float __cdecl floorf(float);
PALIMPORT double __cdecl ceil(double);
PALIMPORT float __cdecl ceilf(float);
PALIMPORT float __cdecl fabsf(float);
PALIMPORT double __cdecl modf(double, double *);
PALIMPORT float __cdecl modff(float, float *);

PALIMPORT int __cdecl _finite(double);
PALIMPORT int __cdecl _isnan(double);
PALIMPORT double __cdecl _copysign(double, double);
Expand All @@ -6424,9 +6381,13 @@ inline __int64 abs(__int64 _X) {
#endif
#endif

PALIMPORT void * __cdecl malloc(size_t);
PALIMPORT void __cdecl free(void *);
PALIMPORT void * __cdecl realloc(void *, size_t);
#ifdef INCLUDE_PAL_INTERNAL_
/* FIXME remove
* PAL wrappers around memory management functions, only used inside PAL */
PALIMPORT void * __cdecl PAL_malloc(size_t);
PALIMPORT void __cdecl PAL_free(void *);
PALIMPORT void * __cdecl PAL_realloc(void *, size_t);
#endif
PALIMPORT char * __cdecl _strdup(const char *);

#if defined(_MSC_VER)
Expand Down
207 changes: 0 additions & 207 deletions pal/src/cruntime/finite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,210 +136,3 @@ _copysignf(
return ret;
}

/*++
Function:
acos
See MSDN.
--*/
PALIMPORT double __cdecl PAL_acos(double x)
{
double ret;

PERF_ENTRY(acos);
ENTRY("acos (x=%f)\n", x);
#if !HAVE_COMPATIBLE_ACOS
errno = 0;
#endif // HAVE_COMPATIBLE_ACOS
ret = acos(x);
#if !HAVE_COMPATIBLE_ACOS
if (errno == EDOM)
{
ret = PAL_NAN; // NaN
}
#endif // HAVE_COMPATIBLE_ACOS
LOGEXIT("acos returns double %f\n", ret);
PERF_EXIT(acos);
return ret;
}

/*++
Function:
asin
See MSDN.
--*/
PALIMPORT double __cdecl PAL_asin(double x)
{
double ret;

PERF_ENTRY(asin);
ENTRY("asin (x=%f)\n", x);
#if !HAVE_COMPATIBLE_ASIN
errno = 0;
#endif // HAVE_COMPATIBLE_ASIN
ret = asin(x);
#if !HAVE_COMPATIBLE_ASIN
if (errno == EDOM)
{
ret = PAL_NAN; // NaN
}
#endif // HAVE_COMPATIBLE_ASIN
LOGEXIT("asin returns double %f\n", ret);
PERF_EXIT(asin);
return ret;
}

/*++
Function:
atan2
See MSDN.
--*/
PALIMPORT double __cdecl PAL_atan2(double y, double x)
{
double ret;

PERF_ENTRY(atan2);
ENTRY("atan2 (y=%f, x=%f)\n", y, x);
#if !HAVE_COMPATIBLE_ATAN2
errno = 0;
#endif // !HAVE_COMPATIBLE_ATAN2
ret = atan2(y, x);
#if !HAVE_COMPATIBLE_ATAN2
if (errno == EDOM)
{
#if HAVE_COPYSIGN
if (x == 0.0 && y == 0.0)
{
const double sign_x = copysign (1.0, x);
const double sign_y = copysign (1.0, y);
if (sign_x > 0)
{
ret = copysign (0.0, sign_y);
}
else
{
ret = copysign (atan2 (0.0, -1.0), sign_y);
}
}
#else // HAVE_COPYSIGN
#error Missing copysign or equivalent on this platform!
#endif // HAVE_COPYSIGN
}
#endif // !HAVE_COMPATIBLE_ATAN2
LOGEXIT("atan2 returns double %f\n", ret);
PERF_EXIT(atan2);
return ret;
}

/*++
Function:
exp
See MSDN.
--*/
PALIMPORT double __cdecl PAL_exp(double x)
{
double ret;

PERF_ENTRY(exp);
ENTRY("exp (x=%f)\n", x);
#if !HAVE_COMPATIBLE_EXP
if (x == 1.0)
{
ret = M_E;
}
else
{
ret = exp(x);
}
#else // !HAVE_COMPATIBLE_EXP
ret = exp(x);
#endif // !HAVE_COMPATIBLE_EXP
LOGEXIT("exp returns double %f\n", ret);
PERF_EXIT(exp);
return ret;
}

/*++
Function:
labs
See MSDN.
--*/
PALIMPORT LONG __cdecl PAL_labs(LONG l)
{
long lRet;

PERF_ENTRY(labs);
ENTRY("labs (l=%ld)\n", l);

lRet = labs(l);

LOGEXIT("labs returns long %ld\n", lRet);
PERF_EXIT(labs);
/* This explicit cast to LONG is used to silence any potential warnings
due to implicitly casting the native long lRet to LONG when returning. */
return (LONG)lRet;
}

/*++
Function:
log
See MSDN.
--*/
PALIMPORT double __cdecl PAL_log(double x)
{
double ret;

PERF_ENTRY(log);
ENTRY("log (x=%f)\n", x);
#if !HAVE_COMPATIBLE_LOG
errno = 0;
#endif // !HAVE_COMPATIBLE_LOG
ret = log(x);
#if !HAVE_COMPATIBLE_LOG
if (errno == EDOM)
{
if (x < 0)
{
ret = PAL_NAN; // NaN
}
}
#endif // !HAVE_COMPATIBLE_LOG
LOGEXIT("log returns double %f\n", ret);
PERF_EXIT(log);
return ret;
}

/*++
Function:
log10
See MSDN.
--*/
PALIMPORT double __cdecl PAL_log10(double x)
{
double ret;

PERF_ENTRY(log10);
ENTRY("log10 (x=%f)\n", x);
#if !HAVE_COMPATIBLE_LOG10
errno = 0;
#endif // !HAVE_COMPATIBLE_LOG10
ret = log10(x);
#if !HAVE_COMPATIBLE_LOG10
if (errno == EDOM)
{
if (x < 0)
{
ret = PAL_NAN; // NaN
}
}
#endif // !HAVE_COMPATIBLE_LOG10
LOGEXIT("log10 returns double %f\n", ret);
PERF_EXIT(log10);
return ret;
}

0 comments on commit 1fc39e8

Please sign in to comment.