From patchwork Wed Dec 4 11:54:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Newton X-Patchwork-Id: 22012 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f72.google.com (mail-pb0-f72.google.com [209.85.160.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8FCDA202E0 for ; Wed, 4 Dec 2013 11:55:12 +0000 (UTC) Received: by mail-pb0-f72.google.com with SMTP id jt11sf43724234pbb.11 for ; Wed, 04 Dec 2013 03:55:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=T3Uymx1Vwaqty3katZjVIRhViVbT+VDirlcRwHvJTwM=; b=GkI8PvxgUSuVLMlGgS1mJswVZcnHqIS18agVJMkljsWW9W7Lvw/Qqbsw8YBLJOzJLS 85Jgg7HLpxI8OmfaXwNFUD+Wubu9n1Iox3JLMtvw1MqPTq0JYW0YM2ZqJGcTtYupD1va fJki9kVn8+iNb04SYRNZvPj0qeVYg0adjzPnYwLmLeG8x9lqdQnNjlqHJ+SfMfC8Iomk JKbftl25m6hhXRQu/xPWGqmk4LMR49EatWVXUMkK/+yyNE/0dGPzMsIB9SIEwFiqnyp3 VJFVLOeMSCJSaknslxdB0krjgNf54U03Z+/VeLBB76vnOxSdM9GAAfmfAIN8DYY6/doZ YSQw== X-Gm-Message-State: ALoCoQnRzK8izwPAjqCzjx8qhcgYsbk8x8AHrQvrRSMqlK5PelIdAzvfLfok78zMHzR7ZJpFNUM7 X-Received: by 10.66.227.103 with SMTP id rz7mr25919746pac.18.1386158111884; Wed, 04 Dec 2013 03:55:11 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.60.37 with SMTP id e5ls295765qer.84.gmail; Wed, 04 Dec 2013 03:55:11 -0800 (PST) X-Received: by 10.58.217.169 with SMTP id oz9mr371811vec.42.1386158111683; Wed, 04 Dec 2013 03:55:11 -0800 (PST) Received: from mail-vc0-f179.google.com (mail-vc0-f179.google.com [209.85.220.179]) by mx.google.com with ESMTPS id tj6si32871780vcb.43.2013.12.04.03.55.11 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 04 Dec 2013 03:55:11 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.179 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.179; Received: by mail-vc0-f179.google.com with SMTP id ie18so11445000vcb.10 for ; Wed, 04 Dec 2013 03:55:11 -0800 (PST) X-Received: by 10.52.121.104 with SMTP id lj8mr2224391vdb.33.1386158111444; Wed, 04 Dec 2013 03:55:11 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp285952vcz; Wed, 4 Dec 2013 03:55:11 -0800 (PST) X-Received: by 10.180.82.161 with SMTP id j1mr6817567wiy.23.1386158110555; Wed, 04 Dec 2013 03:55:10 -0800 (PST) Received: from mail-wi0-f176.google.com (mail-wi0-f176.google.com [209.85.212.176]) by mx.google.com with ESMTPS id gy5si32610534wjc.122.2013.12.04.03.55.10 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 04 Dec 2013 03:55:10 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.176 is neither permitted nor denied by best guess record for domain of will.newton@linaro.org) client-ip=209.85.212.176; Received: by mail-wi0-f176.google.com with SMTP id hq4so8076897wib.9 for ; Wed, 04 Dec 2013 03:55:10 -0800 (PST) X-Received: by 10.194.175.66 with SMTP id by2mr11571045wjc.59.1386158110126; Wed, 04 Dec 2013 03:55:10 -0800 (PST) Received: from localhost.localdomain (cpc6-seac21-2-0-cust453.7-2.cable.virginm.net. [82.1.113.198]) by mx.google.com with ESMTPSA id qc10sm6258318wic.9.2013.12.04.03.55.09 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Dec 2013 03:55:09 -0800 (PST) From: Will Newton To: qemu-devel@nongnu.org Cc: patches@linaro.org Subject: [PATCH v8 4/6] softfloat: Add minNum() and maxNum() functions to softfloat. Date: Wed, 4 Dec 2013 11:54:57 +0000 Message-Id: <1386158099-9239-5-git-send-email-will.newton@linaro.org> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1386158099-9239-1-git-send-email-will.newton@linaro.org> References: <1386158099-9239-1-git-send-email-will.newton@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: will.newton@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.179 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Add floatnn_minnum() and floatnn_maxnum() functions which are equivalent to the minNum() and maxNum() functions from IEEE 754-2008. They are similar to min() and max() but differ in the handling of QNaN arguments. Signed-off-by: Will Newton --- fpu/softfloat.c | 32 +++++++++++++++++++++++++++++--- include/fpu/softfloat.h | 4 ++++ 2 files changed, 33 insertions(+), 3 deletions(-) Changes in v8: - Use existing MINMAX macro to implement minnum and maxnum - Improve comment diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 97bf627..dbda61b 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -6705,10 +6705,17 @@ int float128_compare_quiet( float128 a, float128 b STATUS_PARAM ) /* min() and max() functions. These can't be implemented as * 'compare and pick one input' because that would mishandle * NaNs and +0 vs -0. + * + * minnum() and maxnum() functions. These are similar to the min() + * and max() functions but if one of the arguments is a QNaN and + * the other is numerical then the numerical argument is returned. + * minnum() and maxnum correspond to the IEEE 754-2008 minNum() + * and maxNum() operations. min() and max() are the typical min/max + * semantics provided by many CPUs which predate that specification. */ #define MINMAX(s) \ INLINE float ## s float ## s ## _minmax(float ## s a, float ## s b, \ - int ismin STATUS_PARAM ) \ + int ismin, int isieee STATUS_PARAM) \ { \ flag aSign, bSign; \ uint ## s ## _t av, bv; \ @@ -6716,6 +6723,15 @@ INLINE float ## s float ## s ## _minmax(float ## s a, float ## s b, \ b = float ## s ## _squash_input_denormal(b STATUS_VAR); \ if (float ## s ## _is_any_nan(a) || \ float ## s ## _is_any_nan(b)) { \ + if (isieee) { \ + if (float ## s ## _is_quiet_nan(a) && \ + !float ## s ##_is_any_nan(b)) { \ + return b; \ + } else if (float ## s ## _is_quiet_nan(b) && \ + !float ## s ## _is_any_nan(a)) { \ + return a; \ + } \ + } \ return propagateFloat ## s ## NaN(a, b STATUS_VAR); \ } \ aSign = extractFloat ## s ## Sign(a); \ @@ -6739,12 +6755,22 @@ INLINE float ## s float ## s ## _minmax(float ## s a, float ## s b, \ \ float ## s float ## s ## _min(float ## s a, float ## s b STATUS_PARAM) \ { \ - return float ## s ## _minmax(a, b, 1 STATUS_VAR); \ + return float ## s ## _minmax(a, b, 1, 0 STATUS_VAR); \ } \ \ float ## s float ## s ## _max(float ## s a, float ## s b STATUS_PARAM) \ { \ - return float ## s ## _minmax(a, b, 0 STATUS_VAR); \ + return float ## s ## _minmax(a, b, 0, 0 STATUS_VAR); \ +} \ + \ +float ## s float ## s ## _minnum(float ## s a, float ## s b STATUS_PARAM) \ +{ \ + return float ## s ## _minmax(a, b, 1, 1 STATUS_VAR); \ +} \ + \ +float ## s float ## s ## _maxnum(float ## s a, float ## s b STATUS_PARAM) \ +{ \ + return float ## s ## _minmax(a, b, 0, 1 STATUS_VAR); \ } MINMAX(32) diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h index f3927e2..2365274 100644 --- a/include/fpu/softfloat.h +++ b/include/fpu/softfloat.h @@ -302,6 +302,8 @@ int float32_compare( float32, float32 STATUS_PARAM ); int float32_compare_quiet( float32, float32 STATUS_PARAM ); float32 float32_min(float32, float32 STATUS_PARAM); float32 float32_max(float32, float32 STATUS_PARAM); +float32 float32_minnum(float32, float32 STATUS_PARAM); +float32 float32_maxnum(float32, float32 STATUS_PARAM); int float32_is_quiet_nan( float32 ); int float32_is_signaling_nan( float32 ); float32 float32_maybe_silence_nan( float32 ); @@ -408,6 +410,8 @@ int float64_compare( float64, float64 STATUS_PARAM ); int float64_compare_quiet( float64, float64 STATUS_PARAM ); float64 float64_min(float64, float64 STATUS_PARAM); float64 float64_max(float64, float64 STATUS_PARAM); +float64 float64_minnum(float64, float64 STATUS_PARAM); +float64 float64_maxnum(float64, float64 STATUS_PARAM); int float64_is_quiet_nan( float64 a ); int float64_is_signaling_nan( float64 ); float64 float64_maybe_silence_nan( float64 );