[glibc] math: Add fast-path to fma

Adhemerval Zanella via Glibc-cvs <[email protected]>
Newsgroups gmane.comp.lib.glibc.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=dfb150f3aadd93118a78ef9e19c2663f0e1994b7

commit dfb150f3aadd93118a78ef9e19c2663f0e1994b7
Author: Adhemerval Zanella <[email protected]>
Date:   Mon Mar 9 17:11:12 2026 -0300

    math: Add fast-path to fma
    
    For normal numbers there is no need to issue scalbn, the fma can set
    the exponend directly.   Performance-wise on x86_64-linux-gnu without
    multi-arch it shows a latency improvement of ~5% and throughput of %7
    (and sligth more for ABIs witht tail-call optimization).
    
    Checked on x86_64-linux-gnu and i686-linux-gnu with --disable-multi-arch.
    Reviewed-by: Wilco Dijkstra  <[email protected]>

Diff:
---
 sysdeps/ieee754/dbl-64/s_fma.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/sysdeps/ieee754/dbl-64/s_fma.c b/sysdeps/ieee754/dbl-64/s_fma.c
index d65d505915..88bda86943 100644
--- a/sysdeps/ieee754/dbl-64/s_fma.c
+++ b/sysdeps/ieee754/dbl-64/s_fma.c
@@ -192,7 +192,10 @@ __fma (double x, double y, double z)
     i = -i;
   double r = convertfromint64 (i); /* |r| is in [0x1p62,0x1p63] */
 
-  if (e < -1022 - 62)
+  if (__glibc_likely (e >= -1084 && e <= 960))
+    /* Fast-path for normal numbers.  */
+    return asdouble (asuint64 (r) + ((int64_t) e << MANTISSA_WIDTH));
+  else if (e < -1022 - 62)
     {
       /* Result is subnormal before rounding.  */
       if (e == -1022 - 63)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.