Received: from eggs.gnu.org ([2001:4830:134:3::10]:36730) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c44hq-0006vM-TI for qemu-devel@nongnu.org; Tue, 08 Nov 2016 06:36:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c44hl-00059z-VJ for qemu-devel@nongnu.org; Tue, 08 Nov 2016 06:36:46 -0500 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:33572) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c44hl-00058b-OD for qemu-devel@nongnu.org; Tue, 08 Nov 2016 06:36:41 -0500 Received: by mail-wm0-x241.google.com with SMTP id u144so21970767wmu.0 for ; Tue, 08 Nov 2016 03:36:41 -0800 (PST) Sender: Richard Henderson References: <20161107144445.14069-1-kbastian@mail.uni-paderborn.de> <20161107144445.14069-2-kbastian@mail.uni-paderborn.de> From: Richard Henderson Message-ID: <036ccf78-710b-074a-1e6b-e3948061ee5f@twiddle.net> Date: Tue, 8 Nov 2016 12:36:37 +0100 MIME-Version: 1.0 In-Reply-To: <20161107144445.14069-2-kbastian@mail.uni-paderborn.de> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 1/5] target-tricore: Added FTOUZ instruction List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Bastian Koppelmann , qemu-devel@nongnu.org On 11/07/2016 03:44 PM, Bastian Koppelmann wrote: > Converts a 32-bit floating point number to an unsigned int. The > result is rounded towards zero. > > Signed-off-by: Bastian Koppelmann > --- > v1 -> v2: > - ftouz: Correctly convert the result from uint32 to f32 > > target-tricore/fpu_helper.c | 43 +++++++++++++++++++++++++++++++++++++++++++ > target-tricore/helper.h | 1 + > target-tricore/translate.c | 3 +++ > 3 files changed, 47 insertions(+) > > diff --git a/target-tricore/fpu_helper.c b/target-tricore/fpu_helper.c > index 98fe947..f717b53 100644 > --- a/target-tricore/fpu_helper.c > +++ b/target-tricore/fpu_helper.c > @@ -215,3 +215,46 @@ uint32_t helper_itof(CPUTriCoreState *env, uint32_t arg) > } > return (uint32_t)f_result; > } > + > +uint32_t helper_ftouz(CPUTriCoreState *env, uint32_t arg) > +{ > + float32 f_arg = make_float32(arg); > + uint32_t result; > + int32_t flags; > + result = float32_to_uint32_round_to_zero(f_arg, &env->fp_status); > + > + flags = f_get_excp_flags(env); > + if (flags) { > + if (float32_is_any_nan(f_arg)) { > + flags |= float_flag_invalid; > + result = 0; > + /* f_real(D[a]) < 0.0 */ > + } else if (float32_lt_quiet(f_arg, 0.0, &env->fp_status)) { > + flags |= float_flag_invalid; > + result = 0; > + /* f_real(D[a]) > 2^32 -1 */ > + } else if (float32_lt_quiet(0x4f800000, f_arg, &env->fp_status)) { > + flags |= float_flag_invalid; > + result = 0xffffffff; > + } else { > + flags &= ~float_flag_invalid; > + } I don't understand this bit. Surely float_flag_invalid is already set by softfloat. And the bounding is done as well. What's up? > + /* once invalid flag has been set, we cannot set inexact anymore > + since each FPU operation can only assert ONE flag. (see > + TriCore ISA Manual Vol. 1 (11-9)) */ > + if (!(flags & float_flag_invalid)) { > + if (!float32_eq(f_arg, uint32_to_float32(result, &env->fp_status), > + &env->fp_status)) { > + flags |= float_flag_inexact; > + } else { > + flags &= ~float_flag_inexact; > + } > + } else { > + flags &= ~float_flag_inexact; > + } And inexact is already set as well. The best I can think is meant is /* Only one flag can be asserted. */ if (flags & float_flag_invalid) { flags &= ~float_flag_inexact; } > + f_update_psw_flags(env, flags); > + } else { > + env->FPU_FS = 0; > + } > + return result; > +} r~