Skip to contentSkip to conversation

implement 680x0 FPU (part 5)

PATCH In review Laurent Vivier 2 participants 13 messages Mar 12, 2018 – Mar 15, 2018

lore
Share & tools
lore
#0 lore raw

cover implement 680x0 FPU (part 5)

Implement fcosh, fsinh, ftanh, fatanh, facos, fasin, fatan, fsincos, fcos, fsin, ftan.

This is the last series to implement FPU instructions for 680x0...

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".

I think this series will need some improvemants in the future:
for intance sin and cos functions can be merged in sincos function (and we have unmodified "adjn" variable in floatx80_cos() and floatx80_sin() that can be removed otherwise).

"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/

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 (sincos differs [1] because in QEMU we compute it as sin and cos, and on m68040 sin and cos results differ also with sincos results. It looks like a rounding problem, perhaps a bug in m68040 FPU? or in my test program?)

I know this will need more work, but for the moment I only would like to provide these new instructions to the maintream of QEMU.

[1] Example:

sincos -6.125952 -> (0.156586, 0.987664)

QEMU:

sincos c0010000c407cd1182c2bb27 -> 3ffc0000a05812beea449a4d

                                     3ffe0000fcd791d65887d19a

sin c0010000c407cd1182c2bb27 -> 3ffc0000a05812beea449a4d
cos c0010000c407cd1182c2bb27 -> 3ffe0000fcd791d65887d19a

m68040:

sincos c0010000c407cd1182c2bb27 -> 3ffc0000a05812beea449a4d

                                     3ffe0000fcd791d65887d199 <<--

sin c0010000c407cd1182c2bb27 -> 3ffc0000a05812beea449a4d
cos c0010000c407cd1182c2bb27 -> 3ffe0000fcd791d65887d19a

test program is basically:

    register long double a, sin, cos, pi;
    long double step;

    asm("fmovecr #0, %0" : "=f" (pi));
    step = pi / 1024;
    for (a = -2*pi; a <= 2*pi; a+= step) {
        asm("fsincos.x %2, %0, %1" : "=f" (cos), "=f" (sin) : "f" (a));
        print_result(a, sin, cos);
        asm("fsin.x %1, %0" : "=f" (sin) : "f" (a));
        asm("fcos.x %1, %0" : "=f" (cos) : "f" (a));
        print_result(a, sin, cos);
    }

Laurent Vivier (11):
target/m68k: implement ftan
target/m68k: implement fsin
target/m68k: implement fcos
target/m68k: implement fsincos
target/m68k: implement fatan
target/m68k: implement fasin
target/m68k: implement facos
target/m68k: implement fatanh
target/m68k: implement ftanh
target/m68k: implement fsinh
target/m68k: implement fcosh

 target/m68k/fpu_helper.c            |   61 ++
 target/m68k/helper.h                |   11 +
 target/m68k/softfloat.c             | 1637 +++++++++++++++++++++++++++++++++++
 target/m68k/softfloat.h             |   11 +
 target/m68k/softfloat_fpsp_tables.h |  267 ++++++
 target/m68k/translate.c             |   38 +
 6 files changed, 2025 insertions(+)
Signature · 1 line
2.14.3
#1 lore raw

PATCH 1/11 target/m68k: implement ftan

Using a local m68k floatx80_tan()
[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             | 210 ++++++++++++++++++++++++++++++++++++
 target/m68k/softfloat.h             |   1 +
 target/m68k/softfloat_fpsp_tables.h | 136 +++++++++++++++++++++++
 target/m68k/translate.c             |   3 +
 6 files changed, 356 insertions(+)
target/m68k/fpu_helper.c +5 -0
index 62cbb0dff1..c41115ea05 100644
@@ -592,3 +592,8 @@ void HELPER(ftentox)(CPUM68KState *env, FPReg *res, FPReg *val)
 {
     res->d = floatx80_tentox(val->d, &env->fp_status);
 }
+
+void HELPER(ftan)(CPUM68KState *env, FPReg *res, FPReg *val)
+{
+    res->d = floatx80_tan(val->d, &env->fp_status);
+}
target/m68k/helper.h +1 -0
index 9a9734c196..af9480fe49 100644
@@ -75,6 +75,7 @@ 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(ftan, 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 +210 -0

213 lines not on this page · raw message

target/m68k/softfloat.h +1 -0
index d28e49fe9f..c5ac54d87b 100644
@@ -34,4 +34,5 @@ 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);
+floatx80 floatx80_tan(floatx80 a, float_status *status);
 #endif
target/m68k/softfloat_fpsp_tables.h +136 -0

140 lines not on this page · raw message

target/m68k/translate.c +3 -0
index 6d5bde0777..af8cdc2580 100644
@@ -5057,6 +5057,9 @@ DISAS_INSN(fpu)
     case 0x06: /* flognp1 */
         gen_helper_flognp1(cpu_env, cpu_dest, cpu_src);
         break;
+    case 0x0f: /* ftan */
+        gen_helper_ftan(cpu_env, cpu_dest, cpu_src);
+        break;
     case 0x10: /* fetox */
         gen_helper_fetox(cpu_env, cpu_dest, cpu_src);
         break;
Signature · 1 line
2.14.3
#2 lore raw

PATCH 2/11 target/m68k: implement fsin

In reply to Laurent Vivier

Using a local m68k floatx80_sin()
[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  | 247 +++++++++++++++++++++++++++++++++++++++++++++++
 target/m68k/softfloat.h  |   1 +
 target/m68k/translate.c  |   3 +
 5 files changed, 257 insertions(+)
target/m68k/fpu_helper.c +5 -0
index c41115ea05..a6cfb4db1a 100644
@@ -597,3 +597,8 @@ void HELPER(ftan)(CPUM68KState *env, FPReg *res, FPReg *val)
 {
     res->d = floatx80_tan(val->d, &env->fp_status);
 }
+
+void HELPER(fsin)(CPUM68KState *env, FPReg *res, FPReg *val)
+{
+    res->d = floatx80_sin(val->d, &env->fp_status);
+}
target/m68k/helper.h +1 -0
index af9480fe49..6d8bfaab64 100644
@@ -76,6 +76,7 @@ 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(ftan, void, env, fp, fp)
+DEF_HELPER_3(fsin, 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 +247 -0

250 lines not on this page · raw message

target/m68k/softfloat.h +1 -0
index c5ac54d87b..e8ccf69ba8 100644
@@ -35,4 +35,5 @@ floatx80 floatx80_etox(floatx80 a, float_status *status);
 floatx80 floatx80_twotox(floatx80 a, float_status *status);
 floatx80 floatx80_tentox(floatx80 a, float_status *status);
 floatx80 floatx80_tan(floatx80 a, float_status *status);
+floatx80 floatx80_sin(floatx80 a, float_status *status);
 #endif
target/m68k/translate.c +3 -0
index af8cdc2580..05ab75e43f 100644
@@ -5057,6 +5057,9 @@ DISAS_INSN(fpu)
     case 0x06: /* flognp1 */
         gen_helper_flognp1(cpu_env, cpu_dest, cpu_src);
         break;
+    case 0x0e: /* fsin */
+        gen_helper_fsin(cpu_env, cpu_dest, cpu_src);
+        break;
     case 0x0f: /* ftan */
         gen_helper_ftan(cpu_env, cpu_dest, cpu_src);
         break;
Signature · 1 line
2.14.3
#3 lore raw

PATCH 3/11 target/m68k: implement fcos

In reply to Laurent Vivier

Using a local m68k floatx80_cos()
[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  | 244 +++++++++++++++++++++++++++++++++++++++++++++++
 target/m68k/softfloat.h  |   1 +
 target/m68k/translate.c  |   3 +
 5 files changed, 254 insertions(+)
target/m68k/fpu_helper.c +5 -0
index a6cfb4db1a..71df19c685 100644
@@ -602,3 +602,8 @@ void HELPER(fsin)(CPUM68KState *env, FPReg *res, FPReg *val)
 {
     res->d = floatx80_sin(val->d, &env->fp_status);
 }
+
+void HELPER(fcos)(CPUM68KState *env, FPReg *res, FPReg *val)
+{
+    res->d = floatx80_cos(val->d, &env->fp_status);
+}
target/m68k/helper.h +1 -0
index 6d8bfaab64..767baf75a3 100644
@@ -77,6 +77,7 @@ DEF_HELPER_3(ftwotox, void, env, fp, fp)
 DEF_HELPER_3(ftentox, void, env, fp, fp)
 DEF_HELPER_3(ftan, void, env, fp, fp)
 DEF_HELPER_3(fsin, void, env, fp, fp)
+DEF_HELPER_3(fcos, 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 +244 -0

247 lines not on this page · raw message

target/m68k/softfloat.h +1 -0
index e8ccf69ba8..4fd5b2c609 100644
@@ -36,4 +36,5 @@ floatx80 floatx80_twotox(floatx80 a, float_status *status);
 floatx80 floatx80_tentox(floatx80 a, float_status *status);
 floatx80 floatx80_tan(floatx80 a, float_status *status);
 floatx80 floatx80_sin(floatx80 a, float_status *status);
+floatx80 floatx80_cos(floatx80 a, float_status *status);
 #endif
target/m68k/translate.c +3 -0
index 05ab75e43f..f47388da4b 100644
@@ -5099,6 +5099,9 @@ DISAS_INSN(fpu)
     case 0x5e: /* fdneg */
         gen_helper_fdneg(cpu_env, cpu_dest, cpu_src);
         break;
+    case 0x1d: /* fcos */
+        gen_helper_fcos(cpu_env, cpu_dest, cpu_src);
+        break;
     case 0x1e: /* fgetexp */
         gen_helper_fgetexp(cpu_env, cpu_dest, cpu_src);
         break;
Signature · 1 line
2.14.3
#4 lore raw

PATCH 4/11 target/m68k: implement fsincos

In reply to Laurent Vivier

using floatx80_sin() and floatx80_cos()

---
 target/m68k/fpu_helper.c | 11 +++++++++++
 target/m68k/helper.h     |  1 +
 target/m68k/translate.c  |  8 ++++++++
 3 files changed, 20 insertions(+)
target/m68k/fpu_helper.c +11 -0
index 71df19c685..36e34d42a8 100644
@@ -607,3 +607,14 @@ void HELPER(fcos)(CPUM68KState *env, FPReg *res, FPReg *val)
 {
     res->d = floatx80_cos(val->d, &env->fp_status);
 }
+
+void HELPER(fsincos)(CPUM68KState *env, FPReg *res0, FPReg *res1, FPReg *val)
+{
+    floatx80 a = val->d;
+    /* If res0 and res1 specify the same floating-point data register,
+     * the sine result is stored in the register, and the cosine
+     * result is discarded.
+     */
+    res1->d = floatx80_cos(a, &env->fp_status);
+    res0->d = floatx80_sin(a, &env->fp_status);
+}
target/m68k/helper.h +1 -0
index 767baf75a3..a168ffbaea 100644
@@ -78,6 +78,7 @@ DEF_HELPER_3(ftentox, void, env, fp, fp)
 DEF_HELPER_3(ftan, void, env, fp, fp)
 DEF_HELPER_3(fsin, void, env, fp, fp)
 DEF_HELPER_3(fcos, void, env, fp, fp)
+DEF_HELPER_4(fsincos, void, env, fp, fp, fp)
 
 DEF_HELPER_3(mac_move, void, env, i32, i32)
 DEF_HELPER_3(macmulf, i64, env, i32, i32)
target/m68k/translate.c +8 -0
index f47388da4b..a78edd8825 100644
@@ -5159,6 +5159,14 @@ DISAS_INSN(fpu)
     case 0x6c: /* fdsub */
         gen_helper_fdsub(cpu_env, cpu_dest, cpu_src, cpu_dest);
         break;
+    case 0x30: case 0x31: case 0x32:
+    case 0x33: case 0x34: case 0x35:
+    case 0x36: case 0x37: {
+            TCGv_ptr cpu_dest2 = gen_fp_ptr(REG(ext, 0));
+            gen_helper_fsincos(cpu_env, cpu_dest, cpu_dest2, cpu_src);
+            tcg_temp_free_ptr(cpu_dest2);
+        }
+        break;
     case 0x38: /* fcmp */
         gen_helper_fcmp(cpu_env, cpu_src, cpu_dest);
         return;
Signature · 1 line
2.14.3
#5 lore raw

PATCH 5/11 target/m68k: implement fatan

In reply to Laurent Vivier

Using a local m68k floatx80_atan()
[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             | 200 ++++++++++++++++++++++++++++++++++++
 target/m68k/softfloat.h             |   1 +
 target/m68k/softfloat_fpsp_tables.h | 131 +++++++++++++++++++++++
 target/m68k/translate.c             |   3 +
 6 files changed, 341 insertions(+)
target/m68k/fpu_helper.c +5 -0
index 36e34d42a8..47328490ee 100644
@@ -618,3 +618,8 @@ void HELPER(fsincos)(CPUM68KState *env, FPReg *res0, FPReg *res1, FPReg *val)
     res1->d = floatx80_cos(a, &env->fp_status);
     res0->d = floatx80_sin(a, &env->fp_status);
 }
+
+void HELPER(fatan)(CPUM68KState *env, FPReg *res, FPReg *val)
+{
+    res->d = floatx80_atan(val->d, &env->fp_status);
+}
target/m68k/helper.h +1 -0
index a168ffbaea..304569e997 100644
@@ -79,6 +79,7 @@ DEF_HELPER_3(ftan, void, env, fp, fp)
 DEF_HELPER_3(fsin, void, env, fp, fp)
 DEF_HELPER_3(fcos, void, env, fp, fp)
 DEF_HELPER_4(fsincos, void, env, fp, fp, fp)
+DEF_HELPER_3(fatan, 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 +200 -0

209 lines not on this page · raw message

target/m68k/softfloat.h +1 -0
index 4fd5b2c609..eec45f3ffe 100644
@@ -37,4 +37,5 @@ floatx80 floatx80_tentox(floatx80 a, float_status *status);
 floatx80 floatx80_tan(floatx80 a, float_status *status);
 floatx80 floatx80_sin(floatx80 a, float_status *status);
 floatx80 floatx80_cos(floatx80 a, float_status *status);
+floatx80 floatx80_atan(floatx80 a, float_status *status);
 #endif
target/m68k/softfloat_fpsp_tables.h +131 -0

135 lines not on this page · raw message

target/m68k/translate.c +3 -0
index a78edd8825..88015e7ed8 100644
@@ -5057,6 +5057,9 @@ DISAS_INSN(fpu)
     case 0x06: /* flognp1 */
         gen_helper_flognp1(cpu_env, cpu_dest, cpu_src);
         break;
+    case 0x0a: /* fatan */
+        gen_helper_fatan(cpu_env, cpu_dest, cpu_src);
+        break;
     case 0x0e: /* fsin */
         gen_helper_fsin(cpu_env, cpu_dest, cpu_src);
         break;
Signature · 1 line
2.14.3
#6 lore raw

PATCH 6/11 target/m68k: implement fasin

In reply to Laurent Vivier

Using a local m68k floatx80_asin()
[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  | 65 ++++++++++++++++++++++++++++++++++++++++++++++++
 target/m68k/softfloat.h  |  1 +
 target/m68k/translate.c  |  3 +++
 5 files changed, 75 insertions(+)
target/m68k/fpu_helper.c +5 -0
index 47328490ee..972cc97d96 100644
@@ -623,3 +623,8 @@ void HELPER(fatan)(CPUM68KState *env, FPReg *res, FPReg *val)
 {
     res->d = floatx80_atan(val->d, &env->fp_status);
 }
+
+void HELPER(fasin)(CPUM68KState *env, FPReg *res, FPReg *val)
+{
+    res->d = floatx80_asin(val->d, &env->fp_status);
+}
target/m68k/helper.h +1 -0
index 304569e997..e1aca375e0 100644
@@ -80,6 +80,7 @@ DEF_HELPER_3(fsin, void, env, fp, fp)
 DEF_HELPER_3(fcos, void, env, fp, fp)
 DEF_HELPER_4(fsincos, void, env, fp, fp, fp)
 DEF_HELPER_3(fatan, void, env, fp, fp)
+DEF_HELPER_3(fasin, 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 +65 -0

68 lines not on this page · raw message

target/m68k/softfloat.h +1 -0
index eec45f3ffe..ca0eb674aa 100644
@@ -38,4 +38,5 @@ floatx80 floatx80_tan(floatx80 a, float_status *status);
 floatx80 floatx80_sin(floatx80 a, float_status *status);
 floatx80 floatx80_cos(floatx80 a, float_status *status);
 floatx80 floatx80_atan(floatx80 a, float_status *status);
+floatx80 floatx80_asin(floatx80 a, float_status *status);
 #endif
target/m68k/translate.c +3 -0
index 88015e7ed8..d4169c4533 100644
@@ -5060,6 +5060,9 @@ DISAS_INSN(fpu)
     case 0x0a: /* fatan */
         gen_helper_fatan(cpu_env, cpu_dest, cpu_src);
         break;
+    case 0x0c: /* fasin */
+        gen_helper_fasin(cpu_env, cpu_dest, cpu_src);
+        break;
     case 0x0e: /* fsin */
         gen_helper_fsin(cpu_env, cpu_dest, cpu_src);
         break;
Signature · 1 line
2.14.3
#7 lore raw

PATCH 7/11 target/m68k: implement facos

In reply to Laurent Vivier

Using a local m68k floatx80_acos()
[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  | 70 ++++++++++++++++++++++++++++++++++++++++++++++++
 target/m68k/softfloat.h  |  1 +
 target/m68k/translate.c  |  3 +++
 5 files changed, 80 insertions(+)
target/m68k/fpu_helper.c +5 -0
index 972cc97d96..18ad6999cb 100644
@@ -628,3 +628,8 @@ void HELPER(fasin)(CPUM68KState *env, FPReg *res, FPReg *val)
 {
     res->d = floatx80_asin(val->d, &env->fp_status);
 }
+
+void HELPER(facos)(CPUM68KState *env, FPReg *res, FPReg *val)
+{
+    res->d = floatx80_acos(val->d, &env->fp_status);
+}
target/m68k/helper.h +1 -0
index e1aca375e0..83247a8143 100644
@@ -81,6 +81,7 @@ DEF_HELPER_3(fcos, void, env, fp, fp)
 DEF_HELPER_4(fsincos, void, env, fp, fp, fp)
 DEF_HELPER_3(fatan, void, env, fp, fp)
 DEF_HELPER_3(fasin, void, env, fp, fp)
+DEF_HELPER_3(facos, 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 +70 -0

79 lines not on this page · raw message

target/m68k/softfloat.h +1 -0
index ca0eb674aa..1140491c81 100644
@@ -39,4 +39,5 @@ floatx80 floatx80_sin(floatx80 a, float_status *status);
 floatx80 floatx80_cos(floatx80 a, float_status *status);
 floatx80 floatx80_atan(floatx80 a, float_status *status);
 floatx80 floatx80_asin(floatx80 a, float_status *status);
+floatx80 floatx80_acos(floatx80 a, float_status *status);
 #endif
target/m68k/translate.c +3 -0
index d4169c4533..5fad76c785 100644
@@ -5105,6 +5105,9 @@ DISAS_INSN(fpu)
     case 0x5e: /* fdneg */
         gen_helper_fdneg(cpu_env, cpu_dest, cpu_src);
         break;
+    case 0x1c: /* facos */
+        gen_helper_facos(cpu_env, cpu_dest, cpu_src);
+        break;
     case 0x1d: /* fcos */
         gen_helper_fcos(cpu_env, cpu_dest, cpu_src);
         break;
Signature · 1 line
2.14.3
#8 lore raw

PATCH 8/11 target/m68k: implement fatanh

In reply to Laurent Vivier

Using a local m68k floatx80_atanh()
[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  | 65 ++++++++++++++++++++++++++++++++++++++++++++++++
 target/m68k/softfloat.h  |  1 +
 target/m68k/translate.c  |  3 +++
 5 files changed, 75 insertions(+)
target/m68k/fpu_helper.c +5 -0
index 18ad6999cb..38b663e1d2 100644
@@ -633,3 +633,8 @@ void HELPER(facos)(CPUM68KState *env, FPReg *res, FPReg *val)
 {
     res->d = floatx80_acos(val->d, &env->fp_status);
 }
+
+void HELPER(fatanh)(CPUM68KState *env, FPReg *res, FPReg *val)
+{
+    res->d = floatx80_atanh(val->d, &env->fp_status);
+}
target/m68k/helper.h +1 -0
index 83247a8143..092baec3d5 100644
@@ -82,6 +82,7 @@ DEF_HELPER_4(fsincos, void, env, fp, fp, fp)
 DEF_HELPER_3(fatan, void, env, fp, fp)
 DEF_HELPER_3(fasin, void, env, fp, fp)
 DEF_HELPER_3(facos, void, env, fp, fp)
+DEF_HELPER_3(fatanh, 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 +65 -0

68 lines not on this page · raw message

target/m68k/softfloat.h +1 -0
index 1140491c81..e9943aed20 100644
@@ -40,4 +40,5 @@ floatx80 floatx80_cos(floatx80 a, float_status *status);
 floatx80 floatx80_atan(floatx80 a, float_status *status);
 floatx80 floatx80_asin(floatx80 a, float_status *status);
 floatx80 floatx80_acos(floatx80 a, float_status *status);
+floatx80 floatx80_atanh(floatx80 a, float_status *status);
 #endif
target/m68k/translate.c +3 -0
index 5fad76c785..2f7caa0ca0 100644
@@ -5063,6 +5063,9 @@ DISAS_INSN(fpu)
     case 0x0c: /* fasin */
         gen_helper_fasin(cpu_env, cpu_dest, cpu_src);
         break;
+    case 0x0d: /* fatanh */
+        gen_helper_fatanh(cpu_env, cpu_dest, cpu_src);
+        break;
     case 0x0e: /* fsin */
         gen_helper_fsin(cpu_env, cpu_dest, cpu_src);
         break;
Signature · 1 line
2.14.3
#9 lore raw

PATCH 9/11 target/m68k: implement ftanh

In reply to Laurent Vivier

Using local m68k floatx80_tanh() and floatx80_etoxm1() [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  | 366 +++++++++++++++++++++++++++++++++++++++++++++++
 target/m68k/softfloat.h  |   2 +
 target/m68k/translate.c  |   3 +
 5 files changed, 377 insertions(+)
target/m68k/fpu_helper.c +5 -0
index 38b663e1d2..7d68879f34 100644
@@ -638,3 +638,8 @@ void HELPER(fatanh)(CPUM68KState *env, FPReg *res, FPReg *val)
 {
     res->d = floatx80_atanh(val->d, &env->fp_status);
 }
+
+void HELPER(ftanh)(CPUM68KState *env, FPReg *res, FPReg *val)
+{
+    res->d = floatx80_tanh(val->d, &env->fp_status);
+}
target/m68k/helper.h +1 -0
index 092baec3d5..f100141367 100644
@@ -83,6 +83,7 @@ DEF_HELPER_3(fatan, void, env, fp, fp)
 DEF_HELPER_3(fasin, void, env, fp, fp)
 DEF_HELPER_3(facos, void, env, fp, fp)
 DEF_HELPER_3(fatanh, void, env, fp, fp)
+DEF_HELPER_3(ftanh, 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 +366 -0

369 lines not on this page · raw message

target/m68k/softfloat.h +2 -0
index e9943aed20..4cdb5a49ca 100644
@@ -41,4 +41,6 @@ floatx80 floatx80_atan(floatx80 a, float_status *status);
 floatx80 floatx80_asin(floatx80 a, float_status *status);
 floatx80 floatx80_acos(floatx80 a, float_status *status);
 floatx80 floatx80_atanh(floatx80 a, float_status *status);
+floatx80 floatx80_etoxm1(floatx80 a, float_status *status);
+floatx80 floatx80_tanh(floatx80 a, float_status *status);
 #endif
target/m68k/translate.c +3 -0
index 2f7caa0ca0..0caae904b5 100644
@@ -5057,6 +5057,9 @@ DISAS_INSN(fpu)
     case 0x06: /* flognp1 */
         gen_helper_flognp1(cpu_env, cpu_dest, cpu_src);
         break;
+    case 0x09: /* ftanh */
+        gen_helper_ftanh(cpu_env, cpu_dest, cpu_src);
+        break;
     case 0x0a: /* fatan */
         gen_helper_fatan(cpu_env, cpu_dest, cpu_src);
         break;
Signature · 1 line
2.14.3
#10 lore raw

PATCH 10/11 target/m68k: implement fsinh

In reply to Laurent Vivier

Using a local m68k floatx80_sinh()
[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  | 89 ++++++++++++++++++++++++++++++++++++++++++++++++
 target/m68k/softfloat.h  |  1 +
 target/m68k/translate.c  |  3 ++
 5 files changed, 99 insertions(+)
target/m68k/fpu_helper.c +5 -0
index 7d68879f34..4c969dfe00 100644
@@ -643,3 +643,8 @@ void HELPER(ftanh)(CPUM68KState *env, FPReg *res, FPReg *val)
 {
     res->d = floatx80_tanh(val->d, &env->fp_status);
 }
+
+void HELPER(fsinh)(CPUM68KState *env, FPReg *res, FPReg *val)
+{
+    res->d = floatx80_sinh(val->d, &env->fp_status);
+}
target/m68k/helper.h +1 -0
index f100141367..acdca1af03 100644
@@ -84,6 +84,7 @@ DEF_HELPER_3(fasin, void, env, fp, fp)
 DEF_HELPER_3(facos, void, env, fp, fp)
 DEF_HELPER_3(fatanh, void, env, fp, fp)
 DEF_HELPER_3(ftanh, void, env, fp, fp)
+DEF_HELPER_3(fsinh, 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 +89 -0

92 lines not on this page · raw message

target/m68k/softfloat.h +1 -0
index 4cdb5a49ca..f033abf9ea 100644
@@ -43,4 +43,5 @@ floatx80 floatx80_acos(floatx80 a, float_status *status);
 floatx80 floatx80_atanh(floatx80 a, float_status *status);
 floatx80 floatx80_etoxm1(floatx80 a, float_status *status);
 floatx80 floatx80_tanh(floatx80 a, float_status *status);
+floatx80 floatx80_sinh(floatx80 a, float_status *status);
 #endif
target/m68k/translate.c +3 -0
index 0caae904b5..7d83aaf91d 100644
@@ -5042,6 +5042,9 @@ DISAS_INSN(fpu)
     case 1: /* fint */
         gen_helper_firound(cpu_env, cpu_dest, cpu_src);
         break;
+    case 2: /* fsinh */
+        gen_helper_fsinh(cpu_env, cpu_dest, cpu_src);
+        break;
     case 3: /* fintrz */
         gen_helper_fitrunc(cpu_env, cpu_dest, cpu_src);
         break;
Signature · 1 line
2.14.3
#11 lore raw

PATCH 11/11 target/m68k: implement fcosh

In reply to Laurent Vivier

Using a local m68k floatx80_cosh()
[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  | 81 ++++++++++++++++++++++++++++++++++++++++++++++++
 target/m68k/softfloat.h  |  1 +
 target/m68k/translate.c  |  3 ++
 5 files changed, 91 insertions(+)
target/m68k/fpu_helper.c +5 -0
index 4c969dfe00..6eeffdf9bb 100644
@@ -648,3 +648,8 @@ void HELPER(fsinh)(CPUM68KState *env, FPReg *res, FPReg *val)
 {
     res->d = floatx80_sinh(val->d, &env->fp_status);
 }
+
+void HELPER(fcosh)(CPUM68KState *env, FPReg *res, FPReg *val)
+{
+    res->d = floatx80_cosh(val->d, &env->fp_status);
+}
target/m68k/helper.h +1 -0
index acdca1af03..feee7be626 100644
@@ -85,6 +85,7 @@ DEF_HELPER_3(facos, void, env, fp, fp)
 DEF_HELPER_3(fatanh, void, env, fp, fp)
 DEF_HELPER_3(ftanh, void, env, fp, fp)
 DEF_HELPER_3(fsinh, void, env, fp, fp)
+DEF_HELPER_3(fcosh, 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 +81 -0

84 lines not on this page · raw message

target/m68k/softfloat.h +1 -0
index f033abf9ea..602661d5a8 100644
@@ -44,4 +44,5 @@ floatx80 floatx80_atanh(floatx80 a, float_status *status);
 floatx80 floatx80_etoxm1(floatx80 a, float_status *status);
 floatx80 floatx80_tanh(floatx80 a, float_status *status);
 floatx80 floatx80_sinh(floatx80 a, float_status *status);
+floatx80 floatx80_cosh(floatx80 a, float_status *status);
 #endif
target/m68k/translate.c +3 -0
index 7d83aaf91d..cef6f663ad 100644
@@ -5105,6 +5105,9 @@ DISAS_INSN(fpu)
     case 0x5c: /* fdabs */
         gen_helper_fdabs(cpu_env, cpu_dest, cpu_src);
         break;
+    case 0x19: /* fcosh */
+        gen_helper_fcosh(cpu_env, cpu_dest, cpu_src);
+        break;
     case 0x1a: /* fneg */
         gen_helper_fneg(cpu_env, cpu_dest, cpu_src);
         break;
Signature · 1 line
2.14.3
Reviewed-by on the v1 series
#12 lore raw
In reply to Laurent Vivier
Quoted 20 lines · Laurent Vivier

I have compared results of these instructions from a real m68040 and from QEMU, and they match (sincos differs [1] because in QEMU we compute it as sin and cos, and on m68040 sin and cos results differ also with sincos results. It looks like a rounding problem, perhaps a bug in m68040 FPU? or in my test program?)

I know this will need more work, but for the moment I only would like to provide these new instructions to the maintream of QEMU.

[1] Example:

sincos -6.125952 -> (0.156586, 0.987664)

QEMU:

sincos c0010000c407cd1182c2bb27 -> 3ffc0000a05812beea449a4d

                                     3ffe0000fcd791d65887d19a

sin c0010000c407cd1182c2bb27 -> 3ffc0000a05812beea449a4d
cos c0010000c407cd1182c2bb27 -> 3ffe0000fcd791d65887d19a

Quoted 6 lines

m68040:

sincos c0010000c407cd1182c2bb27 -> 3ffc0000a05812beea449a4d

                                     3ffe0000fcd791d65887d199 <<--

sin c0010000c407cd1182c2bb27 -> 3ffc0000a05812beea449a4d
cos c0010000c407cd1182c2bb27 -> 3ffe0000fcd791d65887d19a

Wow, this does seem like a processor bug.

Anyway, I've looked through the patch set and nothing stands out,

r~