From nobody Wed Feb 11 01:44:46 2026 Delivered-To: importer2@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+importer2=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 1673860789134612.3999031991744; Mon, 16 Jan 2023 01:19:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHLeG-0000pQ-GH; Mon, 16 Jan 2023 04:19:24 -0500 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 1pHLeE-0000nG-5D for qemu-devel@nongnu.org; Mon, 16 Jan 2023 04:19:22 -0500 Received: from mout.kundenserver.de ([212.227.17.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pHLeB-0003CU-2L for qemu-devel@nongnu.org; Mon, 16 Jan 2023 04:19:21 -0500 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MLyvH-1ozXoQ3aiX-00Hw87; Mon, 16 Jan 2023 10:19:16 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: Laurent Vivier , Mark Cave-Ayland , Richard Henderson Subject: [PULL 4/4] target/m68k: fix FPSR quotient byte for frem instruction Date: Mon, 16 Jan 2023 10:19:12 +0100 Message-Id: <20230116091912.1882152-5-laurent@vivier.eu> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230116091912.1882152-1-laurent@vivier.eu> References: <20230116091912.1882152-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:jV9j+LW0sPg5/X1vogxojXtutHc00qoQwgctwjpMfMIcl2CoXLZ pqhgegn8ydc2p2OphKN1f05w8HJl3X/3CSIxKtfgFeavgzq5+U0pvin2yG8WFZaIzuePCNJ gQ8/SztqLtDgl+sraxUrznFs3DuNt00KL8ogxnlGnhQH51++6Uz+Wn3Jtz1+cweqRtJWkw3 OCU77ybN4uLKd16Z0utSA== UI-OutboundReport: notjunk:1;M01:P0:tGqbjgI6OV8=;vcU2pTwem0YPMHa05ua65qag1MT yYY8Yy5QxwWWrQlUc2cCdpNfXp/RngkOwYqJPh/Z7Xnh4BVptu0U0TElmXsxz8y9d3SZvtjOy qFqFh3Rb7G8ePuXdwWR1TGsztLVB49dAjrOw1pcE+aej7kDEwhC3DRO1kBU3aR3kpHLObER2c 5JA/mEUHJq+eVkrtrS45TSZikSX7geL6R7WmemWSORhdqoyBTLQZQfvMDMpABMXWQu09QQ6DL MMjk4EZXeN+4GToBX6blYzJRlxSA0kU2sSFTYv41l6PS0zwGOMjrCnJeuQvQrx1+IFfRdzR/Z zn7AOj4Lk/6tNqxEbfha508d7mU1/2/FkNRLgWDuoElBcfBWO2JKWieZRcGeLyPKJdlFinYwv JR3ezar83UA8vadSk5DDa7AKjOhm1MwW7gHEx9Gi2dQEqxMCb9OfIffzXslvs6MVx2oud4vXC IpxidkrPoHePKur2Y/AdIEODs2fVD5SxhNtmM96uF0J/xit+/P1MYo5E1rQ8K2qrmYp1WXpO/ guyTnGu81WEaB2l6P1Z29wSJ4vQvzjnaiykA/Ow0V99HzPOoAjrUkSMe+jXCZnqYD39qkeYHM Y85dlojxfIDPcXP4L7Lm/d83UOs7qqr1DBWEF/ky3iMrMMhyCkkXz65vN5iHapGoT6kJOgIOe 03CtAmaRZce2IEnBoPSWwZlu4+Ou7ISVq4y9TntCMQ== 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=212.227.17.24; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZM-MESSAGEID: 1673860790921100003 Content-Type: text/plain; charset="utf-8" From: Mark Cave-Ayland The FPSR quotient byte should be set to the value of the quotient and not t= he result. Manually calculate the quotient in the frem helper in round to near= est even mode (note this is different from the quotient calculated internally f= or fmod), and use it to set the quotient byte accordingly. Signed-off-by: Mark Cave-Ayland Fixes: https://gitlab.com/qemu-project/qemu/-/issues/1314 Reviewed-by: Richard Henderson Message-Id: <20230114232959.118224-5-mark.cave-ayland@ilande.co.uk> Signed-off-by: Laurent Vivier --- target/m68k/fpu_helper.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/target/m68k/fpu_helper.c b/target/m68k/fpu_helper.c index 5fd094a33cff..3a37d8f584d6 100644 --- a/target/m68k/fpu_helper.c +++ b/target/m68k/fpu_helper.c @@ -538,18 +538,27 @@ void HELPER(fmod)(CPUM68KState *env, FPReg *res, FPRe= g *val0, FPReg *val1) =20 void HELPER(frem)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1) { - uint32_t quotient; - int sign; - - res->d =3D floatx80_rem(val1->d, val0->d, &env->fp_status); - - if (floatx80_is_any_nan(res->d)) { - return; + FPReg fp_quot; + floatx80 fp_rem; + + fp_rem =3D floatx80_rem(val1->d, val0->d, &env->fp_status); + if (!floatx80_is_any_nan(fp_rem)) { + float_status fp_status =3D { }; + uint32_t quotient; + int sign; + + /* Calculate quotient directly using round to nearest mode */ + set_float_rounding_mode(float_round_nearest_even, &fp_status); + set_floatx80_rounding_precision( + get_floatx80_rounding_precision(&env->fp_status), &fp_status); + fp_quot.d =3D floatx80_div(val1->d, val0->d, &fp_status); + + sign =3D extractFloatx80Sign(fp_quot.d); + quotient =3D floatx80_to_int32(floatx80_abs(fp_quot.d), &env->fp_s= tatus); + make_quotient(env, sign, quotient); } =20 - sign =3D extractFloatx80Sign(res->d); - quotient =3D floatx80_to_int32(floatx80_abs(res->d), &env->fp_status); - make_quotient(env, sign, quotient); + res->d =3D fp_rem; } =20 void HELPER(fgetexp)(CPUM68KState *env, FPReg *res, FPReg *val) --=20 2.38.1