From patchwork Wed Feb 21 11:05:21 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: 129031 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp503153ljc; Wed, 21 Feb 2018 03:19:50 -0800 (PST) X-Google-Smtp-Source: AH8x226ep0bIqcxbqaKsm8rsneGWMuPtwsp4DfrfC5Da8QpNU3HesiDg9P9v35bvA8OiH4TizKT1 X-Received: by 10.13.224.65 with SMTP id j62mr1802134ywe.185.1519211990259; Wed, 21 Feb 2018 03:19:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519211990; cv=none; d=google.com; s=arc-20160816; b=TmWrQfXTPxZTqRem6tDoFJpo9/JQ+qE3ZZP9RN94E+4dkq5Z+G62UsBxPolHKL+Z+L v3S7APGH1EH9rOF3GMV1FWrT4t9CXdkzI7CMy/OrZJgX6eHIvMGZoZWCt+W5OfqiGIbd Fdk6vypqFPYwiYjcf2vL4OgUTMRcqFlUEXowD43bbbFEi6eKK5V1aTkiL8/NKmltYVdM h4jrFQKGGDHvFuDVp6Y2MRL+q+ObwkzmvZL8p/WHPj9Yj9zGpnbtnKLiPIeTMl3Bev68 KntQD/PVTNA6EXw0M0WFSyeO4fzX2/cW2jXbxPLIFLfowFDrdWWia2XnMzA3lN+hkeAK aitA== 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=RnV04Edpog3RnuLmmy7/hRUb4LfDq7/ZIw1VFw1SSvA=; b=iQH2qC5u3vX4cP7c03rsM+TRnOUuwyBk8fR7sVZT98J9nKUMguM6zIs8lxVsPzkPwi 59RF++p074ZwPBsSUxZwswNYCRF/D9eec2SxvH3ipSQ88VN7tdzcGiQbLxqtMG6pbJL9 tUDI6qPhzeBNYNbC71q4eAlWaFCyCQkvkhoZA5YrBN3qmxzUOqWCqk08dI1lWJqgF8/f OSRagVgL2quIWxqnI5gPXwBtqtAAEU4g0DL7lLxRIpwpLAw0hM99mQP3z/KvVZ2K+RUE Lb4PWD6+Kl+xfB8BKY8zxB8cQNNKH0/ICh6Sc7kY/tHSqHvg1NpFeHXysHvqqIWo7Gh5 5GjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=iP3CukeX; 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 f187si1535361ywd.455.2018.02.21.03.19.50 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 21 Feb 2018 03:19:50 -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=iP3CukeX; 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]:60117 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eoSRB-0006pT-HQ for patch@linaro.org; Wed, 21 Feb 2018 06:19:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35466) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eoSDm-0004D2-2W for qemu-devel@nongnu.org; Wed, 21 Feb 2018 06:06:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eoSDf-0006mi-M8 for qemu-devel@nongnu.org; Wed, 21 Feb 2018 06:05:58 -0500 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:34347) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eoSDf-0006mO-Bp for qemu-devel@nongnu.org; Wed, 21 Feb 2018 06:05:51 -0500 Received: by mail-wr0-x241.google.com with SMTP id m5so3302882wrg.1 for ; Wed, 21 Feb 2018 03:05:51 -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=RnV04Edpog3RnuLmmy7/hRUb4LfDq7/ZIw1VFw1SSvA=; b=iP3CukeX8x1Rf37TN34THfCs2QCelXPtkxCWACJ68NVlv37167T2gJkYbBzxpNYtoz 9TIEqF81LW9/4Abde4g2eTgV/ujWmaIgWZi0HUA3bB56AoR0Snms++oVLncBLVHfYJVm C0BxcXii0HqCci1YDdxu9CFC9Ujuh+0JI+PY4= 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=RnV04Edpog3RnuLmmy7/hRUb4LfDq7/ZIw1VFw1SSvA=; b=k9zv2RCkztrAylbbuPt6m7GtzukHf7+pbLQNnqlE4kpFia3thyWAJhpyxSDDG8mhmQ r7m5OD6zZRDdQ+5Pv1YZMpeKRmQUtJvcjaNHK3+szQ2lj8OFu8LH1QIiWYu3GwxLSA4N 8SyUld3u0wrJ0HPBS6q7f3/RQB1N/rWmooa0r/Ew4fiXXdI1SFSA9u+EYGKMc1S7ruQi kYWy2s3zbWTuM/y2FI4kbadmzU6V1ELUoK5ZiCsyGP+fUGoRsxZyKJ5ybwoaTPicgIlP EKrKz3mrnpHFaElkPewvXyst9Uw6uX8RjGHCNf8AiQe2WJQQRVtTwx84DMW7/AOygrBh AOPA== X-Gm-Message-State: APf1xPC0dg2z9S32nFc/uVT6YT5cKAeOZVeH8iO1s1EenHu2Obryn9A0 qEjduQUY/XU/A+IHpXP82MJ4uQ== X-Received: by 10.28.166.206 with SMTP id p197mr1662999wme.81.1519211150218; Wed, 21 Feb 2018 03:05:50 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id 41sm39191488wrc.12.2018.02.21.03.05.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Feb 2018 03:05:46 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id D2D8B3E0176; Wed, 21 Feb 2018 11:05:24 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Wed, 21 Feb 2018 11:05:21 +0000 Message-Id: <20180221110523.859-22-alex.bennee@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180221110523.859-1-alex.bennee@linaro.org> References: <20180221110523.859-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] [PULL 21/22] 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" The compare function was already expanded from a macro. I keep the macro expansion but move most of the logic into a compare_decomposed. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson -- 2.15.1 diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 7a53c36da4..4bc425d7e4 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -1783,6 +1783,86 @@ MINMAX(64, maxnummag, false, true, true) #undef MINMAX +/* Floating point compare */ +static int compare_floats(FloatParts a, FloatParts b, bool is_quiet, + float_status *s) +{ + if (is_nan(a.cls) || is_nan(b.cls)) { + 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) { + if (b.cls == float_class_zero) { + return float_relation_equal; + } + return b.sign ? float_relation_greater : float_relation_less; + } else if (b.cls == float_class_zero) { + return a.sign ? float_relation_less : float_relation_greater; + } + + /* The only really important thing about infinity is its sign. If + * both are infinities the sign marks the smallest of the two. + */ + if (a.cls == float_class_inf) { + if ((b.cls == float_class_inf) && (a.sign == b.sign)) { + return float_relation_equal; + } + return a.sign ? float_relation_less : float_relation_greater; + } else if (b.cls == float_class_inf) { + return b.sign ? float_relation_greater : float_relation_less; + } + + 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) \ +{ \ + FloatParts pa = float ## sz ## _unpack_canonical(a, s); \ + FloatParts pb = float ## sz ## _unpack_canonical(b, s); \ + return compare_floats(pa, pb, false, s); \ +} \ +int float ## sz ## _compare_quiet(float ## sz a, float ## sz b, \ + float_status *s) \ +{ \ + FloatParts pa = float ## sz ## _unpack_canonical(a, s); \ + FloatParts pb = float ## sz ## _unpack_canonical(b, s); \ + return compare_floats(pa, pb, true, s); \ +} + +COMPARE(16) +COMPARE(32) +COMPARE(64) + +#undef COMPARE + /* Multiply A by 2 raised to the power N. */ static FloatParts scalbn_decomposed(FloatParts a, int n, float_status *s) { @@ -6884,60 +6964,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 35df225a55..cebe37b716 100644 --- a/include/fpu/softfloat.h +++ b/include/fpu/softfloat.h @@ -251,6 +251,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);