From nobody Tue Feb 10 20:14:34 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1517936420024280.87872728688114; Tue, 6 Feb 2018 09:00:20 -0800 (PST) Received: from localhost ([::1]:37982 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ej6bM-00030F-4w for importer@patchew.org; Tue, 06 Feb 2018 12:00:12 -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) 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) 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-Google-Smtp-Source: AH8x2245ETSrvn+FlDdlwk75Z+PSQ3lNsXut/+ZC+RIlpLbjFTKWbBZGNDs6r+8Edilrfpx5EF2KyA== X-Received: by 10.28.107.134 with SMTP id a6mr2424828wmi.136.1517936112496; Tue, 06 Feb 2018 08:55:12 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450: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=20Benn=C3=A9e?= , qemu-devel@nongnu.org, Aurelien Jarno Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 These structures pave the way for generic softfloat helper routines that will operate on fully decomposed numbers. Signed-off-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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(-) 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" =20 /* We only need stdlib for abort() */ @@ -186,6 +185,91 @@ static inline flag extractFloat64Sign(float64 a) return float64_val(a) >> 63; } =20 +/* + * Classify a floating point number. Everything above float_class_qnan + * is a NaN so cls >=3D 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_PO= INT + * 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 =3D E, \ + .exp_bias =3D ((1 << E) - 1) >> 1, \ + .exp_max =3D (1 << E) - 1, \ + .frac_size =3D F, \ + .frac_shift =3D DECOMPOSED_BINARY_POINT - F, \ + .frac_lsb =3D 1ull << (DECOMPOSED_BINARY_POINT - F), \ + .frac_lsbm1 =3D 1ull << ((DECOMPOSED_BINARY_POINT - F) - 1), \ + .round_mask =3D (1ull << (DECOMPOSED_BINARY_POINT - F)) - 1, \ + .roundeven_mask =3D (2ull << (DECOMPOSED_BINARY_POINT - F)) - 1 + +static const FloatFmt float16_params =3D { + FLOAT_PARAMS(5, 10) +}; + +static const FloatFmt float32_params =3D { + FLOAT_PARAMS(8, 23) +}; + +static const FloatFmt float64_params =3D { + 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 --=20 2.15.1