qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
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 v3 14/16] target-m68k: add explicit single and double precision operations
Date: Tue,  7 Feb 2017 01:59:28 +0100	[thread overview]
Message-ID: <20170207005930.28327-15-laurent@vivier.eu> (raw)
In-Reply-To: <20170207005930.28327-1-laurent@vivier.eu>

Add fssqrt, fdsqrt, fsabs, fdabs, fsneg, fdneg, fsadd, fdadd,
fssub, fdsub, fsmul, fdmul, fsdiv, fddiv, fsmove and fdmove.

The precision is managed using set_floatx80_rounding_precision(),
except for fsmove, fdmove, fsneg, fdneg, fsabs and fdabs:
the value is converted manually to the given precision and
converted back to floatx80.

Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 target/m68k/fpu_helper.c | 178 ++++++++++++++++++++++++++++++++++++++++++++++-
 target/m68k/helper.h     |  16 ++++-
 target/m68k/translate.c  |  76 +++++++++++++++++---
 3 files changed, 259 insertions(+), 11 deletions(-)

diff --git a/target/m68k/fpu_helper.c b/target/m68k/fpu_helper.c
index 8a3eed3..c69efe1 100644
--- a/target/m68k/fpu_helper.c
+++ b/target/m68k/fpu_helper.c
@@ -294,6 +294,16 @@ void HELPER(itrunc_FP0)(CPUM68KState *env)
     floatx80_to_FP0(env, res);
 }
 
+#define PREC_BEGIN(prec)                                        \
+    do {                                                        \
+        int old;                                                \
+        old = get_floatx80_rounding_precision(&env->fp_status); \
+        set_floatx80_rounding_precision(prec, &env->fp_status)  \
+
+#define PREC_END()                                              \
+        set_floatx80_rounding_precision(old, &env->fp_status);  \
+    } while (0)
+
 void HELPER(sqrt_FP0)(CPUM68KState *env)
 {
     floatx80 res;
@@ -303,6 +313,28 @@ void HELPER(sqrt_FP0)(CPUM68KState *env)
     floatx80_to_FP0(env, res);
 }
 
+void HELPER(ssqrt_FP0)(CPUM68KState *env)
+{
+    floatx80 res;
+
+    PREC_BEGIN(32);
+    res = floatx80_sqrt(FP0_to_floatx80(env), &env->fp_status);
+    PREC_END();
+
+    floatx80_to_FP0(env, res);
+}
+
+void HELPER(dsqrt_FP0)(CPUM68KState *env)
+{
+    floatx80 res;
+
+    PREC_BEGIN(64);
+    res = floatx80_sqrt(FP0_to_floatx80(env), &env->fp_status);
+    PREC_END();
+
+    floatx80_to_FP0(env, res);
+}
+
 void HELPER(abs_FP0)(CPUM68KState *env)
 {
     floatx80 res;
@@ -312,11 +344,59 @@ void HELPER(abs_FP0)(CPUM68KState *env)
     floatx80_to_FP0(env, res);
 }
 
-void HELPER(chs_FP0)(CPUM68KState *env)
+void HELPER(sabs_FP0)(CPUM68KState *env)
 {
     floatx80 res;
+    float32 f32;
+
+    res = floatx80_abs(FP0_to_floatx80(env));
+    f32 = floatx80_to_float32(res, &env->fp_status);
+    res = float32_to_floatx80(f32, &env->fp_status);
+
+    floatx80_to_FP0(env, res);
+}
+
+void HELPER(dabs_FP0)(CPUM68KState *env)
+{
+    floatx80 res;
+    float64 f64;
+
+    res = floatx80_abs(FP0_to_floatx80(env));
+    f64 = floatx80_to_float64(res, &env->fp_status);
+    res = float64_to_floatx80(f64, &env->fp_status);
+
+    floatx80_to_FP0(env, res);
+}
+
+void HELPER(neg_FP0)(CPUM68KState *env)
+{
+    floatx80 res;
+
+    res = floatx80_chs(FP0_to_floatx80(env));
+
+    floatx80_to_FP0(env, res);
+}
+
+void HELPER(sneg_FP0)(CPUM68KState *env)
+{
+    floatx80 res;
+    float32 f32;
+
+    res = floatx80_chs(FP0_to_floatx80(env));
+    f32 = floatx80_to_float32(res, &env->fp_status);
+    res = float32_to_floatx80(f32, &env->fp_status);
+
+    floatx80_to_FP0(env, res);
+}
+
+void HELPER(dneg_FP0)(CPUM68KState *env)
+{
+    floatx80 res;
+    float64 f64;
 
     res = floatx80_chs(FP0_to_floatx80(env));
+    f64 = floatx80_to_float64(res, &env->fp_status);
+    res = float64_to_floatx80(f64, &env->fp_status);
 
     floatx80_to_FP0(env, res);
 }
@@ -331,6 +411,30 @@ void HELPER(add_FP0_FP1)(CPUM68KState *env)
     floatx80_to_FP0(env, res);
 }
 
+void HELPER(sadd_FP0_FP1)(CPUM68KState *env)
+{
+    floatx80 res;
+
+    PREC_BEGIN(32);
+    res = floatx80_add(FP0_to_floatx80(env), FP1_to_floatx80(env),
+                      &env->fp_status);
+    PREC_END();
+
+    floatx80_to_FP0(env, res);
+}
+
+void HELPER(dadd_FP0_FP1)(CPUM68KState *env)
+{
+    floatx80 res;
+
+    PREC_BEGIN(64);
+    res = floatx80_add(FP0_to_floatx80(env), FP1_to_floatx80(env),
+                      &env->fp_status);
+    PREC_END();
+
+    floatx80_to_FP0(env, res);
+}
+
 void HELPER(sub_FP0_FP1)(CPUM68KState *env)
 {
     floatx80 res;
@@ -341,6 +445,30 @@ void HELPER(sub_FP0_FP1)(CPUM68KState *env)
     floatx80_to_FP0(env, res);
 }
 
+void HELPER(ssub_FP0_FP1)(CPUM68KState *env)
+{
+    floatx80 res;
+
+    PREC_BEGIN(32);
+    res = floatx80_sub(FP1_to_floatx80(env), FP0_to_floatx80(env),
+                       &env->fp_status);
+    PREC_END();
+
+    floatx80_to_FP0(env, res);
+}
+
+void HELPER(dsub_FP0_FP1)(CPUM68KState *env)
+{
+    floatx80 res;
+
+    PREC_BEGIN(64);
+    res = floatx80_sub(FP1_to_floatx80(env), FP0_to_floatx80(env),
+                       &env->fp_status);
+    PREC_END();
+
+    floatx80_to_FP0(env, res);
+}
+
 void HELPER(mul_FP0_FP1)(CPUM68KState *env)
 {
     floatx80 res;
@@ -351,6 +479,30 @@ void HELPER(mul_FP0_FP1)(CPUM68KState *env)
     floatx80_to_FP0(env, res);
 }
 
+void HELPER(smul_FP0_FP1)(CPUM68KState *env)
+{
+    floatx80 res;
+
+    PREC_BEGIN(32);
+    res = floatx80_mul(FP0_to_floatx80(env), FP1_to_floatx80(env),
+                       &env->fp_status);
+    PREC_END();
+
+    floatx80_to_FP0(env, res);
+}
+
+void HELPER(dmul_FP0_FP1)(CPUM68KState *env)
+{
+    floatx80 res;
+
+    PREC_BEGIN(64);
+    res = floatx80_mul(FP0_to_floatx80(env), FP1_to_floatx80(env),
+                       &env->fp_status);
+    PREC_END();
+
+    floatx80_to_FP0(env, res);
+}
+
 void HELPER(sglmul_FP0_FP1)(CPUM68KState *env)
 {
     float64 a, b, res;
@@ -372,6 +524,30 @@ void HELPER(div_FP0_FP1)(CPUM68KState *env)
     floatx80_to_FP0(env, res);
 }
 
+void HELPER(sdiv_FP0_FP1)(CPUM68KState *env)
+{
+    floatx80 res;
+
+    PREC_BEGIN(32);
+    res = floatx80_div(FP1_to_floatx80(env), FP0_to_floatx80(env),
+                       &env->fp_status);
+    PREC_END();
+
+    floatx80_to_FP0(env, res);
+}
+
+void HELPER(ddiv_FP0_FP1)(CPUM68KState *env)
+{
+    floatx80 res;
+
+    PREC_BEGIN(64);
+    res = floatx80_div(FP1_to_floatx80(env), FP0_to_floatx80(env),
+                       &env->fp_status);
+    PREC_END();
+
+    floatx80_to_FP0(env, res);
+}
+
 void HELPER(sgldiv_FP0_FP1)(CPUM68KState *env)
 {
     float64 a, b, res;
diff --git a/target/m68k/helper.h b/target/m68k/helper.h
index c30e5f7..07aa04f 100644
--- a/target/m68k/helper.h
+++ b/target/m68k/helper.h
@@ -21,13 +21,27 @@ DEF_HELPER_1(reds32_FP0, void, env)
 DEF_HELPER_1(iround_FP0, void, env)
 DEF_HELPER_1(itrunc_FP0, void, env)
 DEF_HELPER_1(sqrt_FP0, void, env)
+DEF_HELPER_1(ssqrt_FP0, void, env)
+DEF_HELPER_1(dsqrt_FP0, void, env)
 DEF_HELPER_1(abs_FP0, void, env)
-DEF_HELPER_1(chs_FP0, void, env)
+DEF_HELPER_1(sabs_FP0, void, env)
+DEF_HELPER_1(dabs_FP0, void, env)
+DEF_HELPER_1(neg_FP0, void, env)
+DEF_HELPER_1(sneg_FP0, void, env)
+DEF_HELPER_1(dneg_FP0, void, env)
 DEF_HELPER_1(add_FP0_FP1, void, env)
+DEF_HELPER_1(sadd_FP0_FP1, void, env)
+DEF_HELPER_1(dadd_FP0_FP1, void, env)
 DEF_HELPER_1(sub_FP0_FP1, void, env)
+DEF_HELPER_1(ssub_FP0_FP1, void, env)
+DEF_HELPER_1(dsub_FP0_FP1, void, env)
 DEF_HELPER_1(mul_FP0_FP1, void, env)
+DEF_HELPER_1(smul_FP0_FP1, void, env)
+DEF_HELPER_1(dmul_FP0_FP1, void, env)
 DEF_HELPER_1(sglmul_FP0_FP1, void, env)
 DEF_HELPER_1(div_FP0_FP1, void, env)
+DEF_HELPER_1(sdiv_FP0_FP1, void, env)
+DEF_HELPER_1(ddiv_FP0_FP1, void, env)
 DEF_HELPER_1(sgldiv_FP0_FP1, void, env)
 DEF_HELPER_1(cmp_FP0_FP1, void, env)
 DEF_HELPER_2(set_fpcr, void, env, i32)
diff --git a/target/m68k/translate.c b/target/m68k/translate.c
index 99f41d3..883f4ff 100644
--- a/target/m68k/translate.c
+++ b/target/m68k/translate.c
@@ -4612,7 +4612,15 @@ DISAS_INSN(fpu)
         gen_op_load_fpr_FP0(REG(ext, 10));
     }
     switch (opmode) {
-    case 0: case 0x40: case 0x44: /* fmove */
+    case 0: /* fmove */
+        break;
+    case 0x40: /* fsmove */
+        gen_helper_redf32_FP0(cpu_env);
+        gen_helper_extf32_FP0(cpu_env);
+        break;
+    case 0x44: /* fdmove */
+        gen_helper_redf64_FP0(cpu_env);
+        gen_helper_extf64_FP0(cpu_env);
         break;
     case 1: /* fint */
         gen_helper_iround_FP0(cpu_env);
@@ -4620,14 +4628,32 @@ DISAS_INSN(fpu)
     case 3: /* fintrz */
         gen_helper_itrunc_FP0(cpu_env);
         break;
-    case 4: case 0x41: case 0x45: /* fsqrt */
+    case 4: /* fsqrt */
         gen_helper_sqrt_FP0(cpu_env);
         break;
-    case 0x18: case 0x58: case 0x5c: /* fabs */
+    case 0x41: /* fssqrt */
+        gen_helper_ssqrt_FP0(cpu_env);
+        break;
+    case 0x45: /* fdsqrt */
+        gen_helper_dsqrt_FP0(cpu_env);
+        break;
+    case 0x18: /* fabs */
         gen_helper_abs_FP0(cpu_env);
         break;
-    case 0x1a: case 0x5a: case 0x5e: /* fneg */
-        gen_helper_chs_FP0(cpu_env);
+    case 0x58: /* fsabs */
+        gen_helper_sabs_FP0(cpu_env);
+        break;
+    case 0x5c: /* fdabs */
+        gen_helper_dabs_FP0(cpu_env);
+        break;
+    case 0x1a: /* fneg */
+        gen_helper_neg_FP0(cpu_env);
+        break;
+    case 0x5a: /* fsneg */
+        gen_helper_sneg_FP0(cpu_env);
+        break;
+    case 0x5e: /* fdneg */
+        gen_helper_dneg_FP0(cpu_env);
         break;
     case 0x1e: /* fgetexp */
         gen_helper_getexp_FP0(cpu_env);
@@ -4635,22 +4661,46 @@ DISAS_INSN(fpu)
     case 0x1f: /* fgetman */
         gen_helper_getman_FP0(cpu_env);
         break;
-    case 0x20: case 0x60: case 0x64: /* fdiv */
+    case 0x20: /* fdiv */
         gen_op_load_fpr_FP1(REG(ext, 7));
         gen_helper_div_FP0_FP1(cpu_env);
         break;
+    case 0x60: /* fsdiv */
+        gen_op_load_fpr_FP1(REG(ext, 7));
+        gen_helper_sdiv_FP0_FP1(cpu_env);
+        break;
+    case 0x64: /* fddiv */
+        gen_op_load_fpr_FP1(REG(ext, 7));
+        gen_helper_ddiv_FP0_FP1(cpu_env);
+        break;
     case 0x21: /* fmod */
         gen_op_load_fpr_FP1(REG(ext, 7));
         gen_helper_mod_FP0_FP1(cpu_env);
         break;
-    case 0x22: case 0x62: case 0x66: /* fadd */
+    case 0x22: /* fadd */
         gen_op_load_fpr_FP1(REG(ext, 7));
         gen_helper_add_FP0_FP1(cpu_env);
         break;
-    case 0x23: case 0x63: case 0x67: /* fmul */
+    case 0x62: /* fsadd */
+        gen_op_load_fpr_FP1(REG(ext, 7));
+        gen_helper_sadd_FP0_FP1(cpu_env);
+        break;
+    case 0x66: /* fdadd */
+        gen_op_load_fpr_FP1(REG(ext, 7));
+        gen_helper_dadd_FP0_FP1(cpu_env);
+        break;
+    case 0x23: /* fmul */
         gen_op_load_fpr_FP1(REG(ext, 7));
         gen_helper_mul_FP0_FP1(cpu_env);
         break;
+    case 0x63: /* fsmul */
+        gen_op_load_fpr_FP1(REG(ext, 7));
+        gen_helper_smul_FP0_FP1(cpu_env);
+        break;
+    case 0x67: /* fdmul */
+        gen_op_load_fpr_FP1(REG(ext, 7));
+        gen_helper_dmul_FP0_FP1(cpu_env);
+        break;
     case 0x24: /* fsgldiv */
         gen_op_load_fpr_FP1(REG(ext, 7));
         gen_helper_sgldiv_FP0_FP1(cpu_env);
@@ -4663,10 +4713,18 @@ DISAS_INSN(fpu)
         gen_op_load_fpr_FP1(REG(ext, 7));
         gen_helper_sglmul_FP0_FP1(cpu_env);
         break;
-    case 0x28: case 0x68: case 0x6c: /* fsub */
+    case 0x28: /* fsub */
         gen_op_load_fpr_FP1(REG(ext, 7));
         gen_helper_sub_FP0_FP1(cpu_env);
         break;
+    case 0x68: /* fssub */
+        gen_op_load_fpr_FP1(REG(ext, 7));
+        gen_helper_ssub_FP0_FP1(cpu_env);
+        break;
+    case 0x6c: /* fdsub */
+        gen_op_load_fpr_FP1(REG(ext, 7));
+        gen_helper_dsub_FP0_FP1(cpu_env);
+        break;
     case 0x38: /* fcmp */
         gen_op_load_fpr_FP1(REG(ext, 7));
         gen_helper_cmp_FP0_FP1(cpu_env);
-- 
2.9.3

  parent reply	other threads:[~2017-02-07  1:00 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-07  0:59 [Qemu-devel] [PATCH v3 00/16] target-m68k: implement 680x0 FPU Laurent Vivier
2017-02-07  0:59 ` [Qemu-devel] [PATCH v3 01/16] softfloat: define 680x0 specific values Laurent Vivier
2017-02-08 21:30   ` Richard Henderson
2017-02-07  0:59 ` [Qemu-devel] [PATCH v3 02/16] softloat: disable floatx80_invalid_encoding() for m68k Laurent Vivier
2017-02-08 21:32   ` Richard Henderson
2017-02-08 22:58   ` Peter Maydell
2017-02-09  8:07     ` Laurent Vivier
2017-02-07  0:59 ` [Qemu-devel] [PATCH v3 03/16] target-m68k: move FPU helpers to fpu_helper.c Laurent Vivier
2017-02-08 21:33   ` Richard Henderson
2017-02-07  0:59 ` [Qemu-devel] [PATCH v3 04/16] target-m68k: define ext_opsize Laurent Vivier
2017-02-08 21:33   ` Richard Henderson
2017-02-07  0:59 ` [Qemu-devel] [PATCH v3 05/16] target-m68k: use floatx80 internally Laurent Vivier
2017-02-15 22:59   ` Richard Henderson
2017-02-07  0:59 ` [Qemu-devel] [PATCH v3 06/16] target-m68k: add FPCR and FPSR Laurent Vivier
2017-02-16  1:10   ` Richard Henderson
2017-02-07  0:59 ` [Qemu-devel] [PATCH v3 07/16] target-m68k: manage FPU exceptions Laurent Vivier
2017-02-16  1:16   ` Richard Henderson
2017-02-07  0:59 ` [Qemu-devel] [PATCH v3 08/16] target-m68k: define 96bit FP registers for gdb on 680x0 Laurent Vivier
2017-02-16  1:17   ` Richard Henderson
2017-02-07  0:59 ` [Qemu-devel] [PATCH v3 09/16] target-m68k: add fmovem Laurent Vivier
2017-02-16  1:22   ` Richard Henderson
2017-02-07  0:59 ` [Qemu-devel] [PATCH v3 10/16] target-m68k: add fscc Laurent Vivier
2017-02-16  1:27   ` Richard Henderson
2017-02-07  0:59 ` [Qemu-devel] [PATCH v3 11/16] target-m68k: add fmovecr Laurent Vivier
2017-02-16  1:28   ` Richard Henderson
2017-02-07  0:59 ` [Qemu-devel] [PATCH v3 12/16] target-m68k: add fscale, fgetman, fgetexp and fmod Laurent Vivier
2017-02-16  1:34   ` Richard Henderson
2017-02-07  0:59 ` [Qemu-devel] [PATCH v3 13/16] target-m68k: add fsglmul and fsgldiv Laurent Vivier
2017-02-16  1:36   ` Richard Henderson
2017-02-07  0:59 ` Laurent Vivier [this message]
2017-02-16  1:41   ` [Qemu-devel] [PATCH v3 14/16] target-m68k: add explicit single and double precision operations Richard Henderson
2017-02-07  0:59 ` [Qemu-devel] [PATCH v3 15/16] target-m68k: add more FPU instructions Laurent Vivier
2017-02-16  1:46   ` Richard Henderson
2017-02-16 10:18     ` Andreas Schwab
2017-02-16 21:01       ` Richard Henderson
2017-02-17  9:06         ` Andreas Schwab
2017-02-07  0:59 ` [Qemu-devel] [PATCH v3 16/16] target-m68k: add fsincos Laurent Vivier
2017-02-07  1:25 ` [Qemu-devel] [PATCH v3 00/16] target-m68k: implement 680x0 FPU no-reply

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=20170207005930.28327-15-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).