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:
grischka 2020-02-24 15:48:01 +01:00
parent 024214af2d
commit d019586378

View file

@ -496,7 +496,7 @@ extern "C" {
__asm__ ( __asm__ (
"fldl %1\n" "fldl %1\n"
"frndint \n" "frndint \n"
"fstl %0\n" : "=m" (retval) : "m" (x)); "fstpl %0\n" : "=m" (retval) : "m" (x));
return retval; return retval;
} }
@ -506,18 +506,23 @@ extern "C" {
__asm__ ( __asm__ (
"flds %1\n" "flds %1\n"
"frndint \n" "frndint \n"
"fsts %0\n" : "=m" (retval) : "m" (x)); "fstps %0\n" : "=m" (retval) : "m" (x));
return retval; return retval;
} }
__CRT_INLINE long double __cdecl rintl (long double x) __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; long double retval;
__asm__ ( __asm__ (
"fldt %1\n" "fldt %1\n"
"frndint \n" "frndint \n"
"fstt %0\n" : "=m" (retval) : "m" (x)); "fstpt %0\n" : "=m" (retval) : "m" (x));
return retval; return retval;
#endif
} }
/* 7.12.9.5 */ /* 7.12.9.5 */
@ -591,7 +596,7 @@ extern "C" {
__asm__ ("fldcw %0;" : : "m" (tmp_cw)); __asm__ ("fldcw %0;" : : "m" (tmp_cw));
__asm__ ("fldl %1;" __asm__ ("fldl %1;"
"frndint;" "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 */ __asm__ ("fldcw %0;" : : "m" (saved_cw) ); /* restore saved control word */
return retval; return retval;
} }