]> git.proxmox.com Git - mirror_qemu.git/commitdiff
target/m68k: implement flog2
authorLaurent Vivier <laurent@vivier.eu>
Mon, 5 Mar 2018 20:39:07 +0000 (21:39 +0100)
committerLaurent Vivier <laurent@vivier.eu>
Fri, 9 Mar 2018 14:50:38 +0000 (15:50 +0100)
Using a local m68k floatx80_log2()
[copied from previous:
Written by Andreas Grabher for Previous, NeXT Computer Emulator.]

Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20180305203910.10391-6-laurent@vivier.eu>

target/m68k/fpu_helper.c
target/m68k/helper.h
target/m68k/softfloat.c
target/m68k/softfloat.h
target/m68k/translate.c

index 26285341364182fdc052aaa34c810b7dfeb9c242..97a450112690193df022ad8cd2f236d5b637e98c 100644 (file)
@@ -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);
+}
index d1f38f260f5756d2441c13b716dcb512ac1d432e..15f63b353f9444b91b1b3f31f6dfb738c8fcf297 100644 (file)
@@ -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)
index 22fd7f6341b003bb8ad4560ddad5c33b39fc7bb5..9fa6d6fd05100922614b2ee1db50a26088abe7e4 100644 (file)
@@ -715,3 +715,70 @@ floatx80 floatx80_log10(floatx80 a, float_status *status)
 
     return a;
 }
+
+/*----------------------------------------------------------------------------
+ | Log base 2
+ *----------------------------------------------------------------------------*/
+
+floatx80 floatx80_log2(floatx80 a, float_status *status)
+{
+    flag aSign;
+    int32_t aExp;
+    uint64_t aSig;
+
+    int8_t user_rnd_mode, user_rnd_prec;
+
+    floatx80 fp0, fp1;
+
+    aSig = extractFloatx80Frac(a);
+    aExp = extractFloatx80Exp(a);
+    aSign = extractFloatx80Sign(a);
+
+    if (aExp == 0x7FFF) {
+        if ((uint64_t) (aSig << 1)) {
+            propagateFloatx80NaNOneArg(a, status);
+        }
+        if (aSign == 0) {
+            return packFloatx80(0, floatx80_infinity.high,
+                                floatx80_infinity.low);
+        }
+    }
+
+    if (aExp == 0) {
+        if (aSig == 0) {
+            float_raise(float_flag_divbyzero, status);
+            return packFloatx80(1, floatx80_infinity.high,
+                                floatx80_infinity.low);
+        }
+        normalizeFloatx80Subnormal(aSig, &aExp, &aSig);
+    }
+
+    if (aSign) {
+        float_raise(float_flag_invalid, status);
+        return floatx80_default_nan(status);
+    }
+
+    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;
+
+    if (aSig == one_sig) { /* X is 2^k */
+        status->float_rounding_mode = user_rnd_mode;
+        status->floatx80_rounding_precision = user_rnd_prec;
+
+        a = int32_to_floatx80(aExp - 0x3FFF, status);
+    } else {
+        fp0 = floatx80_logn(a, status);
+        fp1 = packFloatx80(0, 0x3FFF, LIT64(0xB8AA3B295C17F0BC)); /* INV_L2 */
+
+        status->float_rounding_mode = user_rnd_mode;
+        status->floatx80_rounding_precision = user_rnd_prec;
+
+        a = floatx80_mul(fp0, fp1, status); /* LOGN(X)*INV_L2 */
+    }
+
+    float_raise(float_flag_inexact, status);
+
+    return a;
+}
index ac29e76189a20cebd9e90f6372118e90c4a76986..c0b77cf01b35902ee1abd5cae4be7145d32a581d 100644 (file)
@@ -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
index f1130df314dc08709326a42fca4d3260be723f23..189b23d38d8e629c9cc0026b84362a91af73ce36 100644 (file)
@@ -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;