On 6/3/22, Martin Storsjö <[email protected]> wrote:
>
> For long double, I would presume that you'd still need to use x87, as SSE
> can't handle 80 bit long doubles, right? (Or converting down to a plain
> double first, then using SSE, probably also works - but I guess that also
> might generate x87 instructions.)

I wasn't sure about long double anyway, won't touch that.

> For the other functions, do the SSE intrinsics honor the rounding
> mode/direction that you've set fesetround()?
>
> // Martin

Documentation [1] doesn't seem to have such detail.

Haven't booted to windows, but ran the following on i686 linux:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <fenv.h>
#include <xmmintrin.h>

static __inline long lrint_x87(double _x) {
    long val;
    __asm__ __volatile__ ("fistpl %0" : "=m" (val) : "t" (_x) : "st");
    return val;
}

int main (int argc, char **argv)
{
    long x87, sse2;
    double d;
    if (argc != 2) return -1;
    d = atof(argv[1]);
    fesetround(FE_DOWNWARD);
    x87 = lrint_x87(d);
    sse2 = _mm_cvtsd_si32(_mm_load_sd(&d));
    printf("%ld, %ld\n", x87, sse2);
    return 0;
}

If I keep the fesetround(FE_DOWNWARD); line uncommented,
it prints 1 for 1.999 instead of 2.

--
O.S.

[1] 
https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#techs=SSE2&ig_expand=4288,2216,2215&text=_mm_cvtsd_si32


_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to