From patchwork Mon Dec 11 12:57:05 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: 121410 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp2770604qgn; Mon, 11 Dec 2017 05:10:04 -0800 (PST) X-Google-Smtp-Source: ACJfBouMLIHmrSChs9txuvoKS8V8lsDw2guorXV+bH0uhutLJj+w9vLSZhc0GzGUaASqIxEk56Ff X-Received: by 10.37.122.194 with SMTP id v185mr202881ybc.359.1512997804569; Mon, 11 Dec 2017 05:10:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512997804; cv=none; d=google.com; s=arc-20160816; b=qT7SWStbX3UotDiBGN/wI6GZ0UQrHyLLXJSFfgIvLqPqVvqwE4mZDMlGYpHJhTtzhs EpZCUp/DhlpVCPuEJJeDIwWJP1oNBQ9f3ViAQRI3Q0G2cXzWxpgrtRWf1aHXxJGqQ6RK yxH42tGoC789xYcIToY9HAHUeraHaykmDYRjYfRBR4f29F8vOXrQMb+9M0MQ2fputRys RXx1ouOD3Usjbo/1V/FD3G+Zp/7YMnWhmlcYav4Bq3KFsVM8dzbmuwj/DBHogULfaHq3 aA4UyBF9GPrW+JQ/Ulb+TGe1TSPAI2jptKF/Mok9uXqDtPCfeb4B6Hl23QfGJVA+rgXf L1CQ== 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=T6rRmFgNcU7BCPuXiNHLXdJhOz6C1zxyD5Wfblt1xto=; b=TJlqE2CDlSX/VqeFFjTctef0P1nVEoG0Bi7+kZjPgTIMbOVq6MHi+f6bPviEk2wRTU IbZD/M+xiCFe19fPOKZ1uhSBvIvxBOVzQHOpXEIfqnp76xnsDMEI4bb6yGSykAIrDyam skpxAI4uvNAsm6/Wt/fKLUpYAk7MWKfm67rtFTah9HkZN2mZLgzLt/LFVI7y6mILZeWv O+4qD6hvkAOtjKQxxgPso3sI8DaUYYfPNuM525tVfnavrvJdFhI0bSCklcj/NmOWws7f bnSFLIgcBu00j7wql7hdIbVkm5pR+3DO/nTMLeOPnw81o8a65NXw/mCumBBz8CmXJrFJ t3mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Uq9Ysd32; 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 e188si3065143ywf.603.2017.12.11.05.10.04 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 11 Dec 2017 05:10:04 -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=Uq9Ysd32; 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]:52724 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eONqO-0000re-3C for patch@linaro.org; Mon, 11 Dec 2017 08:10:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51667) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eONe9-0002UQ-F1 for qemu-devel@nongnu.org; Mon, 11 Dec 2017 07:57:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eONe8-0007ol-6T for qemu-devel@nongnu.org; Mon, 11 Dec 2017 07:57:25 -0500 Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]:41737) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eONe7-0007o1-Tb for qemu-devel@nongnu.org; Mon, 11 Dec 2017 07:57:24 -0500 Received: by mail-wr0-x244.google.com with SMTP id z18so17479337wrb.8 for ; Mon, 11 Dec 2017 04:57:23 -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=T6rRmFgNcU7BCPuXiNHLXdJhOz6C1zxyD5Wfblt1xto=; b=Uq9Ysd326VlxZqBR0xEfmU6+oxNjN14XgK3iZgokuNRq2zcAoXEL5hvufb3ZDOpSeM SDkTFkrzSlYzCCOk0fBDg6++yi7lAS+w7Gq048GCLsA7tMCtNBIocbM8Urfqi2Edv6Uf p4B4iye4F94h4I1p5ZwsPJd/ZFPvsu0X/qfTc= 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=T6rRmFgNcU7BCPuXiNHLXdJhOz6C1zxyD5Wfblt1xto=; b=uYM9v7kdA/QrQSOT9IBVbuTNGk2aoumTRV/XixJ0MDZYJzvS2WRdvb+usX6Jfc7BLb YU1OvTxNoms+r+QGzp+xeWB+ZAnce1vXeXdPXHMc6l/9o3OiwflPYnNV8yVVZIsu+p3d JeCheyZYvQY0VNJ9ITQo3vmqLpjjzXvg0pUxqaM0VsjJ2RQqnYf1EOcGuTaa2sO2o7M/ P6WOmnFJNrSeRRLLRrVoaIJfejI0i3bwcB0cc6vcNMQLR+75afamNTZWAaUMX+63EgC0 xe2UOC9/SJN0V119dMQIJsNCnLld7LNNcF1bb8OjtfVFor1SoxGKvNYlHEdl3zeViOQN Qlcw== X-Gm-Message-State: AKGB3mI5H/wrZcN1OqjRdgHsgi3At1pslFQKiQLlEKj/iAhdLL1x/+03 EvH0CwlC0a/VXmduA3im36uukw== X-Received: by 10.223.190.135 with SMTP id i7mr311595wrh.91.1512997042713; Mon, 11 Dec 2017 04:57:22 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id l3sm17758139wrg.2.2017.12.11.04.57.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Dec 2017 04:57:18 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id C97233E122C; 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:57:05 +0000 Message-Id: <20171211125705.16120-20-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 19/19] fpu/softfloat: re-factor compare 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" Signed-off-by: Alex Bennée --- fpu/softfloat.c | 135 +++++++++++++++++++++++++++++------------------- include/fpu/softfloat.h | 2 + 2 files changed, 83 insertions(+), 54 deletions(-) -- 2.15.1 diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 5eba996932..31b437e000 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -1793,6 +1793,87 @@ MINMAX(64, maxnummag, false, true, true) #undef MINMAX +/* Floating point compare */ +static int compare_decomposed(decomposed_parts a, decomposed_parts b, + bool is_quiet, float_status *s) +{ + if (a.cls >= float_class_qnan + || + b.cls >= float_class_qnan) { + if (!is_quiet || + a.cls == float_class_snan || + b.cls == float_class_snan) { + s->float_exception_flags |= float_flag_invalid; + } + return float_relation_unordered; + } + + if (a.cls == float_class_zero || b.cls == float_class_zero) { + if (a.cls == float_class_normal) { + return a.sign ? float_relation_less : float_relation_greater; + } else if (b.cls == float_class_normal) { + return b.sign ? float_relation_greater : float_relation_less; + } else if (a.cls == b.cls) { + return float_relation_equal; + } + } + + /* The only infinity we need to explicitly worry about is + * comparing two together, otherwise the max_exp/sign details are + * enough to compare to normal numbers + */ + if (a.cls == float_class_inf && b.cls == float_class_inf) { + if (a.sign != b.sign) { + return a.sign ? float_relation_less : float_relation_greater; + } else { + return float_relation_equal; + } + } + + if (a.sign != b.sign) { + return a.sign ? float_relation_less : float_relation_greater; + } + + if (a.exp == b.exp) { + if (a.frac == b.frac) { + return float_relation_equal; + } + if (a.sign) { + return a.frac > b.frac ? + float_relation_less : float_relation_greater; + } else { + return a.frac > b.frac ? + float_relation_greater : float_relation_less; + } + } else { + if (a.sign) { + return a.exp > b.exp ? float_relation_less : float_relation_greater; + } else { + return a.exp > b.exp ? float_relation_greater : float_relation_less; + } + } +} + +#define COMPARE(sz) \ +int float ## sz ## _compare(float ## sz a, float ## sz b, float_status *s) \ +{ \ + decomposed_parts pa = float ## sz ## _unpack_canonical(a, s); \ + decomposed_parts pb = float ## sz ## _unpack_canonical(b, s); \ + return compare_decomposed(pa, pb, false, s); \ +} \ +int float ## sz ## _compare_quiet(float ## sz a, float ## sz b, float_status *s) \ +{ \ + decomposed_parts pa = float ## sz ## _unpack_canonical(a, s); \ + decomposed_parts pb = float ## sz ## _unpack_canonical(b, s); \ + return compare_decomposed(pa, pb, true, s); \ +} + +COMPARE(16) +COMPARE(32) +COMPARE(64) + +#undef COMPARE + /* Multiply A by 2 raised to the power N. */ static decomposed_parts scalbn_decomposed(decomposed_parts a, int n, float_status *s) @@ -6894,60 +6975,6 @@ int float128_unordered_quiet(float128 a, float128 b, float_status *status) return 0; } -#define COMPARE(s, nan_exp) \ -static inline int float ## s ## _compare_internal(float ## s a, float ## s b,\ - int is_quiet, float_status *status) \ -{ \ - flag aSign, bSign; \ - uint ## s ## _t av, bv; \ - a = float ## s ## _squash_input_denormal(a, status); \ - b = float ## s ## _squash_input_denormal(b, status); \ - \ - if (( ( extractFloat ## s ## Exp( a ) == nan_exp ) && \ - extractFloat ## s ## Frac( a ) ) || \ - ( ( extractFloat ## s ## Exp( b ) == nan_exp ) && \ - extractFloat ## s ## Frac( b ) )) { \ - if (!is_quiet || \ - float ## s ## _is_signaling_nan(a, status) || \ - float ## s ## _is_signaling_nan(b, status)) { \ - float_raise(float_flag_invalid, status); \ - } \ - return float_relation_unordered; \ - } \ - aSign = extractFloat ## s ## Sign( a ); \ - bSign = extractFloat ## s ## Sign( b ); \ - av = float ## s ## _val(a); \ - bv = float ## s ## _val(b); \ - if ( aSign != bSign ) { \ - if ( (uint ## s ## _t) ( ( av | bv )<<1 ) == 0 ) { \ - /* zero case */ \ - return float_relation_equal; \ - } else { \ - return 1 - (2 * aSign); \ - } \ - } else { \ - if (av == bv) { \ - return float_relation_equal; \ - } else { \ - return 1 - 2 * (aSign ^ ( av < bv )); \ - } \ - } \ -} \ - \ -int float ## s ## _compare(float ## s a, float ## s b, float_status *status) \ -{ \ - return float ## s ## _compare_internal(a, b, 0, status); \ -} \ - \ -int float ## s ## _compare_quiet(float ## s a, float ## s b, \ - float_status *status) \ -{ \ - return float ## s ## _compare_internal(a, b, 1, status); \ -} - -COMPARE(32, 0xff) -COMPARE(64, 0x7ff) - static inline int floatx80_compare_internal(floatx80 a, floatx80 b, int is_quiet, float_status *status) { diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h index ba248ffa39..a5232bcc87 100644 --- a/include/fpu/softfloat.h +++ b/include/fpu/softfloat.h @@ -360,6 +360,8 @@ float16 float16_minnum(float16, float16, float_status *status); float16 float16_maxnum(float16, float16, float_status *status); float16 float16_minnummag(float16, float16, float_status *status); float16 float16_maxnummag(float16, float16, float_status *status); +int float16_compare(float16, float16, float_status *status); +int float16_compare_quiet(float16, float16, float_status *status); int float16_is_quiet_nan(float16, float_status *status); int float16_is_signaling_nan(float16, float_status *status);