Skip to contentSkip to conversation

target/m68k: implement 680x0 FPU (part 4)

PATCH New Laurent Vivier 1 participant 9 messages Mar 5, 2018

lore
Share & tools
lore
#0 lore raw

cover target/m68k: implement 680x0 FPU (part 4)

Implement flognp1, flogn, flog10, flog2, fetox, ftwotox, ftentox

As previously, all the floatx80 functions are copied from "Previous", the NeXT Computer Emulator, and written by Andreas Grabher.

I did not improve or clean up the code, it's a simple port of Andreas' work from "Previous".

"Previous" code I have ported to QEMU can be found in (r844):

http://svn.code.sf.net/p/previous/code/trunk/src/softfloat/

"Previous" code is a C implementation of m68040 assembly language functions found in ($NetBSD: copyright.s,v 1.2 1994/10/26 07:48:57 cgd Exp)

https://ftp.netbsd.org/pub/NetBSD/NetBSD-current/src/sys/arch/m68k/fpsp/

floatx80_move() comes from WinUAE (3600b8):

https://github.com/tonioni/WinUAE/blob/master/softfloat/softfloat.cpp

All the original work is under SoftFloat-2a license, and additional work under BSD license or GPL-v2-or-later license.

All softfloat new functions are added in target/m68k as they are derived from m68k code.

I have compared results of these instructions from a real m68040 and from QEMU, and they match.

Laurent Vivier (8):
target/m68k: define floatx80_move()
target/m68k: implement flognp1
target/m68k: implement flogn
target/m68k: implement flog10
target/m68k: implement flog2
target/m68k: implement fetox
target/m68k: implement ftwotox
target/m68k: implement ftentox

 target/m68k/fpu_helper.c            |   35 ++
 target/m68k/helper.h                |    7 +
 target/m68k/softfloat.c             | 1019 +++++++++++++++++++++++++++++++++++
 target/m68k/softfloat.h             |    8 +
 target/m68k/softfloat_fpsp_tables.h |  374 +++++++++++++
 target/m68k/translate.c             |   21 +
 6 files changed, 1464 insertions(+)
 create mode 100755 target/m68k/softfloat_fpsp_tables.h
Signature · 1 line
2.14.3
#1 lore raw

PATCH 1/8 target/m68k: define floatx80_move()

This functions is needed by upcoming m68k softfloat functions.

Source code copied for WinUAE (tag 3500) (The WinUAE file has been copied from QEMU and has the QEMU licensing notice)

---
 target/m68k/softfloat.c | 27 +++++++++++++++++++++++++++
 target/m68k/softfloat.h |  1 +
 2 files changed, 28 insertions(+)
target/m68k/softfloat.c +27 -0
index 9cb141900c..55eb7a260a 100644
@@ -247,3 +247,30 @@ floatx80 floatx80_scale(floatx80 a, floatx80 b, float_status *status)
     return roundAndPackFloatx80(status->floatx80_rounding_precision,
                                 aSign, aExp, aSig, 0, status);
 }
+
+floatx80 floatx80_move(floatx80 a, float_status *status)
+{
+    flag aSign;
+    int32_t aExp;
+    uint64_t aSig;
+
+    aSig = extractFloatx80Frac(a);
+    aExp = extractFloatx80Exp(a);
+    aSign = extractFloatx80Sign(a);
+
+    if (aExp == 0x7FFF) {
+        if ((uint64_t)(aSig << 1)) {
+            return propagateFloatx80NaNOneArg(a, status);
+        }
+        return a;
+    }
+    if (aExp == 0) {
+        if (aSig == 0) {
+            return a;
+        }
+        normalizeRoundAndPackFloatx80(status->floatx80_rounding_precision,
+                                      aSign, aExp, aSig, 0, status);
+    }
+    return roundAndPackFloatx80(status->floatx80_rounding_precision, aSign,
+                                aExp, aSig, 0, status);
+}
target/m68k/softfloat.h +1 -0
index 78fbc0cd0c..18561b870d 100644
@@ -26,4 +26,5 @@ floatx80 floatx80_mod(floatx80 a, floatx80 b, float_status *status);
 floatx80 floatx80_getman(floatx80 a, float_status *status);
 floatx80 floatx80_getexp(floatx80 a, float_status *status);
 floatx80 floatx80_scale(floatx80 a, floatx80 b, float_status *status);
+floatx80 floatx80_move(floatx80 a, float_status *status);
 #endif
Signature · 1 line
2.14.3
#2 lore raw

PATCH 2/8 target/m68k: implement flognp1

In reply to Laurent Vivier

Using a local m68k floatx80_lognp1()
[copied from previous:
Written by Andreas Grabher for Previous, NeXT Computer Emulator.]

---
 target/m68k/fpu_helper.c            |   5 +
 target/m68k/helper.h                |   1 +
 target/m68k/softfloat.c             | 216 ++++++++++++++++++++++++++++++++++++
 target/m68k/softfloat.h             |   1 +
 target/m68k/softfloat_fpsp_tables.h | 154 +++++++++++++++++++++++++
 target/m68k/translate.c             |   3 +
 6 files changed, 380 insertions(+)
 create mode 100755 target/m68k/softfloat_fpsp_tables.h
target/m68k/fpu_helper.c +5 -0
index cdb9b50462..614064612e 100644
@@ -557,3 +557,8 @@ void HELPER(fscale)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1)
 {
     res->d = floatx80_scale(val1->d, val0->d, &env->fp_status);
 }
+
+void HELPER(flognp1)(CPUM68KState *env, FPReg *res, FPReg *val)
+{
+    res->d = floatx80_lognp1(val->d, &env->fp_status);
+}
target/m68k/helper.h +1 -0
index c348dced3a..f7e6fc8c40 100644
@@ -68,6 +68,7 @@ DEF_HELPER_4(frem, void, env, fp, fp, fp)
 DEF_HELPER_3(fgetexp, void, env, fp, fp)
 DEF_HELPER_3(fgetman, void, env, fp, fp)
 DEF_HELPER_4(fscale, void, env, fp, fp, fp)
+DEF_HELPER_3(flognp1, void, env, fp, fp)
 
 DEF_HELPER_3(mac_move, void, env, i32, i32)
 DEF_HELPER_3(macmulf, i64, env, i32, i32)
target/m68k/softfloat.c +216 -0

225 lines not on this page · raw message

target/m68k/softfloat.h +1 -0
index 18561b870d..4d74eaf862 100644
@@ -27,4 +27,5 @@ floatx80 floatx80_getman(floatx80 a, float_status *status);
 floatx80 floatx80_getexp(floatx80 a, float_status *status);
 floatx80 floatx80_scale(floatx80 a, floatx80 b, float_status *status);
 floatx80 floatx80_move(floatx80 a, float_status *status);
+floatx80 floatx80_lognp1(floatx80 a, float_status *status);
 #endif
target/m68k/softfloat_fpsp_tables.h new file +154 -0

154 lines not on this page · raw message

target/m68k/translate.c +3 -0
index dbb24f8d84..2c3d20154a 100644
@@ -5054,6 +5054,9 @@ DISAS_INSN(fpu)
     case 0x45: /* fdsqrt */
         gen_helper_fdsqrt(cpu_env, cpu_dest, cpu_src);
         break;
+    case 0x06: /* flognp1 */
+        gen_helper_flognp1(cpu_env, cpu_dest, cpu_src);
+        break;
     case 0x18: /* fabs */
         gen_helper_fabs(cpu_env, cpu_dest, cpu_src);
         break;
Signature · 1 line
2.14.3
#3 lore raw

PATCH 3/8 target/m68k: implement flogn

In reply to Laurent Vivier

Using a local m68k floatx80_logn()
[copied from previous:
Written by Andreas Grabher for Previous, NeXT Computer Emulator.]

---
 target/m68k/fpu_helper.c |   5 ++
 target/m68k/helper.h     |   1 +
 target/m68k/softfloat.c  | 168 +++++++++++++++++++++++++++++++++++++++++++++++
 target/m68k/softfloat.h  |   1 +
 target/m68k/translate.c  |   3 +
 5 files changed, 178 insertions(+)
target/m68k/fpu_helper.c +5 -0
index 614064612e..cc6d3dfa52 100644
@@ -562,3 +562,8 @@ void HELPER(flognp1)(CPUM68KState *env, FPReg *res, FPReg *val)
 {
     res->d = floatx80_lognp1(val->d, &env->fp_status);
 }
+
+void HELPER(flogn)(CPUM68KState *env, FPReg *res, FPReg *val)
+{
+    res->d = floatx80_logn(val->d, &env->fp_status);
+}
target/m68k/helper.h +1 -0
index f7e6fc8c40..68e5f4c0a7 100644
@@ -69,6 +69,7 @@ DEF_HELPER_3(fgetexp, void, env, fp, fp)
 DEF_HELPER_3(fgetman, void, env, fp, fp)
 DEF_HELPER_4(fscale, void, env, fp, fp, fp)
 DEF_HELPER_3(flognp1, void, env, fp, fp)
+DEF_HELPER_3(flogn, void, env, fp, fp)
 
 DEF_HELPER_3(mac_move, void, env, i32, i32)
 DEF_HELPER_3(macmulf, i64, env, i32, i32)
target/m68k/softfloat.c +168 -0

171 lines not on this page · raw message

target/m68k/softfloat.h +1 -0
index 4d74eaf862..161bd6dff7 100644
@@ -28,4 +28,5 @@ floatx80 floatx80_getexp(floatx80 a, float_status *status);
 floatx80 floatx80_scale(floatx80 a, floatx80 b, float_status *status);
 floatx80 floatx80_move(floatx80 a, float_status *status);
 floatx80 floatx80_lognp1(floatx80 a, float_status *status);
+floatx80 floatx80_logn(floatx80 a, float_status *status);
 #endif
target/m68k/translate.c +3 -0
index 2c3d20154a..705b9b0d5b 100644
@@ -5057,6 +5057,9 @@ DISAS_INSN(fpu)
     case 0x06: /* flognp1 */
         gen_helper_flognp1(cpu_env, cpu_dest, cpu_src);
         break;
+    case 0x14: /* flogn */
+        gen_helper_flogn(cpu_env, cpu_dest, cpu_src);
+        break;
     case 0x18: /* fabs */
         gen_helper_fabs(cpu_env, cpu_dest, cpu_src);
         break;
Signature · 1 line
2.14.3
#4 lore raw

PATCH 4/8 target/m68k: implement flog10

In reply to Laurent Vivier

Using a local m68k floatx80_log10()
[copied from previous:
Written by Andreas Grabher for Previous, NeXT Computer Emulator.]

---
 target/m68k/fpu_helper.c |  5 +++++
 target/m68k/helper.h     |  1 +
 target/m68k/softfloat.c  | 57 ++++++++++++++++++++++++++++++++++++++++++++++++
 target/m68k/softfloat.h  |  1 +
 target/m68k/translate.c  |  3 +++
 5 files changed, 67 insertions(+)
target/m68k/fpu_helper.c +5 -0
index cc6d3dfa52..2628534136 100644
@@ -567,3 +567,8 @@ void HELPER(flogn)(CPUM68KState *env, FPReg *res, FPReg *val)
 {
     res->d = floatx80_logn(val->d, &env->fp_status);
 }
+
+void HELPER(flog10)(CPUM68KState *env, FPReg *res, FPReg *val)
+{
+    res->d = floatx80_log10(val->d, &env->fp_status);
+}
target/m68k/helper.h +1 -0
index 68e5f4c0a7..d1f38f260f 100644
@@ -70,6 +70,7 @@ DEF_HELPER_3(fgetman, void, env, fp, fp)
 DEF_HELPER_4(fscale, void, env, fp, fp, fp)
 DEF_HELPER_3(flognp1, void, env, fp, fp)
 DEF_HELPER_3(flogn, void, env, fp, fp)
+DEF_HELPER_3(flog10, void, env, fp, fp)
 
 DEF_HELPER_3(mac_move, void, env, i32, i32)
 DEF_HELPER_3(macmulf, i64, env, i32, i32)
target/m68k/softfloat.c +57 -0

60 lines not on this page · raw message

target/m68k/softfloat.h +1 -0
index 161bd6dff7..ac29e76189 100644
@@ -29,4 +29,5 @@ floatx80 floatx80_scale(floatx80 a, floatx80 b, float_status *status);
 floatx80 floatx80_move(floatx80 a, float_status *status);
 floatx80 floatx80_lognp1(floatx80 a, float_status *status);
 floatx80 floatx80_logn(floatx80 a, float_status *status);
+floatx80 floatx80_log10(floatx80 a, float_status *status);
 #endif
target/m68k/translate.c +3 -0
index 705b9b0d5b..f1130df314 100644
@@ -5060,6 +5060,9 @@ DISAS_INSN(fpu)
     case 0x14: /* flogn */
         gen_helper_flogn(cpu_env, cpu_dest, cpu_src);
         break;
+    case 0x15: /* flog10 */
+        gen_helper_flog10(cpu_env, cpu_dest, cpu_src);
+        break;
     case 0x18: /* fabs */
         gen_helper_fabs(cpu_env, cpu_dest, cpu_src);
         break;
Signature · 1 line
2.14.3
#5 lore raw

PATCH 5/8 target/m68k: implement flog2

In reply to Laurent Vivier

Using a local m68k floatx80_log2()
[copied from previous:
Written by Andreas Grabher for Previous, NeXT Computer Emulator.]

---
 target/m68k/fpu_helper.c |  5 ++++
 target/m68k/helper.h     |  1 +
 target/m68k/softfloat.c  | 67 ++++++++++++++++++++++++++++++++++++++++++++++++
 target/m68k/softfloat.h  |  1 +
 target/m68k/translate.c  |  3 +++
 5 files changed, 77 insertions(+)
target/m68k/fpu_helper.c +5 -0
index 2628534136..97a4501126 100644
@@ -572,3 +572,8 @@ void HELPER(flog10)(CPUM68KState *env, FPReg *res, FPReg *val)
 {
     res->d = floatx80_log10(val->d, &env->fp_status);
 }
+
+void HELPER(flog2)(CPUM68KState *env, FPReg *res, FPReg *val)
+{
+    res->d = floatx80_log2(val->d, &env->fp_status);
+}
target/m68k/helper.h +1 -0
index d1f38f260f..15f63b353f 100644
@@ -71,6 +71,7 @@ DEF_HELPER_4(fscale, void, env, fp, fp, fp)
 DEF_HELPER_3(flognp1, void, env, fp, fp)
 DEF_HELPER_3(flogn, void, env, fp, fp)
 DEF_HELPER_3(flog10, void, env, fp, fp)
+DEF_HELPER_3(flog2, void, env, fp, fp)
 
 DEF_HELPER_3(mac_move, void, env, i32, i32)
 DEF_HELPER_3(macmulf, i64, env, i32, i32)
target/m68k/softfloat.c +67 -0

70 lines not on this page · raw message

target/m68k/softfloat.h +1 -0
index ac29e76189..c0b77cf01b 100644
@@ -30,4 +30,5 @@ floatx80 floatx80_move(floatx80 a, float_status *status);
 floatx80 floatx80_lognp1(floatx80 a, float_status *status);
 floatx80 floatx80_logn(floatx80 a, float_status *status);
 floatx80 floatx80_log10(floatx80 a, float_status *status);
+floatx80 floatx80_log2(floatx80 a, float_status *status);
 #endif
target/m68k/translate.c +3 -0
index f1130df314..189b23d38d 100644
@@ -5063,6 +5063,9 @@ DISAS_INSN(fpu)
     case 0x15: /* flog10 */
         gen_helper_flog10(cpu_env, cpu_dest, cpu_src);
         break;
+    case 0x16: /* flog2 */
+        gen_helper_flog2(cpu_env, cpu_dest, cpu_src);
+        break;
     case 0x18: /* fabs */
         gen_helper_fabs(cpu_env, cpu_dest, cpu_src);
         break;
Signature · 1 line
2.14.3
#6 lore raw

PATCH 6/8 target/m68k: implement fetox

In reply to Laurent Vivier

Using a local m68k floatx80_etox()
[copied from previous:
Written by Andreas Grabher for Previous, NeXT Computer Emulator.]

---
 target/m68k/fpu_helper.c            |   5 +
 target/m68k/helper.h                |   1 +
 target/m68k/softfloat.c             | 183 ++++++++++++++++++++++++++++++++++++
 target/m68k/softfloat.h             |   1 +
 target/m68k/softfloat_fpsp_tables.h | 134 ++++++++++++++++++++++++++
 target/m68k/translate.c             |   3 +
 6 files changed, 327 insertions(+)
target/m68k/fpu_helper.c +5 -0
index 97a4501126..154666cbb5 100644
@@ -577,3 +577,8 @@ void HELPER(flog2)(CPUM68KState *env, FPReg *res, FPReg *val)
 {
     res->d = floatx80_log2(val->d, &env->fp_status);
 }
+
+void HELPER(fetox)(CPUM68KState *env, FPReg *res, FPReg *val)
+{
+    res->d = floatx80_etox(val->d, &env->fp_status);
+}
target/m68k/helper.h +1 -0
index 15f63b353f..70aeb2da7c 100644
@@ -72,6 +72,7 @@ DEF_HELPER_3(flognp1, void, env, fp, fp)
 DEF_HELPER_3(flogn, void, env, fp, fp)
 DEF_HELPER_3(flog10, void, env, fp, fp)
 DEF_HELPER_3(flog2, void, env, fp, fp)
+DEF_HELPER_3(fetox, void, env, fp, fp)
 
 DEF_HELPER_3(mac_move, void, env, i32, i32)
 DEF_HELPER_3(macmulf, i64, env, i32, i32)
target/m68k/softfloat.c +183 -0

186 lines not on this page · raw message

target/m68k/softfloat.h +1 -0
index c0b77cf01b..250f0d926f 100644
@@ -31,4 +31,5 @@ floatx80 floatx80_lognp1(floatx80 a, float_status *status);
 floatx80 floatx80_logn(floatx80 a, float_status *status);
 floatx80 floatx80_log10(floatx80 a, float_status *status);
 floatx80 floatx80_log2(floatx80 a, float_status *status);
+floatx80 floatx80_etox(floatx80 a, float_status *status);
 #endif
target/m68k/softfloat_fpsp_tables.h +134 -0

138 lines not on this page · raw message

target/m68k/translate.c +3 -0
index 189b23d38d..4774310ded 100644
@@ -5057,6 +5057,9 @@ DISAS_INSN(fpu)
     case 0x06: /* flognp1 */
         gen_helper_flognp1(cpu_env, cpu_dest, cpu_src);
         break;
+    case 0x10: /* fetox */
+        gen_helper_fetox(cpu_env, cpu_dest, cpu_src);
+        break;
     case 0x14: /* flogn */
         gen_helper_flogn(cpu_env, cpu_dest, cpu_src);
         break;
Signature · 1 line
2.14.3
#7 lore raw

PATCH 7/8 target/m68k: implement ftwotox

In reply to Laurent Vivier

Using a local m68k floatx80_twotox()
[copied from previous:
Written by Andreas Grabher for Previous, NeXT Computer Emulator.]

---
 target/m68k/fpu_helper.c            |   5 ++
 target/m68k/helper.h                |   1 +
 target/m68k/softfloat.c             | 148 ++++++++++++++++++++++++++++++++++++
 target/m68k/softfloat.h             |   1 +
 target/m68k/softfloat_fpsp_tables.h |  86 +++++++++++++++++++++
 target/m68k/translate.c             |   3 +
 6 files changed, 244 insertions(+)
target/m68k/fpu_helper.c +5 -0
index 154666cbb5..f488a92ab2 100644
@@ -582,3 +582,8 @@ void HELPER(fetox)(CPUM68KState *env, FPReg *res, FPReg *val)
 {
     res->d = floatx80_etox(val->d, &env->fp_status);
 }
+
+void HELPER(ftwotox)(CPUM68KState *env, FPReg *res, FPReg *val)
+{
+    res->d = floatx80_twotox(val->d, &env->fp_status);
+}
target/m68k/helper.h +1 -0
index 70aeb2da7c..8caa82296d 100644
@@ -73,6 +73,7 @@ DEF_HELPER_3(flogn, void, env, fp, fp)
 DEF_HELPER_3(flog10, void, env, fp, fp)
 DEF_HELPER_3(flog2, void, env, fp, fp)
 DEF_HELPER_3(fetox, void, env, fp, fp)
+DEF_HELPER_3(ftwotox, void, env, fp, fp)
 
 DEF_HELPER_3(mac_move, void, env, i32, i32)
 DEF_HELPER_3(macmulf, i64, env, i32, i32)
target/m68k/softfloat.c +148 -0

151 lines not on this page · raw message

target/m68k/softfloat.h +1 -0
index 250f0d926f..964275d2a5 100644
@@ -32,4 +32,5 @@ floatx80 floatx80_logn(floatx80 a, float_status *status);
 floatx80 floatx80_log10(floatx80 a, float_status *status);
 floatx80 floatx80_log2(floatx80 a, float_status *status);
 floatx80 floatx80_etox(floatx80 a, float_status *status);
+floatx80 floatx80_twotox(floatx80 a, float_status *status);
 #endif
target/m68k/softfloat_fpsp_tables.h +86 -0

90 lines not on this page · raw message

target/m68k/translate.c +3 -0
index 4774310ded..c65c82e258 100644
@@ -5060,6 +5060,9 @@ DISAS_INSN(fpu)
     case 0x10: /* fetox */
         gen_helper_fetox(cpu_env, cpu_dest, cpu_src);
         break;
+    case 0x11: /* ftwotox */
+        gen_helper_ftwotox(cpu_env, cpu_dest, cpu_src);
+        break;
     case 0x14: /* flogn */
         gen_helper_flogn(cpu_env, cpu_dest, cpu_src);
         break;
Signature · 1 line
2.14.3
#8 lore raw

PATCH 8/8 target/m68k: implement ftentox

In reply to Laurent Vivier

Using a local m68k floatx80_tentox()
[copied from previous:
Written by Andreas Grabher for Previous, NeXT Computer Emulator.]

---
 target/m68k/fpu_helper.c |   5 ++
 target/m68k/helper.h     |   1 +
 target/m68k/softfloat.c  | 153 +++++++++++++++++++++++++++++++++++++++++++++++
 target/m68k/softfloat.h  |   1 +
 target/m68k/translate.c  |   3 +
 5 files changed, 163 insertions(+)
target/m68k/fpu_helper.c +5 -0
index f488a92ab2..62cbb0dff1 100644
@@ -587,3 +587,8 @@ void HELPER(ftwotox)(CPUM68KState *env, FPReg *res, FPReg *val)
 {
     res->d = floatx80_twotox(val->d, &env->fp_status);
 }
+
+void HELPER(ftentox)(CPUM68KState *env, FPReg *res, FPReg *val)
+{
+    res->d = floatx80_tentox(val->d, &env->fp_status);
+}
target/m68k/helper.h +1 -0
index 8caa82296d..9a9734c196 100644
@@ -74,6 +74,7 @@ DEF_HELPER_3(flog10, void, env, fp, fp)
 DEF_HELPER_3(flog2, void, env, fp, fp)
 DEF_HELPER_3(fetox, void, env, fp, fp)
 DEF_HELPER_3(ftwotox, void, env, fp, fp)
+DEF_HELPER_3(ftentox, void, env, fp, fp)
 
 DEF_HELPER_3(mac_move, void, env, i32, i32)
 DEF_HELPER_3(macmulf, i64, env, i32, i32)
target/m68k/softfloat.c +153 -0

156 lines not on this page · raw message

target/m68k/softfloat.h +1 -0
index 964275d2a5..d28e49fe9f 100644
@@ -33,4 +33,5 @@ floatx80 floatx80_log10(floatx80 a, float_status *status);
 floatx80 floatx80_log2(floatx80 a, float_status *status);
 floatx80 floatx80_etox(floatx80 a, float_status *status);
 floatx80 floatx80_twotox(floatx80 a, float_status *status);
+floatx80 floatx80_tentox(floatx80 a, float_status *status);
 #endif
target/m68k/translate.c +3 -0
index c65c82e258..6d5bde0777 100644
@@ -5063,6 +5063,9 @@ DISAS_INSN(fpu)
     case 0x11: /* ftwotox */
         gen_helper_ftwotox(cpu_env, cpu_dest, cpu_src);
         break;
+    case 0x12: /* ftentox */
+        gen_helper_ftentox(cpu_env, cpu_dest, cpu_src);
+        break;
     case 0x14: /* flogn */
         gen_helper_flogn(cpu_env, cpu_dest, cpu_src);
         break;
Signature · 1 line
2.14.3