From patchwork Wed Jan 24 13:13: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: 125654 Delivered-To: patch@linaro.org Received: by 10.46.66.141 with SMTP id h13csp415758ljf; Wed, 24 Jan 2018 05:29:09 -0800 (PST) X-Google-Smtp-Source: AH8x2267/OaLbjzUKfBLHP0MrYJzAC1Ifr+huAv3Fi2UIJBIDSFUrogievoCdjzrCwbWoAj6qdZY X-Received: by 10.37.255.1 with SMTP id c1mr4954586ybe.301.1516800548955; Wed, 24 Jan 2018 05:29:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516800548; cv=none; d=google.com; s=arc-20160816; b=RjUDF3rFGwSPNTATwn1zpVjT/JZqcbB0p5Nt7S8ndnL8A+6fVmn5G4NAAeSK2LCDSa dYMi9n2Aq8tSChDutZ+Evz4Ti/VRYa7766Wr3bUOJLfJA4BWZQnUd4JyTE7ZSZGCgO3Q pqopdLYnfkNneE5/bWr8WagZ4ABS3eFKbtSgjacynygBT5lj8uVhv6IFVei+yDPyQ8eZ m6A+rlDVDPnK+HvOR43+7gpQRL5Z5RdbvNArBkLMGTY3fszI+6U63VQqTmvMCmXZE1N5 jNvA7NAm2fc4SbKypM81w+VSVPt4O0pm3iq6kuq9qmGYiuU7p+xxb7WAeKzR2+bphty+ wLgg== 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=8c+/sVF4/VYt3J5Vx/8A2fol2iTQfVQClqf8nu69NmI=; b=JsezCWpoCngGI7YTZIXzK6TYaJUJo2gi/YDeHxh5ZLYWGI2pDMSmERqHhhfR4kO9Rl Oj6TawQkHuMOwq4C+aChSfGjEaen1A1ug9pCHyXfAwzrS9Fir1sDXx4pliFMXXOnB3FJ WHa/3DrDT9S/PLOOesx+Q/JgNLkvqsYzAUHKtbYWQhWEdPtBY0MrHsOIpzYtoFnajphg E1wXjJCqIAYttZ3Xsie/BwUIPYbMqvFMTUre2Rs7udfHnjjMvn8iOE7AjW85T9U/cm0x IlEEfBBVrMeuOAqP4+2/lDCEc4fbsp4T511MgGdf4llL4nTs2Ddn/hO46QqqsJVFQtwR evyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Ty0iuyf6; 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 q184si2735380ybg.395.2018.01.24.05.29.08 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 24 Jan 2018 05:29:08 -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=Ty0iuyf6; 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]:48602 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eeL6y-0006D9-8H for patch@linaro.org; Wed, 24 Jan 2018 08:29:08 -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) 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-Received: by 10.223.197.72 with SMTP id s8mr5954500wrf.96.1516799609353; Wed, 24 Jan 2018 05:13:29 -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) 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: 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 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_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 --- 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 Reviewed-by: Philippe Mathieu-Daudé 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