Received: from eggs.gnu.org ([2001:4830:134:3::10]:56975) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XoAaN-0003VX-2s for qemu-devel@nongnu.org; Tue, 11 Nov 2014 07:30:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XoAaF-0000pX-2l for qemu-devel@nongnu.org; Tue, 11 Nov 2014 07:30:14 -0500 Received: from forward2m.mail.yandex.net ([37.140.138.2]:58364) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XoAaE-0000a1-KS for qemu-devel@nongnu.org; Tue, 11 Nov 2014 07:30:07 -0500 From: Dmitry Poletaev In-Reply-To: References: <3936561405348528@web11m.yandex.ru> <5212091406116528@web27m.yandex.ru> <3654261406127876@web2h.yandex.ru> <53D7F0CB.9020101@twiddle.net> <3399611413283128@web17g.yandex.ru> MIME-Version: 1.0 Message-Id: <185941415708979@web10m.yandex.ru> Date: Tue, 11 Nov 2014 15:29:39 +0300 Content-Type: text/plain; charset=koi8-r Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] target-i386/FPU: wrong conversion infinity from float80 to int32/int64 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: QEMU Developers , Richard Henderson From: Dmitry Poletaev Signed-off-by: Dmitry Poletaev --- target-i386/fpu_helper.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/target-i386/fpu_helper.c b/target-i386/fpu_helper.c index ab19b71..fc25a03 100644 --- a/target-i386/fpu_helper.c +++ b/target-i386/fpu_helper.c @@ -251,16 +251,34 @@ int32_t helper_fist_ST0(CPUX86State *env) int32_t helper_fistl_ST0(CPUX86State *env) { int32_t val; - + signed char old_exp_flags; + =20 + old_exp_flags =3D get_float_exception_flags(&env->fp_status); + set_float_exception_flags(0, &env->fp_status); + =20 val =3D floatx80_to_int32(ST0, &env->fp_status); + if (get_float_exception_flags(&env->fp_status) & float_flag_invalid)= { + val =3D 0x80000000; + } + set_float_exception_flags(get_float_exception_flags(&env->fp_status) + | old_exp_flags, &env->fp_status); return val; } int64_t helper_fistll_ST0(CPUX86State *env) { int64_t val; - - val =3D floatx80_to_int64(ST0, &env->fp_status); + signed char old_exp_flags; + =20 + old_exp_flags =3D get_float_exception_flags(&env->fp_status); + set_float_exception_flags(0, &env->fp_status); + =20 + val =3D floatx80_to_int32(ST0, &env->fp_status); + if (get_float_exception_flags(&env->fp_status) & float_flag_invalid)= { + val =3D 0x8000000000000000ULL; + } + set_float_exception_flags(get_float_exception_flags(&env->fp_status) + | old_exp_flags, &env->fp_status); return val; } --=20 1.8.4.msysgit.0 14.10.2014, 15:56, "Peter Maydell" : > On 14 October 2014 12:38, Dmitry Poletaev wro= te: >> =9A29.07.2014, 23:07, "Richard Henderson" : >>> =9AOn 07/23/2014 05:04 AM, Dmitry Poletaev wrote: >>>> =9A=9A+ =9A=9A=9Aif (env->fp_status.float_exception_flags & FPUS_IE)= { >>> =9AMixing bit masks. =9As/FPUS_IE/float_status_invalid/ > > [Please don't top-post.] >> =9AWhat do you mean? > > Richard means that the set of defined flags for > float_exception_flags does not include "FPUS_IE" > (which is defining a symbolic constant for a bit > in an x86 register). You want to use "float_flag_invalid". > (The two happen to have the same value, 1, which is why > your code worked by accident.) > > thanks > -- PMM