From patchwork Mon Jul 3 16:23:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 783543 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3x1XXW5DFkz9s4q for ; Tue, 4 Jul 2017 02:24:33 +1000 (AEST) Received: from localhost ([::1]:36225 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dS49H-0002jH-B5 for incoming@patchwork.ozlabs.org; Mon, 03 Jul 2017 12:24:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48887) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dS48m-0002ij-4R for qemu-devel@nongnu.org; Mon, 03 Jul 2017 12:24:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dS48i-0000wQ-QW for qemu-devel@nongnu.org; Mon, 03 Jul 2017 12:24:00 -0400 Received: from mout.kundenserver.de ([212.227.17.13]:58663) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dS48i-0000vJ-Fc for qemu-devel@nongnu.org; Mon, 03 Jul 2017 12:23:56 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue104 [212.227.15.183]) with ESMTPSA (Nemesis) id 0McEqN-1dBDRC48sp-00JZOU; Mon, 03 Jul 2017 18:23:34 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Mon, 3 Jul 2017 18:23:27 +0200 Message-Id: <20170703162328.24474-4-laurent@vivier.eu> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170703162328.24474-1-laurent@vivier.eu> References: <20170703162328.24474-1-laurent@vivier.eu> X-Provags-ID: V03:K0:DGpghOCXYuZGuSZa4zx90rzlds1/uEffAhJpMvFSYoBfld92g/u L+FjcTrE1BmAI5Hssvpw+t3NPzb9N+oKxm8sttcNfpy63LrFJNVaSVOwpCbOI9jS92p+A9d t3BgbUCJMTV8ajEH7Xgt2GR+WtUiGpBN7UZQ/jRny0fC5WUqnx4p0boeediEgNsqW6+N3pP ntOEE7Uw1SmcMGywVyjnA== X-UI-Out-Filterresults: notjunk:1; V01:K0:PgxCATZTdog=:c1OOJm1/j7sP73nJ/lAuWu DsHpXd9ZQmvD7X/IriZZWpcQ+Hq8VN6KHeQ/R61X8B7KTADdBRGlu3IRQWYxtEGNxeVeAawqp 2Np2ZfsKsl+mE9cWGPUBb6BY7P6/HcOxPfqweLYeYCzbUkkE0kKb/0oHlox+A5zjNLUlPpgmY SihhozKkxeTrc2S+gC0N38OgT7Pe490FJoWvQOyG1ddumMnP4C4UCDIcGR41Mb2QUorrt1d7Y GIlo+TtWEyxSKRdryXYJ7XgZdJlrlhyazGSPIa3DOzNOmwiunacBkh4j7E8973pfb3x7EoL5y YBYL40CAw7tGNvLNCS/9UIQdhL4NqyJ8zHZvSIaI1CcZMJQH0YovnqrnRGAYcmOX4Et5jYpbz eP1Rvl+nWh0rkL1VbBqEN5WuakiWijahQMXpC4cWBnDNDeWYL4cTTjjQajzueIyyp8+pkRqES kysPNKEpFAerZg3hIshsZvb7l4vFg2/M+Pyodl71oy0KFmxBT2LdcAs9otCzAFKZgfDzRjjB7 FgxUyRixAekqvDrGiuS6grKjvCf8iOwQYidXBuQVYt/d0RMVYW6FVRBtFhLSEyBu1w7mzzHby NQzkytAWa1M9xR+0ZWaX/Z8R8FP3dMFkj+gwk+F5vF1x0ZkNjZHFLVVrK0m25HjNbEsdLpSaD k0XrdJOzGI0ia9dnQDKs0wHleZsyQ8rRSKd/xMwe51xAUlzsPyTtr8z0jLcF8cyrSdIc= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.17.13 Subject: [Qemu-devel] [PATCH 3/4] target/m68k: add fmod/frem X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Aurelien Jarno , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Use libm functions fmodl() and remainderl(). The quotient byte of the FPSR is updated with the result of the operation. Signed-off-by: Laurent Vivier Reviewed-by: Richard Henderson --- target/m68k/cpu.h | 1 + target/m68k/fpu_helper.c | 35 +++++++++++++++++++++++++++++++++++ target/m68k/helper.h | 2 ++ target/m68k/translate.c | 6 ++++++ 4 files changed, 44 insertions(+) diff --git a/target/m68k/cpu.h b/target/m68k/cpu.h index f8f4dd5..84794a9 100644 --- a/target/m68k/cpu.h +++ b/target/m68k/cpu.h @@ -236,6 +236,7 @@ typedef enum { /* Quotient */ #define FPSR_QT_MASK 0x00ff0000 +#define FPSR_QT_SHIFT 16 /* Floating-Point Control Register */ /* Rounding mode */ diff --git a/target/m68k/fpu_helper.c b/target/m68k/fpu_helper.c index 2b07cb9..715b9be 100644 --- a/target/m68k/fpu_helper.c +++ b/target/m68k/fpu_helper.c @@ -736,3 +736,38 @@ void HELPER(fsincos)(CPUM68KState *env, FPReg *res0, FPReg *res1, FPReg *val) res1->d = ldouble_to_floatx80(dcos, &env->fp_status); res0->d = ldouble_to_floatx80(dsin, &env->fp_status); } + +static void make_quotient(CPUM68KState *env, long double val, uint32_t sign) +{ + uint32_t quotient = (uint32_t)fabsl(val); + quotient = (sign << 7) | (quotient & 0x7f); + env->fpsr = (env->fpsr & ~FPSR_QT_MASK) | (quotient << FPSR_QT_SHIFT); +} + +void HELPER(fmod)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1) +{ + long double src, dst; + uint32_t sign = floatx80_is_neg(val0->d) ^ floatx80_is_neg(val1->d); + + src = floatx80_to_ldouble(val0->d); + dst = floatx80_to_ldouble(val1->d); + + dst = fmodl(dst, src); + + make_quotient(env, dst, sign); + res->d = ldouble_to_floatx80(dst, &env->fp_status); +} + +void HELPER(frem)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1) +{ + long double src, dst; + uint32_t sign = floatx80_is_neg(val0->d) ^ floatx80_is_neg(val1->d); + + src = floatx80_to_ldouble(val0->d); + dst = floatx80_to_ldouble(val1->d); + + dst = remainderl(dst, src); + + make_quotient(env, dst, sign); + res->d = ldouble_to_floatx80(dst, &env->fp_status); +} diff --git a/target/m68k/helper.h b/target/m68k/helper.h index 302b6c0..889978e 100644 --- a/target/m68k/helper.h +++ b/target/m68k/helper.h @@ -77,6 +77,8 @@ DEF_HELPER_3(fcosh, void, env, fp, fp) DEF_HELPER_3(facos, void, env, fp, fp) DEF_HELPER_3(fcos, void, env, fp, fp) DEF_HELPER_4(fsincos, void, env, fp, fp, fp) +DEF_HELPER_4(fmod, void, env, fp, fp, fp) +DEF_HELPER_4(frem, void, env, fp, fp, fp) DEF_HELPER_3(mac_move, void, env, i32, i32) DEF_HELPER_3(macmulf, i64, env, i32, i32) diff --git a/target/m68k/translate.c b/target/m68k/translate.c index 8a712b3..fe9e0bf 100644 --- a/target/m68k/translate.c +++ b/target/m68k/translate.c @@ -4727,6 +4727,9 @@ DISAS_INSN(fpu) case 0x64: /* fddiv */ gen_helper_fddiv(cpu_env, cpu_dest, cpu_src, cpu_dest); break; + case 0x21: /* fmod */ + gen_helper_fmod(cpu_env, cpu_dest, cpu_src, cpu_dest); + break; case 0x22: /* fadd */ gen_helper_fadd(cpu_env, cpu_dest, cpu_src, cpu_dest); break; @@ -4748,6 +4751,9 @@ DISAS_INSN(fpu) case 0x24: /* fsgldiv */ gen_helper_fsgldiv(cpu_env, cpu_dest, cpu_src, cpu_dest); break; + case 0x25: /* frem */ + gen_helper_frem(cpu_env, cpu_dest, cpu_src, cpu_dest); + break; case 0x27: /* fsglmul */ gen_helper_fsglmul(cpu_env, cpu_dest, cpu_src, cpu_dest); break;