From patchwork Thu Dec 20 11:10:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 154329 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6026099ljp; Thu, 20 Dec 2018 03:11:54 -0800 (PST) X-Google-Smtp-Source: AFSGD/WW9lSjtuprwQLrdFyXPnAvNpsz5K9r8LD5wRuBFsnMDkT/26rUwK6uCx/PwhFNYa1t58PX X-Received: by 2002:ac8:5344:: with SMTP id d4mr25385735qto.372.1545304314872; Thu, 20 Dec 2018 03:11:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545304314; cv=none; d=google.com; s=arc-20160816; b=Xw9SoJyze6+WERNxjVupI738coSmOE7A9JDs9u4X0cIVzWg1cVzRDFf0hzXCtwfjeD LO1FlkgFAnKj7z64dsF8or7mCpOI7tDRWhV/lgm4kdAv3KIciqgCDJEga8gSuCM2FSKB 5gHzUtzzu6+TA/Bgyxyga2oXO9kpmEHmNIu6CzUWcTGsmPrdwyqzEpcyp3+S5c4V2nHA hMM1ViiW+YieI8MmjjOYmu+XwsfBkpkducK/1smwG+BqwbutWMfuEH8I9nxJuHqxP/IX Sqz8BvLV65iO/Jl3uKjyM0ssdebZYfA43s8cXdWHUYnK64foX7od6hvdTE6Kh/WDKUIb +sAQ== 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:subject :content-transfer-encoding:mime-version:message-id:date:to:from :dkim-signature; bh=CLEy4EypX5hb9wrXwR6jYX+R+Inoh2VumlXfXIcCTuc=; b=EELqjSavaTyTbPglY880cAlWW1CLpp8mnoOziodD/dndwJwDArfJaiBtFm49vc44CA 3WLDTbd8Tgum7rWWhE3yqg9tmVCIAFAFEYco0NdzQLd1DuXv2GHuqSOR3Crs5nsIMYZz I2agt+2YVsd+5T5LXUynFSJZWo+fxWzNOL/KX6Lldl7egz+p/nDH3SalrnyfmCaR12Ga VlZ4DfvaH9FKD5iwkaRJifTaXhK5q6SVzKiXfswh1muODPGEuXYic2u9Xjp2qQ1MhLSY D5pgUuAPuhik9nL6zGB90EaMoGokGIfTmPfVVdFqhCFHbSrCyrbotb4Tp67inlMnuvCv Ouvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=MAOzAc4J; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id x45si1247192qtk.221.2018.12.20.03.11.54 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 20 Dec 2018 03:11:54 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=MAOzAc4J; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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]:36655 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gZwF8-00085n-CS for patch@linaro.org; Thu, 20 Dec 2018 06:11:54 -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) 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-Received: by 2002:a1c:87cc:: with SMTP id j195mr10891234wmd.2.1545304221637; Thu, 20 Dec 2018 03:10:21 -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) From: =?utf-8?q?Alex_Benn=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 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_Benn=C3=A9e?= , Aurelien Jarno Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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ée Cc: Emilio G. Cota --- fpu/softfloat.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) -- 2.17.1 Acked-by: Aleksandar Markovic Tested-by: Laurent Desnogues 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 +/* + * 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__ == 2 && __GLIBC_MINOR__ <= 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, int flags, float_status *s) ub.s = xb; uc.s = xc; + 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, int flags, float_status *s) ub.s = xb; uc.s = xc; + if (!QEMU_HARDFLOAT_USE_FMA) { + goto soft; + } if (unlikely(!can_use_fpu(s))) { goto soft; }