From nobody Sat Sep 28 18:14:21 2024 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 154767035172431.200107440408146; Wed, 16 Jan 2019 12:25:51 -0800 (PST) Received: from localhost ([127.0.0.1]:45586 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjrks-0007z5-7q for importer@patchew.org; Wed, 16 Jan 2019 15:25:42 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42846) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjrj9-0006ut-GW for qemu-devel@nongnu.org; Wed, 16 Jan 2019 15:23:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gjrj8-000653-HV for qemu-devel@nongnu.org; Wed, 16 Jan 2019 15:23:55 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:34597) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gjrj8-00060F-AN for qemu-devel@nongnu.org; Wed, 16 Jan 2019 15:23:54 -0500 Received: by mail-wm1-x342.google.com with SMTP id y185so1921552wmd.1 for ; Wed, 16 Jan 2019 12:23:54 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id s1sm115908380wro.9.2019.01.16.12.23.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 16 Jan 2019 12:23:50 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id A48A13E0F77; Wed, 16 Jan 2019 20:23:49 +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=V4sA7A65E2SWFC74zBDODZmknqvCshvStCQltJmAmqo=; b=adhpLQusJL5zHwRexa4Zd+cLrLGFFUnQ5PJ3RKhZZpJlqmbXUdrMKVQjNJmfPrDlxL NOzx7zZqQd2d4/z2XvWzcbEAhQbgz1XwY3JnuLKaWTSkrDvBrzh+Mpf+urrI/wslfRs+ FlirSqgMltJ2alV5xah4uGcy0LYY6XQpf7hv0= 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=V4sA7A65E2SWFC74zBDODZmknqvCshvStCQltJmAmqo=; b=tHiBr3AyQScFNt3PchDOqdaLea1+6qU3uFIT462vdRHbN2OQaOq1lDPxtFrNE1G5Mj knzYY2ASbnqdTcDcntmjDF2mYpNCvtmTstcY55gqBa8HfSs7/l/u0SlQ36lCeRBhsHLV PQ7JrGbaaS61f3khoOAAzdwXpgKOtWKh6GWL9410mvZvJXHOmEtTPqZ6FMQafGZ61qzU yiKTIZywEmiXHxr/qNN0oPDKW6Yj7xojd6gNLNbEFKU5e9J7rekeFnnB1WCPXpySQTxA 3RITaFUnJd6AHvQS0Msfv9OdlPKqcNVH+dV9QmZUlDZqsp7tyFoP1xFXNQ8wJw4eQenX ZJKA== X-Gm-Message-State: AJcUukeQ2fUgQ7sHEWazKSRkE2YA6d+Iob+qqjhYiXcISfO7xF1u+BLU JXsDFO+7OKJfLKmRN+m6G6PViA== X-Google-Smtp-Source: ALg8bN72u4XzEvzvzcmLolZpKZ10oJ4lM5QVtf6OHdNVwcSl8+gsrFjEnm/trLV8yxfzrlzUXriIpg== X-Received: by 2002:a7b:c757:: with SMTP id w23mr8430756wmk.59.1547670232663; Wed, 16 Jan 2019 12:23:52 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 16 Jan 2019 20:23:45 +0000 Message-Id: <20190116202349.29272-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190116202349.29272-1-alex.bennee@linaro.org> References: <20190116202349.29272-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::342 Subject: [Qemu-devel] [PATCH v2 3/7] 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 , cohuck@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , "Emilio G. Cota" , 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 Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- 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