From patchwork Thu Sep 5 13:00:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 825651 Delivered-To: patch@linaro.org Received: by 2002:adf:a345:0:b0:367:895a:4699 with SMTP id d5csp288214wrb; Thu, 5 Sep 2024 06:05:42 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUg19PvY0BytXDr2NxrJ62CK4ztKKpalCiTFG29j2GFea97FXvsZ0hS24fLIAAAvDbAbIxKUQ==@linaro.org X-Google-Smtp-Source: AGHT+IG3TcUvZn9/IWdgwVL3dex96Ym/ginDSA+xZhWZu66acq/tOKq4NG0f/JByuRAz/9jyePAA X-Received: by 2002:a0c:f802:0:b0:6c3:510e:900b with SMTP id 6a1803df08f44-6c518efff0emr84799276d6.16.1725541542326; Thu, 05 Sep 2024 06:05:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725541542; cv=none; d=google.com; s=arc-20240605; b=U5c9IrW/bcyJ1aJbnQhSAtXL7EwapJ+W2nDE9AaSA9aK5u6qY17ptBls0kADpXmalx /VAOaUSty6t63OZ6w3R6D2MpZsu6m1HeUJ/Ixc2vla4tvZn5ML2zSoXkIhGmiNcHsZpr jQysCeUCUaiIJrviMup3DOByEBiWwO/Er73wpvjm2UJZV9Ko6mU7MHfCm/ZuMTBESEny LJp7x/CBq+rNb0r9/dYJbJcjWhO1w9n8Zpv+2VqCxJReWrnPhfVTrRPwCiSway/3RbVT DXTl1BgRz8Macxsd1SL5jicj+P31OtXSuT6lFooHH/Ha77r9q5eKvGPSqC9ca/SnMVzc B6yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to: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=kA1Nhy36wEyQLROB85TcAoe1vw16tXcqprGuuXecm48=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=WvLK+htJ2VhRuilZALnHQiyBlhMTfa5tZLVUrBhdAWIIZhKmU/unwLQ07exPpAd0g1 6cV5hUBAiTVIy6WOsooqnylCqygkvTU1nZoNlC8fSEGZFOtVwEcEK9izeezlBeSQJRRC Xjl2AXq2GFUnM5rqNieW9QAP3+k59zbDaXMI1FTlJxTM03w5uMCKrXtlAcZxvDXej8A8 PVWdONwLvCpINiwT4MHEkY/z1P/7Ze03YyptHajb7YYYEFq7Mfb1ohLk2IaMDdbhiqGW HGAlElScVOYKXE2Iwex/PbYYzma7IkOykPMbyUaOsO35WHZNe6aX2kwOAe2y3zD/E2AE iwtw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pa84iWPG; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 6a1803df08f44-6c5201e1354si19462256d6.19.2024.09.05.06.05.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 05 Sep 2024 06:05:42 -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=pa84iWPG; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1smC75-0001X6-9n; Thu, 05 Sep 2024 09:01:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1smC6v-00010m-R8 for qemu-devel@nongnu.org; Thu, 05 Sep 2024 09:01:17 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1smC6s-0001jc-7M for qemu-devel@nongnu.org; Thu, 05 Sep 2024 09:01:17 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-42c828c8863so6187945e9.3 for ; Thu, 05 Sep 2024 06:01:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725541269; x=1726146069; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=kA1Nhy36wEyQLROB85TcAoe1vw16tXcqprGuuXecm48=; b=pa84iWPGmV5efqSHBf+ePBpk31g4dKhiY36IUaIDKPzRU8wVhj4d6IzEi7FXwAsDRJ QBGf6kbvUJjpY5nC+ldSDy4djlllF0ZdubVzFtntRKKs0D2FVBd/fwZdgK3RuQTVXvyb 4o8NjOnWnf66Z1iMqxadlcX7SLiUmh1ZdNE7xvRp8YTpUk6vkgkjyp5vqXCOn2A8zRu5 iYcsY7yu1gjbrSZ69zqOYNwmdsWLE27brDp6hoVf8H3EwXWp21lhdwSEKydx4WSWcjDq 5j1rfHoklXyYw6BChQz7seRXqhXT8gevM9JLLGTadSCjCri/eh/0YyrNko/lgnkaDjIG M2+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725541269; x=1726146069; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kA1Nhy36wEyQLROB85TcAoe1vw16tXcqprGuuXecm48=; b=Bt6RUDFI86hiPeJnLYMbR1M4cKZxPgwJG6jwzyVt6Z+7qlLV8Vva07sAB8aj6tRYN4 pPwIDofu1Xpefn9x0xPmoG/GICH1bWk4OaEcYhMUYTSzwEgrJP9/Fm0pdyrO4yFMDZGG BTZcnWp7hnCtAb0emayqPTNUPMurekPg5JCeD10uvMdeBhmOelHfCJlKdPNdejh6WAOl bYoq0Mh1M0OrehxN0UOMHoo6TZ/Un7GYdxUBzuDnUUN8ldWsaBGpiEnm14UEKX+xdh+0 ky92q66OjulZwX/3/aHElJi7+z0A+F4fU0NEqXICl7H3+KMNXbECRoix03JH+b8JrlJN F1tg== X-Gm-Message-State: AOJu0YyBPS3tJX9SskGBMECm+KcNMTX5lOqB65T1+6XSe2co08R8+3hp GIUULAmHCj9+klTDtDUIuqioZQJ+J/xqUmooRnUS0BorZ5YnSjQWR8qGWNZVdtIr/laEd5afKqc g X-Received: by 2002:a05:600c:4652:b0:42c:9e39:d066 with SMTP id 5b1f17b1804b1-42c9e39d0f8mr1212575e9.3.1725541268541; Thu, 05 Sep 2024 06:01:08 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42bb6e355dfsm232251365e9.46.2024.09.05.06.01.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 06:01:07 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 07/25] target/arm: Implement FPCR.EBF=1 semantics for bfdotadd() Date: Thu, 5 Sep 2024 14:00:42 +0100 Message-Id: <20240905130100.298768-8-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240905130100.298768-1-peter.maydell@linaro.org> References: <20240905130100.298768-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32c.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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@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-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Implement the FPCR.EBF=1 semantics for bfdotadd() operations: * is_ebf() sets up fpst and fpst_odd * bfdotadd_ebf() implements the fused paired-multiply-and-add operation that we need The paired-multiply-and-add is similar to f16_dotadd() and we use the same trick here as in that function, but the inputs here are bfloat16 rather than float16. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- target/arm/tcg/vec_helper.c | 57 +++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/target/arm/tcg/vec_helper.c b/target/arm/tcg/vec_helper.c index b0de74b55f1..22ddb968817 100644 --- a/target/arm/tcg/vec_helper.c +++ b/target/arm/tcg/vec_helper.c @@ -2792,7 +2792,20 @@ DO_MMLA_B(gvec_usmmla_b, do_usmmla_b) bool is_ebf(CPUARMState *env, float_status *statusp, float_status *oddstatusp) { - /* FPCR is ignored for BFDOT and BFMMLA. */ + /* + * For BFDOT, BFMMLA, etc, the behaviour depends on FPCR.EBF. + * For EBF = 0, we ignore the FPCR bits which determine rounding + * mode and denormal-flushing, and we do unfused multiplies and + * additions with intermediate rounding of all products and sums. + * For EBF = 1, we honour FPCR rounding mode and denormal-flushing bits, + * and we perform a fused two-way sum-of-products without intermediate + * rounding of the products. + * In either case, we don't set fp exception flags. + * + * EBF is AArch64 only, so even if it's set in the FPCR it has + * no effect on AArch32 instructions. + */ + bool ebf = is_a64(env) && env->vfp.fpcr & FPCR_EBF; *statusp = (float_status){ .tininess_before_rounding = float_tininess_before_rounding, .float_rounding_mode = float_round_to_odd_inf, @@ -2801,7 +2814,18 @@ bool is_ebf(CPUARMState *env, float_status *statusp, float_status *oddstatusp) .default_nan_mode = true, }; - return false; + if (ebf) { + float_status *fpst = &env->vfp.fp_status; + set_flush_to_zero(get_flush_to_zero(fpst), statusp); + set_flush_inputs_to_zero(get_flush_inputs_to_zero(fpst), statusp); + set_float_rounding_mode(get_float_rounding_mode(fpst), statusp); + + /* EBF=1 needs to do a step with round-to-odd semantics */ + *oddstatusp = *statusp; + set_float_rounding_mode(float_round_to_odd, oddstatusp); + } + + return ebf; } float32 bfdotadd(float32 sum, uint32_t e1, uint32_t e2, float_status *fpst) @@ -2823,7 +2847,34 @@ 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) { - g_assert_not_reached(); + /* + * 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(e1 << 16, fpst); + float64 e1c = float32_to_float64(e1 & 0xffff0000u, fpst); + float64 e2r = float32_to_float64(e2 << 16, fpst); + float64 e2c = float32_to_float64(e2 & 0xffff0000u, fpst); + float64 t64; + float32 t32; + + /* + * 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. + */ + t64 = float64_mul(e1r, e2r, fpst_odd); + t64 = float64r32_muladd(e1c, e2c, t64, 0, fpst); + + /* This conversion is exact, because we've already rounded. */ + t32 = float64_to_float32(t64, fpst); + + /* The final accumulation step is not fused. */ + return float32_add(sum, t32, fpst); } void HELPER(gvec_bfdot)(void *vd, void *vn, void *vm, void *va,