From patchwork Sun May 16 12:33:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 439852 Delivered-To: patch@linaro.org Received: by 2002:a02:7a1b:0:0:0:0:0 with SMTP id a27csp258105jac; Sun, 16 May 2021 05:44:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySTVFP3PmWu/x0kkGyc70hZAgJnOwAnbpeU8e/WTlj4Q/KaCfF1HmPspzpeyz9tG1MEjOZ X-Received: by 2002:ac8:5894:: with SMTP id t20mr51206158qta.134.1621169050286; Sun, 16 May 2021 05:44:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621169050; cv=none; d=google.com; s=arc-20160816; b=BZoevGDCVx8CftzUtTTJaEa9foiIxo9cIAxlk+pmt4hjD3BJ4GdcHUN6Nu8zHpESrA G5JW/v3Mjy15ehY885uWNX2rkzEXmSqdgsIMzBSDvDku+kn2lZYGb5dNfzYe49s+ox/C 099sZoRp4zFQDgTN5Dps7ViL5DbXIO3acCGi8feiHGLziLNgSofOigzXLIiysSEFgyD+ zmIBPevqGuWwHu7VSyT7JT7KVvq2vBttBJS74cqW7+gE2y7wmR+9+L8h2j/9hdroKC8j 7e1us238LRnbfIJBqm942GQKvin5z1TXdwVFOIGshJXqW6pW6JFInSE/n6jOWxSHK7dd GLSw== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=J2jECUv0KB/VRaKbNWjXBjsVAbH6ZqCf4a3f43XZat8=; b=Hnoh4aRImKNnDq1XFiJg7FnfIXDTuywbCXZQWgCIKBK8SoIF/93z8BJCkigmKrNEUP z0B2kmuLqy2hvtLO30Xjd3YpTxt4TEBbsA47lKaM/UypQrVf8lkGEsMDIFLNnBbMd/sA p4Ug2nYDwC9mWWEEVqFW8I5xp3ZjGRFoCcB2IhF5MPvGw5CbkJIlNfRUQCBNYX2n1UIu gwA6mziZIAndCqhEg/3zfj1ze9XmB6Pp5XANsQkzlaLswMX9UcWx3IYcvTPiI4n3gmJk 1YoE26wvsJyfuApAqVQ7t9ym5WKB9BBKG2gPlXGjd4UfNkakPzRs7ufEOWCwoHcQBYcj zLXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jwCh6rrf; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m13si8889748qtk.331.2021.05.16.05.44.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 16 May 2021 05:44:10 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jwCh6rrf; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:50122 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1liG7t-00081T-LP for patch@linaro.org; Sun, 16 May 2021 08:44:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43070) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1liFz0-0007Pz-9d for qemu-devel@nongnu.org; Sun, 16 May 2021 08:34:58 -0400 Received: from mail-qk1-x72d.google.com ([2607:f8b0:4864:20::72d]:37607) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1liFyl-0007kz-Ts for qemu-devel@nongnu.org; Sun, 16 May 2021 08:34:54 -0400 Received: by mail-qk1-x72d.google.com with SMTP id i67so3308675qkc.4 for ; Sun, 16 May 2021 05:34:42 -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=J2jECUv0KB/VRaKbNWjXBjsVAbH6ZqCf4a3f43XZat8=; b=jwCh6rrfJbb1xV5SIS6Sij5OrpTm/g5qdLmso/I/C2kE/DEX7VAEfGHBmORiVbYhUh 5pfiOltwC5sQrQifPv2zejAIhUfETlDYBT3b8OWA+yeJ9SkeEz57KBGr4UVM6A1CWA6N zWZQ1r7UUTQ1kPwFfXnvK6eFlta3opfWVmw2fW+OOloLwl7XN2PA06isxycxH/JsaqxF R5Wo+X20b08hubWE/RG8y886IR/bLEJawu7oXXb7k8qnbhI2h3jbBz0khexP3BRupGIn +NzRSssbCLktewDw1nUCey9bgfqtikz9kD9baI7OuJsPtjgj1WltfOBXJr6jke8FG1Jr RSwg== 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=J2jECUv0KB/VRaKbNWjXBjsVAbH6ZqCf4a3f43XZat8=; b=VGsvnC2yLw2Qt60LcOgDlSEgnRZX8O5iJz4rWYdOjVvrUneW5Pi9y58Bh3qqKJ9o4V pky03ypAov1WqN54r1kByVZJ81Fxy9WHhV4ySR8gcX3gCFog7+y/VtDJlXzFSfWvSvRW KeyNBAevug/NPJdCxACxfzkf/NugPmbUVK2SaCuafI1KLCKLvfZ0wAbRoCuELYcF1ZZC gYX1BkLWTbxlt+4VWVMLn6A91Lwho827E1zYnaH2vsJrnvFEe/9oYFaSvLJYbGR2IkpO VZ5KZvAZa4M+djEq0yM+ImcNNOWGP7j0Pniasl10231/DAibMWwduvTNJFYMcRFtbavd 4zqw== X-Gm-Message-State: AOAM531pgBHhZT9YT4c5OcgagApqZlIZ4MjwJVGtj6ZzMoJxp7PTe8L7 c0WXy5hE7p/dj7kRPjx7AsUkQJcSRQJMpqjDyzc= X-Received: by 2002:a37:7306:: with SMTP id o6mr16495344qkc.38.1621168481391; Sun, 16 May 2021 05:34:41 -0700 (PDT) Received: from localhost.localdomain (163.189-204-200.bestelclientes.com.mx. [189.204.200.163]) by smtp.gmail.com with ESMTPSA id s5sm8500553qkg.88.2021.05.16.05.34.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 May 2021 05:34:41 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 10/46] softfloat: Add float_cmask and constants Date: Sun, 16 May 2021 07:33:55 -0500 Message-Id: <20210516123431.718318-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210516123431.718318-1-richard.henderson@linaro.org> References: <20210516123431.718318-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::72d; envelope-from=richard.henderson@linaro.org; helo=mail-qk1-x72d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?utf-8?q?Alex_Benn=C3=A9e?= , David Hildenbrand Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Testing more than one class at a time is better done with masks. This reduces the static branch count. Reviewed-by: Alex Bennée Reviewed-by: David Hildenbrand Signed-off-by: Richard Henderson --- fpu/softfloat.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) -- 2.25.1 diff --git a/fpu/softfloat.c b/fpu/softfloat.c index ee4b5073b6..64edb23793 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -469,6 +469,20 @@ typedef enum __attribute__ ((__packed__)) { float_class_snan, } FloatClass; +#define float_cmask(bit) (1u << (bit)) + +enum { + float_cmask_zero = float_cmask(float_class_zero), + float_cmask_normal = float_cmask(float_class_normal), + float_cmask_inf = float_cmask(float_class_inf), + float_cmask_qnan = float_cmask(float_class_qnan), + float_cmask_snan = float_cmask(float_class_snan), + + float_cmask_infzero = float_cmask_zero | float_cmask_inf, + float_cmask_anynan = float_cmask_qnan | float_cmask_snan, +}; + + /* Simple helpers for checking if, or what kind of, NaN we have */ static inline __attribute__((unused)) bool is_nan(FloatClass c) { @@ -1338,26 +1352,28 @@ bfloat16 QEMU_FLATTEN bfloat16_mul(bfloat16 a, bfloat16 b, float_status *status) static FloatParts muladd_floats(FloatParts a, FloatParts b, FloatParts c, int flags, float_status *s) { - bool inf_zero = ((1 << a.cls) | (1 << b.cls)) == - ((1 << float_class_inf) | (1 << float_class_zero)); - bool p_sign; + bool inf_zero, p_sign; bool sign_flip = flags & float_muladd_negate_result; FloatClass p_class; uint64_t hi, lo; int p_exp; + int ab_mask, abc_mask; + + ab_mask = float_cmask(a.cls) | float_cmask(b.cls); + abc_mask = float_cmask(c.cls) | ab_mask; + inf_zero = ab_mask == float_cmask_infzero; /* It is implementation-defined whether the cases of (0,inf,qnan) * and (inf,0,qnan) raise InvalidOperation or not (and what QNaN * they return if they do), so we have to hand this information * off to the target-specific pick-a-NaN routine. */ - if (is_nan(a.cls) || is_nan(b.cls) || is_nan(c.cls)) { + if (unlikely(abc_mask & float_cmask_anynan)) { return pick_nan_muladd(a, b, c, inf_zero, s); } if (inf_zero) { float_raise(float_flag_invalid, s); - s->float_exception_flags |= float_flag_invalid; return parts_default_nan(s); } @@ -1371,9 +1387,9 @@ static FloatParts muladd_floats(FloatParts a, FloatParts b, FloatParts c, p_sign ^= 1; } - if (a.cls == float_class_inf || b.cls == float_class_inf) { + if (ab_mask & float_cmask_inf) { p_class = float_class_inf; - } else if (a.cls == float_class_zero || b.cls == float_class_zero) { + } else if (ab_mask & float_cmask_zero) { p_class = float_class_zero; } else { p_class = float_class_normal;