From patchwork Fri Jun 6 12:34:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 894452 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:ecd:b0:3a4:ee3f:8f15 with SMTP id ea13csp483637wrb; Fri, 6 Jun 2025 05:42:52 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWbg2e5In8oMtYJO++JsB2REBm++0HIIXLRbFokD/Z2KJlWoo/VwXkyznpyQiN8GyFQ/yA6bA==@linaro.org X-Google-Smtp-Source: AGHT+IExEYY+U4DLsi5DlJvXT+NwtM3UMmvXmLc1CbNQEak2Sk8tRUqxZqiybgffl9rQWVwtI+wf X-Received: by 2002:a05:6214:d6b:b0:6fa:c168:8de4 with SMTP id 6a1803df08f44-6fb08f8d36emr54741766d6.33.1749213772235; Fri, 06 Jun 2025 05:42:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1749213772; cv=none; d=google.com; s=arc-20240605; b=X7A1gLyxI3fUT8rqjRHkyiodRHucz7VSZtF8c4fafeMBVebIF5Aw1cfrGMOB7gyKxt he5bTXi/GKKhz8vHqM8tNicTH91cVb2kQ8tcgMimqc5u6i6f8dXttgC+2IhVpwS4m+JK UboppdMPsdi1oefbzrdVBwP2kAgBc3WlHKq6Op1k8/e7L3kSM3b2w7lUKuZbqiOl+jOg lSa02Uy6c1e8A92DE4+IuxWoQ4ZXxtP5WZWgDqv3nstiKHZJXMFfb2MFBTk7WnFlM3bQ 3wSFDH7xCyc2zqnkXg3Faksb0b3wKgyVdKD3uRH69wmpV4eXqNXPzOopes0aSKcQJ1qN /U0g== 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=lyIpbhdOi8uKuobeqFQ0SyC2g54IbnY9g+PvajejF10=; fh=LCBicqeu5OWASEl1rLR9HJKJ77k8ScftFktlzJMVrFY=; b=MzWoRuqukHpkyiW45guWhAmColTSVnPtR5xsZ5X/vd5PDRRj0H0Y7srzbvMxQw+O93 NqtjdLXple72DIL9pSopaLCPNNK0pqIo2IHp9C3RV4u/H8yGjuwJ0gIWXeQwlraIUqYN zoisCGdJUa0imjjV60EOaF/zfBVbaWY9FJURSReZE6xbcmnHzkre8Np7mdBDEWYGMb4X phR5nguY0hAWo7at+ZqL4l2OnFyr3OHnekk8059Zwygsp5EUHNF/NVyH4FejVTGtFM7s OXoRxa6By0MwHu2cS4Ku2OErUiVx7CTmA3u2NKhqr88aaz0gol6i8kKvX/LyYfHx9f49 J98w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=N2HElMrV; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 6a1803df08f44-6fb09ab056fsi16915266d6.88.2025.06.06.05.42.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 06 Jun 2025 05:42:52 -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=@redhat.com header.s=mimecast20190719 header.b=N2HElMrV; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=redhat.com Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uNWLH-0005M8-R4; Fri, 06 Jun 2025 08:38:41 -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 1uNWJF-0003jx-Ax for qemu-devel@nongnu.org; Fri, 06 Jun 2025 08:36:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uNWJC-00060h-Ev for qemu-devel@nongnu.org; Fri, 06 Jun 2025 08:36:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749213388; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lyIpbhdOi8uKuobeqFQ0SyC2g54IbnY9g+PvajejF10=; b=N2HElMrVS5ieGU1kCd3Pc4CRAAHPcWzqvXk4IWVFc+KsL5FxyfJ5cdJ92rsoW+1nfK/5LE fUBde688UODXvDVD5jySnkfG8TbYs+CkqIMHOQAJ/fK513tGe9KzcDstF2kRayP8llE4/c QVHtj/DaT5IEdDSiTW4yC4CT5fWH/uQ= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-695-nLeCYytqNBi-mSEcZKGdGA-1; Fri, 06 Jun 2025 08:36:27 -0400 X-MC-Unique: nLeCYytqNBi-mSEcZKGdGA-1 X-Mimecast-MFC-AGG-ID: nLeCYytqNBi-mSEcZKGdGA_1749213386 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-3a3696a0d3aso857882f8f.2 for ; Fri, 06 Jun 2025 05:36:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749213386; x=1749818186; 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=lyIpbhdOi8uKuobeqFQ0SyC2g54IbnY9g+PvajejF10=; b=IRZSHb1Il/dNhAu97qYJ5A5/h1iI4sCqE77KCObQvQVDA8nmfZSUY+EMryu/UMIep1 XfnAc1OtZ/A68UR2dgY7JsYfX/fAaemuWJ/Q5JmevRBPJNv4ncaQfjS6C6Jt5jpWKOT0 O3KyXbdzIA/FXMsorcoLOnwjj8Wl6shvLEwJB7lQDtRIqBfcAlMBHSrekr81xSES0fZr aEAQVZGwiXN454/q53oFP5SUsYSSSKxResXLJxurvpgsrho4VZzVesZaOXqIzOQ9eJuh MFC8kiSY8NTZOwXH65+ICM1WHbssdGinXgOor33V6LqkvZGs1F32HT7NAnB2BJaPXTkk t4pQ== X-Gm-Message-State: AOJu0Yyd1jPhoUr+e3lb51IkEJ/axFTI+2gHSxrYIJo47/Rjh1yrrj57 XoK8mwEjejjjbUDb/3jyIbyr1D735IBRSNtwkNeoUxLIH96sdXc9/Mm3kmipcs4ZYzfIUeHX6i8 5DCUdxA3caSmJ1Ishcn9S7dG3FA4D4Q0AQo9692Fy6diYMOJ6oudFcXuMRCD22kb46Pe+SucyvO LzvmhP2J+bQu8XOf4BuPmCOA5fsdK1f38x/miw3L5t X-Gm-Gg: ASbGncsoVSVKMJiVvj7Lc1X6GfgBJHFPjhilcu2xXsvIH7jfVutseUKkgUphmI3Oeb8 N6szmlyAA5wZ1JMcU1EoDJXRDuO1d1Q2YOsNaiNO2EEEjdXCxKz+vhZcWBXgyTiZwC0lLkyN+5L gfI0jth3dW4bsLqpn6JfkJqjbOxl8v4VIStDD70rHzRe+6oyFwP98oCTQ3nx7b0D/ZO3KJpvZc3 8JkDxGeYxV4ukjw1i9iOQCZCrvtYj0hm0/nkyIWpVSxplWADj2t0OOy8aRLFz1LGIbMl47+AE4G oOLoid1PLTzqgQ== X-Received: by 2002:a05:6000:24c7:b0:3a4:eb80:762d with SMTP id ffacd0b85a97d-3a531ced4d6mr2688897f8f.56.1749213385680; Fri, 06 Jun 2025 05:36:25 -0700 (PDT) X-Received: by 2002:a05:6000:24c7:b0:3a4:eb80:762d with SMTP id ffacd0b85a97d-3a531ced4d6mr2688876f8f.56.1749213385201; Fri, 06 Jun 2025 05:36:25 -0700 (PDT) Received: from [192.168.10.48] ([151.49.64.79]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4526e05636dsm20342895e9.4.2025.06.06.05.36.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jun 2025 05:36:22 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Peter Maydell , Richard Henderson , Zhao Liu Subject: [PULL 28/31] target/i386: Detect flush-to-zero after rounding Date: Fri, 6 Jun 2025 14:34:42 +0200 Message-ID: <20250606123447.538131-29-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250606123447.538131-1-pbonzini@redhat.com> References: <20250606123447.538131-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.104, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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 From: Peter Maydell 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 Reviewed-by: Zhao Liu Link: https://lore.kernel.org/r/20250519145114.2786534-2-peter.maydell@linaro.org Signed-off-by: Paolo Bonzini --- 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 1cbadb14533..9ea67ea76c8 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)