From patchwork Tue Nov 5 11:19:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 840767 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1ace:b0:37d:45d0:187 with SMTP id i14csp285347wry; Tue, 5 Nov 2024 03:21:14 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCV4KmoJ5zS2asNl1vCnYdyul7oRqGyW4/sYrsHzvSj6KyHAwJGQwckE/p/UgbsZLfBeZjdbWg==@linaro.org X-Google-Smtp-Source: AGHT+IFHxa6aRRe6mWwYUPFajJPXk59Oj552PZ8KqP1EJILCIl6VbVSr9RVL7h4FRn2S4ZqARrjS X-Received: by 2002:ac8:5a8d:0:b0:460:a9ec:b50e with SMTP id d75a77b69052e-462b8755cf9mr221369561cf.38.1730805673882; Tue, 05 Nov 2024 03:21:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1730805673; cv=none; d=google.com; s=arc-20240605; b=jYz6limG8HVubOzjYIq1p25oMjefbzZl2jtqjJfHsSGjuILDphUqY1tzprkjlM+D6P AQf8EmZJX9f7BfEawcjpT8K6YyGYaa2zsQdqjsnGV784aTRSDqKzDz+IiT3PUIWFmuxc 4dcIujNCt9Vo9Q7o/+8gCKBLEvJZ/1b+Lfa7oZ62RVa1P7WZ/BsA3FpPshTW1cNRUFLm grnyjy3OP5UVhr0HIm25NGuekG10eBHvwsR1rNELaF8WJCwkeoz2W8I6mg0vanUt29lo 4aRMde7JcvGC8saKHk1SOmOujANLxZHFBbjEhZ5p0rBpAVDnOv3jFk2ABK0CW0Go7jUj arew== 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=SsKJm0cgG3cclmW2jQ7Wow6omeKg5AA44umCDXD6jSQ=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=biYr0/YDnNTkpU6fF6wj+cW0YUL89IkTtJ0ZLvqrOCTLY2zwA5jwvjo4UM1nCWTyOB i4altvt8bs3PfsgXTyLJ0iqCa3HornqON87y6jDYGwgDBJwD2GZLVfMpEvcbL/0Hhjze 64uVICpRzP80vbd+QH0yKAo2PmJs+CsECLkwIhrdOsMfthNKZ8vb9XXWA5amov3HbsB5 /OOGyh60NIfU0C8z6dFLaxxIfjZ0UjWFKrnzfVZHYnntpJ2U86cAjRjAvU33XVHnT9mp DvnjcxZNmb080e/SMd8Ambt2ki5fGo3I3vuUEiUbLqSuRrUid4M7d6OOied/sT9KKtdL pwhw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aw6w2Cpo; 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 d75a77b69052e-462be13affesi106016261cf.392.2024.11.05.03.21.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Nov 2024 03:21:13 -0800 (PST) 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=aw6w2Cpo; 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 1t8HbD-0004SX-Lj; Tue, 05 Nov 2024 06:19:51 -0500 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 1t8HbB-0004RY-1G for qemu-devel@nongnu.org; Tue, 05 Nov 2024 06:19:49 -0500 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t8Hb6-000751-FC for qemu-devel@nongnu.org; Tue, 05 Nov 2024 06:19:48 -0500 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-4316f3d3c21so41098995e9.3 for ; Tue, 05 Nov 2024 03:19:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730805579; x=1731410379; 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=SsKJm0cgG3cclmW2jQ7Wow6omeKg5AA44umCDXD6jSQ=; b=aw6w2CpoQUXCprwSkO9uo51gCWBdIQjF6yduYqQIAgqQ6MFqmsg1wJk1R99LNWkfgv H5KDPIoyR0NbZGMuEVsVYbb1E/b5/KpkVa509fCKP0suGZO+DonySA6ox5Wp4pV4aRKE EgUlEsGRyfrfmsOUJE36CIKjqm1O0gaJnUaP2qvo11ijo+tIZjAjffRuYhKRF45LL5w6 Eh4n53Tat9A6r/+OLec+2OLnMmkOuzy/TGfJPjG4KUiycGDanqxbui65LXUm/v2Pq0HR SuABph4yk9cRH8yATz5oLLvWD1PLQrNCx26wQyJGs6wHzXGyBhM2uKhU45/8x8h4jayg p+0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730805579; x=1731410379; 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=SsKJm0cgG3cclmW2jQ7Wow6omeKg5AA44umCDXD6jSQ=; b=B+VsdU46D9lg/sKZoLPfVvj70l4GJxjcoTWGOmVEK1GSbCd+GQIghywOMNESH18bOn rnSml089dUFT0HK6fa0LszqeqOdC/NS8HT0MgpLS57hy+ktDGdoC2GoWzCqrgcCOyuep YKQVXVqEIgDxIWhyXxU+X06LvK2bED+c4gKtFi706smGZG5+UG7RgY1h2vUZHnRyEWRm M7dlrqAGHa1wEZSn8MYd6uxqG5A8l+vQbdXIJTwKpO9fys5uRbXik7QzS9QIeVtFRzIg sqAanZHRIvByDxCmRsMCayn5DvaM50wzarMCpsHY+GYRgy15l0OWeqWLMbzCfpqKxwgB Tj0A== X-Gm-Message-State: AOJu0YyuJHdhPd564toNymmJzOgSRA3VFpkscbZw/pOMUJ/m8o0ax4+z w2zfnAwVTeVNThrxPPbyAobRECTmck+tKIzoSZfCyp1hRZ5oCLA4UIkXzO81+NaEJwtpFL1s6dD g X-Received: by 2002:a05:600c:1f82:b0:430:57f2:bae2 with SMTP id 5b1f17b1804b1-431bb9d14afmr189910775e9.23.1730805579447; Tue, 05 Nov 2024 03:19:39 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432a3688813sm16354555e9.1.2024.11.05.03.19.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 03:19:39 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 03/31] target/arm: Explicitly set 2-NaN propagation rule Date: Tue, 5 Nov 2024 11:19:07 +0000 Message-Id: <20241105111935.2747034-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105111935.2747034-1-peter.maydell@linaro.org> References: <20241105111935.2747034-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x330.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-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 Set the 2-NaN propagation rule explicitly in the float_status words we use. We wrap this plus the pre-existing setting of the tininess-before-rounding flag in a new function arm_set_default_fp_behaviours() to avoid repetition, since we have a lot of float_status words at this point. The situation with FPA11 emulation in linux-user is a little odd, and arguably "correct" behaviour there would be to exactly match a real Linux kernel's FPA11 emulation. However FPA11 emulation is essentially dead at this point and so it seems better to continue with QEMU's current behaviour and leave a comment describing the situation. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20241025141254.2141506-4-peter.maydell@linaro.org --- linux-user/arm/nwfpe/fpa11.c | 18 ++++++++++++++++++ target/arm/cpu.c | 25 +++++++++++++++++-------- fpu/softfloat-specialize.c.inc | 13 ++----------- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/linux-user/arm/nwfpe/fpa11.c b/linux-user/arm/nwfpe/fpa11.c index 9a93610d245..8356beb52c6 100644 --- a/linux-user/arm/nwfpe/fpa11.c +++ b/linux-user/arm/nwfpe/fpa11.c @@ -51,6 +51,24 @@ void resetFPA11(void) #ifdef MAINTAIN_FPCR fpa11->fpcr = MASK_RESET; #endif + + /* + * Real FPA11 hardware does not handle NaNs, but always takes an + * exception for them to be software-emulated (ARM7500FE datasheet + * section 10.4). There is no documented architectural requirement + * for NaN propagation rules and it will depend on how the OS + * level software emulation opted to do it. We here use prop_s_ab + * which matches the later VFP hardware choice and how QEMU's + * fpa11 emulation has worked in the past. The real Linux kernel + * does something slightly different: arch/arm/nwfpe/softfloat-specialize + * propagateFloat64NaN() has the curious behaviour that it prefers + * the QNaN over the SNaN, but if both are QNaN it picks A and + * if both are SNaN it picks B. In theory we could add this as + * a NaN propagation rule, but in practice FPA11 emulation is so + * close to totally dead that it's not worth trying to match it at + * this late date. + */ + set_float_2nan_prop_rule(float_2nan_prop_s_ab, &fpa11->fp_status); } void SetRoundingMode(const unsigned int opcode) diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 5b751439bdc..6938161b954 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -168,6 +168,18 @@ void arm_register_el_change_hook(ARMCPU *cpu, ARMELChangeHookFn *hook, QLIST_INSERT_HEAD(&cpu->el_change_hooks, entry, node); } +/* + * Set the float_status behaviour to match the Arm defaults: + * * tininess-before-rounding + * * 2-input NaN propagation prefers SNaN over QNaN, and then + * operand A over operand B (see FPProcessNaNs() pseudocode) + */ +static void arm_set_default_fp_behaviours(float_status *s) +{ + set_float_detect_tininess(float_tininess_before_rounding, s); + set_float_2nan_prop_rule(float_2nan_prop_s_ab, s); +} + static void cp_reg_reset(gpointer key, gpointer value, gpointer opaque) { /* Reset a single ARMCPRegInfo register */ @@ -549,14 +561,11 @@ static void arm_cpu_reset_hold(Object *obj, ResetType type) set_flush_inputs_to_zero(1, &env->vfp.standard_fp_status); set_default_nan_mode(1, &env->vfp.standard_fp_status); set_default_nan_mode(1, &env->vfp.standard_fp_status_f16); - set_float_detect_tininess(float_tininess_before_rounding, - &env->vfp.fp_status); - set_float_detect_tininess(float_tininess_before_rounding, - &env->vfp.standard_fp_status); - set_float_detect_tininess(float_tininess_before_rounding, - &env->vfp.fp_status_f16); - set_float_detect_tininess(float_tininess_before_rounding, - &env->vfp.standard_fp_status_f16); + arm_set_default_fp_behaviours(&env->vfp.fp_status); + arm_set_default_fp_behaviours(&env->vfp.standard_fp_status); + arm_set_default_fp_behaviours(&env->vfp.fp_status_f16); + arm_set_default_fp_behaviours(&env->vfp.standard_fp_status_f16); + #ifndef CONFIG_USER_ONLY if (kvm_enabled()) { kvm_arm_reset_vcpu(cpu); diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc index fae6794a152..70cd3628b54 100644 --- a/fpu/softfloat-specialize.c.inc +++ b/fpu/softfloat-specialize.c.inc @@ -402,19 +402,10 @@ static int pickNaN(FloatClass a_cls, FloatClass b_cls, /* target didn't set the rule: fall back to old ifdef choices */ #if defined(TARGET_AVR) || defined(TARGET_HEXAGON) \ || defined(TARGET_RISCV) || defined(TARGET_SH4) \ - || defined(TARGET_TRICORE) + || defined(TARGET_TRICORE) || defined(TARGET_ARM) g_assert_not_reached(); -#elif defined(TARGET_ARM) || defined(TARGET_MIPS) || defined(TARGET_HPPA) || \ +#elif defined(TARGET_MIPS) || defined(TARGET_HPPA) || \ defined(TARGET_LOONGARCH64) || defined(TARGET_S390X) - /* - * ARM mandated NaN propagation rules (see FPProcessNaNs()), take - * the first of: - * 1. A if it is signaling - * 2. B if it is signaling - * 3. A (quiet) - * 4. B (quiet) - * A signaling NaN is always quietened before returning it. - */ /* * According to MIPS specifications, if one of the two operands is * a sNaN, a new qNaN has to be generated. This is done in