From patchwork Sun Feb 4 04:11:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 126802 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp925651ljc; Sat, 3 Feb 2018 20:18:09 -0800 (PST) X-Google-Smtp-Source: AH8x224qcs0y5MNwBmFM+y9PrbQNwYR89bKJTdlahv4PF06fWBRS/OSdg8tC8Osa5QDKH9FhyhDU X-Received: by 10.13.251.6 with SMTP id l6mr29243473ywf.323.1517717889423; Sat, 03 Feb 2018 20:18:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517717889; cv=none; d=google.com; s=arc-20160816; b=QyuvpFN71Az9pgwaVcat+TKz+lPTmQHzpWwIRKFhpjoI8CtzmUU3x3QhOwbV4fVZ1e sXMzUrS1W5HA+mNM+7+ux8WrE9ISRri3sxjSVfxl54QflVKOOEyeZLKP1Wb2YQUAFFa9 1NH9rpcYl+3oQSLmlMG9lU5630GYzSvVgFn+T0xj0FmrAd0eP5UDRvsLgdgmFdgDqilj MEgp0OrHRJ7wGtAZKfPT6ITNpJZDJZEG1fLN3CpzJSgRwUwIijmUAr/xeO/oXub2kbKl ngD9J8/b6LvGcN8NLdUa+QC8TdOWAlqBqelqUQt4bVxLsQlw0XdLV9G0xzbAzECdwPF3 an8w== 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:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=Af/PXTq+IgzRg9HgEw7D2//efNwqImJJDPE3gWEjVgc=; b=UlWcwzJhLYkGyDK3SwBl+rEw19lL6wDexTqRCalAImoJTsFN74wmEPu1/hs7WyD5Wm cPOIPGHuvlavJ8xhrOIk6KVBilKFEeczpHmFzWK/+gwk8YE36FtjQVT/Fd9uCQa/yLs1 CwG8zkc+vB7d2L8LxJGPRD7gBNkUK2Uh/YEOHU0AeGZVLSynplDgvvD0YomgndrpQwSG XstsRhe9TH6HvYqGJYdoqgnSzzn0aDjz2uaPnJ1Fx2HWXptWuCiDo2IE22KnjYpa5jRF VEq66S6fHe80x/JH8w2KdmL1awI8zwzuT+8P3eXvVX/Q8d8VhAsuVy0xfgTaf9I+67WM dwSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=E+XtDy52; 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 f1si1018121ywd.449.2018.02.03.20.18.09 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 03 Feb 2018 20:18:09 -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=E+XtDy52; 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]:58275 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eiBkm-0001OU-Lv for patch@linaro.org; Sat, 03 Feb 2018 23:18:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47421) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eiBf0-0004rr-Nm for qemu-devel@nongnu.org; Sat, 03 Feb 2018 23:12:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eiBey-00053d-QA for qemu-devel@nongnu.org; Sat, 03 Feb 2018 23:12:10 -0500 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:46162) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eiBey-00052K-Fq for qemu-devel@nongnu.org; Sat, 03 Feb 2018 23:12:08 -0500 Received: by mail-pg0-x243.google.com with SMTP id s9so15973632pgq.13 for ; Sat, 03 Feb 2018 20:12:08 -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; bh=Af/PXTq+IgzRg9HgEw7D2//efNwqImJJDPE3gWEjVgc=; b=E+XtDy52dwMvOBaq2B5p7LGv4uCHx8LsTtabC0PpYAniaqkMQMg2xsSIj4X0cnAbPt DBXBBZlhXZZFzhhiRdaAPUuVe5tF9tTm0umL2+/RTNWDaqZlRhhZcbra1yk+19kz1TU3 4aW8kYzWXgF4IwgLH9C1lPMgSO/8s7qwrnsbQ= 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; bh=Af/PXTq+IgzRg9HgEw7D2//efNwqImJJDPE3gWEjVgc=; b=Cevx6ll+FgD9ONhyggi30y3LExOAyY2AtJOIZzeeL1s3TK/e3IMekAsoggSZHryp0M SKpEZfUIM6OBHInpKlgc+3KgznIfbERnnx4NK3r36xXX7DFEj0PBjinbBxrQJ4V6bXw9 U1py56X0APjQqwqNvpCFKDuMqBh/4wKcuUO3w6mNCvOZGpOJRQVB8gxRpbSE9UTEOgI0 d8bfJqVh4vxyKW/XMPhmGP3kAcgs2xIxRZriJxSvb1PPcQdxuUJsA5wZOK//9QcrL4ZR t/sDk2BN14EQm8NQqo1To0R92BoWIoxXFK+tlkyVLFhqGx5XYoTEMrQf3hiMMez8Mz5t go4A== X-Gm-Message-State: AKwxytfvgYVPSOK1w47E2uikC/vbPNWW0+ZihE5ZOTGeXOF7rNRHaOi6 KaCTrEgXT+1OhmS3Wy3pe2x+TRmhS04= X-Received: by 10.99.110.10 with SMTP id j10mr17972686pgc.72.1517717527216; Sat, 03 Feb 2018 20:12:07 -0800 (PST) Received: from cloudburst.twiddle.net (174-21-6-47.tukw.qwest.net. [174.21.6.47]) by smtp.gmail.com with ESMTPSA id k3sm1399425pgr.12.2018.02.03.20.12.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 03 Feb 2018 20:12:06 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 3 Feb 2018 20:11:31 -0800 Message-Id: <20180204041136.17525-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180204041136.17525-1-richard.henderson@linaro.org> References: <20180204041136.17525-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::243 Subject: [Qemu-devel] [PATCH 19/24] fpu: Implement min/max with soft-fp.h 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: peter.maydell@linaro.org, cota@braap.org, alex.bennee@linaro.org, hsp.cat7@gmail.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Add routines for float16 and float128. Signed-off-by: Richard Henderson --- include/fpu/softfloat.h | 12 ++++++ fpu/floatxx.inc.c | 89 ++++++++++++++++++++++++++++++++++++++++ fpu/softfloat.c | 107 ------------------------------------------------ 3 files changed, 101 insertions(+), 107 deletions(-) -- 2.14.3 diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h index 80df716a55..95590d8420 100644 --- a/include/fpu/softfloat.h +++ b/include/fpu/softfloat.h @@ -260,6 +260,12 @@ int float16_lt_quiet(float16, float16, float_status *status); int float16_unordered_quiet(float16, float16, float_status *status); int float16_compare(float16, float16, float_status *status); int float16_compare_quiet(float16, float16, float_status *status); +float16 float16_min(float16, float16, float_status *status); +float16 float16_max(float16, float16, float_status *status); +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_is_quiet_nan(float16, float_status *status); int float16_is_signaling_nan(float16, float_status *status); @@ -682,6 +688,12 @@ int float128_lt_quiet(float128, float128, float_status *status); int float128_unordered_quiet(float128, float128, float_status *status); int float128_compare(float128, float128, float_status *status); int float128_compare_quiet(float128, float128, float_status *status); +float128 float128_min(float128, float128, float_status *status); +float128 float128_max(float128, float128, float_status *status); +float128 float128_minnum(float128, float128, float_status *status); +float128 float128_maxnum(float128, float128, float_status *status); +float128 float128_minnummag(float128, float128, float_status *status); +float128 float128_maxnummag(float128, float128, float_status *status); int float128_is_quiet_nan(float128, float_status *status); int float128_is_signaling_nan(float128, float_status *status); float128 float128_maybe_silence_nan(float128, float_status *status); diff --git a/fpu/floatxx.inc.c b/fpu/floatxx.inc.c index db49423723..0b6b8b4fd3 100644 --- a/fpu/floatxx.inc.c +++ b/fpu/floatxx.inc.c @@ -26,6 +26,10 @@ (X##_e == _FP_EXPMAX_##fs && !_FP_FRAC_ZEROP_##wc (X)) #define FP_ISNAN(fs, wc, X) \ _FP_ISNAN(fs, wc, X) +#define FP_CHOOSENAN(fs, wc, R, A, B, OP) \ + _FP_CHOOSENAN(fs, wc, R, A, B, OP) +#define FP_SETQNAN(fs, wc, X) \ + _FP_SETQNAN(fs, wc, X) #define FP_ADD_INTERNAL(fs, wc, R, A, B, OP) \ _FP_ADD_INTERNAL(fs, wc, R, A, B, '-') @@ -263,3 +267,88 @@ int glue(FLOATXX,_unordered_quiet)(FLOATXX a, FLOATXX b, float_status *status) { return compare_internal(a, b, status, true) == float_relation_unordered; } + +#define MINMAX_MAX 0 +#define MINMAX_MIN 1 +#define MINMAX_IEEE 2 +#define MINMAX_MAG 4 + +static FLOATXX minmax_internal(FLOATXX a, FLOATXX b, + float_status *status, int flags) +{ + FP_DECL_EX; + glue(FP_DECL_, FS)(A); + glue(FP_DECL_, FS)(B); + bool save_A_s; + int cmp; + + FP_INIT_EXCEPTIONS; + glue(FP_UNPACK_RAW_, FS)(A, a); + glue(FP_UNPACK_RAW_, FS)(B, b); + + /* When comparing magnitudes, squish the signs. */ + save_A_s = A_s; + if (flags & MINMAX_MAG) { + A_s = B_s = 0; + } + + glue(FP_CMP_, FS)(cmp, A, B, float_relation_unordered, 1); + FP_HANDLE_EXCEPTIONS; + + if (unlikely(cmp == float_relation_unordered)) { + glue(FP_DECL_, FS)(R); + FLOATXX r; + + if (flags & MINMAX_IEEE) { + if (glue(FP_ISSIGNAN_, FS)(A) || glue(FP_ISSIGNAN_, FS)(B)) { + /* fall through to FP_CHOOSENAN */ + } else if (!FP_ISNAN(FS, WC, A)) { + return a; + } else if (!FP_ISNAN(FS, WC, B)) { + return b; + } + } + + FP_CHOOSENAN(FS, WC, R, A, B, 'm'); + FP_SETQNAN(FS, WC, R); + glue(FP_PACK_RAW_, FS)(r, R); + return r; + } + + /* Specially handle min(+0.0, -0.0) = -0.0, which compare as equal. */ + cmp = (cmp == 0 ? save_A_s : cmp < 0); + cmp ^= flags & MINMAX_MIN; + return cmp ? b : a; +} + +FLOATXX glue(FLOATXX,_max)(FLOATXX a, FLOATXX b, float_status *status) +{ + return minmax_internal(a, b, status, MINMAX_MAX); +} + +FLOATXX glue(FLOATXX,_min)(FLOATXX a, FLOATXX b, float_status *status) +{ + return minmax_internal(a, b, status, MINMAX_MIN); +} + +FLOATXX glue(FLOATXX,_maxnum)(FLOATXX a, FLOATXX b, float_status *status) +{ + return minmax_internal(a, b, status, MINMAX_MAX | MINMAX_IEEE); +} + +FLOATXX glue(FLOATXX,_minnum)(FLOATXX a, FLOATXX b, float_status *status) +{ + return minmax_internal(a, b, status, MINMAX_MIN | MINMAX_IEEE); +} + +FLOATXX glue(FLOATXX,_maxnummag)(FLOATXX a, FLOATXX b, float_status *status) +{ + return minmax_internal(a, b, status, + MINMAX_MAX | MINMAX_IEEE | MINMAX_MAG); +} + +FLOATXX glue(FLOATXX,_minnummag)(FLOATXX a, FLOATXX b, float_status *status) +{ + return minmax_internal(a, b, status, + MINMAX_MIN | MINMAX_IEEE | MINMAX_MAG); +} diff --git a/fpu/softfloat.c b/fpu/softfloat.c index f75cd0bac4..68dfb464d5 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -4299,113 +4299,6 @@ int floatx80_unordered_quiet(floatx80 a, floatx80 b, float_status *status) == float_relation_unordered; } -/* 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. - * - * minnummag() and maxnummag() functions correspond to minNumMag() - * and minNumMag() from the IEEE-754 2008. - */ -#define MINMAX(s) \ -static inline float ## s float ## s ## _minmax(float ## s a, float ## s b, \ - int ismin, int isieee, \ - int ismag, \ - float_status *status) \ -{ \ - flag aSign, bSign; \ - uint ## s ## _t av, bv, aav, abv; \ - a = float ## s ## _squash_input_denormal(a, status); \ - b = float ## s ## _squash_input_denormal(b, status); \ - if (float ## s ## _is_any_nan(a) || \ - float ## s ## _is_any_nan(b)) { \ - if (isieee) { \ - if (float ## s ## _is_quiet_nan(a, status) && \ - !float ## s ##_is_any_nan(b)) { \ - return b; \ - } else if (float ## s ## _is_quiet_nan(b, status) && \ - !float ## s ## _is_any_nan(a)) { \ - return a; \ - } \ - } \ - return propagateFloat ## s ## NaN(a, b, status); \ - } \ - aSign = extractFloat ## s ## Sign(a); \ - bSign = extractFloat ## s ## Sign(b); \ - av = float ## s ## _val(a); \ - bv = float ## s ## _val(b); \ - if (ismag) { \ - aav = float ## s ## _abs(av); \ - abv = float ## s ## _abs(bv); \ - if (aav != abv) { \ - if (ismin) { \ - return (aav < abv) ? a : b; \ - } else { \ - return (aav < abv) ? b : a; \ - } \ - } \ - } \ - if (aSign != bSign) { \ - if (ismin) { \ - return aSign ? a : b; \ - } else { \ - return aSign ? b : a; \ - } \ - } else { \ - if (ismin) { \ - return (aSign ^ (av < bv)) ? a : b; \ - } else { \ - return (aSign ^ (av < bv)) ? b : a; \ - } \ - } \ -} \ - \ -float ## s float ## s ## _min(float ## s a, float ## s b, \ - float_status *status) \ -{ \ - return float ## s ## _minmax(a, b, 1, 0, 0, status); \ -} \ - \ -float ## s float ## s ## _max(float ## s a, float ## s b, \ - float_status *status) \ -{ \ - return float ## s ## _minmax(a, b, 0, 0, 0, status); \ -} \ - \ -float ## s float ## s ## _minnum(float ## s a, float ## s b, \ - float_status *status) \ -{ \ - return float ## s ## _minmax(a, b, 1, 1, 0, status); \ -} \ - \ -float ## s float ## s ## _maxnum(float ## s a, float ## s b, \ - float_status *status) \ -{ \ - return float ## s ## _minmax(a, b, 0, 1, 0, status); \ -} \ - \ -float ## s float ## s ## _minnummag(float ## s a, float ## s b, \ - float_status *status) \ -{ \ - return float ## s ## _minmax(a, b, 1, 1, 1, status); \ -} \ - \ -float ## s float ## s ## _maxnummag(float ## s a, float ## s b, \ - float_status *status) \ -{ \ - return float ## s ## _minmax(a, b, 0, 1, 1, status); \ -} - -MINMAX(32) -MINMAX(64) - - /* Multiply A by 2 raised to the power N. */ float32 float32_scalbn(float32 a, int n, float_status *status) {