[0/3] fp_barrier improvements

Submitted by Szabolcs Nagy on April 27, 2019, 10:13 p.m.

Details

Message ID 20190427221334.GK26605@port70.net
State New
Series "fp_barrier improvements"
Headers show

Patch hide | download patch | download mbox

From 34341757cbaffc878f10676aeb6820f3a02ac29d Mon Sep 17 00:00:00 2001
From: Szabolcs Nagy <nsz@port70.net>
Date: Sat, 27 Apr 2019 19:32:49 +0000
Subject: [PATCH 3/3] math: use fp_force_eval and fp_barrier in fma

Idiomatic fenv handling with the new fp_arch.h, less portable, but
it means a bit smaller code size.
---
 src/math/fma.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/math/fma.c b/src/math/fma.c
index 0c6f90c9..84dfeec1 100644
--- a/src/math/fma.c
+++ b/src/math/fma.c
@@ -1,6 +1,7 @@ 
 #include <stdint.h>
 #include <float.h>
 #include <math.h>
+#include "libm.h"
 #include "atomic.h"
 
 #define ASUINT64(x) ((union {double f; uint64_t i;}){x}).i
@@ -163,11 +164,10 @@  double fma(double x, double y, double z)
 				r = i;
 				r = 2*r - c; /* remove top bit */
 
-				/* raise underflow portably, such that it
-				   cannot be optimized away */
+				/* raise underflow */
 				{
-					double_t tiny = DBL_MIN/FLT_MIN * r;
-					r += (double)(tiny*tiny) * (r-r);
+					double_t tiny = fp_barrier(DBL_MIN/FLT_MIN);
+					fp_force_eval(tiny*tiny);
 				}
 			}
 		} else {
-- 
2.21.0