mirror of
https://github.com/mirror/tinycc.git
synced 2025-02-04 06:30:10 +08:00
win32 tcc_libm.h: Implemented overrides for msvcrt.dll's frexp(), ldexp(), and fabs() with speedups 4.5X, 7.3X and 6.3X correspondingly.
This is the last commit on this for now.
This commit is contained in:
parent
4a42b0d95e
commit
13a18906ef
@ -232,6 +232,23 @@ __CRT_INLINE double __cdecl scalbn(double x, int n) {
|
||||
return x * u.f;
|
||||
}
|
||||
|
||||
/* MUSL: Override msvcrt frexp(): 4.5x speedup! */
|
||||
|
||||
__CRT_INLINE double __cdecl frexp(double x, int *e) {
|
||||
union {double f; uint64_t i;} u = {.f = x};
|
||||
int ee = u.i>>52 & 0x7ff;
|
||||
if (!ee) {
|
||||
if (x) x = frexp(x*0x1p64, e), *e -= 64;
|
||||
else *e = 0;
|
||||
return x;
|
||||
} else if (ee == 0x7ff)
|
||||
return x;
|
||||
*e = ee - 0x3fe;
|
||||
u.i &= 0x800fffffffffffffull;
|
||||
u.i |= 0x3fe0000000000000ull;
|
||||
return u.f;
|
||||
}
|
||||
|
||||
/* MUSL nan */
|
||||
|
||||
__CRT_INLINE double __cdecl nan(const char* s) {
|
||||
@ -273,7 +290,11 @@ __CRT_INLINE long double __cdecl scalblnl(long double x, long n) {
|
||||
return scalbn(x, n);
|
||||
}
|
||||
|
||||
/* Override msvcrt ldexp(): 7.3x speedup! */
|
||||
|
||||
__CRT_INLINE double __cdecl ldexp(double x, int expn) {
|
||||
return scalbn(x, expn);
|
||||
}
|
||||
__CRT_INLINE float __cdecl ldexpf(float x, int expn) {
|
||||
return scalbn(x, expn);
|
||||
}
|
||||
@ -391,14 +412,16 @@ __CRT_INLINE long double __cdecl nexttowardl(long double x, long double to) {
|
||||
return nextafter(x, to);
|
||||
}
|
||||
|
||||
/* Override msvcrt fabs(): 6.3x speedup! */
|
||||
|
||||
__CRT_INLINE float __cdecl fabsf (float x) {
|
||||
union {float f; uint32_t i;} u = {.f = x};
|
||||
u.i &= 0x7fffffff; return u.f;
|
||||
__CRT_INLINE double __cdecl fabs(double x) {
|
||||
return x < 0 ? -x : x;
|
||||
}
|
||||
__CRT_INLINE long double __cdecl fabsl (long double x) {
|
||||
union {double f; uint64_t i;} u = {.f = x};
|
||||
u.i &= 0x7fffffffffffffff; return u.f;
|
||||
__CRT_INLINE float __cdecl fabsf(float x) {
|
||||
return x < 0 ? -x : x;
|
||||
}
|
||||
__CRT_INLINE long double __cdecl fabsl(long double x) {
|
||||
return x < 0 ? -x : x;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user