From patchwork Sun Mar 14 23:48:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 400230 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2980998jai; Sun, 14 Mar 2021 16:52:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlnuvYtWPiXNAAvq4DYOTVhSiIxi3U66V98Aovp8NzS8WcY5VcfH7gVDLju/0zW8s1075C X-Received: by 2002:a25:ddc3:: with SMTP id u186mr32105779ybg.238.1615765934450; Sun, 14 Mar 2021 16:52:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615765934; cv=none; d=google.com; s=arc-20160816; b=mE6vMbRc9I9wjE74wwa8cIvW1tno5brBdrfNXMtOEtzEjAUVl12AqJ0TcyFmUMy7LN SCR+PPpzQoTEdUeK/VL3A/ue++XM9ALFYfOPSe1hLDipnBeiRt1UAVBmzpdO77EaoBrt z6SKyuvkAz1xsrkgQUQC30BU0YsOsJOVBrbknBxBtJZfLAt42veM9VX6y+vJOMVwbbYg qS4az3udug6P5ncGIweyxTHSKAxErjG480S1Xmfnx5fBBpU0qy1aqxA7HbZmKE2k4yOM ftLvSDdBMer3rN7IJNOWNQfYqyOo+fsNtmMHzYlxbQbbnBA7l9cuBhMYhFlF7zUB6fGS d5vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature; bh=wNCxluSBSDLQf80mm1IAxRjvrsypZp9PbQQJIGVe3gs=; b=h96bWBOq3sLdHttKvJWAnS5Zy/32xOVeFjK3FjWc0WgK7wwo12Rx9v4G/bPwAHTbu9 UOnMKkqFssU688RqovDBFuQJyORTnv036e2cIEBJ+far4+WChaTSMmqyU5D8IzDuir1z x/MhU04dZYQL7C3sdEiG3ZhBxa866Xb/RCA2HkXTr8UqTgBOx9S1I2gMV8uU+BDx9Djh G9XrDQ4UIQ/8ErLlg+q2H2EU3ymKzJvhJlOMVMBEnsjpj4IdtN4PW/S9KUxPMLC/acbh o4ag8mkRU8wqwfpvYfEgOI2pawHaxQ7+iZXSOSSnqkP234jBiI8IKVGjuqvoe8m5BCsk womQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=jbvw42eW; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w62si13591981ybe.483.2021.03.14.16.52.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 14 Mar 2021 16:52:14 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=jbvw42eW; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:35218 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLaWr-0003vx-Qp for patch@linaro.org; Sun, 14 Mar 2021 19:52:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46950) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLaTD-0001ie-Jw for qemu-devel@nongnu.org; Sun, 14 Mar 2021 19:48:31 -0400 Received: from mail-qv1-xf2e.google.com ([2607:f8b0:4864:20::f2e]:41503) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLaTB-0003oT-F3 for qemu-devel@nongnu.org; Sun, 14 Mar 2021 19:48:27 -0400 Received: by mail-qv1-xf2e.google.com with SMTP id h3so6970069qvh.8 for ; Sun, 14 Mar 2021 16:48:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=wNCxluSBSDLQf80mm1IAxRjvrsypZp9PbQQJIGVe3gs=; b=jbvw42eWcjDrm7NBRH0KB8lQ10kMcTuYdeKVbVKkxLZQnLM6yT5buJZ5t3DKDbzMw3 gbUH+sN6DZhD7gGQoXe3RGXJmK1a/PDsxm21rz2kRTr/VxnlFPjyrCgLOFW4pTniaO32 Om4KGxDNkGTP3Wkbv6zU8NcVfPtYWHMRCevXGtOdG4Rqk5ItHuZ2+RGgfq3XbU8C1uJB RrN5llivISAOY6M00Xt9Muzom3FI0AUh8r7vQqT/s3wpfo7cMWKgELTxLmVk/SXt4LzY ulycO9123musKHUkik6h7mCPodVB/0g7Y3RBfNF3U6uQVRUfLp9Q6twD8uP97IVE4Y5i 0ZeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=wNCxluSBSDLQf80mm1IAxRjvrsypZp9PbQQJIGVe3gs=; b=bfvn17S++fSByPckw1S4xpzesgN5/jIeLrY6jZR9Kmkl7q1HoMjnEnx1A3zkc6RsJ8 oTAYT7NeqCSe5HmiWD4sIMIs7qgQs4nQSGxEDca43agpxKUJUgS3Dp7NKENPvImp8dYa +PO4GLIznET7Wx2GiXeVTDJsQFFgVbO35EXIl+fHgetkJeZjuyIyBuoWezytU4gJrhcJ ts9gd1u0mOU2oLVj0pLugBwPSX5rPxnHuVtCmsviSuTeplUk9UTSiE3aUfuDjaACQyuu 5zol8tm9n0z+ZrMS1YL2bV0BrYrIQfPJn15rrmGVgTgSfFROfJxT6okbE1H4gizgV7Sr jI/w== X-Gm-Message-State: AOAM530rxVjmC+Zn6LL2XgGpxFGb9q8tOxKg787IKNjOhP2Zesmy4fqZ 8FSP/X+8cWzhGaYa8HdCRoQkgTIYEC0P8Y7h X-Received: by 2002:a0c:fe0c:: with SMTP id x12mr8187095qvr.16.1615765703978; Sun, 14 Mar 2021 16:48:23 -0700 (PDT) Received: from localhost.localdomain (fixed-187-189-51-144.totalplay.net. [187.189.51.144]) by smtp.gmail.com with ESMTPSA id f186sm11192370qkj.106.2021.03.14.16.48.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 16:48:23 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH] utils: Use fma in qemu_strtosz Date: Sun, 14 Mar 2021 17:48:21 -0600 Message-Id: <20210314234821.1954428-1-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::f2e; envelope-from=richard.henderson@linaro.org; helo=mail-qv1-xf2e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, berrange@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- util/cutils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.25.1 Reviewed-by: Thomas Huth 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: