Easiest way to use FMA instruction
Ben Jones
fake at fake.fake
Thu Jan 9 22:50:37 UTC 2020
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;
}
}
`
More information about the Digitalmars-d-learn
mailing list