From nobody Wed Oct 1 09:31:00 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548194191131825.6233153475359; Tue, 22 Jan 2019 13:56:31 -0800 (PST) Received: from localhost ([127.0.0.1]:50867 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gm422-00049D-0z for importer@patchew.org; Tue, 22 Jan 2019 16:56:30 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60932) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gm3wQ-0007SZ-Bh for qemu-devel@nongnu.org; Tue, 22 Jan 2019 16:50:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gm3wP-0008Eu-25 for qemu-devel@nongnu.org; Tue, 22 Jan 2019 16:50:42 -0500 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:53089) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gm3wL-0007ph-70 for qemu-devel@nongnu.org; Tue, 22 Jan 2019 16:50:37 -0500 Received: by mail-wm1-x341.google.com with SMTP id m1so81910wml.2 for ; Tue, 22 Jan 2019 13:50:23 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id f187sm39611990wma.4.2019.01.22.13.50.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Jan 2019 13:50:19 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id AD8E33E0B76; Tue, 22 Jan 2019 21:50:16 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=faBd61OejxUkxq2rvQ3pDsb42Y/YIlwTE9s8AKa1cmg=; b=KeP0kqWau5nI7FaqnskD8K9BYGaUs789d8O9AfKetFJ/Y1t/oWMlUn3MgA26p7Sg4n acl1XhdHokeENrbBPX3G7UqIvpB6iIeVZJHqhV/kPg1q6sU6ZtIEczVgg6UPgjQfqyNW 0zDK5tbBhq+OgNjlIKZexY8edRBF2YIjSMD6I= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=faBd61OejxUkxq2rvQ3pDsb42Y/YIlwTE9s8AKa1cmg=; b=E4gTOxL0JH+K9CpANJye0kH7W21OceD6rF1KIYI672D5Wtxr/AobSnPTR28WFMRdhT puOrDoRMzWsOYPYn2aCUOhTrIiSXInYXuDV5QGbX1kB1XBPjFtJP8KkDG65GK8lZiSjy l+EzZFvWo0fe1fMm8Oaht73Qqzc6rlZxloPzyHeaEPPue94CYD9+fK5+NNlvxEceAj10 zJRYi9CSCaJP7TM6TaAC0wsy1npp82oys7wYHu3iYFJdhrW+OmVy3cWSEBMrnFBz9tC5 +DsUTBNjiBIwUkDZVaSslF4Lw+qQqV2dtpY+2Kr370LEuBj/VdVQSF0P3Xva00rXlVWq qlpA== X-Gm-Message-State: AJcUukfCe7LzD+I9mZE8Q58LEJirT3ZHOJZYUpv3ZCU00bT+m4HOLAbX 6WYq7cI30M1F5i4VdJyGaF6lQ47qDJY= X-Google-Smtp-Source: ALg8bN61uy/vPybzTOiC7FIguQXKpDOaCMEiwkjCtmWetfrlPXenHA2d+J5I1jAlhkZ700OQvPkE7Q== X-Received: by 2002:a1c:4855:: with SMTP id v82mr179502wma.15.1548193822289; Tue, 22 Jan 2019 13:50:22 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Tue, 22 Jan 2019 21:50:12 +0000 Message-Id: <20190122215016.18697-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190122215016.18697-1-alex.bennee@linaro.org> References: <20190122215016.18697-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 Subject: [Qemu-devel] [PATCH v3 07/11] softfloat: enforce softfloat if the host's FMA is broken X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Emilio G. Cota" , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Aurelien Jarno Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: "Emilio G. Cota" The added branch to the FMA ops is marked as unlikely and therefore its impact on performance (measured with fp-bench) is within noise range when measured on an Intel(R) Xeon(R) Gold 6142 CPU @ 2.60GHz. Reported-by: Laurent Desnogues Signed-off-by: Emilio G. Cota Reviewed-by: Richard Henderson Signed-off-by: Alex Benn=C3=A9e --- fpu/softfloat.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 59eac97d10..9132d7a0b0 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -1542,6 +1542,8 @@ soft_f64_muladd(float64 a, float64 b, float64 c, int = flags, return float64_round_pack_canonical(pr, status); } =20 +static bool force_soft_fma; + float32 QEMU_FLATTEN float32_muladd(float32 xa, float32 xb, float32 xc, int flags, float_status= *s) { @@ -1562,6 +1564,11 @@ float32_muladd(float32 xa, float32 xb, float32 xc, i= nt flags, float_status *s) if (unlikely(!f32_is_zon3(ua, ub, uc))) { goto soft; } + + if (unlikely(force_soft_fma)) { + goto soft; + } + /* * When (a || b) =3D=3D 0, there's no need to check for under/over flo= w, * since we know the addend is (normal || 0) and the product is 0. @@ -1623,6 +1630,11 @@ float64_muladd(float64 xa, float64 xb, float64 xc, i= nt flags, float_status *s) if (unlikely(!f64_is_zon3(ua, ub, uc))) { goto soft; } + + if (unlikely(force_soft_fma)) { + goto soft; + } + /* * When (a || b) =3D=3D 0, there's no need to check for under/over flo= w, * since we know the addend is (normal || 0) and the product is 0. @@ -7974,3 +7986,24 @@ float128 float128_scalbn(float128 a, int n, float_st= atus *status) , status); =20 } + +static void __attribute__((constructor)) softfloat_init(void) +{ + union_float64 ua, ub, uc, ur; + + if (QEMU_NO_HARDFLOAT) { + return; + } + /* + * Test that the host's FMA is not obviously broken. For example, + * glibc < 2.23 can perform an incorrect FMA on certain hosts; see + * https://sourceware.org/bugzilla/show_bug.cgi?id=3D13304 + */ + ua.s =3D 0x0020000000000001ULL; + ub.s =3D 0x3ca0000000000000ULL; + uc.s =3D 0x0020000000000000ULL; + ur.h =3D fma(ua.h, ub.h, uc.h); + if (ur.s !=3D 0x0020000000000001ULL) { + force_soft_fma =3D true; + } +} --=20 2.17.1