mirror of
https://github.com/frida/tinycc
synced 2025-01-11 22:29:18 +03:00
win32/include/math.h: rint/trunc: pop fp stack
... in order to avoid fp stack overflow (see test below). #include <math.h> #include <stdio.h> int main() { printf("%f %f %f %f\n", trunc(1.2), rint(1.2), trunc(1.2), rint(1.2)); printf("%f %f %f %f\n", trunc(1.2), rint(1.2), trunc(1.2), rint(1.2)); printf("%f %f %f %f\n", trunc(1.2), rint(1.2), trunc(1.2), rintl(1.2)); } Also in rintl: - 'long double' is not a ten-byte float on windows.
This commit is contained in:
parent
024214af2d
commit
d019586378
@ -496,7 +496,7 @@ extern "C" {
|
||||
__asm__ (
|
||||
"fldl %1\n"
|
||||
"frndint \n"
|
||||
"fstl %0\n" : "=m" (retval) : "m" (x));
|
||||
"fstpl %0\n" : "=m" (retval) : "m" (x));
|
||||
return retval;
|
||||
}
|
||||
|
||||
@ -506,18 +506,23 @@ extern "C" {
|
||||
__asm__ (
|
||||
"flds %1\n"
|
||||
"frndint \n"
|
||||
"fsts %0\n" : "=m" (retval) : "m" (x));
|
||||
"fstps %0\n" : "=m" (retval) : "m" (x));
|
||||
return retval;
|
||||
}
|
||||
|
||||
__CRT_INLINE long double __cdecl rintl (long double x)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
// on win32 'long double' is double internally
|
||||
return rint(x);
|
||||
#else
|
||||
long double retval;
|
||||
__asm__ (
|
||||
"fldt %1\n"
|
||||
"frndint \n"
|
||||
"fstt %0\n" : "=m" (retval) : "m" (x));
|
||||
"fstpt %0\n" : "=m" (retval) : "m" (x));
|
||||
return retval;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* 7.12.9.5 */
|
||||
@ -591,7 +596,7 @@ extern "C" {
|
||||
__asm__ ("fldcw %0;" : : "m" (tmp_cw));
|
||||
__asm__ ("fldl %1;"
|
||||
"frndint;"
|
||||
"fstl %0;" : "=m" (retval) : "m" (_x)); /* round towards zero */
|
||||
"fstpl %0;" : "=m" (retval) : "m" (_x)); /* round towards zero */
|
||||
__asm__ ("fldcw %0;" : : "m" (saved_cw) ); /* restore saved control word */
|
||||
return retval;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user