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
1 changed files with 29 additions and 6 deletions
|
@ -232,6 +232,23 @@ __CRT_INLINE double __cdecl scalbn(double x, int n) {
|
||||||
return x * u.f;
|
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 */
|
/* MUSL nan */
|
||||||
|
|
||||||
__CRT_INLINE double __cdecl nan(const char* s) {
|
__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);
|
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) {
|
__CRT_INLINE float __cdecl ldexpf(float x, int expn) {
|
||||||
return scalbn(x, 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);
|
return nextafter(x, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Override msvcrt fabs(): 6.3x speedup! */
|
||||||
|
|
||||||
__CRT_INLINE float __cdecl fabsf (float x) {
|
__CRT_INLINE double __cdecl fabs(double x) {
|
||||||
union {float f; uint32_t i;} u = {.f = x};
|
return x < 0 ? -x : x;
|
||||||
u.i &= 0x7fffffff; return u.f;
|
|
||||||
}
|
}
|
||||||
__CRT_INLINE long double __cdecl fabsl (long double x) {
|
__CRT_INLINE float __cdecl fabsf(float x) {
|
||||||
union {double f; uint64_t i;} u = {.f = x};
|
return x < 0 ? -x : x;
|
||||||
u.i &= 0x7fffffffffffffff; return u.f;
|
}
|
||||||
|
__CRT_INLINE long double __cdecl fabsl(long double x) {
|
||||||
|
return x < 0 ? -x : x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue