From: Laurent Vivier <laurent@vivier.eu>
To: qemu-devel@nongnu.org
Cc: Aurelien Jarno <aurelien@aurel32.net>,
Richard Henderson <rth@twiddle.net>,
Laurent Vivier <laurent@vivier.eu>
Subject: [Qemu-devel] [PATCH 3/4] target/m68k: add fmod/frem
Date: Mon, 3 Jul 2017 18:23:27 +0200 [thread overview]
Message-ID: <20170703162328.24474-4-laurent@vivier.eu> (raw)
In-Reply-To: <20170703162328.24474-1-laurent@vivier.eu>
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 <laurent@vivier.eu>
---
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;
--
2.9.4
next prev parent reply other threads:[~2017-07-03 16:24 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-03 16:23 [Qemu-devel] [PATCH 0/4] target/m68k: implement 680x0 FPU (part 3) Laurent Vivier
2017-07-03 16:23 ` [Qemu-devel] [PATCH 1/4] softfloat: use floatx80_infinity in softfloat Laurent Vivier
2017-07-03 18:06 ` Richard Henderson
2017-07-03 16:23 ` [Qemu-devel] [PATCH 2/4] target/m68k: add FPU trigonometric instructions Laurent Vivier
2017-07-03 19:11 ` Richard Henderson
2017-07-03 19:17 ` Richard Henderson
2017-07-03 16:23 ` Laurent Vivier [this message]
2017-07-03 19:14 ` [Qemu-devel] [PATCH 3/4] target/m68k: add fmod/frem Richard Henderson
2017-07-03 16:23 ` [Qemu-devel] [PATCH 4/4] target-m68k: add fscale, fgetman and fgetexp Laurent Vivier
2017-07-03 19:26 ` Richard Henderson
2017-07-03 19:50 ` Laurent Vivier
2017-07-03 20:31 ` Richard Henderson
2017-07-04 0:07 ` Laurent Vivier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170703162328.24474-4-laurent@vivier.eu \
--to=laurent@vivier.eu \
--cc=aurelien@aurel32.net \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).