Message ID | 20170625192125.9992-4-laurent@vivier.eu |
---|---|
State | New |
Headers | show |
Hi Laurent, On 06/25/2017 04:21 PM, Laurent Vivier wrote: > fsglmul and fsgldiv truncate data to single precision before computing > results. > > Signed-off-by: Laurent Vivier <laurent@vivier.eu> > --- > target/m68k/fpu_helper.c | 22 ++++++++++++++++++++++ > target/m68k/helper.h | 2 ++ > target/m68k/translate.c | 6 ++++++ > 3 files changed, 30 insertions(+) > > diff --git a/target/m68k/fpu_helper.c b/target/m68k/fpu_helper.c > index 912c0b7..0d83925 100644 > --- a/target/m68k/fpu_helper.c > +++ b/target/m68k/fpu_helper.c > @@ -183,11 +183,33 @@ void HELPER(fmul)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1) > res->d = floatx80_mul(val0->d, val1->d, &env->fp_status); > } > > +void HELPER(fsglmul)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1) > +{ > + float32 a, b, c; > + > + a = floatx80_to_float32(val0->d, &env->fp_status); > + b = floatx80_to_float32(val1->d, &env->fp_status); > + c = float32_mul(a, b, &env->fp_status); Why not use floatx80_mul() directly? > + > + res->d = float32_to_floatx80(c, &env->fp_status); > +} > + > void HELPER(fdiv)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1) > { > res->d = floatx80_div(val1->d, val0->d, &env->fp_status); > } > > +void HELPER(fsgldiv)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1) > +{ > + float32 a, b, c; > + > + a = floatx80_to_float32(val1->d, &env->fp_status); > + b = floatx80_to_float32(val0->d, &env->fp_status); > + c = float32_div(a, b, &env->fp_status); floatx80_div()? > + > + res->d = float32_to_floatx80(c, &env->fp_status); > +} > + > static int float_comp_to_cc(int float_compare) > { > switch (float_compare) { > diff --git a/target/m68k/helper.h b/target/m68k/helper.h > index d6e80e4..5a006de 100644 > --- a/target/m68k/helper.h > +++ b/target/m68k/helper.h > @@ -31,7 +31,9 @@ DEF_HELPER_3(fchs, void, env, fp, fp) > DEF_HELPER_4(fadd, void, env, fp, fp, fp) > DEF_HELPER_4(fsub, void, env, fp, fp, fp) > DEF_HELPER_4(fmul, void, env, fp, fp, fp) > +DEF_HELPER_4(fsglmul, void, env, fp, fp, fp) > DEF_HELPER_4(fdiv, void, env, fp, fp, fp) > +DEF_HELPER_4(fsgldiv, void, env, fp, fp, fp) > DEF_HELPER_FLAGS_3(fcmp, TCG_CALL_NO_RWG, void, env, fp, fp) > DEF_HELPER_FLAGS_2(set_fpcr, TCG_CALL_NO_RWG, void, env, i32) > DEF_HELPER_FLAGS_2(ftst, TCG_CALL_NO_RWG, void, env, fp) > diff --git a/target/m68k/translate.c b/target/m68k/translate.c > index a54da87..a50bf5f 100644 > --- a/target/m68k/translate.c > +++ b/target/m68k/translate.c > @@ -4622,6 +4622,12 @@ DISAS_INSN(fpu) > case 0x23: case 0x63: case 0x67: /* fmul */ > gen_helper_fmul(cpu_env, cpu_dest, cpu_src, cpu_dest); > break; > + case 0x24: /* fsgldiv */ > + gen_helper_fsgldiv(cpu_env, cpu_dest, cpu_src, cpu_dest); > + break; > + case 0x27: /* fsglmul */ > + gen_helper_fsglmul(cpu_env, cpu_dest, cpu_src, cpu_dest); > + break; > case 0x28: case 0x68: case 0x6c: /* fsub */ > gen_helper_fsub(cpu_env, cpu_dest, cpu_src, cpu_dest); > break; >
Le 25/06/2017 à 21:44, Philippe Mathieu-Daudé a écrit : > Hi Laurent, > > On 06/25/2017 04:21 PM, Laurent Vivier wrote: >> fsglmul and fsgldiv truncate data to single precision before computing >> results. >> >> Signed-off-by: Laurent Vivier <laurent@vivier.eu> >> --- >> target/m68k/fpu_helper.c | 22 ++++++++++++++++++++++ >> target/m68k/helper.h | 2 ++ >> target/m68k/translate.c | 6 ++++++ >> 3 files changed, 30 insertions(+) >> >> diff --git a/target/m68k/fpu_helper.c b/target/m68k/fpu_helper.c >> index 912c0b7..0d83925 100644 >> --- a/target/m68k/fpu_helper.c >> +++ b/target/m68k/fpu_helper.c >> @@ -183,11 +183,33 @@ void HELPER(fmul)(CPUM68KState *env, FPReg *res, >> FPReg *val0, FPReg *val1) >> res->d = floatx80_mul(val0->d, val1->d, &env->fp_status); >> } >> +void HELPER(fsglmul)(CPUM68KState *env, FPReg *res, FPReg *val0, >> FPReg *val1) >> +{ >> + float32 a, b, c; >> + >> + a = floatx80_to_float32(val0->d, &env->fp_status); >> + b = floatx80_to_float32(val1->d, &env->fp_status); >> + c = float32_mul(a, b, &env->fp_status); > > Why not use floatx80_mul() directly? > >> + >> + res->d = float32_to_floatx80(c, &env->fp_status); >> +} >> + >> void HELPER(fdiv)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg >> *val1) >> { >> res->d = floatx80_div(val1->d, val0->d, &env->fp_status); >> } >> +void HELPER(fsgldiv)(CPUM68KState *env, FPReg *res, FPReg *val0, >> FPReg *val1) >> +{ >> + float32 a, b, c; >> + >> + a = floatx80_to_float32(val1->d, &env->fp_status); >> + b = floatx80_to_float32(val0->d, &env->fp_status); >> + c = float32_div(a, b, &env->fp_status); > > floatx80_div()? > Just to follow the spec of the instruction: "if either operand requires more than 24 bits of mantissa to be accurately represented, the extraneous mantissa bits are truncated prior to the multiplication;" Do you think I should keep them in floatx80 and use the floatx80_round() (I introduce latter in the series) to reduce the precision prior the floatx80_mul()? Thanks, Laurent
On 06/26/2017 01:05 AM, Laurent Vivier wrote: >> floatx80_div()? >> > > Just to follow the spec of the instruction: > > "if either operand requires more than 24 bits of mantissa to be > accurately represented, the extraneous mantissa bits are truncated prior > to the multiplication;" > > Do you think I should keep them in floatx80 and use the floatx80_round() > (I introduce latter in the series) to reduce the precision prior the > floatx80_mul()? Actually, yes. The spec explicitly says that the exponent will be in extended precision. r~
diff --git a/target/m68k/fpu_helper.c b/target/m68k/fpu_helper.c index 912c0b7..0d83925 100644 --- a/target/m68k/fpu_helper.c +++ b/target/m68k/fpu_helper.c @@ -183,11 +183,33 @@ void HELPER(fmul)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1) res->d = floatx80_mul(val0->d, val1->d, &env->fp_status); } +void HELPER(fsglmul)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1) +{ + float32 a, b, c; + + a = floatx80_to_float32(val0->d, &env->fp_status); + b = floatx80_to_float32(val1->d, &env->fp_status); + c = float32_mul(a, b, &env->fp_status); + + res->d = float32_to_floatx80(c, &env->fp_status); +} + void HELPER(fdiv)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1) { res->d = floatx80_div(val1->d, val0->d, &env->fp_status); } +void HELPER(fsgldiv)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1) +{ + float32 a, b, c; + + a = floatx80_to_float32(val1->d, &env->fp_status); + b = floatx80_to_float32(val0->d, &env->fp_status); + c = float32_div(a, b, &env->fp_status); + + res->d = float32_to_floatx80(c, &env->fp_status); +} + static int float_comp_to_cc(int float_compare) { switch (float_compare) { diff --git a/target/m68k/helper.h b/target/m68k/helper.h index d6e80e4..5a006de 100644 --- a/target/m68k/helper.h +++ b/target/m68k/helper.h @@ -31,7 +31,9 @@ DEF_HELPER_3(fchs, void, env, fp, fp) DEF_HELPER_4(fadd, void, env, fp, fp, fp) DEF_HELPER_4(fsub, void, env, fp, fp, fp) DEF_HELPER_4(fmul, void, env, fp, fp, fp) +DEF_HELPER_4(fsglmul, void, env, fp, fp, fp) DEF_HELPER_4(fdiv, void, env, fp, fp, fp) +DEF_HELPER_4(fsgldiv, void, env, fp, fp, fp) DEF_HELPER_FLAGS_3(fcmp, TCG_CALL_NO_RWG, void, env, fp, fp) DEF_HELPER_FLAGS_2(set_fpcr, TCG_CALL_NO_RWG, void, env, i32) DEF_HELPER_FLAGS_2(ftst, TCG_CALL_NO_RWG, void, env, fp) diff --git a/target/m68k/translate.c b/target/m68k/translate.c index a54da87..a50bf5f 100644 --- a/target/m68k/translate.c +++ b/target/m68k/translate.c @@ -4622,6 +4622,12 @@ DISAS_INSN(fpu) case 0x23: case 0x63: case 0x67: /* fmul */ gen_helper_fmul(cpu_env, cpu_dest, cpu_src, cpu_dest); break; + case 0x24: /* fsgldiv */ + gen_helper_fsgldiv(cpu_env, cpu_dest, cpu_src, cpu_dest); + break; + case 0x27: /* fsglmul */ + gen_helper_fsglmul(cpu_env, cpu_dest, cpu_src, cpu_dest); + break; case 0x28: case 0x68: case 0x6c: /* fsub */ gen_helper_fsub(cpu_env, cpu_dest, cpu_src, cpu_dest); break;
fsglmul and fsgldiv truncate data to single precision before computing results. Signed-off-by: Laurent Vivier <laurent@vivier.eu> --- target/m68k/fpu_helper.c | 22 ++++++++++++++++++++++ target/m68k/helper.h | 2 ++ target/m68k/translate.c | 6 ++++++ 3 files changed, 30 insertions(+)