From nobody Mon Feb 9 18:18:42 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=1588812264; cv=none; d=zohomail.com; s=zohoarc; b=eVb7BqXJRchLJIPqcYuINC02ziODq2ODVYmYCk3/SIK4He1pG0F77c0vumiNfB9rEhliatHT/JnPrVoi3MkXXyJ/F82bmKCLl4Fx81GmGjZA7Im5BN4dlKZk0hPYDk+9wZQ1VsGgEeusKw3rOVP6vFZMVMRKT3z9L6BMWrSzV4I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588812264; 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=fEjJ8qP+GBSuzB0foP6Vms2V8c7NeiK1pKF65YjlnaI=; b=QZm3/kPXcTEji3wYL2MtLLg60gKfdVVtH6Zo8btCRAbaxVJ2qa00BJ80vQphp+gajVryxFLQ/pUc0aRW2oFYm3UpQVb3M4w2NLaaJ1FMkx1XNT+2I0Zvokc2t6AEM8V0pX2ye2xI2gixIsaw3L6sWSeGSKo150ga3Px6HguHE/A= 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 1588812264271513.9136148328635; Wed, 6 May 2020 17:44:24 -0700 (PDT) Received: from localhost ([::1]:37060 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jWUeF-0000Oo-1d for importer@patchew.org; Wed, 06 May 2020 20:44:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36542) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWUdW-0008IH-AE for qemu-devel@nongnu.org; Wed, 06 May 2020 20:43:38 -0400 Received: from esa2.mentor.iphmx.com ([68.232.141.98]:64318) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWUdV-0005Hr-77 for qemu-devel@nongnu.org; Wed, 06 May 2020 20:43:38 -0400 Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 06 May 2020 16:43:35 -0800 IronPort-SDR: IVAgpWDatbo3gUJbYGUafrA5CnHOq9OBqvzByIZa6LAAsBeThi8M9d3/+NmS7Pa1Nn7a1gXyxu nyLpZDJXS789Y1TUry0hs72yr1VlY4j9mOWjHJXl+XEXRHvbzScZ3G+Acvkm/7bp+Qg8KIe1EA bOOSSrs3TG2/gtFCfhIQKl8/5MAC+9DzO0VYosU723wUTevEI9Tyz1hI9Xip57bHs/TMKWHF4G /y7vyQZpbZhBOtmI1m5TyTzxFS9yrzoHaHJQfRdREOpYn1yxyaT/K1PGbdd4FRExcNUmil0AK5 xX8= X-IronPort-AV: E=Sophos;i="5.73,361,1583222400"; d="scan'208";a="48541250" IronPort-SDR: ZpAXnzSfiifbSkHIYJm8z22yEw3tkzeVG1XVQyltkkxkDzwcdHRVAIbCzvOo2wyiduUOkHOKJ1 0M6PDYafp8t5IYqfp8QqjXvYAi28e3X3LaG2xG8w1yyRbcB+68bfLgW18zqcn5gFVKdiXHn3fU zM02hShcH0iJmhNuVpAbms9OOaG/lmijxHYd4Fkuz9n14fgOolsD9v3P++qrKZKLnIvs0jT6RB vIfTmXXDonT8kttTR0iXnPRPGL5Hz7CVi4EqIugpLL8Jd7eS6StbC8Y+s94Sev/HqDcls4QE5N RAo= Date: Thu, 7 May 2020 00:43:30 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: , , , Subject: [PATCH 1/5] target/i386: implement special cases for fxtract 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-07.mgc.mentorg.com (139.181.222.7) 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.141.98; envelope-from=joseph_myers@mentor.com; helo=esa2.mentor.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/06 20:42:37 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, 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 fxtract instruction treats all nonzero operands as normal numbers, so yielding incorrect results for invalid formats, infinities, NaNs and subnormal and pseudo-denormal operands. Implement appropriate handling of all those cases. Signed-off-by: Joseph Myers Acked-by: Alex Benn=C3=A9e --- target/i386/fpu_helper.c | 25 +++++- tests/tcg/i386/test-i386-fxtract.c | 120 +++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/i386/test-i386-fxtract.c diff --git a/target/i386/fpu_helper.c b/target/i386/fpu_helper.c index 792a128a6d..71a696a863 100644 --- a/target/i386/fpu_helper.c +++ b/target/i386/fpu_helper.c @@ -767,10 +767,33 @@ void helper_fxtract(CPUX86State *env) &env->fp_status); fpush(env); ST0 =3D temp.d; + } else if (floatx80_invalid_encoding(ST0)) { + float_raise(float_flag_invalid, &env->fp_status); + ST0 =3D floatx80_default_nan(&env->fp_status); + fpush(env); + ST0 =3D ST1; + } else if (floatx80_is_any_nan(ST0)) { + 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); + } + fpush(env); + ST0 =3D ST1; + } else if (floatx80_is_infinity(ST0)) { + fpush(env); + ST0 =3D ST1; + ST1 =3D floatx80_infinity; } else { int expdif; =20 - expdif =3D EXPD(temp) - EXPBIAS; + if (EXPD(temp) =3D=3D 0) { + int shift =3D clz64(temp.l.lower); + temp.l.lower <<=3D shift; + expdif =3D 1 - EXPBIAS - shift; + float_raise(float_flag_input_denormal, &env->fp_status); + } else { + expdif =3D EXPD(temp) - EXPBIAS; + } /* DP exponent bias */ ST0 =3D int32_to_floatx80(expdif, &env->fp_status); fpush(env); diff --git a/tests/tcg/i386/test-i386-fxtract.c b/tests/tcg/i386/test-i386-= fxtract.c new file mode 100644 index 0000000000..64fd93d333 --- /dev/null +++ b/tests/tcg/i386/test-i386-fxtract.c @@ -0,0 +1,120 @@ +/* Test fxtract instruction. */ + +#include +#include + +union u { + struct { uint64_t sig; uint16_t sign_exp; } s; + long double ld; +}; + +volatile union u ld_pseudo_m16382 =3D { .s =3D { UINT64_C(1) << 63, 0 } }; +volatile union u ld_invalid_1 =3D { .s =3D { 1, 1234 } }; +volatile union u ld_invalid_2 =3D { .s =3D { 0, 1234 } }; +volatile union u ld_invalid_3 =3D { .s =3D { 0, 0x7fff } }; +volatile union u ld_invalid_4 =3D { .s =3D { (UINT64_C(1) << 63) - 1, 0x7f= ff } }; + +volatile long double ld_sig, ld_exp; + +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 ("fxtract" : "=3Dt" (ld_sig), "=3Du" (ld_exp) : "0" (= 2.5L)); + if (ld_sig !=3D 1.25L || ld_exp !=3D 1.0L) { + printf("FAIL: fxtract 2.5\n"); + ret =3D 1; + } + __asm__ volatile ("fxtract" : "=3Dt" (ld_sig), "=3Du" (ld_exp) : "0" (= 0.0L)); + if (ld_sig !=3D 0.0L || __builtin_copysignl(1.0L, ld_sig) !=3D 1.0L || + ld_exp !=3D -__builtin_infl()) { + printf("FAIL: fxtract 0.0\n"); + ret =3D 1; + } + __asm__ volatile ("fxtract" : "=3Dt" (ld_sig), "=3Du" (ld_exp) : "0" (= -0.0L)); + if (ld_sig !=3D -0.0L || __builtin_copysignl(1.0L, ld_sig) !=3D -1.0L = || + ld_exp !=3D -__builtin_infl()) { + printf("FAIL: fxtract -0.0\n"); + ret =3D 1; + } + __asm__ volatile ("fxtract" : "=3Dt" (ld_sig), "=3Du" (ld_exp) : + "0" (__builtin_infl())); + if (ld_sig !=3D __builtin_infl() || ld_exp !=3D __builtin_infl()) { + printf("FAIL: fxtract inf\n"); + ret =3D 1; + } + __asm__ volatile ("fxtract" : "=3Dt" (ld_sig), "=3Du" (ld_exp) : + "0" (-__builtin_infl())); + if (ld_sig !=3D -__builtin_infl() || ld_exp !=3D __builtin_infl()) { + printf("FAIL: fxtract -inf\n"); + ret =3D 1; + } + __asm__ volatile ("fxtract" : "=3Dt" (ld_sig), "=3Du" (ld_exp) : + "0" (__builtin_nanl(""))); + if (!isnan_ld(ld_sig) || issignaling_ld(ld_sig) || + !isnan_ld(ld_exp) || issignaling_ld(ld_exp)) { + printf("FAIL: fxtract qnan\n"); + ret =3D 1; + } + __asm__ volatile ("fxtract" : "=3Dt" (ld_sig), "=3Du" (ld_exp) : + "0" (__builtin_nansl(""))); + if (!isnan_ld(ld_sig) || issignaling_ld(ld_sig) || + !isnan_ld(ld_exp) || issignaling_ld(ld_exp)) { + printf("FAIL: fxtract snan\n"); + ret =3D 1; + } + __asm__ volatile ("fxtract" : "=3Dt" (ld_sig), "=3Du" (ld_exp) : + "0" (0x1p-16445L)); + if (ld_sig !=3D 1.0L || ld_exp !=3D -16445.0L) { + printf("FAIL: fxtract subnormal\n"); + ret =3D 1; + } + __asm__ volatile ("fxtract" : "=3Dt" (ld_sig), "=3Du" (ld_exp) : + "0" (ld_pseudo_m16382.ld)); + if (ld_sig !=3D 1.0L || ld_exp !=3D -16382.0L) { + printf("FAIL: fxtract pseudo\n"); + ret =3D 1; + } + __asm__ volatile ("fxtract" : "=3Dt" (ld_sig), "=3Du" (ld_exp) : + "0" (ld_invalid_1.ld)); + if (!isnan_ld(ld_sig) || issignaling_ld(ld_sig) || + !isnan_ld(ld_exp) || issignaling_ld(ld_exp)) { + printf("FAIL: fxtract invalid 1\n"); + ret =3D 1; + } + __asm__ volatile ("fxtract" : "=3Dt" (ld_sig), "=3Du" (ld_exp) : + "0" (ld_invalid_2.ld)); + if (!isnan_ld(ld_sig) || issignaling_ld(ld_sig) || + !isnan_ld(ld_exp) || issignaling_ld(ld_exp)) { + printf("FAIL: fxtract invalid 2\n"); + ret =3D 1; + } + __asm__ volatile ("fxtract" : "=3Dt" (ld_sig), "=3Du" (ld_exp) : + "0" (ld_invalid_3.ld)); + if (!isnan_ld(ld_sig) || issignaling_ld(ld_sig) || + !isnan_ld(ld_exp) || issignaling_ld(ld_exp)) { + printf("FAIL: fxtract invalid 3\n"); + ret =3D 1; + } + __asm__ volatile ("fxtract" : "=3Dt" (ld_sig), "=3Du" (ld_exp) : + "0" (ld_invalid_4.ld)); + if (!isnan_ld(ld_sig) || issignaling_ld(ld_sig) || + !isnan_ld(ld_exp) || issignaling_ld(ld_exp)) { + printf("FAIL: fxtract invalid 4\n"); + ret =3D 1; + } + return ret; +} --=20 2.17.1 --=20 Joseph S. Myers joseph@codesourcery.com