diff options
author | Laurent Vivier <laurent@vivier.eu> | 2018-03-12 21:27:25 +0100 |
---|---|---|
committer | Laurent Vivier <laurent@vivier.eu> | 2018-03-13 16:34:42 +0100 |
commit | e3655afa137b2e0999537eef273a2845ba21d68c (patch) | |
tree | cabf56fb6e2be1530f9f7f0290219f2013b943fd /target/m68k | |
parent | c84813b807fc82c68ff6d72387f95b15ad283bf6 (diff) |
target/m68k: implement fatanh
Using a local m68k floatx80_atanh()
[copied from previous:
Written by Andreas Grabher for Previous, NeXT Computer Emulator.]
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20180312202728.23790-9-laurent@vivier.eu>
Diffstat (limited to 'target/m68k')
-rw-r--r-- | target/m68k/fpu_helper.c | 5 | ||||
-rw-r--r-- | target/m68k/helper.h | 1 | ||||
-rw-r--r-- | target/m68k/softfloat.c | 65 | ||||
-rw-r--r-- | target/m68k/softfloat.h | 1 | ||||
-rw-r--r-- | target/m68k/translate.c | 3 |
5 files changed, 75 insertions, 0 deletions
diff --git a/target/m68k/fpu_helper.c b/target/m68k/fpu_helper.c index 18ad6999cb..38b663e1d2 100644 --- a/target/m68k/fpu_helper.c +++ b/target/m68k/fpu_helper.c @@ -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); +} diff --git a/target/m68k/helper.h b/target/m68k/helper.h index 83247a8143..092baec3d5 100644 --- a/target/m68k/helper.h +++ b/target/m68k/helper.h @@ -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) diff --git a/target/m68k/softfloat.c b/target/m68k/softfloat.c index 3d66f6946f..5ce8413e96 100644 --- a/target/m68k/softfloat.c +++ b/target/m68k/softfloat.c @@ -2302,3 +2302,68 @@ floatx80 floatx80_acos(floatx80 a, float_status *status) return a; } + +/*---------------------------------------------------------------------------- + | Hyperbolic arc tangent + *----------------------------------------------------------------------------*/ + +floatx80 floatx80_atanh(floatx80 a, float_status *status) +{ + flag aSign; + int32_t aExp; + uint64_t aSig; + + int8_t user_rnd_mode, user_rnd_prec; + + int32_t compact; + floatx80 fp0, fp1, fp2, one; + + aSig = extractFloatx80Frac(a); + aExp = extractFloatx80Exp(a); + aSign = extractFloatx80Sign(a); + + if (aExp == 0x7FFF && (uint64_t) (aSig << 1)) { + return propagateFloatx80NaNOneArg(a, status); + } + + if (aExp == 0 && aSig == 0) { + return packFloatx80(aSign, 0, 0); + } + + compact = floatx80_make_compact(aExp, aSig); + + if (compact >= 0x3FFF8000) { /* |X| >= 1 */ + if (aExp == one_exp && aSig == one_sig) { /* |X| == 1 */ + float_raise(float_flag_divbyzero, status); + return packFloatx80(aSign, floatx80_infinity.high, + floatx80_infinity.low); + } else { /* |X| > 1 */ + float_raise(float_flag_invalid, status); + return floatx80_default_nan(status); + } + } /* |X| < 1 */ + + user_rnd_mode = status->float_rounding_mode; + user_rnd_prec = status->floatx80_rounding_precision; + status->float_rounding_mode = float_round_nearest_even; + status->floatx80_rounding_precision = 80; + + one = packFloatx80(0, one_exp, one_sig); + fp2 = packFloatx80(aSign, 0x3FFE, one_sig); /* SIGN(X) * (1/2) */ + fp0 = packFloatx80(0, aExp, aSig); /* Y = |X| */ + fp1 = packFloatx80(1, aExp, aSig); /* -Y */ + fp0 = floatx80_add(fp0, fp0, status); /* 2Y */ + fp1 = floatx80_add(fp1, one, status); /* 1-Y */ + fp0 = floatx80_div(fp0, fp1, status); /* Z = 2Y/(1-Y) */ + fp0 = floatx80_lognp1(fp0, status); /* LOG1P(Z) */ + + status->float_rounding_mode = user_rnd_mode; + status->floatx80_rounding_precision = user_rnd_prec; + + a = floatx80_mul(fp0, fp2, + status); /* ATANH(X) = SIGN(X) * (1/2) * LOG1P(Z) */ + + float_raise(float_flag_inexact, status); + + return a; +} diff --git a/target/m68k/softfloat.h b/target/m68k/softfloat.h index 1140491c81..e9943aed20 100644 --- a/target/m68k/softfloat.h +++ b/target/m68k/softfloat.h @@ -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 diff --git a/target/m68k/translate.c b/target/m68k/translate.c index 5fad76c785..2f7caa0ca0 100644 --- a/target/m68k/translate.c +++ b/target/m68k/translate.c @@ -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; |