From patchwork Tue Feb 6 16:48: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: 127041 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp3095281ljc; Tue, 6 Feb 2018 08:58:52 -0800 (PST) X-Google-Smtp-Source: AH8x225QMuVVNEvaPqzyYKrAf0Itx7WNBsfcV5rbluoAK9uWhVxJdrCmrqWUl8iE2s8Y/If/vYO6 X-Received: by 10.37.196.68 with SMTP id u65mr1948187ybf.487.1517936332245; Tue, 06 Feb 2018 08:58:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517936332; cv=none; d=google.com; s=arc-20160816; b=TYokv7LrbSL6Jjv168PFczIJSK53OK7bcLkLcxAp+qUohXfdvAFxgrD6+jkaLJpwbs q3omQPt3in+yVbr0XSBA55EyubkRvo+LJt4r4smw+MoOeOJNDQMmA2Ja7r0eoBcaL2YN JnZL64taHA48oWvsKPMMvOnqB9eloPEEIXQaEaYWTf7DH5s/nOYZlWIel7PRgZUsOlA+ /xcbhc6QjujOOoLLxwNixBjdx+OpTO6e7Wree20Wxi0F1BNdtYYMgFm2QksrUs3snCZ1 0utbE1deirLFHprWZ95JDaiAE4jbBF2LnMPE/dhlY4DrQ4NoARCOdR9cU3D1E+jXR3Db HsXg== 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=QSk7rvTnRN7zVjOz/qnoI6MD7fqHW+3DEcMId0sEPMc=; b=iaJF+fbHg/9LN13cs/+4tlpYyaPM/CJolnX8fAeDt9XWzmzYORUJpa7T4WXbZkrzrS rLP+faGUkHVMJHS1lKEUnytuzyBC2FfSOQ2OjIVLh64dnWZNjW9j4lgsJoGYHq/RCDAH guriYPg2cSosINpVxZotuMCX+o3TsiyIqIiOTHWNuf+Eb2E7uTpA+R++3tms6zIEpn2F n+my7TWtmdHN/i7CA2aHC4nTfbN4hWL7hd/AnWdKRt4LJO/+OmfPIb6pk8nx1NPF7cgn 2P0BlIK9ogf0kmQWCq/L+T0SYbvxPHSpljm3JASS2Lp50OSzo/MxRQU3NsmES+SnUVYG Wo3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Krblsqv3; 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 o2si1896949ywo.450.2018.02.06.08.58.52 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 06 Feb 2018 08:58:52 -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=Krblsqv3; 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]:37851 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ej6a3-0001kY-H2 for patch@linaro.org; Tue, 06 Feb 2018 11:58:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35804) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ej6Wc-0007DN-Ug for qemu-devel@nongnu.org; Tue, 06 Feb 2018 11:55:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ej6WY-0001Z1-5G for qemu-devel@nongnu.org; Tue, 06 Feb 2018 11:55:19 -0500 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:32773) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ej6WX-0001YK-Lp for qemu-devel@nongnu.org; Tue, 06 Feb 2018 11:55:14 -0500 Received: by mail-wm0-x243.google.com with SMTP id x4-v6so18722029wmc.0 for ; Tue, 06 Feb 2018 08:55:13 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=QSk7rvTnRN7zVjOz/qnoI6MD7fqHW+3DEcMId0sEPMc=; b=Krblsqv3PsaxUhoAsATH1m8cxStu/2Izs99DyFqZAaTdd9zVBWlWOj/qaAu/u8W/L5 5yA8kRrkY1nC0lzHHyVPfUHRDXMtFTsfy8Z5/8eevjOETgF9lDItkTN5m0T5EXcexU1B qr37gc6SnjClA/zsejfPvhlDthsmL2MRJvi7I= 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=QSk7rvTnRN7zVjOz/qnoI6MD7fqHW+3DEcMId0sEPMc=; b=cjBsFD4lNTagZ1EanatKuwb7eZlEmJFGbc7bkLqcT1NuJ9asyvb1N62qJfvRWzlyBw xYdngUu8m1qJUPWFVkBI51utnZYM3UwQgUxm5UPWLUlqox9XKgF68uwocPb2JsYqTYfK V0HcydePakORszBFo+17SSWRfRxAB1sxAOMCQNs/E8xDrbe4qEDHLC4FYWvsNcVXnf0m InzhtJbS8NADfCumdA8HNGNXzodyCAk1d0Aoo2wRdWUTEu+BcldVTuyD/4W7yJ0TEUJO Ve+k88WeLqb2cq0lAZpEHSw8/MavGffKYoqiGlBSei+Du55XC476i6VBvMc1zpvSAbVd WwOQ== X-Gm-Message-State: APf1xPALVlThOmB5nLaYgN5ARQijJzMhPbtEXpoBusB6G9zIiPeDLvoA twWNaGRetjzk6EFL7Vji5yNTdg== X-Received: by 10.28.107.134 with SMTP id a6mr2424828wmi.136.1517936112496; Tue, 06 Feb 2018 08:55:12 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id y55sm17962590wry.87.2018.02.06.08.55.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Feb 2018 08:55:11 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 1BF5A3E079E; Tue, 6 Feb 2018 16:48:16 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: richard.henderson@linaro.org, peter.maydell@linaro.org, laurent@vivier.eu, bharata@linux.vnet.ibm.com, andrew@andrewdutcher.com Date: Tue, 6 Feb 2018 16:48:04 +0000 Message-Id: <20180206164815.10084-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180206164815.10084-1-alex.bennee@linaro.org> References: <20180206164815.10084-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 v4 11/22] fpu/softfloat: define decompose structures 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-devel@nongnu.org, Aurelien Jarno Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" These structures pave the way for generic softfloat helper routines that will operate on fully decomposed numbers. Signed-off-by: Alex Bennée Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- v3 - comment box style - CamelCase structs - hide DECOMPOSED_BINARY_POINT - frac in macro - more comments - add exp_size, frac_size to FloatFmt - compute exp_bias and exp_max from FLOAT_PARAMS - remove include bitops (in next patch) --- fpu/softfloat.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) -- 2.15.1 diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 297e48f5c9..568d555595 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -83,7 +83,6 @@ this code that are retained. * target-dependent and needs the TARGET_* macros. */ #include "qemu/osdep.h" - #include "fpu/softfloat.h" /* We only need stdlib for abort() */ @@ -186,6 +185,91 @@ static inline flag extractFloat64Sign(float64 a) return float64_val(a) >> 63; } +/* + * Classify a floating point number. Everything above float_class_qnan + * is a NaN so cls >= float_class_qnan is any NaN. + */ + +typedef enum __attribute__ ((__packed__)) { + float_class_unclassified, + float_class_zero, + float_class_normal, + float_class_inf, + float_class_qnan, /* all NaNs from here */ + float_class_snan, + float_class_dnan, + float_class_msnan, /* maybe silenced */ +} FloatClass; + +/* + * Structure holding all of the decomposed parts of a float. The + * exponent is unbiased and the fraction is normalized. All + * calculations are done with a 64 bit fraction and then rounded as + * appropriate for the final format. + * + * Thanks to the packed FloatClass a decent compiler should be able to + * fit the whole structure into registers and avoid using the stack + * for parameter passing. + */ + +typedef struct { + uint64_t frac; + int32_t exp; + FloatClass cls; + bool sign; +} FloatParts; + +#define DECOMPOSED_BINARY_POINT (64 - 2) +#define DECOMPOSED_IMPLICIT_BIT (1ull << DECOMPOSED_BINARY_POINT) +#define DECOMPOSED_OVERFLOW_BIT (DECOMPOSED_IMPLICIT_BIT << 1) + +/* Structure holding all of the relevant parameters for a format. + * exp_size: the size of the exponent field + * exp_bias: the offset applied to the exponent field + * exp_max: the maximum normalised exponent + * frac_size: the size of the fraction field + * 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) + * round_mask/roundeven_mask: masks used for rounding + */ +typedef struct { + int exp_size; + int exp_bias; + int exp_max; + int frac_size; + int frac_shift; + uint64_t frac_lsb; + uint64_t frac_lsbm1; + uint64_t round_mask; + uint64_t roundeven_mask; +} FloatFmt; + +/* Expand fields based on the size of exponent and fraction */ +#define FLOAT_PARAMS(E, F) \ + .exp_size = E, \ + .exp_bias = ((1 << E) - 1) >> 1, \ + .exp_max = (1 << E) - 1, \ + .frac_size = F, \ + .frac_shift = DECOMPOSED_BINARY_POINT - F, \ + .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 + +static const FloatFmt float16_params = { + FLOAT_PARAMS(5, 10) +}; + +static const FloatFmt float32_params = { + FLOAT_PARAMS(8, 23) +}; + +static const FloatFmt float64_params = { + FLOAT_PARAMS(11, 52) +}; + /*---------------------------------------------------------------------------- | Takes a 64-bit fixed-point value `absZ' with binary point between bits 6 | and 7, and returns the properly rounded 32-bit integer corresponding to the