From patchwork Wed May 16 15:52:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 136035 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1130662lji; Wed, 16 May 2018 09:17:49 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpCYRxAkdrM2FYcIoJHiAOENz3FwDV2Ws7k4tfxNqOfRMEt/+gNCNl1D+M9xeYh9NQBexi5 X-Received: by 2002:a37:ddd6:: with SMTP id u83-v6mr1484765qku.234.1526487469789; Wed, 16 May 2018 09:17:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526487469; cv=none; d=google.com; s=arc-20160816; b=q/wcEvkRC3ZUUsOvyadJyp8aPE650CL87cwbbHNnDpaEds99fvub4w8WuJRPXu00D0 r4HarZyt2QxA7Kfjoxk9tV121Ikhl30gmkxR7rbvpUGnym0xB0V4aKcAGP/B+PhpO49c wUmJZecRyT2tnwD/BS2U3ATIvAD/8edXSnEvMltgKWFdYCz702uMaSb+eCuSUAbdeatI MvCIVfcMm5lvYrgS+XchaeB+BXPi+5r264MFEkk+GcKYVKR0Lfhg/sF2wKLXZaSTI2gn DiNb0UGIldqdie9laRsIRLzKUcy2h9sPfndnW88nj8w05INtbCCFxQhodS7OljHGZUYb sBFg== 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=l7WMGMq5FTzJZw/8Ol7jK0ePReknNRBHJTqi+3dsjxg=; b=B3XGNOa/H0FUawEntsLvkppikAHgsX5DtV2ahL+xLCJGgcE4eswb/fJ0jygHp+2BXg PytyPeIOFEXOpHPlfPecTUUBG1hg9aOeVQ8p0syYzZEZlCaFwYLj+UKAjPMMrRaSylZC lTq/awqmL7TejxNZ7+cg9YLwky/9g/0BvM8jf2f6AngopA3m8vnHyk6ZC/3R3VdZk03f y7721XJEgiHMmutA2JX0I1KXmkwM5ONxNNxC0/CQbsg0O5miJfHdzKr8BzbrxtX2uX47 LpScbQYfSKIOk4pwD2p9MqEGKU1D6TjdHD1wqvtiYj9DXD/Faqw5IP1d6DN+PyXt0sA2 92mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=fWt0snpH; 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 q193-v6si2873100qke.80.2018.05.16.09.17.49 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 16 May 2018 09:17:49 -0700 (PDT) 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=fWt0snpH; 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]:53557 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIz7d-0006tP-2S for patch@linaro.org; Wed, 16 May 2018 12:17:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42110) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIyk0-0004h0-9v for qemu-devel@nongnu.org; Wed, 16 May 2018 11:53:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fIyjz-0005Ak-7F for qemu-devel@nongnu.org; Wed, 16 May 2018 11:53:24 -0400 Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]:41215) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fIyjy-0005AO-UF for qemu-devel@nongnu.org; Wed, 16 May 2018 11:53:23 -0400 Received: by mail-pg0-x242.google.com with SMTP id w4-v6so467149pgq.8 for ; Wed, 16 May 2018 08:53:22 -0700 (PDT) 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=l7WMGMq5FTzJZw/8Ol7jK0ePReknNRBHJTqi+3dsjxg=; b=fWt0snpHHjqg2xVVaSWBt8OUqMLf+HqjEKjNlBXFyZ/50KWGRLdo6ARXlts45I0V5B 0fGpfJ4zEd9elPrHy4LTr02qXrmjk5WTU/UGLUicRpKcIH58dL09RQdwT7otWUGsWTDD ilhXsLoKdYqtUMXFFBFJbYqvGYj/vbMyZXMkI= 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=l7WMGMq5FTzJZw/8Ol7jK0ePReknNRBHJTqi+3dsjxg=; b=SBFCzVJgcWNj+KJCh7a7bNhdiE5bvWR+yJcGuHvGVVCCMn4FwBL8f1N0mVU99uPS48 s5khp4XxfI8p9WMxN3oocyzfrGx+2EYEZkHmk41J9xnM4188cG/MPy7UdfunVz5prAYe U4rNlBVBRUJfsJqU9i3iRg6Y7LS75wQPLysF2wL9gbXHQgSfKEigc65d2oB+FLmq+lJ9 oFkU+lST3OfVLRc/12VU6xVDXldPSM4zYJYqctvKPxn1V9holmU3xYgfJrz2nMkmbkab Bq89Cs8KuzASUA3bWKc4j96/+0J9qEYNhccn4hjLnRD5YU43HqmKefO3jIcSEO4iSbfD fUTQ== X-Gm-Message-State: ALKqPweFNvReupqCZDFLEIN7ESAPY78g3bBLOhvjqOnly1bH2d+Q8oSx epUyWsnepSmoC2B4RQwB6TUBsmqbBVo= X-Received: by 2002:a65:6489:: with SMTP id e9-v6mr1180006pgv.44.1526486001489; Wed, 16 May 2018 08:53:21 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-2-170.tukw.qwest.net. [97.113.2.170]) by smtp.gmail.com with ESMTPSA id c3-v6sm4966632pfn.62.2018.05.16.08.53.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 16 May 2018 08:53:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 16 May 2018 08:52:40 -0700 Message-Id: <20180516155243.16937-26-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180516155243.16937-1-richard.henderson@linaro.org> References: <20180516155243.16937-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::242 Subject: [Qemu-devel] [PULL 25/28] fpu/softfloat: Pass FloatClass to pickNaNMulAdd 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 Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" For each operand, pass a single enumeration instead of a pair of booleans. The commit also merges multiple different ifdef-selected implementations of pickNaNMulAdd into a single function whose body is ifdef-selected. Tested-by: Alex Bennée Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- fpu/softfloat-specialize.h | 70 +++++++++++++++----------------------- fpu/softfloat.c | 5 +-- 2 files changed, 28 insertions(+), 47 deletions(-) -- 2.17.0 diff --git a/fpu/softfloat-specialize.h b/fpu/softfloat-specialize.h index 2695183188..0399dfe011 100644 --- a/fpu/softfloat-specialize.h +++ b/fpu/softfloat-specialize.h @@ -594,15 +594,14 @@ static int pickNaN(FloatClass a_cls, FloatClass b_cls, | information. | Return values : 0 : a; 1 : b; 2 : c; 3 : default-NaN *----------------------------------------------------------------------------*/ -#if defined(TARGET_ARM) -static int pickNaNMulAdd(flag aIsQNaN, flag aIsSNaN, flag bIsQNaN, flag bIsSNaN, - flag cIsQNaN, flag cIsSNaN, flag infzero, - float_status *status) +static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, + bool infzero, float_status *status) { +#if defined(TARGET_ARM) /* For ARM, the (inf,zero,qnan) case sets InvalidOp and returns * the default NaN */ - if (infzero && cIsQNaN) { + if (infzero && is_qnan(c_cls)) { float_raise(float_flag_invalid, status); return 3; } @@ -610,25 +609,20 @@ static int pickNaNMulAdd(flag aIsQNaN, flag aIsSNaN, flag bIsQNaN, flag bIsSNaN, /* This looks different from the ARM ARM pseudocode, because the ARM ARM * puts the operands to a fused mac operation (a*b)+c in the order c,a,b. */ - if (cIsSNaN) { + if (is_snan(c_cls)) { return 2; - } else if (aIsSNaN) { + } else if (is_snan(a_cls)) { return 0; - } else if (bIsSNaN) { + } else if (is_snan(b_cls)) { return 1; - } else if (cIsQNaN) { + } else if (is_qnan(c_cls)) { return 2; - } else if (aIsQNaN) { + } else if (is_qnan(a_cls)) { return 0; } else { return 1; } -} #elif defined(TARGET_MIPS) -static int pickNaNMulAdd(flag aIsQNaN, flag aIsSNaN, flag bIsQNaN, flag bIsSNaN, - flag cIsQNaN, flag cIsSNaN, flag infzero, - float_status *status) -{ /* For MIPS, the (inf,zero,qnan) case sets InvalidOp and returns * the default NaN */ @@ -639,41 +633,36 @@ static int pickNaNMulAdd(flag aIsQNaN, flag aIsSNaN, flag bIsQNaN, flag bIsSNaN, if (snan_bit_is_one(status)) { /* Prefer sNaN over qNaN, in the a, b, c order. */ - if (aIsSNaN) { + if (is_snan(a_cls)) { return 0; - } else if (bIsSNaN) { + } else if (is_snan(b_cls)) { return 1; - } else if (cIsSNaN) { + } else if (is_snan(c_cls)) { return 2; - } else if (aIsQNaN) { + } else if (is_qnan(a_cls)) { return 0; - } else if (bIsQNaN) { + } else if (is_qnan(b_cls)) { return 1; } else { return 2; } } else { /* Prefer sNaN over qNaN, in the c, a, b order. */ - if (cIsSNaN) { + if (is_snan(c_cls)) { return 2; - } else if (aIsSNaN) { + } else if (is_snan(a_cls)) { return 0; - } else if (bIsSNaN) { + } else if (is_snan(b_cls)) { return 1; - } else if (cIsQNaN) { + } else if (is_qnan(c_cls)) { return 2; - } else if (aIsQNaN) { + } else if (is_qnan(a_cls)) { return 0; } else { return 1; } } -} #elif defined(TARGET_PPC) -static int pickNaNMulAdd(flag aIsQNaN, flag aIsSNaN, flag bIsQNaN, flag bIsSNaN, - flag cIsQNaN, flag cIsSNaN, flag infzero, - float_status *status) -{ /* For PPC, the (inf,zero,qnan) case sets InvalidOp, but we prefer * to return an input NaN if we have one (ie c) rather than generating * a default NaN @@ -686,31 +675,26 @@ static int pickNaNMulAdd(flag aIsQNaN, flag aIsSNaN, flag bIsQNaN, flag bIsSNaN, /* If fRA is a NaN return it; otherwise if fRB is a NaN return it; * otherwise return fRC. Note that muladd on PPC is (fRA * fRC) + frB */ - if (aIsSNaN || aIsQNaN) { + if (is_nan(a_cls)) { return 0; - } else if (cIsSNaN || cIsQNaN) { + } else if (is_nan(c_cls)) { return 2; } else { return 1; } -} #else -/* A default implementation: prefer a to b to c. - * This is unlikely to actually match any real implementation. - */ -static int pickNaNMulAdd(flag aIsQNaN, flag aIsSNaN, flag bIsQNaN, flag bIsSNaN, - flag cIsQNaN, flag cIsSNaN, flag infzero, - float_status *status) -{ - if (aIsSNaN || aIsQNaN) { + /* A default implementation: prefer a to b to c. + * This is unlikely to actually match any real implementation. + */ + if (is_nan(a_cls)) { return 0; - } else if (bIsSNaN || bIsQNaN) { + } else if (is_nan(b_cls)) { return 1; } else { return 2; } -} #endif +} /*---------------------------------------------------------------------------- | Takes two single-precision floating-point values `a' and `b', one of which diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 55954385ff..8e97602ace 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -601,10 +601,7 @@ static FloatParts pick_nan_muladd(FloatParts a, FloatParts b, FloatParts c, s->float_exception_flags |= float_flag_invalid; } - which = pickNaNMulAdd(is_qnan(a.cls), is_snan(a.cls), - is_qnan(b.cls), is_snan(b.cls), - is_qnan(c.cls), is_snan(c.cls), - inf_zero, s); + which = pickNaNMulAdd(a.cls, b.cls, c.cls, inf_zero, s); if (s->default_nan_mode) { /* Note that this check is after pickNaNMulAdd so that function