Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B3BADCD6E4A for ; Wed, 3 Jun 2026 03:29:06 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wUcHt-0006VQ-OK; Tue, 02 Jun 2026 23:29:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wUcHs-0006VA-Lr for qemu-arm@nongnu.org; Tue, 02 Jun 2026 23:29:00 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wUcHq-0003YJ-T1 for qemu-arm@nongnu.org; Tue, 02 Jun 2026 23:29:00 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-842848fd613so264245b3a.3 for ; Tue, 02 Jun 2026 20:28:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1780457337; x=1781062137; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LCz/+vquVi3LZZj/w2HRkJcZNB7l8GXrNjqQYumcxd0=; b=RusUH4Ra+tflBATMFPut4WxZOV56LOQ3JmfXEOOX+8IGR8B8PsFPN7jUHmDUImnPuw soRbRkmGH4dL/+nAWVeFE4qYJ3raT9bYL8WxD82MuQ/E7UPeMtN/0D0jV3y2izX//Ojk cmMfYhs/nXKSxqgEnmLdz5ym2/loSaNADoiFoOaYq7I7uuUlR427S2J05ACyiMUzMNz5 tOw5JhiRiV9GPAA10DWZRkHfDTxU9c6wb7/0+lw1s6V8qnDRrhj6D8g6bSnPhqQW8WkK dRRRmjreT+sJzOiEkXNNZJHcJa7RzfKD7ggQPdUTtmPdyNa1DsIh+f4fgot1tw/mTfc3 6qmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780457337; x=1781062137; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=LCz/+vquVi3LZZj/w2HRkJcZNB7l8GXrNjqQYumcxd0=; b=hL6KPhERNiQ/TZZ/WpzuIVg4HqbsEe5PYSUxioFuzZQ7Vvn8scUfh9q9nbam3SqmId FNVlHdOSjh+KGolGMQ4+EWcjlEOJ9vSZ+G97LHvUhXjfrF23Ku7ds2k//Xz/oKzm1YXx tvS1RnvlYMouAEqMHmrhXSlhr0Q87DddwfKdBByJ1y7+dZhh/Z1LH3paZFmVSBQV6o7O gUKsewb6SgkhPTnrxtzDuxgApbTy9onNoqdiphFKNJDzcfDlqdawIsVPVOn4hbmErnTC 4iWx5k+rewFZmKU4QXkUS3e//JF9PrtxOAB5BAZtN6tRtniCxdD6x5M59sj6nmDCpNjr JunA== X-Gm-Message-State: AOJu0YwEzA9CjxrFDu/N+M18ObUH/2gjSCl2rUS1kRFDTeFeUl/v+Axy sNUurlcEKWErp14U+3T7th+Tt2uX9JrPoH7VCPMpF3GjXei1nhGGe+VE0Ni+oZb1yWA= X-Gm-Gg: Acq92OGr+PIv4a9X/WFm7srhhYQtFwcNe1jiR4BY7UfUKfeeS6WuDT+mB5KtLhEth5s SUIk+8qJE93bmS6SiLKhKX4DMYLIjauI1lrOwpXrT6DPi421Z4ISVwEnCl/nnMeeOzOTvN69oEw cBsRSGmxMzlB93Ys3fZHD+qFKFg6DZFRI21wKoxEdd/dNObQP6ppfi8q1SONfOrkPIUXjJio4rr eO8MiaOCgMOEtaZjj1jzFdNn0zeT37VoTyRXDVag/nKvapm0QnxLsrHwPW09SkLFSTa5gfEUkDC 7BnPnvheaXndk+shN4/0FiWLERE6iX43l28Uq8MLm4kM6ty7PxZmYntKkEyllmHNy7IS4k6+7L2 tb1FLfNVUtw3oLhq1MRBTqsCAMHPhlii4wCNydkZLUZaHbbwotgKizpgjMTZDH+Oo+2Z+SsxQsg EkfoJABBFTiQnkId1UdRTOPbvVomPGuzDs/8aQfGVVl6YXql7hQA== X-Received: by 2002:a05:6a00:3c95:b0:842:80c5:c420 with SMTP id d2e1a72fcca58-84284f40b57mr1555696b3a.40.1780457337261; Tue, 02 Jun 2026 20:28:57 -0700 (PDT) Received: from stoup.. ([71.212.142.33]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8428222263dsm1477831b3a.2.2026.06.02.20.28.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2026 20:28:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v9 01/45] target/arm: Use FloatParts64 in bfdotadd_ebf Date: Tue, 2 Jun 2026 20:28:10 -0700 Message-ID: <20260603032855.106930-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260603032855.106930-1-richard.henderson@linaro.org> References: <20260603032855.106930-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42d.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=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-arm-bounces+qemu-arm=archiver.kernel.org@nongnu.org Sender: qemu-arm-bounces+qemu-arm=archiver.kernel.org@nongnu.org Use softfloat-parts.h so that we can more naturally perform the required operations witha single rounding step. This happens to also simplify the NaN detection step. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20260517002550.321291-9-richard.henderson@linaro.org> --- target/arm/tcg/vec_helper.c | 77 +++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/target/arm/tcg/vec_helper.c b/target/arm/tcg/vec_helper.c index 91e98d28ae..85bcaac3d1 100644 --- a/target/arm/tcg/vec_helper.c +++ b/target/arm/tcg/vec_helper.c @@ -22,6 +22,7 @@ #include "helper.h" #include "tcg/tcg-gvec-desc.h" #include "fpu/softfloat.h" +#include "fpu/softfloat-parts.h" #include "qemu/int128.h" #include "crypto/clmul.h" #include "vec_internal.h" @@ -2895,61 +2896,63 @@ float32 bfdotadd(float32 sum, uint32_t e1, uint32_t e2, float_status *fpst) float32 bfdotadd_ebf(float32 sum, uint32_t e1, uint32_t e2, float_status *fpst, float_status *fpst_odd) { + /* Unpack two BFloat16 into two Float32, trivially. */ float32 s1r = e1 << 16; float32 s1c = e1 & 0xffff0000u; float32 s2r = e2 << 16; float32 s2c = e2 & 0xffff0000u; float32 t32; + /* + * Compare f16_dotadd() in sme_helper.c, but here we have + * bfloat16 inputs. In particular that means that we do not + * want the FPCR.FZ16 flush semantics, so we use the normal + * float_status for the input handling here. + */ + FloatParts64 p1r = float32_unpack_canonical(s1r, fpst); + FloatParts64 p1c = float32_unpack_canonical(s1c, fpst); + FloatParts64 p2r = float32_unpack_canonical(s2r, fpst); + FloatParts64 p2c = float32_unpack_canonical(s2c, fpst); + + int all_mask = (float_cmask(p1r.cls) | float_cmask(p1c.cls) | + float_cmask(p1r.cls) | float_cmask(p1c.cls)); + /* C.f. FPProcessNaNs4 */ - if (float32_is_any_nan(s1r) || float32_is_any_nan(s1c) || - float32_is_any_nan(s2r) || float32_is_any_nan(s2c)) { - if (float32_is_signaling_nan(s1r, fpst)) { - t32 = s1r; - } else if (float32_is_signaling_nan(s1c, fpst)) { - t32 = s1c; - } else if (float32_is_signaling_nan(s2r, fpst)) { - t32 = s2r; - } else if (float32_is_signaling_nan(s2c, fpst)) { - t32 = s2c; - } else if (float32_is_any_nan(s1r)) { - t32 = s1r; - } else if (float32_is_any_nan(s1c)) { - t32 = s1c; - } else if (float32_is_any_nan(s2r)) { - t32 = s2r; + if (unlikely(all_mask & float_cmask_anynan)) { + if (unlikely(all_mask & float_cmask_snan)) { + if (p1r.cls == float_class_snan) { + t32 = s1r; + } else if (p1c.cls == float_class_snan) { + t32 = s1c; + } else if (p2r.cls == float_class_snan) { + t32 = s2r; + } else { + t32 = s2c; + } } else { - t32 = s2c; + if (p1r.cls == float_class_qnan) { + t32 = s1r; + } else if (p1c.cls == float_class_qnan) { + t32 = s1c; + } else if (p2r.cls == float_class_qnan) { + t32 = s2r; + } else { + t32 = s2c; + } } /* * FPConvertNaN(FPProcessNaN(t32)) will be done as part * of the final addition below. */ } else { - /* - * Compare f16_dotadd() in sme_helper.c, but here we have - * bfloat16 inputs. In particular that means that we do not - * want the FPCR.FZ16 flush semantics, so we use the normal - * float_status for the input handling here. - */ - float64 e1r = float32_to_float64(s1r, fpst); - float64 e1c = float32_to_float64(s1c, fpst); - float64 e2r = float32_to_float64(s2r, fpst); - float64 e2c = float32_to_float64(s2c, fpst); - float64 t64; - /* * The ARM pseudocode function FPDot performs both multiplies - * and the add with a single rounding operation. Emulate this - * by performing the first multiply in round-to-odd, then doing - * the second multiply as fused multiply-add, and rounding to - * float32 all in one step. + * and the add with a single rounding operation. */ - t64 = float64_mul(e1r, e2r, fpst_odd); - t64 = float64r32_muladd(e1c, e2c, t64, 0, fpst); + FloatParts64 tmp = parts64_mul(&p1r, &p2r, fpst); + tmp = parts64_muladd(&p1c, &p2c, &tmp, 0, fpst); - /* This conversion is exact, because we've already rounded. */ - t32 = float64_to_float32(t64, fpst); + t32 = float32_round_pack_canonical(&tmp, fpst); } /* The final accumulation step is not fused. */ -- 2.43.0