From nobody Fri Nov 7 01:54:30 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; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1545304299960477.0404763243022; Thu, 20 Dec 2018 03:11:39 -0800 (PST) Received: from localhost ([::1]:36655 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gZwEg-00085n-1z for importer@patchew.org; Thu, 20 Dec 2018 06:11:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33998) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gZwDi-0007iU-R2 for qemu-devel@nongnu.org; Thu, 20 Dec 2018 06:10:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gZwDf-0002T1-Ns for qemu-devel@nongnu.org; Thu, 20 Dec 2018 06:10:26 -0500 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:40182) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gZwDf-0002S0-EX for qemu-devel@nongnu.org; Thu, 20 Dec 2018 06:10:23 -0500 Received: by mail-wm1-x341.google.com with SMTP id f188so1654201wmf.5 for ; Thu, 20 Dec 2018 03:10:22 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id l20sm16930297wrb.93.2018.12.20.03.10.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Dec 2018 03:10:20 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id C31EF3E059D; Thu, 20 Dec 2018 11:10:19 +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:mime-version :content-transfer-encoding; bh=CLEy4EypX5hb9wrXwR6jYX+R+Inoh2VumlXfXIcCTuc=; b=MAOzAc4Jxrt/rke5ucKy0EyXV5/aTFOQVmSPsAAL3FI171qMtQeuYx/8FtVjeERH7x pz6+ZQM4XYlwRsw0nYvzf/eIAMWCVMXgE53HwVVayw8jy2wgdFgP8S+VH++dONpB0khW OkwLK5WXCTg/e6K/zitt1BJEEydZRLWKQqPcI= 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=CLEy4EypX5hb9wrXwR6jYX+R+Inoh2VumlXfXIcCTuc=; b=LJP04J4aEWp4WrUVVvXDZidHi17W05HAdNUV7xO/gpKRUW9FaprFarGX5H8GLy25SK IALMAOaBucjnaGQpieyJo3QZRS7BHUUoDfXR19H/SbH21yRz4kySNZipneY3adefd4tQ 4cL0LSZ/xzumFxjm5ogQ7EGBkbuFf1Qlk1UnHOOVGlj83hlsSD8N/8vanfQd6kTQzykH +RRkWuVhtRuNTSFdrwiK2xZ7D2fiIUEox5eujSW52DVcCACDP42RHTYpc3TYAcL4HabX nETbmg9cFYLCSr8AmbHvBFDdkTlFr2YEwTtZZrQvIam3oHVGuRZRTjorD9XPEm3yI9EP UgAA== X-Gm-Message-State: AA+aEWY83x5Wyux7mfpsIBXtVaIfZTo3y+Qx2kdKFtVO7uUKivyGzyPO 5ds3G+viqmh6kVtBGN6EpHRn4Q== X-Google-Smtp-Source: AFSGD/V4XRRsgB3bRTlSTh3QgaXe4ynHFibBFUmO2CTeXWQQ3URhnDrNpXuOt1xjTvG05RE6/tuqdw== X-Received: by 2002:a1c:87cc:: with SMTP id j195mr10891234wmd.2.1545304221637; Thu, 20 Dec 2018 03:10:21 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Thu, 20 Dec 2018 11:10:08 +0000 Message-Id: <20181220111008.24954-1-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 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] [RFC PATCH] fpu: add compile time check for old glibc/libm and fma 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, 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) Some versions of glibc have been reported to have problems with fused-multiply-accumulate operations. If the underlying fma implementation does a two step operation it will instroduce subtle rounding errors. Newer versions of the library seem to deal with this better and modern hardware has fused operations which the library can use. Reported-by: Laurent Desnogues Signed-off-by: Alex Benn=C3=A9e Cc: Emilio G. Cota Acked-by: Aleksandar Markovic Tested-by: Laurent Desnogues --- fpu/softfloat.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 59eac97d10..9c2dbd04b5 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -203,6 +203,25 @@ GEN_INPUT_FLUSH3(float64_input_flush3, float64) # define QEMU_HARDFLOAT_3F64_USE_FP 0 #endif =20 +/* + * Choose whether to accelerate fused multiply-accumulate operations + * with hard float functions. Some versions of glibc's maths library + * have been reported to be broken on x86 without FMA instructions. + */ +#if defined(__x86_64__) +/* this was actually reported as glibc-2.12-1.149.el6_6.5.x86_64 was + * broken but glibc 2.12-1.209 works but out of caution lets disable + * for all older glibcs. + */ +#if defined(__GLIBC__) && (__GLIBC__ =3D=3D 2 && __GLIBC_MINOR__ <=3D 12) +#define QEMU_HARDFLOAT_USE_FMA 0 +#else +#define QEMU_HARDFLOAT_USE_FMA 1 +#endif +#else +#define QEMU_HARDFLOAT_USE_FMA 1 +#endif + /* * QEMU_HARDFLOAT_USE_ISINF chooses whether to use isinf() over * float{32,64}_is_infinity when !USE_FP. @@ -1551,6 +1570,9 @@ float32_muladd(float32 xa, float32 xb, float32 xc, in= t flags, float_status *s) ub.s =3D xb; uc.s =3D xc; =20 + if (!QEMU_HARDFLOAT_USE_FMA) { + goto soft; + } if (unlikely(!can_use_fpu(s))) { goto soft; } @@ -1612,6 +1634,9 @@ float64_muladd(float64 xa, float64 xb, float64 xc, in= t flags, float_status *s) ub.s =3D xb; uc.s =3D xc; =20 + if (!QEMU_HARDFLOAT_USE_FMA) { + goto soft; + } if (unlikely(!can_use_fpu(s))) { goto soft; } --=20 2.17.1