From nobody Mon Feb 9 20:11:19 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1588812336; cv=none; d=zohomail.com; s=zohoarc; b=Lko4mX5Tjv1ArUVxGJYaRa1jfalRi+/C/ve0JO1TSUUtUnCHUyMLwCvetV8o2oJmHxaIsBqLxCYbqqIL+LTObhZpZstXyoqUuacvu8VlKt6LXfD0fPsXg6JYz/bQCz+7jTiGzBLZJizqhuPce6lfhHG6sb+ncOVAgMmQh54sw1E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588812336; h=Content-Type:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dXkgqJ1oztwyw4VRh2UWpQaTCpfyIk0OE6zfRDQrHDc=; b=iSvffhXT/S4mJtmfgjI98dUb0ABH6Imn6TOsqjcHKchJ3BirTcMv6AGOW8+zg5JqCYBU8HK7Bo1KxeUrCT0fJguTK+YMP7gsNxNla+yXlAUVFagrSgS+nXq5Q3htdHMHOSyB1d0gm70N4VNXtE7uJt2KdopL1hbv98dg9Iuzz3o= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1588812336284731.5487400264229; Wed, 6 May 2020 17:45:36 -0700 (PDT) Received: from localhost ([::1]:39364 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jWUfP-0001Rk-1c for importer@patchew.org; Wed, 06 May 2020 20:45:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36700) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWUeG-0000eM-1c for qemu-devel@nongnu.org; Wed, 06 May 2020 20:44:24 -0400 Received: from esa4.mentor.iphmx.com ([68.232.137.252]:44374) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWUeE-00065U-VJ for qemu-devel@nongnu.org; Wed, 06 May 2020 20:44:23 -0400 Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 06 May 2020 16:44:20 -0800 IronPort-SDR: +mKhWHNq9RFbJyYDicD0xNHK8O+DTOrGMdcG8mXh5ys7cARXSkp3sWr3tCkcw9epRevLZQ8pnj 2hHBmFH7wB6Xeh36eJHZGic+3IbeseC553k3VkX/WTRnNoSZyiOzDC4gh0bLLcPoapoJCTAWH2 mzfmvUR5e1TBE3E1rxyQVMfrPv2nSGyUMLvHfdxpLgyLG2Uv0Q7Rg32MTxkMnNSGyJ6wiTqUko srABvelF+ii6KvxcChNYetW8renudZbCBi3wG6tGOLyWjYe9eyYTNYwALXJC5OxNQXMYJ4NM4V m/s= X-IronPort-AV: E=Sophos;i="5.73,361,1583222400"; d="scan'208";a="48663331" IronPort-SDR: lknkSjlD/BveaarnrUP4Uc3ICE5+0fdhlZNN4ox0vishQtQb0A7HSxOuOhuFhKz8XZ/SkC1C0f qyOezBlSN+uwfCYuYFw+/Gp/98P6B6+Ia2ExNlbEEHVEf6l/Cv1G+zZbfAkdUUzcSb2bnljp2B jtnUjvy8F9L+qbWy4tVHSRnt8uaO0T6j2eNnRiMzrFLT8bFaaH0MWsYKO7RwFw+6/SGFrllgNt Aj64hyaFos1nSyV4R3Klr0h8jSe0DIexWNKeEoWZpLr70G0qorC975yFgw8eqbuqnoHsut8sWg 6bY= Date: Thu, 7 May 2020 00:44:14 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: , , , Subject: [PATCH 2/5] target/i386: fix fscale handling of signaling NaN In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-06.mgc.mentorg.com (139.181.222.6) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=68.232.137.252; envelope-from=joseph_myers@mentor.com; helo=esa4.mentor.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/06 20:44:20 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The implementation of the fscale instruction returns a NaN exponent unchanged. Fix it to return a quiet NaN when the provided exponent is a signaling NaN. Signed-off-by: Joseph Myers --- target/i386/fpu_helper.c | 4 ++++ tests/tcg/i386/test-i386-fscale.c | 37 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 tests/tcg/i386/test-i386-fscale.c diff --git a/target/i386/fpu_helper.c b/target/i386/fpu_helper.c index 71a696a863..60012c405c 100644 --- a/target/i386/fpu_helper.c +++ b/target/i386/fpu_helper.c @@ -970,6 +970,10 @@ void helper_fscale(CPUX86State *env) { if (floatx80_is_any_nan(ST1)) { ST0 =3D ST1; + if (floatx80_is_signaling_nan(ST0, &env->fp_status)) { + float_raise(float_flag_invalid, &env->fp_status); + ST0 =3D floatx80_silence_nan(ST0, &env->fp_status); + } } else { int n =3D floatx80_to_int32_round_to_zero(ST1, &env->fp_status); ST0 =3D floatx80_scalbn(ST0, n, &env->fp_status); diff --git a/tests/tcg/i386/test-i386-fscale.c b/tests/tcg/i386/test-i386-f= scale.c new file mode 100644 index 0000000000..aecac5125f --- /dev/null +++ b/tests/tcg/i386/test-i386-fscale.c @@ -0,0 +1,37 @@ +/* Test fscale instruction. */ + +#include +#include + +union u { + struct { uint64_t sig; uint16_t sign_exp; } s; + long double ld; +}; + +volatile long double ld_res; + +int isnan_ld(long double x) +{ + union u tmp =3D { .ld =3D x }; + return ((tmp.s.sign_exp & 0x7fff) =3D=3D 0x7fff && + (tmp.s.sig >> 63) !=3D 0 && + (tmp.s.sig << 1) !=3D 0); +} + +int issignaling_ld(long double x) +{ + union u tmp =3D { .ld =3D x }; + return isnan_ld(x) && (tmp.s.sig & UINT64_C(0x4000000000000000)) =3D= =3D 0; +} + +int main(void) +{ + int ret =3D 0; + __asm__ volatile ("fscale" : "=3Dt" (ld_res) : + "0" (2.5L), "u" (__builtin_nansl(""))); + if (!isnan_ld(ld_res) || issignaling_ld(ld_res)) { + printf("FAIL: fscale snan\n"); + ret =3D 1; + } + return ret; +} --=20 2.17.1 --=20 Joseph S. Myers joseph@codesourcery.com