From patchwork Tue May 15 22:25:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 135955 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp90503lji; Tue, 15 May 2018 15:45:05 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqWMh7MGxc140904ccFzZxwInNGACnWr+KjNmaQw4PPwmPLWWvObUcLoNs2M7CHFWPWnowJ X-Received: by 2002:a0c:ba97:: with SMTP id x23-v6mr2151889qvf.112.1526424305744; Tue, 15 May 2018 15:45:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526424305; cv=none; d=google.com; s=arc-20160816; b=uVI3FivCsa2Lv8rj0LexToZYBy0RWe2++swUDb9vI9H9+9ufxWNRvan3GudSzajvCJ 4ql/tG2VhW2zj9WeA7rXEaAI/1fR70LLenqH4WJtLWLQb4YdWgOmncg7BiJhcwRP01oY NYJJXDM/EBEYn9CmKyN6/RpFqLJ6PxUszNCw6VUrpiUXUv/yFRWyCrwnmMN5HRkYE4UJ PMixkyvyCGMKDye1wdgHgu0fJn8SnSsqJcm9xEIMeoJiOLIfYK2lujfTSzSkr0zmw/3b VsJs2v3LQcgVQlmSqqQbHEZF7GZIpWPGfxDZUuVSSA3E2jOA1tr72+WZCgAQn6ZPgJt2 Ecog== 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=8WVCgIbaq/jdNQA6d+Wa1CN7e/ZoYkChVYLL1VI8a6s=; b=Op41jH6qiHZn8yAPFp8hVXt8clFsvusGC7cR3/VvrAfVc9+abbaGJ2jq/4P3PkHBDC Usf1HQA6AouEeJJl0T0L11donMy8ZDzNGPYZ7gjA7vYIfDX9TV3mliR5QQ/dMEhyOOVY BMHwNU9mkAI0ZrXdk1njVac4OkfNY2hwN6qUS4OFdDK1X7NVHqna7wfh7iCzhCvn1eSB Gvi2V3yKgv1iCw0IeX37rgfBfTjLFpyngHsB4j/A+16d411R4lOEq1CPO3Uvv8xqtMqv wZv1z3jn0CLWbhetC/yIYlDuNkfrJ38rHFob1SJS0kevkdc75c1BYDUuoHPQZ8thjpEa FukQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=FvAH2FlJ; 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 l32-v6si820861qtd.355.2018.05.15.15.45.05 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 15 May 2018 15:45:05 -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=FvAH2FlJ; 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]:36403 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIigr-0008T4-4W for patch@linaro.org; Tue, 15 May 2018 18:45:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39591) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIiOR-0003S9-2d for qemu-devel@nongnu.org; Tue, 15 May 2018 18:26:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fIiOP-0005Hu-45 for qemu-devel@nongnu.org; Tue, 15 May 2018 18:26:03 -0400 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]:33149) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fIiOO-0005Ah-Py for qemu-devel@nongnu.org; Tue, 15 May 2018 18:26:00 -0400 Received: by mail-pf0-x241.google.com with SMTP id a20-v6so745323pfo.0 for ; Tue, 15 May 2018 15:26:00 -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=8WVCgIbaq/jdNQA6d+Wa1CN7e/ZoYkChVYLL1VI8a6s=; b=FvAH2FlJ24p7UqSez5AzYqmFezOP/NiGp+wyN09Wc5YqWK48C3SkajB0qZzetHG4il mRtQI3HlbzViwiCYnwRzU4wUdQLNhnLPePGzAx99XQTumwQihGxy7XgF1bY7VdnFLhP7 L4U0XGI25Qgj7cqswyjn7q+V0YM95RshxUU1A= 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=8WVCgIbaq/jdNQA6d+Wa1CN7e/ZoYkChVYLL1VI8a6s=; b=m1YrxMjj0hDQQTT9kRv1Ak+1RZkcrOIPVq2zhnUB0YGw5SrHH2b82ZqjTaFdt5tyBe YutGC2wimthJRDUzX4zzLSh4tnE11lunVATeD+Bfe68QizmpLVK6Turxfg1P7mIz2zYI C7OERdslg3UQ88v1ENNh0fgPhc4BK3Wd+z3tf0LskvoolTgEz4dLntAfRw4KcnPHloqT b8pY6ssvaX2wZw2SfVzOwXPNSLJa5x2ZbsXXttuDZRK0LIGIAvMxeB3JT3XvIa2NbGsK E1T6nkuuAbVeKAeXyaANeKMowIabDi+olaL+Ce4A0GwFu+6WDLBh8+JJa4eu1frUCvGy /Ebg== X-Gm-Message-State: ALKqPwfjRnEBWh9yKOnCArS/H+Gw1wi/aeDjUbPPlB6IAyoS22wHVOBy cr5hHUgtFqkF0g5N7Nv780VGcK5A+OY= X-Received: by 2002:a63:380e:: with SMTP id f14-v6mr6728854pga.242.1526423159515; Tue, 15 May 2018 15:25:59 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-2-170.tukw.qwest.net. [97.113.2.170]) by smtp.gmail.com with ESMTPSA id g11-v6sm941419pgq.62.2018.05.15.15.25.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 15 May 2018 15:25:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 15 May 2018 15:25:23 -0700 Message-Id: <20180515222540.9988-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180515222540.9988-1-richard.henderson@linaro.org> References: <20180515222540.9988-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::241 Subject: [Qemu-devel] [PATCH v6 11/28] fpu/softfloat: Partial support for 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: peter.maydell@linaro.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alex Bennée For float16 ARM supports an alternative half-precision format which sacrifices the ability to represent NaN/Inf in return for a higher dynamic range. 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. Usage of this new flag waits until we re-factor float-to-float conversions. Reviewed-by: Peter Maydell Signed-off-by: Alex Bennée Signed-off-by: Richard Henderson --- v3 - squash NaN to 0 if destination is AHP F16 v4 - handle inf -> ahp max in float_to_float not round_canonical - assert no nan and inf for ahp in round_canonical - check ahp before snan in float_to_float v5 - split out canonicalize and round_canonical changes from the rest --- fpu/softfloat.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) -- 2.17.0 diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 41253c6749..64e1ad4f98 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -220,8 +220,10 @@ typedef struct { * frac_shift: shift to normalise the fraction with DECOMPOSED_BINARY_POINT * The following are computed based the size of fraction * frac_lsb: least significant bit of fraction - * fram_lsbm1: the bit bellow the least significant bit (for rounding) + * frac_lsbm1: the bit below 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; @@ -233,6 +235,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 */ @@ -324,7 +327,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 { @@ -413,7 +416,15 @@ static FloatParts round_canonical(FloatParts p, float_status *s, } frac >>= frac_shift; - if (unlikely(exp >= exp_max)) { + if (parm->arm_althp) { + /* ARM Alt HP eschews Inf and NaN for a wider exponent. */ + if (unlikely(exp > exp_max)) { + /* Overflow. Return the maximum normal. */ + flags = float_flag_invalid; + exp = exp_max; + frac = -1; + } + } else if (unlikely(exp >= exp_max)) { flags |= float_flag_overflow | float_flag_inexact; if (overflow_norm) { exp = exp_max - 1; @@ -464,12 +475,14 @@ static FloatParts round_canonical(FloatParts p, float_status *s, case float_class_inf: do_inf: + assert(!parm->arm_althp); exp = exp_max; frac = 0; break; case float_class_qnan: case float_class_snan: + assert(!parm->arm_althp); exp = exp_max; frac >>= parm->frac_shift; break;