From nobody Mon Feb 9 08:41:58 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516800498032380.70303511005136; Wed, 24 Jan 2018 05:28:18 -0800 (PST) Received: from localhost ([::1]:48602 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eeL69-0006D9-5F for importer@patchew.org; Wed, 24 Jan 2018 08:28:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55742) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eeKrw-0003Qx-KY for qemu-devel@nongnu.org; Wed, 24 Jan 2018 08:13:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eeKrq-0003t0-Mu for qemu-devel@nongnu.org; Wed, 24 Jan 2018 08:13:36 -0500 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:42083) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eeKrq-0003sI-E4 for qemu-devel@nongnu.org; Wed, 24 Jan 2018 08:13:30 -0500 Received: by mail-wr0-x243.google.com with SMTP id e41so3976191wre.9 for ; Wed, 24 Jan 2018 05:13:30 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id k35sm5708280wrc.2.2018.01.24.05.13.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Jan 2018 05:13:23 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 79E833E0AA7; Wed, 24 Jan 2018 13:13: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=8c+/sVF4/VYt3J5Vx/8A2fol2iTQfVQClqf8nu69NmI=; b=Ty0iuyf692ab6Z8PUWatiuYlI/O6lnOP2d3yoUwORhhiM+g0YK5JfqeJXhddTN05dm eZM0oqnyemNhk66T7Jx+DCEN8h7t++zBGsAhAYzIVdY0u7epO1ujGNPH7kEUfnoCHzFj UCSfNkVsSVCxBgixigXifrpXuqZW+vAU/AL/4= 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=8c+/sVF4/VYt3J5Vx/8A2fol2iTQfVQClqf8nu69NmI=; b=GmwAvExylMH/NCqRE6FbxuUqt+uF+RWKxC5Vo4X52aBc8RCNxyrycxTxASZ5pIYPzA LbYjnW15GP0Boi0Exggxi0qvt8f5gxETIXU6EUH4WnbkF4NXYAddJH0O4riSY5Ut826W wKHk9Ectjld6NRg2uyLtfOUDL22duDTrWTV7var/6nyQxV34J2lI2Vu28l2U2H0EWZVQ /0Eo0r2VLT4BL/GQVE6I/rRdR5b3XRf3o5fWOV0NPs6Lld9/BLi8LwjmHm6T6Ntbx/FV gF8G3e9PgKBOHFhDC1Ks6YdHCN2Tm2OdqIP1Z7ko6oAh0PMupfdzSXIPqYVeyo+SK8la j/hQ== X-Gm-Message-State: AKwxytf5RmkD9M7uJLhMunCtdvmsc77MpSjlS1dvdOIiWBMTxlEsGEjM EewSKAjG+S1SdwxJk44Ta5NFow== X-Google-Smtp-Source: AH8x224ARiASXmdQOEL7TgmeO65U/yLkIllUIu2iLvsQLlmXZeNJZihRDJdsldT3HoOlYyT5pKiBZw== X-Received: by 10.223.197.72 with SMTP id s8mr5954500wrf.96.1516799609353; Wed, 24 Jan 2018 05:13:29 -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: Wed, 24 Jan 2018 13:13:04 +0000 Message-Id: <20180124131315.30567-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180124131315.30567-1-alex.bennee@linaro.org> References: <20180124131315.30567-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:c0c::243 Subject: [Qemu-devel] [PATCH v3 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