qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] utils: Use fma in qemu_strtosz
@ 2021-03-14 23:48 Richard Henderson
  2021-03-15  5:32 ` Thomas Huth
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Richard Henderson @ 2021-03-14 23:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, berrange

Use fma to simulatneously scale and round up fraction.

The libm function will always return a properly rounded double precision
value, which will eliminate any extra precision the x87 co-processor may
give us, which will keep the output predictable vs other hosts.

Adding DBL_EPSILON while scaling should help with fractions like
12.345, where the closest representable number is actually 12.3449*.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 util/cutils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/cutils.c b/util/cutils.c
index d89a40a8c3..f7f8e48a68 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -342,7 +342,7 @@ static int do_strtosz(const char *nptr, const char **end,
         retval = -ERANGE;
         goto out;
     }
-    *result = val * mul + (uint64_t) (fraction * mul);
+    *result = val * mul + (uint64_t)fma(fraction, mul, DBL_EPSILON);
     retval = 0;
 
 out:
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-03-15 13:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-14 23:48 [PATCH] utils: Use fma in qemu_strtosz Richard Henderson
2021-03-15  5:32 ` Thomas Huth
2021-03-15 13:20   ` Richard Henderson
2021-03-15  9:10 ` Philippe Mathieu-Daudé
2021-03-15 11:40   ` Eric Blake
2021-03-15 13:19   ` Richard Henderson
2021-03-15 11:38 ` Eric Blake
2021-03-15 13:27   ` Richard Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).