From patchwork Tue Jan 9 12:22:42 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: 123911 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp3963730qgn; Tue, 9 Jan 2018 04:31:35 -0800 (PST) X-Google-Smtp-Source: ACJfBovdkryarvsRTozy5aQOCXKXWkVoI/tyMHHHjJQ89KArWkyUWB9+t4ERFIReuoIj51Sc4fbu X-Received: by 10.129.72.204 with SMTP id v195mr6661579ywa.448.1515501095506; Tue, 09 Jan 2018 04:31:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515501095; cv=none; d=google.com; s=arc-20160816; b=zSdhq8bwp5lf8AjTk6A+kVVabZvQpcl4jO9Edpsrp5h5CK+lYqj+crGMi8Sx1Dd1rJ SXVMEDuXRL4/n51IZel8Nkzrgsd5K2Tn8y8FNx97MvuKho2ZGt/zHcDW4Ke+st1EEgxz c506GRJ5r//rNlDL3kSruKIqrpkkGzt1i5dp6Qs73ihNB7Vz1wZIQTmyeJ8d5+j9V0SI aMm73hwjxg/C3Wt9AVpuCdGvhzOmTMYqJqistUjrzutOqFpn4Q07FFBZGG/oF/ieSnlH pSqAfGQSyQyQnMquzfGootYuqtpeQfvd2bpV98ABHehDVSdmsWO9pR+TEDYoTTzjITOL vcSg== 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=TuqpRZxm6uXuRzIpBThQodutJC+WGgUS7fzwpNjLwqk=; b=NE6veu1dKkP4zWPqC1XKbICEO+71poZRey9Wcu4LewsF1GpUiySAPtIv172EjWNpT2 lH8Lzkk+qhOt9dIPsQBlnDKwGW/CqKGpcjycubIC0NkwSrh//K/YSHn1adykoSif+Bai oS/yweQbLHS8oTy1pkpvLrZizYKuQVgs4HF1BfxnWbfHsdHn1KsjBQzOHR2Lx0FkodCo cmKRirVJB0KSTfYThBfgSlVRp7prmmgRkFsrhlIi7CixN8cssrdYxY+oFzVYsyuM/+9M C6trj+FMrSeCGyTsNKAtWee8dsNu81t7vq/ecDGfedcEl/C88AuCXwGWx7qWSXMZIFwA 9JQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=A7S/kq8M; 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 c190si772465ywh.761.2018.01.09.04.31.35 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 09 Jan 2018 04:31:35 -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=A7S/kq8M; 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]:49538 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eYt43-0004tJ-0X for patch@linaro.org; Tue, 09 Jan 2018 07:31:35 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51451) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eYsvp-0006fS-Nm for qemu-devel@nongnu.org; Tue, 09 Jan 2018 07:23:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eYsvo-0006g2-Nl for qemu-devel@nongnu.org; Tue, 09 Jan 2018 07:23:05 -0500 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:47022) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eYsvo-0006eU-Hl for qemu-devel@nongnu.org; Tue, 09 Jan 2018 07:23:04 -0500 Received: by mail-wr0-x241.google.com with SMTP id g21so8109645wrb.13 for ; Tue, 09 Jan 2018 04:23:04 -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=TuqpRZxm6uXuRzIpBThQodutJC+WGgUS7fzwpNjLwqk=; b=A7S/kq8MN3sgBnRuDtRysm9/2A7lBK1JsDThRptQ3WebRslj1u3Ku1Lz4iYgO+KAAb BIODiy2qflCjKEt7Ald1Kh6ddpbFaA3Y8PC/J6BKK+OKsLyONpdeuxM+t0Sq90/jcZjs QFadUxlxEpMm3EavgbD6A6ooHo4y2XvwB4yic= 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=TuqpRZxm6uXuRzIpBThQodutJC+WGgUS7fzwpNjLwqk=; b=WSU+FjPr6ig6kn8N93hzSqyGu+B8s1RHPSgyOkpW3a1EL+LlEuC0pw2eBumGIqfUkl vf53CBus2FSGGHLmF6Embxccbl8kDRBfbzpqTMDFdFAappYBaWearGgMpNK2ChhbPYA7 hJCBCeKvx1jqg84Z3uwMbnn83lP3nVb47RFd5czo7PqdcsKAoZD5WSyso+9NAQLahFXb FFvba8Dc3vVmkdV+jF1ltdQKrVUYcHohMGipP7TMm68o/VJvLASjAmwbjQoMKlHqaFY1 8dSnVg7zgHhdNMfvqHhiXG/hIlV8KTFU/ahRKZVI0ZkER6Wul9z2Ju3b/7dSrgt5nH8K Y5oQ== X-Gm-Message-State: AKGB3mLjV4wKrlBStVCbzqKA+YBPSge/os5mdgRW6OKmmlHVeyZhUDok IOVbeDEuxoKCd6w/10lJ08kYVg== X-Received: by 10.223.177.143 with SMTP id q15mr12524719wra.228.1515500583457; Tue, 09 Jan 2018 04:23:03 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id 127sm17084022wmk.14.2018.01.09.04.22.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Jan 2018 04:22:59 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id D55333E2B4D; Tue, 9 Jan 2018 12:22:52 +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, 9 Jan 2018 12:22:42 +0000 Message-Id: <20180109122252.17670-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180109122252.17670-1-alex.bennee@linaro.org> References: <20180109122252.17670-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::241 Subject: [Qemu-devel] [PATCH v2 10/20] 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 --- fpu/softfloat.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) -- 2.15.1 diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 59afe81d06..fcba28d3f8 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -83,7 +83,7 @@ this code that are retained. * target-dependent and needs the TARGET_* macros. */ #include "qemu/osdep.h" - +#include "qemu/bitops.h" #include "fpu/softfloat.h" /* We only need stdlib for abort() */ @@ -186,6 +186,74 @@ static inline flag extractFloat64Sign(float64 a) return float64_val(a) >> 63; } +/*---------------------------------------------------------------------------- +| Classify a floating point number. +*----------------------------------------------------------------------------*/ + +typedef enum { + float_class_unclassified, + float_class_zero, + float_class_normal, + float_class_inf, + float_class_qnan, + float_class_snan, + float_class_dnan, + float_class_msnan, /* maybe silenced */ +} float_class; + +/*---------------------------------------------------------------------------- +| Structure holding all of the decomposed parts of a float. +| The exponent is unbiased and the fraction is normalized. +*----------------------------------------------------------------------------*/ + +typedef struct { + uint64_t frac : 64; + int exp : 32; + float_class cls : 8; + int : 23; + bool sign : 1; +} decomposed_parts; + +#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. */ +typedef struct { + int exp_bias; + int exp_max; + int frac_shift; + uint64_t frac_lsb; + uint64_t frac_lsbm1; + uint64_t round_mask; + uint64_t roundeven_mask; +} decomposed_params; + +#define FRAC_PARAMS(F) \ + .frac_shift = F, \ + .frac_lsb = 1ull << (F), \ + .frac_lsbm1 = 1ull << ((F) - 1), \ + .round_mask = (1ull << (F)) - 1, \ + .roundeven_mask = (2ull << (F)) - 1 + +static const decomposed_params float16_params = { + .exp_bias = 0x0f, + .exp_max = 0x1f, + FRAC_PARAMS(DECOMPOSED_BINARY_POINT - 10) +}; + +static const decomposed_params float32_params = { + .exp_bias = 0x7f, + .exp_max = 0xff, + FRAC_PARAMS(DECOMPOSED_BINARY_POINT - 23) +}; + +static const decomposed_params float64_params = { + .exp_bias = 0x3ff, + .exp_max = 0x7ff, + FRAC_PARAMS(DECOMPOSED_BINARY_POINT - 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