Skip to content

Commit 40b7da8

Browse files
committed
Speed up fmaf() on x86
1 parent 6406689 commit 40b7da8

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

libc/tinymath/fmaf.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ float fmaf(float x, float y, float z)
100100

101101
#else
102102

103+
#ifdef __x86_64__
104+
if (X86_HAVE(FMA)) {
105+
asm("vfmadd132ss\t%1,%2,%0" : "+x"(x) : "x"(y), "x"(z));
106+
return x;
107+
} else if (X86_HAVE(FMA4)) {
108+
asm("vfmaddss\t%3,%2,%1,%0" : "=x"(x) : "x"(x), "x"(y), "x"(z));
109+
return x;
110+
}
111+
#endif
112+
103113
/* A double has more than twice as much precision than a float,
104114
so direct double-precision arithmetic suffices, except where
105115
double rounding occurs. */

0 commit comments

Comments
 (0)