From nobody Fri Nov 7 02:12:28 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 154572146907163.547288649255734; Mon, 24 Dec 2018 23:04:29 -0800 (PST) Received: from localhost ([127.0.0.1]:39940 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbglI-0001So-92 for importer@patchew.org; Tue, 25 Dec 2018 02:04:20 -0500 Received: from eggs.gnu.org ([208.118.235.92]:58284) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbgkC-00011S-UE for qemu-devel@nongnu.org; Tue, 25 Dec 2018 02:03:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gbgk7-0008QT-VG for qemu-devel@nongnu.org; Tue, 25 Dec 2018 02:03:12 -0500 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:52511) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gbgk7-0008QE-NT for qemu-devel@nongnu.org; Tue, 25 Dec 2018 02:03:07 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 4BD3121B6F; Tue, 25 Dec 2018 02:03:07 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 25 Dec 2018 02:03:07 -0500 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 92273100B9; Tue, 25 Dec 2018 02:03:05 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id; s=mesmtp; bh=fDbeFzt/7Pv662V tdY1varHQFAL6/NTq/Qv2oxF4fSc=; b=TkeeqQG6zbq5YKnm0rx7yERvS+jXCPc 1HHsvKX4kU5Mg7UxP7CuTvT60HokzRSjWgJrpOcxshHFGUuXH+nN300uRXA4hECf rPGpQ7Rr90Z/asMXkrq2Lqk8xkQr6tvAZl+4bLErvSXMrJTgu6HxfC6CaZYSRoDs fTU1aCEbfeFE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:message-id:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=fDbeFzt/7Pv662VtdY1varHQFAL6/NTq/Qv2oxF4fSc=; b=MQJAkD1n ipmESQYoNCi7d729yLtzq9HynML8pQOSnsQxBuGzGIFqYnIEr5f7V4k7K413l9IR zrkqi9JcFWPNEzLSd74Ok9SPwYmcbs6qqdh8hDLO3d2EmOWncKaxvraa3L4i54vE +DE2MRPkG141SEdI/tqyvTv1gDy99gLdhsizV9TyXa87yNY4rXvmZ/5+CFgKK8/h Yk4hhNgZVfG+fx209vd1DMpHLVwNH6CNNGjLwbsaiTAEHH0cSNkfzKNqLb7MQS7N FoL1nzCekbqlvvZ1yoARPzOTqUB8W952/dsD8DO39Dj+5sBE3nyBLaoeMIW4y7Po EM1QPdGZk8kqDg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtkedrudekvddguddtgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfhuthenuceurghilhhouhhtmecu fedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufffkf fosedttdertdertddtnecuhfhrohhmpedfgfhmihhlihhoucfirdcuvehothgrfdcuoegt ohhtrgessghrrggrphdrohhrgheqnecuffhomhgrihhnpehsohhurhgtvgifrghrvgdroh hrghenucfkphepuddvkedrheelrddvtddrvdduieenucfrrghrrghmpehmrghilhhfrhho mheptghothgrsegsrhgrrghprdhorhhgnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Tue, 25 Dec 2018 02:03:05 -0500 Message-Id: <20181225070305.18221-1-cota@braap.org> X-Mailer: git-send-email 2.17.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.25 Subject: [Qemu-devel] [PATCH v2] 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: laurent.desnogues@gmail.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 Suggested-by: Richard Henderson --- v2: drop the cpuid bits, since that work (1) is only a performance optimization, not a correctness fix and (2) requires additional consolidation work that I do not have time to do right now. 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