On Thursday, 9 January 2020 at 20:57:10 UTC, Ben Jones wrote:
What's the easiest way to use the FMA instruction (fused multiply add that has nice rounding properties)? The FMA function in Phobos just does a*b +c which will round twice.

Do any of the intrinsics libraries include this? Should I write my own inline ASM?

This seems to work with DMD, but seems fragile:

`
///returns round(a*b + c) -- computed as if in infinite precision, rounded at the end
double fma(double a, double b, double c) @safe pure @nogc nothrow{
    asm @safe pure @nogc nothrow {
        naked;
        vfmadd231sd XMM0, XMM1, XMM2;
        ret;
    }
}
`

Reply via email to