From patchwork Thu Feb 13 14:26:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 864828 Delivered-To: patch@linaro.org Received: by 2002:a5d:47a6:0:b0:38f:210b:807b with SMTP id 6csp452238wrb; Thu, 13 Feb 2025 06:26:54 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVJ3YtP6dATK3fS/jhEPoy9GGK04jxgiOx4vNLqZ42oheAT6m3t6Dy3jVWxiYbEJgO88Ubc2A==@linaro.org X-Google-Smtp-Source: AGHT+IE7C9NmXJCADupA7M2yXrGG7XnQOVqf7NKQBaNxVddee94pWyXKz1nyQ5INm8JdV6Q17ZIQ X-Received: by 2002:a05:622a:1448:b0:471:9d8c:da20 with SMTP id d75a77b69052e-471afe03296mr89141271cf.8.1739456814491; Thu, 13 Feb 2025 06:26:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1739456814; cv=none; d=google.com; s=arc-20240605; b=jHMKGfRqPcp/bf/VjEvU9X/t/nBFx4ZzPkkqVe4Go/EeBcgaIgsX2ZSWBANu/34vbD g4sfed4EVihZ2IHckxbGl36/rDjrCMcU4B44lifEmskiE0/80uvtCRVnQAjxyuDD97/v tDpetslSSf4YEeeJLApDUuTtjR1rsHU7mGdoobsvpsCTSKByUcrz5l3Ubpv/jQahZ82w E+Rn71rVYTiX5HNCg2nuZtJtcUdc43U/RwnomSdM0PB508f85qYHzgAkyssKSJ8XqyrC EVrosnzusNCgH17BcdSIe3SCS03ksZ0lFRNJLKFsMxh8Zf3y7YglnEVWypYo94L2mrhA eCVg== 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:cc:to :from:dkim-signature; bh=e8mXjz7rvuk+LBsnPgKyClvuahjJz9F8yaCoKy1+ZSo=; fh=PAYODwlZirpE9wBz0jOP90gCu/93ITqb817G+JU23Zw=; b=cxZjWrEjwfD+NHNzVmjzbez1t3y8TETQ7x9muCH1iIScgD2aeqA70ilSTCSs1rTimz gpt2Y/jZSciIKJyMLRzmJcJlC3cCYs7pP3IABpzYXgn/1r68FvTmZpRpEJP6Gr7P+KmF gF/Je24zcxVTt9I15TGb7F5xp80geW38iSGg+xDjruTGYLC/TqidNtpeI5aJTYFnFpAm PRdxwrP48sTWDb1dzSprS/MiIE6hBCeqtJcR4eGxjCKRYCoh5rAoa0x2amZLBuxnnYHb Ov/9SGLrPoniIk16zKnBm1EF6JSa0yw1P8QNXWRDFfX6Fm9R8hza9Cqdnh8g+39oAkmE Uipg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yLejCSlH; 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-471c29f315csi14511881cf.70.2025.02.13.06.26.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Feb 2025 06:26:54 -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=yLejCSlH; 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 1tiaAa-0004Tj-Mf; Thu, 13 Feb 2025 09:26:24 -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 1tiaAX-0004TD-BG for qemu-devel@nongnu.org; Thu, 13 Feb 2025 09:26:22 -0500 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 1tiaAV-0006mv-Ru for qemu-devel@nongnu.org; Thu, 13 Feb 2025 09:26:21 -0500 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-43964e79314so3835975e9.3 for ; Thu, 13 Feb 2025 06:26:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739456778; x=1740061578; 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=e8mXjz7rvuk+LBsnPgKyClvuahjJz9F8yaCoKy1+ZSo=; b=yLejCSlHQaBpgU9C2USoPo3kyJeNWJTuA+3Le78vMoWehv1Ea+vGisfONoNgNdI/th PIyBt8D0NO8E8eSM7iSY7YRQdg5HdfzPF3Ux4/iGuwb6wJ3VaM5hhyt2oxbmDFLHmcVP Y8zk+R8f1tWEuECtm28pV7jItwrQw8crw43VJtyye3n4OmNxS8qbKXJl5tjjMn1SBL2p 98r5ii4maoPaxfukI4epfWgtLA5yg+Vzyx3vDc0/BTO25PMjz5ahnuRJStRUHfZtB6HK SF7ZIi4etITv2vToNcEovwWxged7Uonhi2AzzCURgTOrG6vxbIt8ufEqOsUmo+t5GSKx dhXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739456778; x=1740061578; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=e8mXjz7rvuk+LBsnPgKyClvuahjJz9F8yaCoKy1+ZSo=; b=ngyNJo2SM37HqC7QjcLNI2OMprG1DMrSDg8DtFajODzY+O3HmokQGGAaDGCNu4pKBb 4v5AgrrOTXHHGazP7VpNhNZWGvJoGJ+zY6AvnEKTrwCnc/+w3Nn2bKxWFbeKdn8mIfIT vZvd9KNhp4nmoLvg//1BzEoecjE5k5VsuK5mgYtNy4hzOGiTZ7TPKDOZSYYXcm6sIWMP k2SVk4kfPBScKC8IY82+dQrgKbWpcFjs3/ELwX1MKh3LS8tpNztLufCuIDIxPlJuCwlg rkR/jhC/NtNyuG++B0Q4uM8HzqVL9AUgT/XJgovJ5WTB8EgJUrrndZ3hTpyZDK7Sx4xI U3ZA== X-Gm-Message-State: AOJu0YwEovOTJEkChspcuI7ewj7z/8ll/8NLG3ukzQnXdgfRoQ2eVILK YKBuKGBeSA7h66WbmC+9hjBMnWnxymW+IZD1bgD8zuVbWWwKO5f436g2GWdF8xyOnk7san5oGPS 0 X-Gm-Gg: ASbGncsrM6z6JLYz/ZLsPRkPZXx/skxbwc7VcBBxtscLXjjzjPU8b4CrHMYXaRdipLf Tatke0LvVS3QdfG0qwr/gI+TFKq17YYHIaYGRcqikd0PZMnElmtQKjr+EA5afU2C+LlnDzB/shK Xp9I/gg57crYRXDmU/PnIEVXgu3I4uwg84wkx3EhvTXAn5IKseZ9J/j14TbPSLpvczY3t3FVonh DvFDRVr6x6SvJueEe/Fu0lZxJE4vOf2ZdNFk4XUkbccx1J9gXkJqf7QmZ/6zKsLP4Ykv/d6R9Wq SVf/S267PwrAa/+IooVjbw== X-Received: by 2002:a05:6000:154c:b0:38f:2111:f5ac with SMTP id ffacd0b85a97d-38f2111fcbfmr4947584f8f.31.1739456778198; Thu, 13 Feb 2025 06:26:18 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f258b4335sm2093604f8f.15.2025.02.13.06.26.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2025 06:26:16 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Richard Henderson , Paolo Bonzini , Zhao Liu , Eduardo Habkost Subject: [PATCH 1/4] target/i386: Detect flush-to-zero after rounding Date: Thu, 13 Feb 2025 14:26:10 +0000 Message-ID: <20250213142613.151308-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250213142613.151308-1-peter.maydell@linaro.org> References: <20250213142613.151308-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 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 The Intel SDM section 10.2.3.3 on the MXCSR.FTZ bit says that we flush outputs to zero when we detect underflow, which is after rounding. Set the detect_ftz flag accordingly. This allows us to enable the test in fma.c which checks this behaviour. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- target/i386/tcg/fpu_helper.c | 8 ++++---- tests/tcg/x86_64/fma.c | 5 ----- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/target/i386/tcg/fpu_helper.c b/target/i386/tcg/fpu_helper.c index f112c6c6737..87fbc149d84 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -189,13 +189,13 @@ void cpu_init_fp_statuses(CPUX86State *env) set_float_default_nan_pattern(0b11000000, &env->mmx_status); set_float_default_nan_pattern(0b11000000, &env->sse_status); /* - * TODO: x86 does flush-to-zero detection after rounding (the SDM + * x86 does flush-to-zero detection after rounding (the SDM * section 10.2.3.3 on the FTZ bit of MXCSR says that we flush * when we detect underflow, which x86 does after rounding). */ - set_float_ftz_detection(float_ftz_before_rounding, &env->fp_status); - set_float_ftz_detection(float_ftz_before_rounding, &env->mmx_status); - set_float_ftz_detection(float_ftz_before_rounding, &env->sse_status); + set_float_ftz_detection(float_ftz_after_rounding, &env->fp_status); + set_float_ftz_detection(float_ftz_after_rounding, &env->mmx_status); + set_float_ftz_detection(float_ftz_after_rounding, &env->sse_status); } static inline uint8_t save_exception_flags(CPUX86State *env) diff --git a/tests/tcg/x86_64/fma.c b/tests/tcg/x86_64/fma.c index 09c622ebc00..46f863005ed 100644 --- a/tests/tcg/x86_64/fma.c +++ b/tests/tcg/x86_64/fma.c @@ -79,14 +79,9 @@ static testdata tests[] = { /* * Flushing of denormal outputs to zero should also happen after * rounding, so setting FTZ should not affect the result or the flags. - * QEMU currently does not emulate this correctly because we do the - * flush-to-zero check before rounding, so we incorrectly produce a - * zero result and set Underflow as well as Precision. */ -#ifdef ENABLE_FAILING_TESTS { 0x3fdfffffffffffff, 0x001fffffffffffff, 0x801fffffffffffff, true, 0x8010000000000000, 0x20 }, /* Enabling FTZ shouldn't change flags */ -#endif }; int main(void) From patchwork Thu Feb 13 14:26:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 864831 Delivered-To: patch@linaro.org Received: by 2002:a5d:47a6:0:b0:38f:210b:807b with SMTP id 6csp452565wrb; Thu, 13 Feb 2025 06:27:33 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVMjn7JMqFCmElsfXUJ5uKgV2yD6E9puooycYoR/8mCVmRbiHng8SFznMSvf8+w7T/usypo3Q==@linaro.org X-Google-Smtp-Source: AGHT+IEeZe+vWL214kAo8kMdPmI3XkcYRLSrcYjqX0Ilqj/ewo3FBwCJJKmDAzsuwd0c/KuMlWKV X-Received: by 2002:a05:622a:94:b0:471:903c:9226 with SMTP id d75a77b69052e-471afef7201mr97978361cf.45.1739456853613; Thu, 13 Feb 2025 06:27:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1739456853; cv=none; d=google.com; s=arc-20240605; b=fMtO3iUn57wVMTrYJXACtqby48HQF3BIS/T2CtLrPGRzs2MT3uOI1dzsAHCk7J4lk8 CKtyYVaqtfNVVsjVrhiaoxDpzhzUxrVXzoKFq1m1shEyKzfMnxYHeEYjYZ4OIDvdnkdI J5wnHsxx7MGrdZDHsRYqBk6AVlTJdru3nUFkLDlyCSaYZpZp8ACNQa3H9Qh7w1gcr1Pa 99k1wSF0dH9BIBnK0SH/ei1XjEmGHYx63PkMOulnjxozZvQMqtGv0QzvoGJSwz/Fvyal 261+jNo5QaSclebPFFzIlix2hy+p4bnbL0g2vMUC56LLVV0GUJ1Ajrw0NR3vl9R2ePpV wlNg== 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:cc:to :from:dkim-signature; bh=SdbBccgNA9iD9ywHMcl4sf5pFjIJuIWSjvGN9CQVHH8=; fh=PAYODwlZirpE9wBz0jOP90gCu/93ITqb817G+JU23Zw=; b=dSiu0r49catUXtV5AHZXFiqDFKuSfkPa7FWSTyizavGYY34o6pfu8BtvSdNggxV9MJ jlvkL8XtI/chF2qHr5oj9yFYTDZqb2ZRPiLz9z/iFJ00dRIhEYKLlJzPUZ/MdCpWuaT8 IttaOH/pgR+NLmju5iPvwzsnVuWpF61+IkDPdSC2lJ9vIyqqUetMyCUPkVFLOdPe9Upw f586lhrEuOhJbEEQlA477VdzkHCs5abS0Om/Ky6Spczx4BxDiZRMu8lEfirRud9Xkrea HpjvCa7K8tAxAi70fV/7Jc7qlvPpaDqzoccf2cyMUDSjHHeBgBcDg/4zF1ahX9PF4hQF +VXQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hyDBOET7; 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-471c2b48a04si14169871cf.436.2025.02.13.06.27.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Feb 2025 06:27:33 -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=hyDBOET7; 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 1tiaAb-0004UA-G5; Thu, 13 Feb 2025 09:26:25 -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 1tiaAZ-0004TV-Os for qemu-devel@nongnu.org; Thu, 13 Feb 2025 09:26:24 -0500 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tiaAX-0006nJ-AE for qemu-devel@nongnu.org; Thu, 13 Feb 2025 09:26:23 -0500 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-38dc0cd94a6so520339f8f.0 for ; Thu, 13 Feb 2025 06:26:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739456780; x=1740061580; 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=SdbBccgNA9iD9ywHMcl4sf5pFjIJuIWSjvGN9CQVHH8=; b=hyDBOET7k6XIAVP4BjPI4cOX0wTucJVI4Km2Ynk8fUlGsrlHbAmhU0IczZIMsyo+aV +2erte1Iau7r3sZE+WWlgNiRWYy7p/FHbK6+FcIAz/AhLkSlidAaMdSO7GJVl8KomUC9 hhonK9XIIZPLwKTrpOAqX2ZKIgRoWzytewYOBttA7qWBX1a2ncMVv+cIu1OTP2MrCX6P BdrkXY9WbTkAgMqeWnTYqd7rmAAEPBrB0nO6YWBQUjZoB6yyPnB2aTrK8eDzUOVHhS66 9qlooSTvxeLcp5YXF1q+mdscSGN2QpXRYLE6KKxnFo8kLYLm1SDvhxdZxzqanSG2lldr zOLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739456780; x=1740061580; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SdbBccgNA9iD9ywHMcl4sf5pFjIJuIWSjvGN9CQVHH8=; b=rCKm+wbpc40CAESZ1GwkSu9hROpZbpUxVR62liRCg0I5CFr317j7xO9HO0uH1JTuKe q72BzX+hJCU+RNoYVVjZQiz9aXHumhuZ9DQTCikMO+SVpn0DY42FQ98KuIRn3mPyaMxt KxXVvCNXSJ+o/86fZw8r95GnHRwpfHwLdGq1Wuihk07TupgPjmuqOpStxcqlmu1+/6yJ TzxkH3YdLmvb7H3URd3wyseV7Fa+rIRR8LkHnvGE/TMJ8gy7Q39+9g1wKQcYLcg1t1Q9 ONdJfbVPpILprV7HU2XhC7ieyuCIo1c/0rVQzjQ1WHoG7t635bUmUF0PO/iPz5tmgp9E //2Q== X-Gm-Message-State: AOJu0YxmLAWZHJszZo9wNKvYL/r8O4aD0OhOn/VtEYlrz3r1B32dlLIz /jdxrYqxdYYrV1ezBxGRaXthnSX6UwlqCFgdmB+nb6ugYysVoGbaSjYEz/KGiNe2Gu/FSPFAUEF P X-Gm-Gg: ASbGncuVTgeCXS+Jm1yeoOwzP5Yj5TiWsyYwji+AheaVJBBchIlZDQb79ePDBZZozlT S73d4Xszj6zNcEBgWpuFwgl6EtPWav6NyaYNxw7tT7q3dr+T0r3eGRfXBWZ7cOG0VexIFhcXq5h lyBtCAF5SysmKqlfAVG2E4qMREWOt/AbLx1KIpsbSwma8DdMBYcQuEFpLRlKaoYaj8i0TkSThlw rUUcqVXkifDB3PkNx39y0dQFmVeU0+GI5YiV8MxZQfOv7iBE+4YUQr4tpZ7mm6NYl0bGWSjHVkp cnNGWde6jm0mfSLq4huQdA== X-Received: by 2002:a05:6000:154c:b0:38d:df70:23e7 with SMTP id ffacd0b85a97d-38f245035f5mr3358807f8f.31.1739456779690; Thu, 13 Feb 2025 06:26:19 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f258b4335sm2093604f8f.15.2025.02.13.06.26.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2025 06:26:18 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Richard Henderson , Paolo Bonzini , Zhao Liu , Eduardo Habkost Subject: [PATCH 2/4] target/i386: Use correct type for get_float_exception_flags() values Date: Thu, 13 Feb 2025 14:26:11 +0000 Message-ID: <20250213142613.151308-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250213142613.151308-1-peter.maydell@linaro.org> References: <20250213142613.151308-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42f.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 The softfloat get_float_exception_flags() function returns 'int', but in various places in target/i386 we incorrectly store the returned value into a uint8_t. This currently has no ill effects because i386 doesn't care about any of the float_flag enum values above 0x40. However, we want to start using float_flag_input_denormal_used, which is 0x4000. Switch to using 'int' so that we can handle all the possible valid float_flag_* values. This includes changing the return type of save_exception_flags() and the argument to merge_exception_flags(). Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- target/i386/ops_sse.h | 16 +++---- target/i386/tcg/fpu_helper.c | 82 ++++++++++++++++++------------------ 2 files changed, 49 insertions(+), 49 deletions(-) diff --git a/target/i386/ops_sse.h b/target/i386/ops_sse.h index f0aa1894aa2..a2e4d480399 100644 --- a/target/i386/ops_sse.h +++ b/target/i386/ops_sse.h @@ -842,7 +842,7 @@ int64_t helper_cvttsd2sq(CPUX86State *env, ZMMReg *s) void glue(helper_rsqrtps, SUFFIX)(CPUX86State *env, ZMMReg *d, ZMMReg *s) { - uint8_t old_flags = get_float_exception_flags(&env->sse_status); + int old_flags = get_float_exception_flags(&env->sse_status); int i; for (i = 0; i < 2 << SHIFT; i++) { d->ZMM_S(i) = float32_div(float32_one, @@ -855,7 +855,7 @@ void glue(helper_rsqrtps, SUFFIX)(CPUX86State *env, ZMMReg *d, ZMMReg *s) #if SHIFT == 1 void helper_rsqrtss(CPUX86State *env, ZMMReg *d, ZMMReg *v, ZMMReg *s) { - uint8_t old_flags = get_float_exception_flags(&env->sse_status); + int old_flags = get_float_exception_flags(&env->sse_status); int i; d->ZMM_S(0) = float32_div(float32_one, float32_sqrt(s->ZMM_S(0), &env->sse_status), @@ -869,7 +869,7 @@ void helper_rsqrtss(CPUX86State *env, ZMMReg *d, ZMMReg *v, ZMMReg *s) void glue(helper_rcpps, SUFFIX)(CPUX86State *env, ZMMReg *d, ZMMReg *s) { - uint8_t old_flags = get_float_exception_flags(&env->sse_status); + int old_flags = get_float_exception_flags(&env->sse_status); int i; for (i = 0; i < 2 << SHIFT; i++) { d->ZMM_S(i) = float32_div(float32_one, s->ZMM_S(i), &env->sse_status); @@ -880,7 +880,7 @@ void glue(helper_rcpps, SUFFIX)(CPUX86State *env, ZMMReg *d, ZMMReg *s) #if SHIFT == 1 void helper_rcpss(CPUX86State *env, ZMMReg *d, ZMMReg *v, ZMMReg *s) { - uint8_t old_flags = get_float_exception_flags(&env->sse_status); + int old_flags = get_float_exception_flags(&env->sse_status); int i; d->ZMM_S(0) = float32_div(float32_one, s->ZMM_S(0), &env->sse_status); for (i = 1; i < 2 << SHIFT; i++) { @@ -1714,7 +1714,7 @@ void glue(helper_phminposuw, SUFFIX)(CPUX86State *env, Reg *d, Reg *s) void glue(helper_roundps, SUFFIX)(CPUX86State *env, Reg *d, Reg *s, uint32_t mode) { - uint8_t old_flags = get_float_exception_flags(&env->sse_status); + int old_flags = get_float_exception_flags(&env->sse_status); signed char prev_rounding_mode; int i; @@ -1738,7 +1738,7 @@ void glue(helper_roundps, SUFFIX)(CPUX86State *env, Reg *d, Reg *s, void glue(helper_roundpd, SUFFIX)(CPUX86State *env, Reg *d, Reg *s, uint32_t mode) { - uint8_t old_flags = get_float_exception_flags(&env->sse_status); + int old_flags = get_float_exception_flags(&env->sse_status); signed char prev_rounding_mode; int i; @@ -1763,7 +1763,7 @@ void glue(helper_roundpd, SUFFIX)(CPUX86State *env, Reg *d, Reg *s, void glue(helper_roundss, SUFFIX)(CPUX86State *env, Reg *d, Reg *v, Reg *s, uint32_t mode) { - uint8_t old_flags = get_float_exception_flags(&env->sse_status); + int old_flags = get_float_exception_flags(&env->sse_status); signed char prev_rounding_mode; int i; @@ -1788,7 +1788,7 @@ void glue(helper_roundss, SUFFIX)(CPUX86State *env, Reg *d, Reg *v, Reg *s, void glue(helper_roundsd, SUFFIX)(CPUX86State *env, Reg *d, Reg *v, Reg *s, uint32_t mode) { - uint8_t old_flags = get_float_exception_flags(&env->sse_status); + int old_flags = get_float_exception_flags(&env->sse_status); signed char prev_rounding_mode; int i; diff --git a/target/i386/tcg/fpu_helper.c b/target/i386/tcg/fpu_helper.c index 87fbc149d84..cd965a1f582 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -198,16 +198,16 @@ void cpu_init_fp_statuses(CPUX86State *env) set_float_ftz_detection(float_ftz_after_rounding, &env->sse_status); } -static inline uint8_t save_exception_flags(CPUX86State *env) +static inline int save_exception_flags(CPUX86State *env) { - uint8_t old_flags = get_float_exception_flags(&env->fp_status); + int old_flags = get_float_exception_flags(&env->fp_status); set_float_exception_flags(0, &env->fp_status); return old_flags; } -static void merge_exception_flags(CPUX86State *env, uint8_t old_flags) +static void merge_exception_flags(CPUX86State *env, int old_flags) { - uint8_t new_flags = get_float_exception_flags(&env->fp_status); + int new_flags = get_float_exception_flags(&env->fp_status); float_raise(old_flags, &env->fp_status); fpu_set_exception(env, ((new_flags & float_flag_invalid ? FPUS_IE : 0) | @@ -220,7 +220,7 @@ static void merge_exception_flags(CPUX86State *env, uint8_t old_flags) static inline floatx80 helper_fdiv(CPUX86State *env, floatx80 a, floatx80 b) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); floatx80 ret = floatx80_div(a, b, &env->fp_status); merge_exception_flags(env, old_flags); return ret; @@ -240,7 +240,7 @@ static void fpu_raise_exception(CPUX86State *env, uintptr_t retaddr) void helper_flds_FT0(CPUX86State *env, uint32_t val) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); union { float32 f; uint32_t i; @@ -253,7 +253,7 @@ void helper_flds_FT0(CPUX86State *env, uint32_t val) void helper_fldl_FT0(CPUX86State *env, uint64_t val) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); union { float64 f; uint64_t i; @@ -271,7 +271,7 @@ void helper_fildl_FT0(CPUX86State *env, int32_t val) void helper_flds_ST0(CPUX86State *env, uint32_t val) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); int new_fpstt; union { float32 f; @@ -288,7 +288,7 @@ void helper_flds_ST0(CPUX86State *env, uint32_t val) void helper_fldl_ST0(CPUX86State *env, uint64_t val) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); int new_fpstt; union { float64 f; @@ -338,7 +338,7 @@ void helper_fildll_ST0(CPUX86State *env, int64_t val) uint32_t helper_fsts_ST0(CPUX86State *env) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); union { float32 f; uint32_t i; @@ -351,7 +351,7 @@ uint32_t helper_fsts_ST0(CPUX86State *env) uint64_t helper_fstl_ST0(CPUX86State *env) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); union { float64 f; uint64_t i; @@ -364,7 +364,7 @@ uint64_t helper_fstl_ST0(CPUX86State *env) int32_t helper_fist_ST0(CPUX86State *env) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); int32_t val; val = floatx80_to_int32(ST0, &env->fp_status); @@ -378,7 +378,7 @@ int32_t helper_fist_ST0(CPUX86State *env) int32_t helper_fistl_ST0(CPUX86State *env) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); int32_t val; val = floatx80_to_int32(ST0, &env->fp_status); @@ -391,7 +391,7 @@ int32_t helper_fistl_ST0(CPUX86State *env) int64_t helper_fistll_ST0(CPUX86State *env) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); int64_t val; val = floatx80_to_int64(ST0, &env->fp_status); @@ -404,7 +404,7 @@ int64_t helper_fistll_ST0(CPUX86State *env) int32_t helper_fistt_ST0(CPUX86State *env) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); int32_t val; val = floatx80_to_int32_round_to_zero(ST0, &env->fp_status); @@ -418,7 +418,7 @@ int32_t helper_fistt_ST0(CPUX86State *env) int32_t helper_fisttl_ST0(CPUX86State *env) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); int32_t val; val = floatx80_to_int32_round_to_zero(ST0, &env->fp_status); @@ -431,7 +431,7 @@ int32_t helper_fisttl_ST0(CPUX86State *env) int64_t helper_fisttll_ST0(CPUX86State *env) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); int64_t val; val = floatx80_to_int64_round_to_zero(ST0, &env->fp_status); @@ -527,7 +527,7 @@ static const int fcom_ccval[4] = {0x0100, 0x4000, 0x0000, 0x4500}; void helper_fcom_ST0_FT0(CPUX86State *env) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); FloatRelation ret; ret = floatx80_compare(ST0, FT0, &env->fp_status); @@ -537,7 +537,7 @@ void helper_fcom_ST0_FT0(CPUX86State *env) void helper_fucom_ST0_FT0(CPUX86State *env) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); FloatRelation ret; ret = floatx80_compare_quiet(ST0, FT0, &env->fp_status); @@ -549,7 +549,7 @@ static const int fcomi_ccval[4] = {CC_C, CC_Z, 0, CC_Z | CC_P | CC_C}; void helper_fcomi_ST0_FT0(CPUX86State *env) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); int eflags; FloatRelation ret; @@ -562,7 +562,7 @@ void helper_fcomi_ST0_FT0(CPUX86State *env) void helper_fucomi_ST0_FT0(CPUX86State *env) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); int eflags; FloatRelation ret; @@ -575,28 +575,28 @@ void helper_fucomi_ST0_FT0(CPUX86State *env) void helper_fadd_ST0_FT0(CPUX86State *env) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); ST0 = floatx80_add(ST0, FT0, &env->fp_status); merge_exception_flags(env, old_flags); } void helper_fmul_ST0_FT0(CPUX86State *env) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); ST0 = floatx80_mul(ST0, FT0, &env->fp_status); merge_exception_flags(env, old_flags); } void helper_fsub_ST0_FT0(CPUX86State *env) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); ST0 = floatx80_sub(ST0, FT0, &env->fp_status); merge_exception_flags(env, old_flags); } void helper_fsubr_ST0_FT0(CPUX86State *env) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); ST0 = floatx80_sub(FT0, ST0, &env->fp_status); merge_exception_flags(env, old_flags); } @@ -615,28 +615,28 @@ void helper_fdivr_ST0_FT0(CPUX86State *env) void helper_fadd_STN_ST0(CPUX86State *env, int st_index) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); ST(st_index) = floatx80_add(ST(st_index), ST0, &env->fp_status); merge_exception_flags(env, old_flags); } void helper_fmul_STN_ST0(CPUX86State *env, int st_index) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); ST(st_index) = floatx80_mul(ST(st_index), ST0, &env->fp_status); merge_exception_flags(env, old_flags); } void helper_fsub_STN_ST0(CPUX86State *env, int st_index) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); ST(st_index) = floatx80_sub(ST(st_index), ST0, &env->fp_status); merge_exception_flags(env, old_flags); } void helper_fsubr_STN_ST0(CPUX86State *env, int st_index) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); ST(st_index) = floatx80_sub(ST0, ST(st_index), &env->fp_status); merge_exception_flags(env, old_flags); } @@ -861,7 +861,7 @@ void helper_fbld_ST0(CPUX86State *env, target_ulong ptr) void helper_fbst_ST0(CPUX86State *env, target_ulong ptr) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); int v; target_ulong mem_ref, mem_end; int64_t val; @@ -1136,7 +1136,7 @@ static const struct f2xm1_data f2xm1_table[65] = { void helper_f2xm1(CPUX86State *env) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); uint64_t sig = extractFloatx80Frac(ST0); int32_t exp = extractFloatx80Exp(ST0); bool sign = extractFloatx80Sign(ST0); @@ -1369,7 +1369,7 @@ static const struct fpatan_data fpatan_table[9] = { void helper_fpatan(CPUX86State *env) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); uint64_t arg0_sig = extractFloatx80Frac(ST0); int32_t arg0_exp = extractFloatx80Exp(ST0); bool arg0_sign = extractFloatx80Sign(ST0); @@ -1806,7 +1806,7 @@ void helper_fpatan(CPUX86State *env) void helper_fxtract(CPUX86State *env) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); CPU_LDoubleU temp; temp.d = ST0; @@ -1855,7 +1855,7 @@ void helper_fxtract(CPUX86State *env) static void helper_fprem_common(CPUX86State *env, bool mod) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); uint64_t quotient; CPU_LDoubleU temp0, temp1; int exp0, exp1, expdiff; @@ -2050,7 +2050,7 @@ static void helper_fyl2x_common(CPUX86State *env, floatx80 arg, int32_t *exp, void helper_fyl2xp1(CPUX86State *env) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); uint64_t arg0_sig = extractFloatx80Frac(ST0); int32_t arg0_exp = extractFloatx80Exp(ST0); bool arg0_sign = extractFloatx80Sign(ST0); @@ -2148,7 +2148,7 @@ void helper_fyl2xp1(CPUX86State *env) void helper_fyl2x(CPUX86State *env) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); uint64_t arg0_sig = extractFloatx80Frac(ST0); int32_t arg0_exp = extractFloatx80Exp(ST0); bool arg0_sign = extractFloatx80Sign(ST0); @@ -2295,7 +2295,7 @@ void helper_fyl2x(CPUX86State *env) void helper_fsqrt(CPUX86State *env) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); if (floatx80_is_neg(ST0)) { env->fpus &= ~0x4700; /* (C3,C2,C1,C0) <-- 0000 */ env->fpus |= 0x400; @@ -2321,14 +2321,14 @@ void helper_fsincos(CPUX86State *env) void helper_frndint(CPUX86State *env) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); ST0 = floatx80_round_to_int(ST0, &env->fp_status); merge_exception_flags(env, old_flags); } void helper_fscale(CPUX86State *env) { - uint8_t old_flags = save_exception_flags(env); + int old_flags = save_exception_flags(env); if (floatx80_invalid_encoding(ST1) || floatx80_invalid_encoding(ST0)) { float_raise(float_flag_invalid, &env->fp_status); ST0 = floatx80_default_nan(&env->fp_status); @@ -2366,7 +2366,7 @@ void helper_fscale(CPUX86State *env) } else { int n; FloatX80RoundPrec save = env->fp_status.floatx80_rounding_precision; - uint8_t save_flags = get_float_exception_flags(&env->fp_status); + int save_flags = get_float_exception_flags(&env->fp_status); set_float_exception_flags(0, &env->fp_status); n = floatx80_to_int32_round_to_zero(ST1, &env->fp_status); set_float_exception_flags(save_flags, &env->fp_status); @@ -3266,7 +3266,7 @@ void update_mxcsr_status(CPUX86State *env) void update_mxcsr_from_sse_status(CPUX86State *env) { - uint8_t flags = get_float_exception_flags(&env->sse_status); + int flags = get_float_exception_flags(&env->sse_status); /* * The MXCSR denormal flag has opposite semantics to * float_flag_input_denormal_flushed (the softfloat code sets that flag From patchwork Thu Feb 13 14:26:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 864830 Delivered-To: patch@linaro.org Received: by 2002:a5d:47a6:0:b0:38f:210b:807b with SMTP id 6csp452457wrb; Thu, 13 Feb 2025 06:27:22 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVhNc3u1l/EAzlj3v7chxCnNX/wlL1cQG2TcRhOR+xzp6OtrlXlt2tY8Y0DHlqKPmtOTsOXcg==@linaro.org X-Google-Smtp-Source: AGHT+IFW7lZxnorLKAVybETwNrSFhVo3Z54BCCrLq5HkJ3p0VmeDMg7lNcV2OFJHysESH0o4Om+d X-Received: by 2002:a05:622a:4c8:b0:471:90b0:373 with SMTP id d75a77b69052e-471bed69735mr59205101cf.21.1739456841892; Thu, 13 Feb 2025 06:27:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1739456841; cv=none; d=google.com; s=arc-20240605; b=H3LAwndmX7uLN+S3j239eNGFfqN03YnzXN+4PfV/bjt5szdnNP0Bwnqd6BP3CuTwVC oINSorJ7mi+rEIrC/j01FSk+FKalsDb8LM/fXEX+i0dT08J7Ns9f0vORaCMuYaWrbYih YoN9NowffeON0fFMWiuZtWPDAqSdP+iCh1PLT9VAEkX0xnGUYC7vLxFuaCKMtz8RZXn7 HiuzSXvOcPAnAWwmFEdF95NMxJ9iuoSn51zWjjfAReEMkBzo7MuCrcStOAXFpQp++zRC pH1g4S2XdonV+mMB2MeOLDuQtVyi5GKC5vvdY6mh2NK30f3OccDWi9Z1GDNsF7Qh/qZs pv7A== 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:cc:to :from:dkim-signature; bh=DNJ8WW6iY498MqH2CWe2uCFtkY9p00Gknfy30JxtKWU=; fh=PAYODwlZirpE9wBz0jOP90gCu/93ITqb817G+JU23Zw=; b=LoQO8WyDUaLGWr1/DGVMd8gkf3bl0MuMQeAiHiYg8oIXJ5yJH7EXlzsss0ooOCbBC7 AgxGTDIWOHvrYogh16gCOpemTqf9qVkeIIzo2Tal7Io+JESnQTJTde3FlHUgB/4zXjkl OFUfYhREMJWNIhJAdyAhtuNWYp/8FycXpHi1qVHp02ngGtxa+mhA8ED/EcJ3hJEzFld3 PmGl/K6HKPpiVIA4RzUXJPxxkvPod0JtHkvtTaNUuuZdrao6YsWvVqwi4UTY2g0LGLyn CAeWPphSHAtU+nCIRM6pg6pCN66vcLtCPYgwnDmahrpOjzGptcxoADvC+2DyErQXhyiC Ze3g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CFQqL22M; 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-471c2a24137si14125431cf.162.2025.02.13.06.27.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Feb 2025 06:27:21 -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=CFQqL22M; 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 1tiaAd-0004VT-8m; Thu, 13 Feb 2025 09:26:27 -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 1tiaAb-0004Tt-3S for qemu-devel@nongnu.org; Thu, 13 Feb 2025 09:26:25 -0500 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tiaAY-0006nY-H9 for qemu-devel@nongnu.org; Thu, 13 Feb 2025 09:26:24 -0500 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-38dc73cc5acso579493f8f.0 for ; Thu, 13 Feb 2025 06:26:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739456781; x=1740061581; 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=DNJ8WW6iY498MqH2CWe2uCFtkY9p00Gknfy30JxtKWU=; b=CFQqL22MW+eLBK0NVu5nJrGGu83FypvraJWI99GModpJdt3hAKG/b++qd2laXNw3iv R85eCGSItBX+oART7h3KPEjeeRtbZfmfv0ZyWxb1b5CT00Dwqg7mRo58Qxu6OZAy+1NH Yq/UWpGICsgaJH0Ce19Snc3ne/y3Ovotp1hM0g+6KUfRSkue6BUWmXV7TtZWV+Yc2seG 4kc9vrvleMDwmFj/cf6fw4mOvtFQc5szOqniAtlDikw3cWEkcX+gmBn6sJN1PcHwGsGM l9N7kci4b54lKJuJA9KUyH6pAr1spH5SgBok6KrQSPYIDqQkQsb661cNMLRyD61x3NpX R7cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739456781; x=1740061581; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DNJ8WW6iY498MqH2CWe2uCFtkY9p00Gknfy30JxtKWU=; b=MrSJ9eRViDGnIX9FMj3dpAGGfV/7ZWteEmA65JWL2oms0SX5e4i53Sqx1Q2gzYYkXJ ZEwMr40uI/S6L4CoKxG5BIjay7Fm7ZNXmZXg1D1uSua8a4o/2pl42NJvqxMdFsfBCSQW QosQ/Z2IUOUZUsHpbhxZ3OaBBtYOzOGOiC/yoJBAbB8INem3KVekCoi/6htVJEY+QQ4Z lN2jRzDchlNgIGErzcBQJ5voYwwztX03ZNh0YoLBlhRNmnjX3R3nv5sO3HeBEMiShumO v+/XssgT48sTG1eyAg3Wvb2bPIcQi7fFPFD0fraje1FGaunYjkO5hoKDmIvwcZkKJJGa uyqA== X-Gm-Message-State: AOJu0Yz3Ln8i9oSGohK7HB3R2gx9dmPwtLT9jVmij2z6OxNumTVLEjLn jE+aDEHhcz/trvMAgZvoP3mE1bgVD/9MsMtVapS6sjJ4rvB/+4wgWL7mpSGvY08jKgumJXBr/dT H X-Gm-Gg: ASbGncs+0Zv+DadBhUAuVFumbwZjFBwl3ETX8F3IUelRnwcvquqKU468s6oD8OxBXOD bm5NlqDkXn8QaYb6B3RC+av4KUJQEt9paJXUwobZK5t48qgm4ZsTCr6QbKPam71JqX979heRt4P UG9GUldKi0HwvmiNODomUAWYb4QaEtAmO0ykF+7zZ+GzdPdhJwyIPc8i1XIG/1b6UyW3jDYZQcN FHRznGFEhSxi/EF/3dxk+lz2a4hzFDADeA6xp4PGGbAW2y52pZp3+a8p8V2HUlcpBdTzmO+yUAm b4IWJIOn2Q5k1VC5Iv8B6g== X-Received: by 2002:a5d:6603:0:b0:38a:4184:14ec with SMTP id ffacd0b85a97d-38f24f06c50mr3087956f8f.1.1739456780880; Thu, 13 Feb 2025 06:26:20 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f258b4335sm2093604f8f.15.2025.02.13.06.26.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2025 06:26:20 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Richard Henderson , Paolo Bonzini , Zhao Liu , Eduardo Habkost Subject: [PATCH 3/4] target/i386: Wire up MXCSR.DE and FPUS.DE correctly Date: Thu, 13 Feb 2025 14:26:12 +0000 Message-ID: <20250213142613.151308-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250213142613.151308-1-peter.maydell@linaro.org> References: <20250213142613.151308-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42a.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 The x86 DE bit in the FPU and MXCSR status is supposed to be set when an input denormal is consumed. We didn't previously report this from softfloat, so the x86 code either simply didn't set the DE bit or else incorrectly wired it up to denormal_flushed, depending on which register you looked at. Now we have input_denormal_used we can wire up these DE bits with the semantics they are supposed to have. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- target/i386/tcg/fpu_helper.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/target/i386/tcg/fpu_helper.c b/target/i386/tcg/fpu_helper.c index cd965a1f582..66febbacee1 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -215,7 +215,7 @@ static void merge_exception_flags(CPUX86State *env, int old_flags) (new_flags & float_flag_overflow ? FPUS_OE : 0) | (new_flags & float_flag_underflow ? FPUS_UE : 0) | (new_flags & float_flag_inexact ? FPUS_PE : 0) | - (new_flags & float_flag_input_denormal_flushed ? FPUS_DE : 0))); + (new_flags & float_flag_input_denormal_used ? FPUS_DE : 0))); } static inline floatx80 helper_fdiv(CPUX86State *env, floatx80 a, floatx80 b) @@ -3251,6 +3251,7 @@ void update_mxcsr_status(CPUX86State *env) /* Set exception flags. */ set_float_exception_flags((mxcsr & FPUS_IE ? float_flag_invalid : 0) | + (mxcsr & FPUS_DE ? float_flag_input_denormal_used : 0) | (mxcsr & FPUS_ZE ? float_flag_divbyzero : 0) | (mxcsr & FPUS_OE ? float_flag_overflow : 0) | (mxcsr & FPUS_UE ? float_flag_underflow : 0) | @@ -3267,14 +3268,8 @@ void update_mxcsr_status(CPUX86State *env) void update_mxcsr_from_sse_status(CPUX86State *env) { int flags = get_float_exception_flags(&env->sse_status); - /* - * The MXCSR denormal flag has opposite semantics to - * float_flag_input_denormal_flushed (the softfloat code sets that flag - * only when flushing input denormals to zero, but SSE sets it - * only when not flushing them to zero), so is not converted - * here. - */ env->mxcsr |= ((flags & float_flag_invalid ? FPUS_IE : 0) | + (flags & float_flag_input_denormal_used ? FPUS_DE : 0) | (flags & float_flag_divbyzero ? FPUS_ZE : 0) | (flags & float_flag_overflow ? FPUS_OE : 0) | (flags & float_flag_underflow ? FPUS_UE : 0) | From patchwork Thu Feb 13 14:26:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 864829 Delivered-To: patch@linaro.org Received: by 2002:a5d:47a6:0:b0:38f:210b:807b with SMTP id 6csp452387wrb; Thu, 13 Feb 2025 06:27:11 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUC2BspDqY5bIjuM5orOeJQrAbtrTzwS5rqC0vAQIYtmWUDQ/3/ei3AvQ6GgOJAhuOt7zjKTA==@linaro.org X-Google-Smtp-Source: AGHT+IEfbJ2LU5pjBs6U92aVybAWMjVKxf84LdAyKAZMqvMs0UTEaiTHICsEDIrVLaqM8AXqVyNJ X-Received: by 2002:a05:622a:4d8d:b0:471:b8e8:eaed with SMTP id d75a77b69052e-471bed8d7f4mr64485471cf.31.1739456831087; Thu, 13 Feb 2025 06:27:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1739456831; cv=none; d=google.com; s=arc-20240605; b=Ey4OUKFHsNA4a+kXOEzPLOzxhdAfC5PkrDSBvOdo6dPX5Rvn9GHxoPZja1ahXjjEX2 N4w7TypDWv9CVNnA1dpmMQBm2It2L1W7nnAoNBS7+BpWgx04vMjyIHQ8g553hBqP2V0F cSgzzdT+veK0KyadoVlGTHtPdkXM/zFT6g4F9YFKjwFdSIXbEBvta51+02EKqWNA7qHi 87zHqzn/MoH3YYX8f6JDTfbTZxP8e5h/c9jCn5ffJeR9keG7MxhGsKlwbZ3O2TlB1OTj SmOkWwbVfEQiu7UobBaU4TMZtnS69k6wSu4/bHmgOBILHCI3EOf8bXgyX38FsULW45ni jLKA== 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:cc:to :from:dkim-signature; bh=KZQiHA1qvCBztocbqsFOi1IRya4/wKDmhY8pdA7/x98=; fh=PAYODwlZirpE9wBz0jOP90gCu/93ITqb817G+JU23Zw=; b=VIS3gxozuz0qhnRDwGi8IIF3+0lXBxFakdVEtb1MjTaNeYxe+D2qQ2yxP4nt9oJmN+ 4MeqvZrs8L/0Ixg9d2VW78WXfbsjN9VMGGMxI3Mfdg1rh0rNM4qY9T5U9K/8Qcw7kIFB cYy7M6PLpY9M0omD3moDgihkCN7KHeQybl2BUAL/GHu6K5KSr1I0ZdKU/lehdHt4Six3 poU+PlK7RVjpiq7bkYDZkMRq86C2+d53XDjUuNy9igpFlGk9eyD0dZaoCVwnEZXz1YsO bDfzSQWaAr4WdgFzgrqKp7wul+21awcIttL8t91bLpCRCoqpEPq0r4C5z6ZDJLEQj7bc m2lQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iHdQUdgX; 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-471c2b7ed09si13971601cf.658.2025.02.13.06.27.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Feb 2025 06:27:11 -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=iHdQUdgX; 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 1tiaAc-0004VK-Nw; Thu, 13 Feb 2025 09:26:26 -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 1tiaAb-0004Tx-9N for qemu-devel@nongnu.org; Thu, 13 Feb 2025 09:26:25 -0500 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tiaAZ-0006nt-Hs for qemu-devel@nongnu.org; Thu, 13 Feb 2025 09:26:25 -0500 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-4395f66a639so6292095e9.0 for ; Thu, 13 Feb 2025 06:26:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739456782; x=1740061582; 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=KZQiHA1qvCBztocbqsFOi1IRya4/wKDmhY8pdA7/x98=; b=iHdQUdgXxxLSPLU0CkMaOttxmD1GDx0FTFzPPHY60sweJLOvJDjVVHP5j3HD2q1QQm ob0oRa4l2V6IcRkyryK+NAB3S4WjOUN52lYkVvrRLb2ISnfEIKqysnDsM2zFUr/dzmfp spQpvxW7xEWa/uCgF5wH2G8kMmo6Uh5PShBk7rG9p4h0lOJyHWd3alZaa9Qhtg9Jt6g/ p/F6Pl/8VDN2mz6V0wWBeITSVxy0TWzogWdQb+v8Ntb536LllNdMxPDMP96vh9WN7R74 2sTrEpfC3f0RO77K5FOqZgvfkGCBuDHhYUUMzqOt1kZxeJZBzSmi3bwwpbr/BS0yek8J eV/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739456782; x=1740061582; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KZQiHA1qvCBztocbqsFOi1IRya4/wKDmhY8pdA7/x98=; b=JBFy47AV1+1kLnGb5EINDWAW2G3SD8F7e/Ftx+adC1s8IvNEedl1CUpXbk6vaDgSix eb62N0nIyClTZY1ItmQFo95tlcqcTxqGB4kRBJKYibc5jYt98kXlhKZOjXVk1mysVEHa zSGeoHSOkps6sFJ+ppm5pjVIdSEX8jHJtSnOEEksGjBs/wN4tCW/xpISuE2rKMzAo8d1 eECzaoNllihsQ41EPhMpyWf+e67QJqpfo6c3AYKIjMAQSVRnK7SPux8aIAgtVDIByH3A b+P6sJXqSQR0syY6uXt3zhpKBPvX2iRGDHf55gp8HKfE+xwKLkr4SesXJDrUQG1UJOWA iNBw== X-Gm-Message-State: AOJu0YyobC3etEZg0V5YtONvkT7YrcAuAi/ZZP4UIWUqoAWw/D3C1Jc0 rbAoPjwcixZfJ6I3xANvuwYYrd6NELDdfej8AK0H14tv+fBEluw4em+Np90Iel45aeCQIxkOfT8 Q X-Gm-Gg: ASbGnctPVd6GhXbfZOoqoJwoRcxxL/3IVm3mLl9TdXkdqWq0spfoumLdksINMLy3m0G hqseoLs1PHKsIupZeS8dewfSgAKFFo7O/PPZfmUl+i8vn75shkNF/4pQKVdHkVKgoBCQAi/EWBc oP4YfOUf5w0E+SNS6iY83ShtUzDGY9BHomJWb1pIpecZi0Kc1cYNgNqjL58FM0XTrL/smFTe0su 4UUkCE/Olhhw84zAkGzA3qmCS4gk7ya4w/uy5y1hJ3bDRszdkMDEHi+xipSouNrSs8scDPZzlU+ ISuT5yMbm/y2cYCCdlrmvA== X-Received: by 2002:a05:600c:450c:b0:434:f3d8:62d0 with SMTP id 5b1f17b1804b1-4395815f428mr76899535e9.3.1739456782015; Thu, 13 Feb 2025 06:26:22 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38f258b4335sm2093604f8f.15.2025.02.13.06.26.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2025 06:26:21 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Richard Henderson , Paolo Bonzini , Zhao Liu , Eduardo Habkost Subject: [PATCH 4/4] tests/tcg/x86_64/fma: add test for exact-denormal output Date: Thu, 13 Feb 2025 14:26:13 +0000 Message-ID: <20250213142613.151308-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250213142613.151308-1-peter.maydell@linaro.org> References: <20250213142613.151308-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x335.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 Add some fma test cases that check for correct handling of FTZ and for the flag that indicates that the input denormal was consumed. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- tests/tcg/x86_64/fma.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/tcg/x86_64/fma.c b/tests/tcg/x86_64/fma.c index 46f863005ed..34219614c0a 100644 --- a/tests/tcg/x86_64/fma.c +++ b/tests/tcg/x86_64/fma.c @@ -82,6 +82,18 @@ static testdata tests[] = { */ { 0x3fdfffffffffffff, 0x001fffffffffffff, 0x801fffffffffffff, true, 0x8010000000000000, 0x20 }, /* Enabling FTZ shouldn't change flags */ + /* + * normal * 0 + a denormal. With FTZ disabled this gives an exact + * result (equal to the input denormal) that has consumed the denormal. + */ + { 0x3cc8000000000000, 0x0000000000000000, 0x8008000000000000, false, + 0x8008000000000000, 0x2 }, /* Denormal */ + /* + * With FTZ enabled, this consumes the denormal, returns zero (because + * flushed) and indicates also Underflow and Precision. + */ + { 0x3cc8000000000000, 0x0000000000000000, 0x8008000000000000, true, + 0x8000000000000000, 0x32 }, /* Precision, Underflow, Denormal */ }; int main(void)