From patchwork Mon Dec 11 12:56:55 2017 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: 121401 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp2762341qgn; Mon, 11 Dec 2017 05:03:36 -0800 (PST) X-Google-Smtp-Source: ACJfBos26UW35wtVm2EltRLpPqwy74zwerdQI0iW5W4oSmECqE9DMyXjW97eCDyX/klYO76oH3SE X-Received: by 10.37.188.146 with SMTP id e18mr206453ybk.31.1512997416451; Mon, 11 Dec 2017 05:03:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512997416; cv=none; d=google.com; s=arc-20160816; b=Q31IOjKiGDsy8K1D2s1rVnMLrPY6YHLw+Ihwv438DG6V7OnrBQaV3RQxHZnxUqeEW5 ZTlUesRUR00p7g+TNQBFFaTnR9KPmHu4M0ia3JC7/MrJZc56hfxz483UHd1mO+4inVlX YvDgEWGfqj8F/t3r1bQ3YCfjAEvxn7lZPu1yEI5Sf2q5DRtbRrDiUHSbE13CbyWcPdej vW1hIXGUrgIYSRMRy/fc5llMEAgJ7u6u1Lh6dDJCieUD3ixA9Ooh9IEB7sTBOu4xD9V3 wYDRIDH14uTe+Q8SpXZhB1f8cUHliFEoGwAovzUL8HQBHvy20g+m14u6o5lL5B9rdfUF kJJg== 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=XPya0JZDgDrSn8vFhXRH6qNNUTXHPncbbdbXFArQOvM=; b=oeKuLfwp3oxxKhiLJropcztC8du+ifcVfkYG97DnG204Acv9Az5qvonc7q0DXYPJhC h0fsQ2el92hbpD0WjCDvYnZNDRJJozKD+OdzGS8VlyQjMO5O0JEEYanqrqMc5g497uEV V0xI9l48ypgwWFGL5jT5eiI9j76mT/ipkd9+efOBNnaZpXq1QaybnOl8XZd6gVMjvDiD 11aXDEgtAtG86bYBNa474isEUJ8j5buQAHLpoOayvvGTObtyYMEMEZQ8BuYM6EvGKHd/ G4oqin12pFJ8m/cAOpx6+anG5U4Kwz/YZtVk+O0AYi5m3JvQ6BQ1He6AGC1r/fUorCiO m04w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=EVv5w8UL; 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 g193si1121322ybf.201.2017.12.11.05.03.36 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 11 Dec 2017 05:03:36 -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=EVv5w8UL; 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]:52615 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eONk7-0000Fj-Ut for patch@linaro.org; Mon, 11 Dec 2017 08:03:36 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51575) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eONe4-0002QN-Cv for qemu-devel@nongnu.org; Mon, 11 Dec 2017 07:57:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eONe3-0007jL-Bs for qemu-devel@nongnu.org; Mon, 11 Dec 2017 07:57:20 -0500 Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]:36469) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eONe3-0007iW-5f for qemu-devel@nongnu.org; Mon, 11 Dec 2017 07:57:19 -0500 Received: by mail-wr0-x244.google.com with SMTP id v105so17471258wrc.3 for ; Mon, 11 Dec 2017 04:57:18 -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=XPya0JZDgDrSn8vFhXRH6qNNUTXHPncbbdbXFArQOvM=; b=EVv5w8ULzcZjILOSuXU0PM1TzaHEmVd3TXJONEqS1HUDz//nG/SIeUp/1RrF0pU2qa hUXsbdWLMvNawC8xLqlfleftONhDqbDJUfpW5qnOmzfVYbwOqj9XfMNHzlncO2ktnC6A /VQdBnCoKaAkNJrnXFCO+6NbkkFyx1utYeFuM= 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=XPya0JZDgDrSn8vFhXRH6qNNUTXHPncbbdbXFArQOvM=; b=j+2eWIiFULg2dFGN6N7G+9G25aRDUiM602lKc8Ik6vMsbVLXl+1uXljBQO0krhll1t pL7EjUQCvWrY3Rhtv3GTljFanMWgYS++IhHu17bX+Rm5gBOs/A9mh0nvFiegCIU8dH62 sq7XP2szgifCIe7b1ms/MhQGt6hcE8cbvLVlfSgKSBjEpE8maBzvwmvUpForwD20a5mG 2GDsPx8F3113Q6Xt+yqy3zWdvBjWUbFfPPd/FTRe9YrmUQm9hekvLwZ2hgi/7kFr7Na4 Znafi9vo/jWthfRydTiKG8O+/KkHBr2aHgvfSokHaVBfcFOJuOIKS98che2RuwLVbwVl DaTw== X-Gm-Message-State: AKGB3mIO98EPTu7fCPTnCRbH1/wAhCQ89/eT5kiP66aPFFNC2GvwTnaH 7AxlsnrmvEKSuzN0qVPHankmCw== X-Received: by 10.223.139.199 with SMTP id w7mr323225wra.282.1512997038000; Mon, 11 Dec 2017 04:57:18 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id k5sm9548239wmg.21.2017.12.11.04.57.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Dec 2017 04:57:11 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 0D75A3E09C4; Mon, 11 Dec 2017 12:57:06 +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, aleksandar.markovic@imgtec.com Date: Mon, 11 Dec 2017 12:56:55 +0000 Message-Id: <20171211125705.16120-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171211125705.16120-1-alex.bennee@linaro.org> References: <20171211125705.16120-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::244 Subject: [Qemu-devel] [PATCH v1 09/19] 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 --- fpu/softfloat.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) -- 2.15.1 Signed-off-by: Richard Henderson diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 0850a78149..fe443ff234 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() */ @@ -185,6 +185,76 @@ 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