From patchwork Thu May 10 09:42:02 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: 135396 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp783480lji; Thu, 10 May 2018 02:44:23 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrqK5R7HscPfFWnB1MSSOBcziRa8R4+vfkhuLiJ1fwMSBIkxG+3vl0rwricccOVxQpYF6Ks X-Received: by 2002:aed:2547:: with SMTP id w7-v6mr587702qtc.1.1525945463256; Thu, 10 May 2018 02:44:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525945463; cv=none; d=google.com; s=arc-20160816; b=i6RxeTtqfVFekstGXYbVJkJa12TZ3hPdCXXlY4XkCIKGeKN9/Ce5QHYCKs4aPEGZtF 2bc5aEQwf1xQU0QgksW5v8oO3y9Ko7gVKmJHLFJRCeeSEBcrdniR/5d80T4CK/Otj+Sk L5sktWGwxjWBjcNExDht/fWBKEcSzRoQUUbQ19zHZlqSlhRtPBljcZrdsbbxxf4T5pqT GgtGfBeBbM2qyIy1JNX6RNN6McWOg2RAeH7PqIL6Q9cDx/qXr9hNXP4RS08dUS2GtqG7 u6QdVdfifAjOZWfvRtILALib3FzvjhunRgzpW8jHUrP/GgRTVJNjqpPKQQSct1U8V+cz 1ngA== 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:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=tOgAfXKKAqziF7kn5+ziCSVWOZFyCQv8n6aKMpwaqis=; b=NuqS1L2qqaV5gjvRGs6BceY+WKbftOzgwicPItEAgOjaF5CKsAXlcwZnqdJ7FPv1zk mEQ1+rgyIFmYmybQY+VG8Wks1t/CS9UpEBKvzZB4j3Xz/EhTPtsOwXGO+dz6R9v7XvG6 WiCwtj+0YHMWX47xuL4wUKcsp+hPqL/6/oe0EMiHxqnAMWtfku1c4OVie7OvkS9oHF9g ud7ocmbAkaPYYBT2R6SCCIWTn+caNZVYZ641EMJ1KmiAsYGJLb1nKoVLwFlNCZpyrOGZ 7ZV/82P5A6lvQ0GtyWfjci5kH77DwK6SgRxt96BjM7kJ9aPzB/HoXd7M5CgG5uYjBw+R woUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=E3fEePNu; 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 q5-v6si376226qkf.70.2018.05.10.02.44.23 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 10 May 2018 02:44:23 -0700 (PDT) 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=E3fEePNu; 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]:60992 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGi7a-0005Wd-No for patch@linaro.org; Thu, 10 May 2018 05:44:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46125) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGi5V-0002Ek-Ft for qemu-devel@nongnu.org; Thu, 10 May 2018 05:42:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGi5S-0004SH-5J for qemu-devel@nongnu.org; Thu, 10 May 2018 05:42:13 -0400 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:42605) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fGi5R-0004Rd-Vc for qemu-devel@nongnu.org; Thu, 10 May 2018 05:42:10 -0400 Received: by mail-wr0-x243.google.com with SMTP id v5-v6so1326837wrf.9 for ; Thu, 10 May 2018 02:42:09 -0700 (PDT) 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=tOgAfXKKAqziF7kn5+ziCSVWOZFyCQv8n6aKMpwaqis=; b=E3fEePNuGr3wm6JU1/6BqcrQepB2rHDYWB0F+IMmrhgPXDQQ8Ms5cGP83wZT2Xk5kP KWegYTzE3PZ5HfF9Pfq7Lz45w6IkuYAyLqR0gjVQ3meOdBJ8NpJV7GITq6MHiH2PWxYV pwyJ7PbAWDx9nLUS24M/Q8RigkUUj7elVV7mE= 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=tOgAfXKKAqziF7kn5+ziCSVWOZFyCQv8n6aKMpwaqis=; b=L5TqVqpq/1YYjt73kOx39R7G+OFPZLg1oLPCNzLlymEhlYaPEFCwWBvQJRBILrgrhw 8YA8bUIOTpVrwv0SyvM92CsJ1GAVu4K+2IILWg99VqKaPFa/gvT5m28mvIxBpeYSk170 bCrESnMuIdUic9S1wGOFiiIPu2WYjaILpvhh1KDLrAU164yl0jWZ5qI3zyuCOMDWhq5T xE9qH9FfgugyGgtkgxujLT/sEsk81YZm9PJmQ2L2skIjUY3pb8E4kt8Gfvn5XfIf5Mmi O4Z155WcSm44C5YRAeXlOKxD6IQhCT7qif5e798EwU6VINsxsbaK+CR5ESKkDI1RyTpR 4S2w== X-Gm-Message-State: ALKqPwc5sH+c8h13vLglFzMovEhvSMqfnTyFrxuXEsTadhyKgIgwgwaB LrO1wKEjaiMQySE4zHZh8Hhcdw== X-Received: by 2002:adf:9a8e:: with SMTP id a14-v6mr750339wrc.50.1525945328928; Thu, 10 May 2018 02:42:08 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id d54-v6sm616952wrd.94.2018.05.10.02.42.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 May 2018 02:42:07 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 0276A3E0335; Thu, 10 May 2018 10:42:07 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Thu, 10 May 2018 10:42:02 +0100 Message-Id: <20180510094206.15354-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180510094206.15354-1-alex.bennee@linaro.org> References: <20180510094206.15354-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::243 Subject: [Qemu-devel] [PATCH v3 1/5] fpu/softfloat: int_to_float ensure r fully initialised 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: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-arm@nongnu.org, richard.henderson@linaro.org, qemu-devel@nongnu.org, Aurelien Jarno Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reported by Coverity (CID1390635). We ensure this for uint_to_float later on so we might as well mirror that. Signed-off-by: Alex Bennée --- fpu/softfloat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.17.0 Reviewed-by: Peter Maydell Reviewed-by: Richard Henderson diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 70e0c40a1c..3adf6a06e4 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -1517,7 +1517,7 @@ FLOAT_TO_UINT(64, 64) static FloatParts int_to_float(int64_t a, float_status *status) { - FloatParts r; + FloatParts r = {}; if (a == 0) { r.cls = float_class_zero; r.sign = false; From patchwork Thu May 10 09:42:03 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: 135399 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp784524lji; Thu, 10 May 2018 02:45:40 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpYWsVff2sqSc5SZEgmwfjOGihPLcG65yJX1aORrJk6fLQicVGV6nCGCHwm9YNhCsjvhk+M X-Received: by 2002:a37:1399:: with SMTP id 25-v6mr538505qkt.37.1525945540155; Thu, 10 May 2018 02:45:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525945540; cv=none; d=google.com; s=arc-20160816; b=YR4PErppXNiwZqqxHvXpN7gGjMDM9jKyg/v8vEnOzqlCp5BJsvEZ7Xm5Jz/l6fbOG8 fJg3yNkMsMEdBstRaUSIB41O07J5lVZy+duPfkUaOGz9vONaFDSzlBdGTWKK+A+LlKas JLS1Hz2sFmMKvj9Sei8ljx+mPxbeZI/YlBY9KFwSqwkbns3YYdJUfaeD/VUd2tv4MrcJ 1wg+OBIqRVqKmD0VpADpmFkBYv7FZiFlLKp3cPW6R1rx/7dVBAGPHJlIJZ1+t62tB3IS xBYRrKgC6mnNnxXYkwUiwPkSLIJPu0Fuha9DtIDAJS8Ds3BFVmoIfOeuIAGqt/ybGTL6 5XKA== 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:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=ZiFo48ylx4kobz9sTdYlzGMusxqIyZ33DMZStufP2UM=; b=Q9ErNAKYPfz9cIP7wA0A7z0Hcm7dC6plCyBu3qIq6RAAJ+iv0bIEYzftZTsZ3VcrgH ntvQOQrUQc41YOVghed6QQPXeu0B4UaXB5mudwXYIdRaIm4B9tHXBPRRiGhIQZqkJVjC 7MslyZNzsKbAKRRBY9H6X+QVyg76xXdvZ0CSGo4AoC/UDMXY6TJiXMACaQCi0qXYIOQs YekbamYeA4Liuk1TBEuYlj5QFQOKB/4lC+kVMDejCWtPakL62Yp9XAuKr4uhVk6t2FMW SazzzdufqlmJV1Bz3cjhI/hrUh3BzWuWo8htLzCXJ7kyey7HKfBMQfVNL4RrPIr4Yyor plng== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=CVDMld8K; 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 f5-v6si379290qtd.130.2018.05.10.02.45.39 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 10 May 2018 02:45:40 -0700 (PDT) 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=CVDMld8K; 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]:32772 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGi8p-0007mL-Hm for patch@linaro.org; Thu, 10 May 2018 05:45:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46197) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGi5X-0002G0-FZ for qemu-devel@nongnu.org; Thu, 10 May 2018 05:42:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGi5U-0004TO-0c for qemu-devel@nongnu.org; Thu, 10 May 2018 05:42:15 -0400 Received: from mail-wr0-x230.google.com ([2a00:1450:400c:c0c::230]:46441) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fGi5T-0004Sm-L1 for qemu-devel@nongnu.org; Thu, 10 May 2018 05:42:11 -0400 Received: by mail-wr0-x230.google.com with SMTP id a12-v6so1318595wrn.13 for ; Thu, 10 May 2018 02:42:11 -0700 (PDT) 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=ZiFo48ylx4kobz9sTdYlzGMusxqIyZ33DMZStufP2UM=; b=CVDMld8Ko6LO2/tujyEMlf36MlUHUZwkg4yJRM5j8kewcHJleh8SUmqZY0xomano5A 1XBfCJ+6XYj5jvievugoOC2XCDPuWxEFi1fLxyfc3alSTbxH7txjtgPg30g3ra4Ld2a2 Kj5jGmLawQPx5YYsiTRE+blTbqLFKJ2FUY92I= 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=ZiFo48ylx4kobz9sTdYlzGMusxqIyZ33DMZStufP2UM=; b=Nd803DSt1q/Ak4TLjCKgwFokKp2f8DCvszrDFuo2mR8eln5PStyE4mDWtOVrithbir zm6eCVfmOYc875nMTY0q11DfKHPwZbg0muEJtFhJvdNhxafJJvU3UC70VolhwL//puPH UWFDcS69HG0WeBXj1XbLaso591d1jLEUsUV3ZIMxi5pq5nEG5D7yLpZeKyogZ7j6F77i vxJFsGbWsiYwX1czNpUuUs36Et+u+Lki4GiOz1XRoDcYVTbQGnoLvM6dzj5Woj9TvblV YY2/YCqlbgvsWmWdLmYZQK6wWFpH5N+O0o2cEL1pk+3kPREHxTTnW2FgXWwp1cNOzch7 IMPw== X-Gm-Message-State: ALKqPwdts6k0viW9ef1WKOEu3YbmFw37q0Z/pz31Ws69UY72LlevnzDm ELHzoxayIZlhRIIpyFuojILw6g== X-Received: by 2002:adf:9d0d:: with SMTP id k13-v6mr703905wre.179.1525945330251; Thu, 10 May 2018 02:42:10 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id x16-v6sm321060wmc.42.2018.05.10.02.42.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 May 2018 02:42:08 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 1D18D3E0348; Thu, 10 May 2018 10:42:07 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Thu, 10 May 2018 10:42:03 +0100 Message-Id: <20180510094206.15354-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180510094206.15354-1-alex.bennee@linaro.org> References: <20180510094206.15354-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::230 Subject: [Qemu-devel] [PATCH v3 2/5] fpu/softfloat: re-factor float to float conversions 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: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-arm@nongnu.org, richard.henderson@linaro.org, qemu-devel@nongnu.org, Aurelien Jarno Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This allows us to delete a lot of additional boilerplate code which is no longer needed. Currently the ieee flag is ignored (everything is assumed to be ieee). Handling for ARM AHP will be in the next patch. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- v2 - pass FloatFmt to float_to_float instead of sizes - split AHP handling to another patch - use rth's suggested re-packing (+ setting .exp) v3 - also rm extractFloat16Sign --- fpu/softfloat-specialize.h | 40 ---- fpu/softfloat.c | 452 +++++++------------------------------ include/fpu/softfloat.h | 8 +- 3 files changed, 88 insertions(+), 412 deletions(-) -- 2.17.0 diff --git a/fpu/softfloat-specialize.h b/fpu/softfloat-specialize.h index 27834af0de..a20b440159 100644 --- a/fpu/softfloat-specialize.h +++ b/fpu/softfloat-specialize.h @@ -293,46 +293,6 @@ float16 float16_maybe_silence_nan(float16 a_, float_status *status) return a_; } -/*---------------------------------------------------------------------------- -| Returns the result of converting the half-precision floating-point NaN -| `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid -| exception is raised. -*----------------------------------------------------------------------------*/ - -static commonNaNT float16ToCommonNaN(float16 a, float_status *status) -{ - commonNaNT z; - - if (float16_is_signaling_nan(a, status)) { - float_raise(float_flag_invalid, status); - } - z.sign = float16_val(a) >> 15; - z.low = 0; - z.high = ((uint64_t) float16_val(a)) << 54; - return z; -} - -/*---------------------------------------------------------------------------- -| Returns the result of converting the canonical NaN `a' to the half- -| precision floating-point format. -*----------------------------------------------------------------------------*/ - -static float16 commonNaNToFloat16(commonNaNT a, float_status *status) -{ - uint16_t mantissa = a.high >> 54; - - if (status->default_nan_mode) { - return float16_default_nan(status); - } - - if (mantissa) { - return make_float16(((((uint16_t) a.sign) << 15) - | (0x1F << 10) | mantissa)); - } else { - return float16_default_nan(status); - } -} - #ifdef NO_SIGNALING_NANS int float32_is_quiet_nan(float32 a_, float_status *status) { diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 3adf6a06e4..042e5c901d 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -123,15 +123,6 @@ static inline int extractFloat16Exp(float16 a) return (float16_val(a) >> 10) & 0x1f; } -/*---------------------------------------------------------------------------- -| Returns the sign bit of the single-precision floating-point value `a'. -*----------------------------------------------------------------------------*/ - -static inline flag extractFloat16Sign(float16 a) -{ - return float16_val(a)>>15; -} - /*---------------------------------------------------------------------------- | Returns the fraction bits of the single-precision floating-point value `a'. *----------------------------------------------------------------------------*/ @@ -1194,6 +1185,90 @@ float64 float64_div(float64 a, float64 b, float_status *status) return float64_round_pack_canonical(pr, status); } +/* + * Float to Float conversions + * + * Returns the result of converting one float format to another. The + * conversion is performed according to the IEC/IEEE Standard for + * Binary Floating-Point Arithmetic. + * + * The float_to_float helper only needs to take care of raising + * invalid exceptions and handling the conversion on NaNs. + */ + +static FloatParts float_to_float(FloatParts a, + const FloatFmt *srcf, const FloatFmt *dstf, + float_status *s) +{ + if (is_nan(a.cls)) { + + if (is_snan(a.cls)) { + s->float_exception_flags |= float_flag_invalid; + } + + if (s->default_nan_mode) { + a.cls = float_class_dnan; + return a; + } + + /* + * Our only option now is to "re-pack" the NaN. As the + * canonilization process doesn't mess with fraction bits for + * NaNs we do it all here. We also reset a.exp to the + * destination format exp_max as the maybe_silence_nan code + * assumes it is correct (which is would be for non-conversions). + */ + a.frac = a.frac << (64 - srcf->frac_size) >> (64 - dstf->frac_size); + a.exp = dstf->exp_max; + a.cls = float_class_msnan; + } + + return a; +} + +float32 float16_to_float32(float16 a, bool ieee, float_status *s) +{ + FloatParts p = float16_unpack_canonical(a, s); + FloatParts pr = float_to_float(p, &float16_params, &float32_params, s); + return float32_round_pack_canonical(pr, s); +} + +float64 float16_to_float64(float16 a, bool ieee, float_status *s) +{ + FloatParts p = float16_unpack_canonical(a, s); + FloatParts pr = float_to_float(p, &float16_params, &float64_params, s); + return float64_round_pack_canonical(pr, s); +} + +float16 float32_to_float16(float32 a, bool ieee, float_status *s) +{ + FloatParts p = float32_unpack_canonical(a, s); + FloatParts pr = float_to_float(p, &float32_params, &float16_params, s); + return float16_round_pack_canonical(pr, s); +} + +float64 float32_to_float64(float32 a, float_status *s) +{ + FloatParts p = float32_unpack_canonical(a, s); + FloatParts pr = float_to_float(p, &float32_params, &float64_params, s); + return float64_round_pack_canonical(pr, s); +} + +float16 float64_to_float16(float64 a, bool ieee, float_status *s) +{ + FloatParts p = float64_unpack_canonical(a, s); + FloatParts pr = float_to_float(p, &float64_params, &float16_params, s); + return float16_round_pack_canonical(pr, s); +} + +float32 float64_to_float32(float64 a, float_status *s) +{ + FloatParts p = float64_unpack_canonical(a, s); + FloatParts pr = float_to_float(p, &float64_params, &float32_params, s); + return float32_round_pack_canonical(pr, s); +} + + /* * Rounds the floating-point value `a' to an integer, and returns the * result as a floating-point value. The operation is performed @@ -3142,41 +3217,6 @@ float128 uint64_to_float128(uint64_t a, float_status *status) return normalizeRoundAndPackFloat128(0, 0x406E, a, 0, status); } - - - -/*---------------------------------------------------------------------------- -| Returns the result of converting the single-precision floating-point value -| `a' to the double-precision floating-point format. The conversion is -| performed according to the IEC/IEEE Standard for Binary Floating-Point -| Arithmetic. -*----------------------------------------------------------------------------*/ - -float64 float32_to_float64(float32 a, float_status *status) -{ - flag aSign; - int aExp; - uint32_t aSig; - a = float32_squash_input_denormal(a, status); - - aSig = extractFloat32Frac( a ); - aExp = extractFloat32Exp( a ); - aSign = extractFloat32Sign( a ); - if ( aExp == 0xFF ) { - if (aSig) { - return commonNaNToFloat64(float32ToCommonNaN(a, status), status); - } - return packFloat64( aSign, 0x7FF, 0 ); - } - if ( aExp == 0 ) { - if ( aSig == 0 ) return packFloat64( aSign, 0, 0 ); - normalizeFloat32Subnormal( aSig, &aExp, &aSig ); - --aExp; - } - return packFloat64( aSign, aExp + 0x380, ( (uint64_t) aSig )<<29 ); - -} - /*---------------------------------------------------------------------------- | Returns the result of converting the single-precision floating-point value | `a' to the extended double-precision floating-point format. The conversion @@ -3695,173 +3735,6 @@ int float32_unordered_quiet(float32 a, float32 b, float_status *status) return 0; } - -/*---------------------------------------------------------------------------- -| Returns the result of converting the double-precision floating-point value -| `a' to the single-precision floating-point format. The conversion is -| performed according to the IEC/IEEE Standard for Binary Floating-Point -| Arithmetic. -*----------------------------------------------------------------------------*/ - -float32 float64_to_float32(float64 a, float_status *status) -{ - flag aSign; - int aExp; - uint64_t aSig; - uint32_t zSig; - a = float64_squash_input_denormal(a, status); - - aSig = extractFloat64Frac( a ); - aExp = extractFloat64Exp( a ); - aSign = extractFloat64Sign( a ); - if ( aExp == 0x7FF ) { - if (aSig) { - return commonNaNToFloat32(float64ToCommonNaN(a, status), status); - } - return packFloat32( aSign, 0xFF, 0 ); - } - shift64RightJamming( aSig, 22, &aSig ); - zSig = aSig; - if ( aExp || zSig ) { - zSig |= 0x40000000; - aExp -= 0x381; - } - return roundAndPackFloat32(aSign, aExp, zSig, status); - -} - - -/*---------------------------------------------------------------------------- -| Packs the sign `zSign', exponent `zExp', and significand `zSig' into a -| half-precision floating-point value, returning the result. After being -| shifted into the proper positions, the three fields are simply added -| together to form the result. This means that any integer portion of `zSig' -| will be added into the exponent. Since a properly normalized significand -| will have an integer portion equal to 1, the `zExp' input should be 1 less -| than the desired result exponent whenever `zSig' is a complete, normalized -| significand. -*----------------------------------------------------------------------------*/ -static float16 packFloat16(flag zSign, int zExp, uint16_t zSig) -{ - return make_float16( - (((uint32_t)zSign) << 15) + (((uint32_t)zExp) << 10) + zSig); -} - -/*---------------------------------------------------------------------------- -| Takes an abstract floating-point value having sign `zSign', exponent `zExp', -| and significand `zSig', and returns the proper half-precision floating- -| point value corresponding to the abstract input. Ordinarily, the abstract -| value is simply rounded and packed into the half-precision format, with -| the inexact exception raised if the abstract input cannot be represented -| exactly. However, if the abstract value is too large, the overflow and -| inexact exceptions are raised and an infinity or maximal finite value is -| returned. If the abstract value is too small, the input value is rounded to -| a subnormal number, and the underflow and inexact exceptions are raised if -| the abstract input cannot be represented exactly as a subnormal half- -| precision floating-point number. -| The `ieee' flag indicates whether to use IEEE standard half precision, or -| ARM-style "alternative representation", which omits the NaN and Inf -| encodings in order to raise the maximum representable exponent by one. -| The input significand `zSig' has its binary point between bits 22 -| and 23, which is 13 bits to the left of the usual location. This shifted -| significand must be normalized or smaller. If `zSig' is not normalized, -| `zExp' must be 0; in that case, the result returned is a subnormal number, -| and it must not require rounding. In the usual case that `zSig' is -| normalized, `zExp' must be 1 less than the ``true'' floating-point exponent. -| Note the slightly odd position of the binary point in zSig compared with the -| other roundAndPackFloat functions. This should probably be fixed if we -| need to implement more float16 routines than just conversion. -| The handling of underflow and overflow follows the IEC/IEEE Standard for -| Binary Floating-Point Arithmetic. -*----------------------------------------------------------------------------*/ - -static float16 roundAndPackFloat16(flag zSign, int zExp, - uint32_t zSig, flag ieee, - float_status *status) -{ - int maxexp = ieee ? 29 : 30; - uint32_t mask; - uint32_t increment; - bool rounding_bumps_exp; - bool is_tiny = false; - - /* Calculate the mask of bits of the mantissa which are not - * representable in half-precision and will be lost. - */ - if (zExp < 1) { - /* Will be denormal in halfprec */ - mask = 0x00ffffff; - if (zExp >= -11) { - mask >>= 11 + zExp; - } - } else { - /* Normal number in halfprec */ - mask = 0x00001fff; - } - - switch (status->float_rounding_mode) { - case float_round_nearest_even: - increment = (mask + 1) >> 1; - if ((zSig & mask) == increment) { - increment = zSig & (increment << 1); - } - break; - case float_round_ties_away: - increment = (mask + 1) >> 1; - break; - case float_round_up: - increment = zSign ? 0 : mask; - break; - case float_round_down: - increment = zSign ? mask : 0; - break; - default: /* round_to_zero */ - increment = 0; - break; - } - - rounding_bumps_exp = (zSig + increment >= 0x01000000); - - if (zExp > maxexp || (zExp == maxexp && rounding_bumps_exp)) { - if (ieee) { - float_raise(float_flag_overflow | float_flag_inexact, status); - return packFloat16(zSign, 0x1f, 0); - } else { - float_raise(float_flag_invalid, status); - return packFloat16(zSign, 0x1f, 0x3ff); - } - } - - if (zExp < 0) { - /* Note that flush-to-zero does not affect half-precision results */ - is_tiny = - (status->float_detect_tininess == float_tininess_before_rounding) - || (zExp < -1) - || (!rounding_bumps_exp); - } - if (zSig & mask) { - float_raise(float_flag_inexact, status); - if (is_tiny) { - float_raise(float_flag_underflow, status); - } - } - - zSig += increment; - if (rounding_bumps_exp) { - zSig >>= 1; - zExp++; - } - - if (zExp < -10) { - return packFloat16(zSign, 0, 0); - } - if (zExp < 0) { - zSig >>= -zExp; - zExp = 0; - } - return packFloat16(zSign, zExp, zSig >> 13); -} - /*---------------------------------------------------------------------------- | If `a' is denormal and we are in flush-to-zero mode then set the | input-denormal exception and return zero. Otherwise just return the value. @@ -3877,163 +3750,6 @@ float16 float16_squash_input_denormal(float16 a, float_status *status) return a; } -static void normalizeFloat16Subnormal(uint32_t aSig, int *zExpPtr, - uint32_t *zSigPtr) -{ - int8_t shiftCount = countLeadingZeros32(aSig) - 21; - *zSigPtr = aSig << shiftCount; - *zExpPtr = 1 - shiftCount; -} - -/* Half precision floats come in two formats: standard IEEE and "ARM" format. - The latter gains extra exponent range by omitting the NaN/Inf encodings. */ - -float32 float16_to_float32(float16 a, flag ieee, float_status *status) -{ - flag aSign; - int aExp; - uint32_t aSig; - - aSign = extractFloat16Sign(a); - aExp = extractFloat16Exp(a); - aSig = extractFloat16Frac(a); - - if (aExp == 0x1f && ieee) { - if (aSig) { - return commonNaNToFloat32(float16ToCommonNaN(a, status), status); - } - return packFloat32(aSign, 0xff, 0); - } - if (aExp == 0) { - if (aSig == 0) { - return packFloat32(aSign, 0, 0); - } - - normalizeFloat16Subnormal(aSig, &aExp, &aSig); - aExp--; - } - return packFloat32( aSign, aExp + 0x70, aSig << 13); -} - -float16 float32_to_float16(float32 a, flag ieee, float_status *status) -{ - flag aSign; - int aExp; - uint32_t aSig; - - a = float32_squash_input_denormal(a, status); - - aSig = extractFloat32Frac( a ); - aExp = extractFloat32Exp( a ); - aSign = extractFloat32Sign( a ); - if ( aExp == 0xFF ) { - if (aSig) { - /* Input is a NaN */ - if (!ieee) { - float_raise(float_flag_invalid, status); - return packFloat16(aSign, 0, 0); - } - return commonNaNToFloat16( - float32ToCommonNaN(a, status), status); - } - /* Infinity */ - if (!ieee) { - float_raise(float_flag_invalid, status); - return packFloat16(aSign, 0x1f, 0x3ff); - } - return packFloat16(aSign, 0x1f, 0); - } - if (aExp == 0 && aSig == 0) { - return packFloat16(aSign, 0, 0); - } - /* Decimal point between bits 22 and 23. Note that we add the 1 bit - * even if the input is denormal; however this is harmless because - * the largest possible single-precision denormal is still smaller - * than the smallest representable half-precision denormal, and so we - * will end up ignoring aSig and returning via the "always return zero" - * codepath. - */ - aSig |= 0x00800000; - aExp -= 0x71; - - return roundAndPackFloat16(aSign, aExp, aSig, ieee, status); -} - -float64 float16_to_float64(float16 a, flag ieee, float_status *status) -{ - flag aSign; - int aExp; - uint32_t aSig; - - aSign = extractFloat16Sign(a); - aExp = extractFloat16Exp(a); - aSig = extractFloat16Frac(a); - - if (aExp == 0x1f && ieee) { - if (aSig) { - return commonNaNToFloat64( - float16ToCommonNaN(a, status), status); - } - return packFloat64(aSign, 0x7ff, 0); - } - if (aExp == 0) { - if (aSig == 0) { - return packFloat64(aSign, 0, 0); - } - - normalizeFloat16Subnormal(aSig, &aExp, &aSig); - aExp--; - } - return packFloat64(aSign, aExp + 0x3f0, ((uint64_t)aSig) << 42); -} - -float16 float64_to_float16(float64 a, flag ieee, float_status *status) -{ - flag aSign; - int aExp; - uint64_t aSig; - uint32_t zSig; - - a = float64_squash_input_denormal(a, status); - - aSig = extractFloat64Frac(a); - aExp = extractFloat64Exp(a); - aSign = extractFloat64Sign(a); - if (aExp == 0x7FF) { - if (aSig) { - /* Input is a NaN */ - if (!ieee) { - float_raise(float_flag_invalid, status); - return packFloat16(aSign, 0, 0); - } - return commonNaNToFloat16( - float64ToCommonNaN(a, status), status); - } - /* Infinity */ - if (!ieee) { - float_raise(float_flag_invalid, status); - return packFloat16(aSign, 0x1f, 0x3ff); - } - return packFloat16(aSign, 0x1f, 0); - } - shift64RightJamming(aSig, 29, &aSig); - zSig = aSig; - if (aExp == 0 && zSig == 0) { - return packFloat16(aSign, 0, 0); - } - /* Decimal point between bits 22 and 23. Note that we add the 1 bit - * even if the input is denormal; however this is harmless because - * the largest possible single-precision denormal is still smaller - * than the smallest representable half-precision denormal, and so we - * will end up ignoring aSig and returning via the "always return zero" - * codepath. - */ - zSig |= 0x00800000; - aExp -= 0x3F1; - - return roundAndPackFloat16(aSign, aExp, zSig, ieee, status); -} - /*---------------------------------------------------------------------------- | Returns the result of converting the double-precision floating-point value | `a' to the extended double-precision floating-point format. The conversion diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h index 36626a501b..01ef1c6b81 100644 --- a/include/fpu/softfloat.h +++ b/include/fpu/softfloat.h @@ -211,10 +211,10 @@ float128 uint64_to_float128(uint64_t, float_status *status); /*---------------------------------------------------------------------------- | Software half-precision conversion routines. *----------------------------------------------------------------------------*/ -float16 float32_to_float16(float32, flag, float_status *status); -float32 float16_to_float32(float16, flag, float_status *status); -float16 float64_to_float16(float64 a, flag ieee, float_status *status); -float64 float16_to_float64(float16 a, flag ieee, float_status *status); +float16 float32_to_float16(float32, bool ieee, float_status *status); +float32 float16_to_float32(float16, bool ieee, float_status *status); +float16 float64_to_float16(float64 a, bool ieee, float_status *status); +float64 float16_to_float64(float16 a, bool ieee, float_status *status); int16_t float16_to_int16(float16, float_status *status); uint16_t float16_to_uint16(float16 a, float_status *status); int16_t float16_to_int16_round_to_zero(float16, float_status *status); From patchwork Thu May 10 09:42:04 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: 135400 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp785154lji; Thu, 10 May 2018 02:46:30 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpUTfahr1KNIgmSMnBZpFbO4owUujccZuBNMOdMNCoqd91BidC9zuZ98tK1MTYvQGvlBs2p X-Received: by 2002:a0c:8adc:: with SMTP id 28-v6mr501957qvw.241.1525945590429; Thu, 10 May 2018 02:46:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525945590; cv=none; d=google.com; s=arc-20160816; b=q4xuo1PnR6rtTq8oBS6OQfP/T+0Y3kpbEqkfnuZBCwozuK9rt+G6NuUlG2XtqTsoWU QANDjEQ0G8c6n0JJdhCNgY/GdRGK+4KSLLxEa+6kTnSoOZuh5G37ooYNLVyk6HRNymNQ NPSLT4BDRIHj7dTzQlSxdmLftquSpQLBZTwkN72sAIRRIipRrx3U/A+oI07kiAT/rbGt Bv8WW3+fEJwQlx4uSynfeSto79djlSNVz7jWAB+ZkhdJsFUixCE0fSy8XJLG753U9An5 QUe2xwLUegUu6PkomwtoI1dNAf76mSfAJR4ujme6NXzqX7kedQlGsVNtisIMLwU/PMM8 LpyA== 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:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=XibGir2o+sywcUzQXuh0/9bGi5rtuKwMYtOfJuZIbUs=; b=OVNEhoGpPei3XCu/uOXv6SH8BIEvd2W2TqJ0DD7y7MuMiFT8QvjuvGZkOZ/ZXR8OhT LiAUi4j3sq5XZ6LdXSpRcHzhXYvSYjSNkWG/C0MAx3YKXoOjD0gCZoGdmt1tU5JkwX6z RyyQWXD3rauOK8E1ZAgzckTmIeVXPXTv9izulch1A1ZdSjcz/aPgFw6zcNw2WM2QWhR9 7rrihrZwsDLqL6wi0bngYVp5LJKXZ8wJhGke+VQUbv68jwuFhGKct+fHlBJwbAZLhwOS wzM/lyeCgRSlaMvO8MzqzSR7zifXOD6PgWPu5ZawOXAICBNnopHdofprRVysfhgvT2S+ fU8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Dut2xg86; 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 m9-v6si356172qki.378.2018.05.10.02.46.30 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 10 May 2018 02:46:30 -0700 (PDT) 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=Dut2xg86; 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]:32774 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGi9d-0008Im-TI for patch@linaro.org; Thu, 10 May 2018 05:46:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46172) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGi5W-0002FH-Ef for qemu-devel@nongnu.org; Thu, 10 May 2018 05:42:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGi5U-0004Tc-KI for qemu-devel@nongnu.org; Thu, 10 May 2018 05:42:14 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:37296) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fGi5U-0004T3-A5 for qemu-devel@nongnu.org; Thu, 10 May 2018 05:42:12 -0400 Received: by mail-wm0-x243.google.com with SMTP id l1-v6so3226123wmb.2 for ; Thu, 10 May 2018 02:42:12 -0700 (PDT) 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=XibGir2o+sywcUzQXuh0/9bGi5rtuKwMYtOfJuZIbUs=; b=Dut2xg86s1vHOvuPuH1PkbOFeUBb4ba4OfcPPwzwYrOkZj7VjJ/CH299LMg8axUD4Y Pr4at2zEldJZtuy3ddvqII7Qr5VkB4mPWzgB5attqyBwHH5UYsVZ44K8BSOdh/2qnPOT 7pT6OyapzqOjLugaK42ULE0NBb+YGuBIUi5EQ= 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=XibGir2o+sywcUzQXuh0/9bGi5rtuKwMYtOfJuZIbUs=; b=FB+vnwgapBbWvHpf8CynUhK1GZIeRJ5qbLvdvPA0yt2yht1tZyoLom6HQuba3a/rZo 3HjBPJ+RIAh/cmSTXYqbS+KJ8t4QW6Upba4H7yuBlE4qDkfznHYu+iV1H59SkfojZUEt 2VIdRIcGuTXS+YFLFIq/+XDxmBbW4X/xr+C4khMhWBaZ9OdwySq4oMzqSqX4yEsYI/mq XlSj6eu9mgwjPUh7cvmRRXFTxwHurOfp6N5WSifBDxgLWxz19pfduDj7MP6aTScXwOtu J6dz7bTxnEnjwbTqfQzSi7PrD0U72Qj2Qk1D9iV+cRu/NGLfEfSmoNNtvljqRXdEk9+g 2mSA== X-Gm-Message-State: ALKqPweRQbKi61a1xYN4wrFxFCrkv7n04vZqzZiKafkl7W1wklumV+W2 PqCkdhZszymXxm9WBTQX/RB7Hg== X-Received: by 2002:a1c:5cd5:: with SMTP id q204-v6mr714160wmb.158.1525945331075; Thu, 10 May 2018 02:42:11 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id 19-v6sm899577wrz.7.2018.05.10.02.42.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 May 2018 02:42:08 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 3002E3E03C0; Thu, 10 May 2018 10:42:07 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Thu, 10 May 2018 10:42:04 +0100 Message-Id: <20180510094206.15354-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180510094206.15354-1-alex.bennee@linaro.org> References: <20180510094206.15354-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::243 Subject: [Qemu-devel] [PATCH v3 3/5] fpu/softfloat: support ARM Alternative half-precision 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: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-arm@nongnu.org, richard.henderson@linaro.org, qemu-devel@nongnu.org, Aurelien Jarno Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" For float16 ARM supports an alternative half-precision format which sacrifices the ability to represent NaN/Inf in return for a higher dynamic range. To support this I've added an additional FloatFmt (float16_params_ahp). The new FloatFmt flag (arm_althp) is then used to modify the behaviour of canonicalize and round_canonical with respect to representation and exception raising. Finally the float16_to_floatN and floatN_to_float16 conversion routines select the new alternative FloatFmt when !ieee. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- v3 - squash NaN to 0 if destination is AHP F16 --- fpu/softfloat.c | 108 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 85 insertions(+), 23 deletions(-) -- 2.17.0 diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 042e5c901d..79ebc998d3 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -225,6 +225,8 @@ typedef struct { * frac_lsb: least significant bit of fraction * fram_lsbm1: the bit bellow the least significant bit (for rounding) * round_mask/roundeven_mask: masks used for rounding + * The following optional modifiers are available: + * arm_althp: handle ARM Alternative Half Precision */ typedef struct { int exp_size; @@ -236,6 +238,7 @@ typedef struct { uint64_t frac_lsbm1; uint64_t round_mask; uint64_t roundeven_mask; + bool arm_althp; } FloatFmt; /* Expand fields based on the size of exponent and fraction */ @@ -248,12 +251,17 @@ typedef struct { .frac_lsb = 1ull << (DECOMPOSED_BINARY_POINT - F), \ .frac_lsbm1 = 1ull << ((DECOMPOSED_BINARY_POINT - F) - 1), \ .round_mask = (1ull << (DECOMPOSED_BINARY_POINT - F)) - 1, \ - .roundeven_mask = (2ull << (DECOMPOSED_BINARY_POINT - F)) - 1 + .roundeven_mask = (2ull << (DECOMPOSED_BINARY_POINT - F)) - 1, static const FloatFmt float16_params = { FLOAT_PARAMS(5, 10) }; +static const FloatFmt float16_params_ahp = { + FLOAT_PARAMS(5, 10) + .arm_althp = true +}; + static const FloatFmt float32_params = { FLOAT_PARAMS(8, 23) }; @@ -317,7 +325,7 @@ static inline float64 float64_pack_raw(FloatParts p) static FloatParts canonicalize(FloatParts part, const FloatFmt *parm, float_status *status) { - if (part.exp == parm->exp_max) { + if (part.exp == parm->exp_max && !parm->arm_althp) { if (part.frac == 0) { part.cls = float_class_inf; } else { @@ -403,8 +411,9 @@ static FloatParts round_canonical(FloatParts p, float_status *s, exp += parm->exp_bias; if (likely(exp > 0)) { + bool maybe_inexact = false; if (frac & round_mask) { - flags |= float_flag_inexact; + maybe_inexact = true; frac += inc; if (frac & DECOMPOSED_OVERFLOW_BIT) { frac >>= 1; @@ -413,14 +422,26 @@ static FloatParts round_canonical(FloatParts p, float_status *s, } frac >>= frac_shift; - if (unlikely(exp >= exp_max)) { - flags |= float_flag_overflow | float_flag_inexact; - if (overflow_norm) { - exp = exp_max - 1; - frac = -1; - } else { - p.cls = float_class_inf; - goto do_inf; + if (parm->arm_althp) { + if (unlikely(exp >= exp_max + 1)) { + flags |= float_flag_invalid; + frac = -1; + exp = exp_max; + } else if (maybe_inexact) { + flags |= float_flag_inexact; + } + } else { + if (unlikely(exp >= exp_max)) { + flags |= float_flag_overflow | float_flag_inexact; + if (overflow_norm) { + exp = exp_max - 1; + frac = -1; + } else { + p.cls = float_class_inf; + goto do_inf; + } + } else if (maybe_inexact) { + flags |= float_flag_inexact; } } } else if (s->flush_to_zero) { @@ -465,7 +486,13 @@ static FloatParts round_canonical(FloatParts p, float_status *s, case float_class_inf: do_inf: exp = exp_max; - frac = 0; + if (parm->arm_althp) { + flags |= float_flag_invalid; + /* Alt HP returns result = sign:Ones(M-1) */ + frac = -1; + } else { + frac = 0; + } break; case float_class_qnan: @@ -483,12 +510,21 @@ static FloatParts round_canonical(FloatParts p, float_status *s, return p; } +/* Explicit FloatFmt version */ +static FloatParts float16a_unpack_canonical(const FloatFmt *params, + float16 f, float_status *s) +{ + return canonicalize(float16_unpack_raw(f), params, s); +} + static FloatParts float16_unpack_canonical(float16 f, float_status *s) { - return canonicalize(float16_unpack_raw(f), &float16_params, s); + return float16a_unpack_canonical(&float16_params, f, s); } -static float16 float16_round_pack_canonical(FloatParts p, float_status *s) + +static float16 float16a_round_pack_canonical(const FloatFmt *params, + FloatParts p, float_status *s) { switch (p.cls) { case float_class_dnan: @@ -496,11 +532,16 @@ static float16 float16_round_pack_canonical(FloatParts p, float_status *s) case float_class_msnan: return float16_maybe_silence_nan(float16_pack_raw(p), s); default: - p = round_canonical(p, s, &float16_params); + p = round_canonical(p, s, params); return float16_pack_raw(p); } } +static float16 float16_round_pack_canonical(FloatParts p, float_status *s) +{ + return float16a_round_pack_canonical(&float16_params, p, s); +} + static FloatParts float32_unpack_canonical(float32 f, float_status *s) { return canonicalize(float32_unpack_raw(f), &float32_params, s); @@ -1206,6 +1247,17 @@ static FloatParts float_to_float(FloatParts a, s->float_exception_flags |= float_flag_invalid; } + if (dstf->arm_althp) { + /* There is no NaN in the destination format: raise Invalid + * and return a zero with the sign of the input NaN. + */ + s->float_exception_flags |= float_flag_invalid; + a.cls = float_class_zero; + a.frac = 0; + a.exp = 0; + return a; + } + if (s->default_nan_mode) { a.cls = float_class_dnan; return a; @@ -1226,25 +1278,34 @@ static FloatParts float_to_float(FloatParts a, return a; } +/* + * Currently non-ieee implies ARM Alternative Half Precision handling + * for float16 values. If more are needed we'll need to expand the API + * into softfloat. + */ + float32 float16_to_float32(float16 a, bool ieee, float_status *s) { - FloatParts p = float16_unpack_canonical(a, s); - FloatParts pr = float_to_float(p, &float16_params, &float32_params, s); + const FloatFmt *fmt16 = ieee ? &float16_params : &float16_params_ahp; + FloatParts p = float16a_unpack_canonical(fmt16, a, s); + FloatParts pr = float_to_float(p, fmt16, &float32_params, s); return float32_round_pack_canonical(pr, s); } float64 float16_to_float64(float16 a, bool ieee, float_status *s) { - FloatParts p = float16_unpack_canonical(a, s); - FloatParts pr = float_to_float(p, &float16_params, &float64_params, s); + const FloatFmt *fmt16 = ieee ? &float16_params : &float16_params_ahp; + FloatParts p = float16a_unpack_canonical(fmt16, a, s); + FloatParts pr = float_to_float(p, fmt16, &float64_params, s); return float64_round_pack_canonical(pr, s); } float16 float32_to_float16(float32 a, bool ieee, float_status *s) { + const FloatFmt *fmt16 = ieee ? &float16_params : &float16_params_ahp; FloatParts p = float32_unpack_canonical(a, s); - FloatParts pr = float_to_float(p, &float32_params, &float16_params, s); - return float16_round_pack_canonical(pr, s); + FloatParts pr = float_to_float(p, &float32_params, fmt16, s); + return float16a_round_pack_canonical(fmt16, pr, s); } float64 float32_to_float64(float32 a, float_status *s) @@ -1256,9 +1317,10 @@ float64 float32_to_float64(float32 a, float_status *s) float16 float64_to_float16(float64 a, bool ieee, float_status *s) { + const FloatFmt *fmt16 = ieee ? &float16_params : &float16_params_ahp; FloatParts p = float64_unpack_canonical(a, s); - FloatParts pr = float_to_float(p, &float64_params, &float16_params, s); - return float16_round_pack_canonical(pr, s); + FloatParts pr = float_to_float(p, &float64_params, fmt16, s); + return float16a_round_pack_canonical(fmt16, pr, s); } float32 float64_to_float32(float64 a, float_status *s) From patchwork Thu May 10 09:42:05 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: 135401 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp785532lji; Thu, 10 May 2018 02:46:57 -0700 (PDT) X-Google-Smtp-Source: AB8JxZriPgdOTClmSU5mgELBwd6NpXNxvK/aWsCdoVWmuHhNRA5fVQQSlJaay1GdKeiEJoeMZLIX X-Received: by 2002:a0c:8464:: with SMTP id l91-v6mr521648qva.15.1525945617199; Thu, 10 May 2018 02:46:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525945617; cv=none; d=google.com; s=arc-20160816; b=zUx8rZvvqdvBJj2qfNsr8IIZp/SuGK94Y2+Cd0MheJSFGCaZ69dRFdp6mRMfQ7CjcC e8kEYJaU6+6XFkZmv5knR0jLECTzf0Cyqo53KsUOF7PKnCAefceUr/xRvk+jcFSSIyQ8 qT8ev/sggh2s2Gok6H/ozcoq90eyePF6kVK7hr4Jswhjo5q0ZMxdNdrjt2ieEkN7YamM 6uiVJybiOWD96eqmP/UVZgRkMzJUmVAXKfNfju+V+z/TT+fb85WJivorpnvxXi5rh7/n vHIcJFJAAKlFXbuLFSth8Is4nb/Cc71bo00tuR3Dy1KsU2sLbwxxo+p1iRZvuatX3MIJ XpvA== 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:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=PPEWtnTJipioaM2dgVTsaFxHMgQCUxZ901nqxIsireE=; b=gt+IDqHb4uEWbVlrrlPKBq198KkbMGf+L2LQG9P8RncvOt5A/5wPe/ifn1E/5e2ERw 7pshsuUQ7PHl5vGAphDF1NdEJPvgra1UgxSBEWbrUGHeVVyLjudRs9c8C2aEV/Mtrzao lsILT96Kq3eUsItpj6R8cgYB3KTH1u/1fDT6KEYmRAOTpwb+DM2s8chrz5KAhREdC9LS hVj9k+Dd6EodrNdqdufMLdbqFrbjmsXtAk5siWz6+lm/V9lDfVXf1QJclj1N9QyL7Nq8 MAgJs+R7O0MCbLBaC20zzSgi5SOLJbwuurLpylF5lHr2TfPNOVV6KjbW2uA7znedCF0R VcBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=fUN8WEfE; 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 q53-v6si386275qte.271.2018.05.10.02.46.56 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 10 May 2018 02:46:57 -0700 (PDT) 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=fUN8WEfE; 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]:32777 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGiA4-0008Lx-MO for patch@linaro.org; Thu, 10 May 2018 05:46:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46217) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGi5Y-0002HF-KO for qemu-devel@nongnu.org; Thu, 10 May 2018 05:42:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGi5W-0004VM-Ph for qemu-devel@nongnu.org; Thu, 10 May 2018 05:42:16 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:33934) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fGi5W-0004Uj-FZ for qemu-devel@nongnu.org; Thu, 10 May 2018 05:42:14 -0400 Received: by mail-wm0-x243.google.com with SMTP id a137-v6so26707008wme.1 for ; Thu, 10 May 2018 02:42:14 -0700 (PDT) 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=PPEWtnTJipioaM2dgVTsaFxHMgQCUxZ901nqxIsireE=; b=fUN8WEfExdTYWM2czgIbeBdpSfy7Ce2EH/+rK7vcsrb2ir8cQB86TJJnLYfd4p59dV hUoMbr47Q1bcleCuHXbp0TevtxQM+KAfETTqMmuxGGDNqgo+woXvLf2v6MKiw9UWO3WB gYQq6N2Yo6Slf4hFrJZOY6wX1qD/d7oCqAm3Y= 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=PPEWtnTJipioaM2dgVTsaFxHMgQCUxZ901nqxIsireE=; b=bCIf3uVD4qhIjW/R5WViTrsCdgzKPZsbvZys60nfh3VKjR5AekE9ISBpZyiPc49ysX 1daBK3bUOk5XxM40OYzCdAppMIX8C/ZFjBw3QQM5O1kDpM9722HEctEmtUVXYDkCWDUr h3T4EQxFuS8hrrE4jrP1gawJZzoHo8v0tu8SmeTwnQZCOJAfjIqPptplA4/qlcKk3A3w qP6TnvetdjXtQzVtk+JMo5cmsBaS3TL+Gmz2MIgqPu7M3G5aT9K5eTg1qtaFIfSdICy3 pbiJesfBWPcw4afqNMAHltLnt2ngz3A5JZAKfMCGFt4uhR8Kc7j6jVX4tfXP+ePNAx6A I8Sg== X-Gm-Message-State: ALKqPwetWZ23xH+u+WJkP4OBJ1UPmCwaHlgaG9el+dfhpXvT+HHs55UL WtXQ/e/kqvgHeZ8aUYmC9sEeOzrA8TY= X-Received: by 2002:a1c:57c6:: with SMTP id l189-v6mr765972wmb.161.1525945333158; Thu, 10 May 2018 02:42:13 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id s14-v6sm758479wmb.5.2018.05.10.02.42.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 May 2018 02:42:09 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 479763E04AB; Thu, 10 May 2018 10:42:07 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Thu, 10 May 2018 10:42:05 +0100 Message-Id: <20180510094206.15354-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180510094206.15354-1-alex.bennee@linaro.org> References: <20180510094206.15354-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::243 Subject: [Qemu-devel] [PATCH v3 4/5] target/arm: convert conversion helpers to fpst/ahp_flag 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: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-arm@nongnu.org, richard.henderson@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Instead of passing env and leaving it up to the helper to get the right fpstatus we pass it explicitly. There was already a get_fpstatus helper for neon for the 32 bit code. We also add an get_ahp_flag() for passing the state of the alternative FP16 format flag. This leaves scope for later tracking the AHP state in translation flags. Signed-off-by: Alex Bennée --- target/arm/helper.c | 58 ++++++++++++------------------- target/arm/helper.h | 12 +++---- target/arm/translate-a64.c | 38 +++++++++++++++++---- target/arm/translate.c | 70 +++++++++++++++++++++++++++++--------- target/arm/translate.h | 15 ++++++++ 5 files changed, 128 insertions(+), 65 deletions(-) -- 2.17.0 diff --git a/target/arm/helper.c b/target/arm/helper.c index 0fef5d4d06..4dd28bb70c 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -11457,64 +11457,50 @@ uint32_t HELPER(set_neon_rmode)(uint32_t rmode, CPUARMState *env) } /* Half precision conversions. */ -static float32 do_fcvt_f16_to_f32(uint32_t a, CPUARMState *env, float_status *s) +static float32 do_fcvt_f16_to_f32(float16 a, float_status *s, bool ahp) { - int ieee = (env->vfp.xregs[ARM_VFP_FPSCR] & (1 << 26)) == 0; - float32 r = float16_to_float32(make_float16(a), ieee, s); - if (ieee) { - return float32_maybe_silence_nan(r, s); - } - return r; + return float16_to_float32(a, !ahp, s); } -static uint32_t do_fcvt_f32_to_f16(float32 a, CPUARMState *env, float_status *s) +static float16 do_fcvt_f32_to_f16(float32 a, float_status *s, bool ahp) { - int ieee = (env->vfp.xregs[ARM_VFP_FPSCR] & (1 << 26)) == 0; - float16 r = float32_to_float16(a, ieee, s); - if (ieee) { - r = float16_maybe_silence_nan(r, s); - } - return float16_val(r); + return float32_to_float16(a, !ahp, s); } -float32 HELPER(neon_fcvt_f16_to_f32)(uint32_t a, CPUARMState *env) +float32 HELPER(neon_fcvt_f16_to_f32)(float16 a, void *fpstp, uint32_t ahp_mode) { - return do_fcvt_f16_to_f32(a, env, &env->vfp.standard_fp_status); + float_status *fpst = fpstp; + return do_fcvt_f16_to_f32(a, fpst, ahp_mode); } -uint32_t HELPER(neon_fcvt_f32_to_f16)(float32 a, CPUARMState *env) +float16 HELPER(neon_fcvt_f32_to_f16)(float32 a, void *fpstp, uint32_t ahp_mode) { - return do_fcvt_f32_to_f16(a, env, &env->vfp.standard_fp_status); + float_status *fpst = fpstp; + return do_fcvt_f32_to_f16(a, fpst, ahp_mode); } -float32 HELPER(vfp_fcvt_f16_to_f32)(uint32_t a, CPUARMState *env) +float32 HELPER(vfp_fcvt_f16_to_f32)(float16 a, void *fpstp, uint32_t ahp_mode) { - return do_fcvt_f16_to_f32(a, env, &env->vfp.fp_status); + float_status *fpst = fpstp; + return do_fcvt_f16_to_f32(a, fpst, ahp_mode); } -uint32_t HELPER(vfp_fcvt_f32_to_f16)(float32 a, CPUARMState *env) +float16 HELPER(vfp_fcvt_f32_to_f16)(float32 a, void *fpstp, uint32_t ahp_mode) { - return do_fcvt_f32_to_f16(a, env, &env->vfp.fp_status); + float_status *fpst = fpstp; + return do_fcvt_f32_to_f16(a, fpst, ahp_mode); } -float64 HELPER(vfp_fcvt_f16_to_f64)(uint32_t a, CPUARMState *env) +float64 HELPER(vfp_fcvt_f16_to_f64)(float16 a, void *fpstp, uint32_t ahp_mode) { - int ieee = (env->vfp.xregs[ARM_VFP_FPSCR] & (1 << 26)) == 0; - float64 r = float16_to_float64(make_float16(a), ieee, &env->vfp.fp_status); - if (ieee) { - return float64_maybe_silence_nan(r, &env->vfp.fp_status); - } - return r; + float_status *fpst = fpstp; + return float16_to_float64(a, !ahp_mode, fpst); } -uint32_t HELPER(vfp_fcvt_f64_to_f16)(float64 a, CPUARMState *env) +float16 HELPER(vfp_fcvt_f64_to_f16)(float64 a, void *fpstp, uint32_t ahp_mode) { - int ieee = (env->vfp.xregs[ARM_VFP_FPSCR] & (1 << 26)) == 0; - float16 r = float64_to_float16(a, ieee, &env->vfp.fp_status); - if (ieee) { - r = float16_maybe_silence_nan(r, &env->vfp.fp_status); - } - return float16_val(r); + float_status *fpst = fpstp; + return float64_to_float16(a, !ahp_mode, fpst); } #define float32_two make_float32(0x40000000) diff --git a/target/arm/helper.h b/target/arm/helper.h index 34e8cc8904..288480a0e7 100644 --- a/target/arm/helper.h +++ b/target/arm/helper.h @@ -181,12 +181,12 @@ DEF_HELPER_3(vfp_ultoh, f16, i32, i32, ptr) DEF_HELPER_FLAGS_2(set_rmode, TCG_CALL_NO_RWG, i32, i32, ptr) DEF_HELPER_FLAGS_2(set_neon_rmode, TCG_CALL_NO_RWG, i32, i32, env) -DEF_HELPER_2(vfp_fcvt_f16_to_f32, f32, i32, env) -DEF_HELPER_2(vfp_fcvt_f32_to_f16, i32, f32, env) -DEF_HELPER_2(neon_fcvt_f16_to_f32, f32, i32, env) -DEF_HELPER_2(neon_fcvt_f32_to_f16, i32, f32, env) -DEF_HELPER_FLAGS_2(vfp_fcvt_f16_to_f64, TCG_CALL_NO_RWG, f64, i32, env) -DEF_HELPER_FLAGS_2(vfp_fcvt_f64_to_f16, TCG_CALL_NO_RWG, i32, f64, env) +DEF_HELPER_3(vfp_fcvt_f16_to_f32, f32, f16, ptr, i32) +DEF_HELPER_3(vfp_fcvt_f32_to_f16, f16, f32, ptr, i32) +DEF_HELPER_3(neon_fcvt_f16_to_f32, f32, f16, ptr, i32) +DEF_HELPER_3(neon_fcvt_f32_to_f16, f16, f32, ptr, i32) +DEF_HELPER_FLAGS_3(vfp_fcvt_f16_to_f64, TCG_CALL_NO_RWG, f64, f16, ptr, i32) +DEF_HELPER_FLAGS_3(vfp_fcvt_f64_to_f16, TCG_CALL_NO_RWG, f16, f64, ptr, i32) DEF_HELPER_4(vfp_muladdd, f64, f64, f64, f64, ptr) DEF_HELPER_4(vfp_muladds, f32, f32, f32, f32, ptr) diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index 6d49f30b4a..00a7c63240 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -4830,10 +4830,15 @@ static void handle_fp_fcvt(DisasContext *s, int opcode, } else { /* Single to half */ TCGv_i32 tcg_rd = tcg_temp_new_i32(); - gen_helper_vfp_fcvt_f32_to_f16(tcg_rd, tcg_rn, cpu_env); + TCGv_i32 ahp = get_ahp_flag(); + TCGv_ptr fpst = get_fpstatus_ptr(true); + + gen_helper_vfp_fcvt_f32_to_f16(tcg_rd, tcg_rn, fpst, ahp); /* write_fp_sreg is OK here because top half of tcg_rd is zero */ write_fp_sreg(s, rd, tcg_rd); tcg_temp_free_i32(tcg_rd); + tcg_temp_free_i32(ahp); + tcg_temp_free_ptr(fpst); } tcg_temp_free_i32(tcg_rn); break; @@ -4846,9 +4851,13 @@ static void handle_fp_fcvt(DisasContext *s, int opcode, /* Double to single */ gen_helper_vfp_fcvtsd(tcg_rd, tcg_rn, cpu_env); } else { + TCGv_ptr fpst = get_fpstatus_ptr(true); + TCGv_i32 ahp = get_ahp_flag(); /* Double to half */ - gen_helper_vfp_fcvt_f64_to_f16(tcg_rd, tcg_rn, cpu_env); + gen_helper_vfp_fcvt_f64_to_f16(tcg_rd, tcg_rn, fpst, ahp); /* write_fp_sreg is OK here because top half of tcg_rd is zero */ + tcg_temp_free_ptr(fpst); + tcg_temp_free_i32(ahp); } write_fp_sreg(s, rd, tcg_rd); tcg_temp_free_i32(tcg_rd); @@ -4858,17 +4867,21 @@ static void handle_fp_fcvt(DisasContext *s, int opcode, case 0x3: { TCGv_i32 tcg_rn = read_fp_sreg(s, rn); + TCGv_ptr tcg_fpst = get_fpstatus_ptr(true); + TCGv_i32 tcg_ahp = get_ahp_flag(); tcg_gen_ext16u_i32(tcg_rn, tcg_rn); if (dtype == 0) { /* Half to single */ TCGv_i32 tcg_rd = tcg_temp_new_i32(); - gen_helper_vfp_fcvt_f16_to_f32(tcg_rd, tcg_rn, cpu_env); + gen_helper_vfp_fcvt_f16_to_f32(tcg_rd, tcg_rn, tcg_fpst, tcg_ahp); write_fp_sreg(s, rd, tcg_rd); + tcg_temp_free_ptr(tcg_fpst); + tcg_temp_free_i32(tcg_ahp); tcg_temp_free_i32(tcg_rd); } else { /* Half to double */ TCGv_i64 tcg_rd = tcg_temp_new_i64(); - gen_helper_vfp_fcvt_f16_to_f64(tcg_rd, tcg_rn, cpu_env); + gen_helper_vfp_fcvt_f16_to_f64(tcg_rd, tcg_rn, tcg_fpst, tcg_ahp); write_fp_dreg(s, rd, tcg_rd); tcg_temp_free_i64(tcg_rd); } @@ -8487,12 +8500,17 @@ static void handle_2misc_narrow(DisasContext *s, bool scalar, } else { TCGv_i32 tcg_lo = tcg_temp_new_i32(); TCGv_i32 tcg_hi = tcg_temp_new_i32(); + TCGv_ptr fpst = get_fpstatus_ptr(true); + TCGv_i32 ahp = get_ahp_flag(); + tcg_gen_extr_i64_i32(tcg_lo, tcg_hi, tcg_op); - gen_helper_vfp_fcvt_f32_to_f16(tcg_lo, tcg_lo, cpu_env); - gen_helper_vfp_fcvt_f32_to_f16(tcg_hi, tcg_hi, cpu_env); + gen_helper_vfp_fcvt_f32_to_f16(tcg_lo, tcg_lo, fpst, ahp); + gen_helper_vfp_fcvt_f32_to_f16(tcg_hi, tcg_hi, fpst, ahp); tcg_gen_deposit_i32(tcg_res[pass], tcg_lo, tcg_hi, 16, 16); tcg_temp_free_i32(tcg_lo); tcg_temp_free_i32(tcg_hi); + tcg_temp_free_ptr(fpst); + tcg_temp_free_i32(ahp); } break; case 0x56: /* FCVTXN, FCVTXN2 */ @@ -10987,18 +11005,24 @@ static void handle_2misc_widening(DisasContext *s, int opcode, bool is_q, /* 16 -> 32 bit fp conversion */ int srcelt = is_q ? 4 : 0; TCGv_i32 tcg_res[4]; + TCGv_ptr fpst = get_fpstatus_ptr(true); + TCGv_i32 ahp = get_ahp_flag(); + for (pass = 0; pass < 4; pass++) { tcg_res[pass] = tcg_temp_new_i32(); read_vec_element_i32(s, tcg_res[pass], rn, srcelt + pass, MO_16); gen_helper_vfp_fcvt_f16_to_f32(tcg_res[pass], tcg_res[pass], - cpu_env); + fpst, ahp); } for (pass = 0; pass < 4; pass++) { write_vec_element_i32(s, tcg_res[pass], rd, pass, MO_32); tcg_temp_free_i32(tcg_res[pass]); } + + tcg_temp_free_ptr(fpst); + tcg_temp_free_i32(ahp); } } diff --git a/target/arm/translate.c b/target/arm/translate.c index ad208867a7..5eab9d585a 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -3824,53 +3824,75 @@ static int disas_vfp_insn(DisasContext *s, uint32_t insn) gen_vfp_sqrt(dp); break; case 4: /* vcvtb.f32.f16, vcvtb.f64.f16 */ + { + TCGv_ptr fpst = get_fpstatus_ptr(false); + TCGv_i32 ahp_mode = get_ahp_flag(); tmp = gen_vfp_mrs(); tcg_gen_ext16u_i32(tmp, tmp); if (dp) { gen_helper_vfp_fcvt_f16_to_f64(cpu_F0d, tmp, - cpu_env); + fpst, ahp_mode); } else { gen_helper_vfp_fcvt_f16_to_f32(cpu_F0s, tmp, - cpu_env); + fpst, ahp_mode); } + tcg_temp_free_i32(ahp_mode); + tcg_temp_free_ptr(fpst); tcg_temp_free_i32(tmp); break; + } case 5: /* vcvtt.f32.f16, vcvtt.f64.f16 */ + { + TCGv_ptr fpst = get_fpstatus_ptr(false); + TCGv_i32 ahp = get_ahp_flag(); tmp = gen_vfp_mrs(); tcg_gen_shri_i32(tmp, tmp, 16); if (dp) { gen_helper_vfp_fcvt_f16_to_f64(cpu_F0d, tmp, - cpu_env); + fpst, ahp); } else { gen_helper_vfp_fcvt_f16_to_f32(cpu_F0s, tmp, - cpu_env); + fpst, ahp); } tcg_temp_free_i32(tmp); + tcg_temp_free_i32(ahp); + tcg_temp_free_ptr(fpst); break; + } case 6: /* vcvtb.f16.f32, vcvtb.f16.f64 */ + { + TCGv_ptr fpst = get_fpstatus_ptr(false); + TCGv_i32 ahp = get_ahp_flag(); tmp = tcg_temp_new_i32(); + if (dp) { gen_helper_vfp_fcvt_f64_to_f16(tmp, cpu_F0d, - cpu_env); + fpst, ahp); } else { gen_helper_vfp_fcvt_f32_to_f16(tmp, cpu_F0s, - cpu_env); + fpst, ahp); } gen_mov_F0_vreg(0, rd); tmp2 = gen_vfp_mrs(); tcg_gen_andi_i32(tmp2, tmp2, 0xffff0000); tcg_gen_or_i32(tmp, tmp, tmp2); tcg_temp_free_i32(tmp2); + tcg_temp_free_i32(ahp); + tcg_temp_free_ptr(fpst); gen_vfp_msr(tmp); break; + } case 7: /* vcvtt.f16.f32, vcvtt.f16.f64 */ + { + TCGv_ptr fpst = get_fpstatus_ptr(true); + TCGv_i32 ahp = get_ahp_flag(); tmp = tcg_temp_new_i32(); if (dp) { gen_helper_vfp_fcvt_f64_to_f16(tmp, cpu_F0d, - cpu_env); + fpst, ahp); } else { gen_helper_vfp_fcvt_f32_to_f16(tmp, cpu_F0s, - cpu_env); + fpst, ahp); } tcg_gen_shli_i32(tmp, tmp, 16); gen_mov_F0_vreg(0, rd); @@ -3880,6 +3902,7 @@ static int disas_vfp_insn(DisasContext *s, uint32_t insn) tcg_temp_free_i32(tmp2); gen_vfp_msr(tmp); break; + } case 8: /* cmp */ gen_vfp_cmp(dp); break; @@ -7222,53 +7245,68 @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) } break; case NEON_2RM_VCVT_F16_F32: + { + TCGv_ptr fpst; + TCGv_i32 ahp; + if (!arm_dc_feature(s, ARM_FEATURE_VFP_FP16) || q || (rm & 1)) { return 1; } tmp = tcg_temp_new_i32(); tmp2 = tcg_temp_new_i32(); + fpst = get_fpstatus_ptr(true); + ahp = get_ahp_flag(); tcg_gen_ld_f32(cpu_F0s, cpu_env, neon_reg_offset(rm, 0)); - gen_helper_neon_fcvt_f32_to_f16(tmp, cpu_F0s, cpu_env); + gen_helper_neon_fcvt_f32_to_f16(tmp, cpu_F0s, fpst, ahp); tcg_gen_ld_f32(cpu_F0s, cpu_env, neon_reg_offset(rm, 1)); - gen_helper_neon_fcvt_f32_to_f16(tmp2, cpu_F0s, cpu_env); + gen_helper_neon_fcvt_f32_to_f16(tmp2, cpu_F0s, fpst, ahp); tcg_gen_shli_i32(tmp2, tmp2, 16); tcg_gen_or_i32(tmp2, tmp2, tmp); tcg_gen_ld_f32(cpu_F0s, cpu_env, neon_reg_offset(rm, 2)); - gen_helper_neon_fcvt_f32_to_f16(tmp, cpu_F0s, cpu_env); + gen_helper_neon_fcvt_f32_to_f16(tmp, cpu_F0s, fpst, ahp); tcg_gen_ld_f32(cpu_F0s, cpu_env, neon_reg_offset(rm, 3)); neon_store_reg(rd, 0, tmp2); tmp2 = tcg_temp_new_i32(); - gen_helper_neon_fcvt_f32_to_f16(tmp2, cpu_F0s, cpu_env); + gen_helper_neon_fcvt_f32_to_f16(tmp2, cpu_F0s, fpst, ahp); tcg_gen_shli_i32(tmp2, tmp2, 16); tcg_gen_or_i32(tmp2, tmp2, tmp); neon_store_reg(rd, 1, tmp2); tcg_temp_free_i32(tmp); + tcg_temp_free_i32(ahp); + tcg_temp_free_ptr(fpst); break; + } case NEON_2RM_VCVT_F32_F16: + { + TCGv_ptr fpst; + TCGv_i32 ahp; if (!arm_dc_feature(s, ARM_FEATURE_VFP_FP16) || q || (rd & 1)) { return 1; } + fpst = get_fpstatus_ptr(true); + ahp = get_ahp_flag(); tmp3 = tcg_temp_new_i32(); tmp = neon_load_reg(rm, 0); tmp2 = neon_load_reg(rm, 1); tcg_gen_ext16u_i32(tmp3, tmp); - gen_helper_neon_fcvt_f16_to_f32(cpu_F0s, tmp3, cpu_env); + gen_helper_neon_fcvt_f16_to_f32(cpu_F0s, tmp3, fpst, ahp); tcg_gen_st_f32(cpu_F0s, cpu_env, neon_reg_offset(rd, 0)); tcg_gen_shri_i32(tmp3, tmp, 16); - gen_helper_neon_fcvt_f16_to_f32(cpu_F0s, tmp3, cpu_env); + gen_helper_neon_fcvt_f16_to_f32(cpu_F0s, tmp3, fpst, ahp); tcg_gen_st_f32(cpu_F0s, cpu_env, neon_reg_offset(rd, 1)); tcg_temp_free_i32(tmp); tcg_gen_ext16u_i32(tmp3, tmp2); - gen_helper_neon_fcvt_f16_to_f32(cpu_F0s, tmp3, cpu_env); + gen_helper_neon_fcvt_f16_to_f32(cpu_F0s, tmp3, fpst, ahp); tcg_gen_st_f32(cpu_F0s, cpu_env, neon_reg_offset(rd, 2)); tcg_gen_shri_i32(tmp3, tmp2, 16); - gen_helper_neon_fcvt_f16_to_f32(cpu_F0s, tmp3, cpu_env); + gen_helper_neon_fcvt_f16_to_f32(cpu_F0s, tmp3, fpst, ahp); tcg_gen_st_f32(cpu_F0s, cpu_env, neon_reg_offset(rd, 3)); tcg_temp_free_i32(tmp2); tcg_temp_free_i32(tmp3); break; + } case NEON_2RM_AESE: case NEON_2RM_AESMC: if (!arm_dc_feature(s, ARM_FEATURE_V8_AES) || ((rm | rd) & 1)) { diff --git a/target/arm/translate.h b/target/arm/translate.h index 4428c98e2e..41d0b8cd9a 100644 --- a/target/arm/translate.h +++ b/target/arm/translate.h @@ -177,4 +177,19 @@ void arm_free_cc(DisasCompare *cmp); void arm_jump_cc(DisasCompare *cmp, TCGLabel *label); void arm_gen_test_cc(int cc, TCGLabel *label); +/* Return state of Alternate Half-precision flag, caller frees result */ +static inline TCGv_i32 get_ahp_flag(void) +{ + TCGv_i32 fpscr = tcg_temp_new_i32(); + TCGv_i32 ahp_mode = tcg_temp_new_i32(); + + tcg_gen_ld_i32(fpscr, cpu_env, offsetof(CPUARMState, + vfp.xregs[ARM_VFP_FPSCR])); + tcg_gen_extract_i32(ahp_mode, fpscr, 26, 1); + + tcg_temp_free_i32(fpscr); + + return ahp_mode; +} + #endif /* TARGET_ARM_TRANSLATE_H */ From patchwork Thu May 10 09:42:06 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: 135398 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp783761lji; Thu, 10 May 2018 02:44:46 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqA7XBY7Tff9w7xORcaWRtmdLO504ntFKeSs1+2tVTW65Dmk93by02FdwajAboagFRvI33q X-Received: by 2002:ac8:36d1:: with SMTP id b17-v6mr603867qtc.148.1525945486035; Thu, 10 May 2018 02:44:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525945486; cv=none; d=google.com; s=arc-20160816; b=TjZ/E1K62TG4C53HIVHWCTUzQtvVBteTy2cd7N9YvCMAEnq/qudWzysd9iIph4cIg5 fgm0SZD5hsSocVHcj/DzqjIN+7BQsB4LOHT+Vs6No3+68KG4AhaGaS6NKXjwrIK2YUXD KBW7uKoibG+ug8o0zKC+GCwKyJqFoCuaUJQck1W0n8/3fMzEOnelKc+mT1Q0gfU1mag4 ujYqDGri2eHVWEmI5a3xgMCeNOvL24aLDqo0GnCv2O1uxk+Xp+9Q3z72fSPiZABVZOuH ooO9pl9NXtwbtx3gY5GIX76MEmi94BA5tCmlRXvZL3QG3pNY+8I7ktFFW5QY2BOnrE9g PONA== 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:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=1hajm0U+qnqFDGdJa0m1m0J/D5ufKVQ+/rQlp0BRUVA=; b=OVSVZzlyr1ZZ/TW3plDnd/zjyBxvspSHYJ5QmhPg7iu/iKAe95X4xys4N8AkCk7Wps e0rhXndiZc3TK5lZltlZGZJm/YDcTWEKuuNepINdI86eadvsX5QPsktNwLaYmkOt/KG+ wbvDFbP8++aTKsrlp+TUawloYw84+xDskWpY5bA7fVAV4ydeR3+U6w/RUb+i6zTXJoUU Lkg5/XIldXpCCEaNipUgn2ZohHGM1Ge/mSIe8T1gUp7Sk4colEE1G1pbzZDJiSgxBrPv IlCdNTKHGY/+obhR50lUZddUNI/rx2wUbjG3EaFHxdoLqcKxP0n4wsRZCUamxmzDfVOA cCfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=MdGcWO+o; 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 q6-v6si384852qtl.131.2018.05.10.02.44.45 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 10 May 2018 02:44:46 -0700 (PDT) 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=MdGcWO+o; 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]:60995 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGi7x-0005ix-8s for patch@linaro.org; Thu, 10 May 2018 05:44:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46181) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGi5W-0002FW-Nq for qemu-devel@nongnu.org; Thu, 10 May 2018 05:42:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGi5V-0004UI-Hz for qemu-devel@nongnu.org; Thu, 10 May 2018 05:42:14 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:38218) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fGi5V-0004Tl-9k for qemu-devel@nongnu.org; Thu, 10 May 2018 05:42:13 -0400 Received: by mail-wm0-x244.google.com with SMTP id y189-v6so3199508wmc.3 for ; Thu, 10 May 2018 02:42:13 -0700 (PDT) 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=1hajm0U+qnqFDGdJa0m1m0J/D5ufKVQ+/rQlp0BRUVA=; b=MdGcWO+oFGTYGimjrD40A+YqnghQGMKcft9IoYTWrIR2Ip1daNS2mZOB5me0amPr5A x1OvSCSX8Qfxo3uGcEFEKmAUBeUrHBFCI6VwVcA3y1pHPNXNdWqdl52bYWVAvIJ16R3P 9+AE1grYX/3Qg8bQUH+31Cc6+9GkH0ieFx6q4= 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=1hajm0U+qnqFDGdJa0m1m0J/D5ufKVQ+/rQlp0BRUVA=; b=NAvYyy6cOkF+tPyo/FXB9nERdYIVbURmj1iz7SbwyUe2U77hUlvwjsi488qXriatIk Y9RkWjrN2Dr7IuFDmEBOxMif6ieJiYORJXDh5ho/pNXyZJ9m3FHHGcuV4eoNxGs6wtD3 /MF8i+rohZNqyBUn8wfPLql1L99CTTLXojJatXr/xy4SmfmnDmHBiUmFs+M3FrgrrQ1R xzb/GxFrK8+vlDQKS2Fp2lHgls4ihnDB1ml0VePgbINbqf5EKpzp69pXpePuzL9PYCOC QfnSQlx7RnD8CkpdqKCg545lfjcltfSyhCQSDN8wAom2O3NpScZ5V5LZAOS7dK67lo0f EeVQ== X-Gm-Message-State: ALKqPwdDFfnP6V3GWMjwaZhFn0e5UWVRsQavX6D5iPnNBwTNI6JA74Zt YtxPr34LgTrA0WTQbm4THikVThzgQcg= X-Received: by 2002:a1c:2084:: with SMTP id g126-v6mr838578wmg.52.1525945332151; Thu, 10 May 2018 02:42:12 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id f10-v6sm476056wmc.0.2018.05.10.02.42.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 May 2018 02:42:08 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 59C1C3E04F4; Thu, 10 May 2018 10:42:07 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Thu, 10 May 2018 10:42:06 +0100 Message-Id: <20180510094206.15354-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180510094206.15354-1-alex.bennee@linaro.org> References: <20180510094206.15354-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::244 Subject: [Qemu-devel] [PATCH v3 5/5] target/arm: squash FZ16 behaviour for conversions 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: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-arm@nongnu.org, richard.henderson@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The ARM ARM specifies FZ16 is suppressed for conversions. Rather than pushing this logic into the softfloat code we can simply save the FZ state and temporarily disable it for the softfloat call. Signed-off-by: Alex Bennée --- target/arm/helper.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) -- 2.17.0 diff --git a/target/arm/helper.c b/target/arm/helper.c index 4dd28bb70c..17147be58b 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -11459,12 +11459,20 @@ uint32_t HELPER(set_neon_rmode)(uint32_t rmode, CPUARMState *env) /* Half precision conversions. */ static float32 do_fcvt_f16_to_f32(float16 a, float_status *s, bool ahp) { - return float16_to_float32(a, !ahp, s); + flag save_flush_to_zero = s->flush_to_zero; + set_flush_to_zero(false, s); + float32 r = float16_to_float32(a, !ahp, s); + set_flush_to_zero(save_flush_to_zero, s); + return r; } static float16 do_fcvt_f32_to_f16(float32 a, float_status *s, bool ahp) { - return float32_to_float16(a, !ahp, s); + flag save_flush_to_zero = s->flush_to_zero; + set_flush_to_zero(false, s); + float16 r = float32_to_float16(a, !ahp, s); + set_flush_to_zero(save_flush_to_zero, s); + return float16_val(r); } float32 HELPER(neon_fcvt_f16_to_f32)(float16 a, void *fpstp, uint32_t ahp_mode) @@ -11494,13 +11502,21 @@ float16 HELPER(vfp_fcvt_f32_to_f16)(float32 a, void *fpstp, uint32_t ahp_mode) float64 HELPER(vfp_fcvt_f16_to_f64)(float16 a, void *fpstp, uint32_t ahp_mode) { float_status *fpst = fpstp; - return float16_to_float64(a, !ahp_mode, fpst); + flag save_flush_to_zero = fpst->flush_to_zero; + set_flush_to_zero(false, fpst); + float64 r = float16_to_float64(a, !ahp_mode, fpst); + set_flush_to_zero(save_flush_to_zero, fpst); + return r; } float16 HELPER(vfp_fcvt_f64_to_f16)(float64 a, void *fpstp, uint32_t ahp_mode) { float_status *fpst = fpstp; - return float64_to_float16(a, !ahp_mode, fpst); + flag save_flush_to_zero = fpst->flush_to_zero; + set_flush_to_zero(false, fpst); + float16 r = float64_to_float16(a, !ahp_mode, fpst); + set_flush_to_zero(save_flush_to_zero, fpst); + return float16_val(r); } #define float32_two make_float32(0x40000000)