target-m68k: implement 680x0 FPU
v4 cover target-m68k: implement 680x0 FPU
This series modifies the original ColdFire FPU implementation to use floatx80 instead of float64 internally as this is the native datatype for 680x0. I didn't keep the float64 type for ColdFire, but if someone thinks it's required I can update this series in this way.
The series also adds the FPU status and control registers.
The floatx80 datatype used here is not exactly the same as the one used by 680x0 for its extended precision data type, because normally the signaling bit of 680x0 NAN is the MSB of the mantissa minus one and in floatx80 it is the MSB.
We also add the gdb server parts to read the new FPU registers. A strange thing happens here: while the gdb client running remotely from a debian etch-m68k has no issue working with 96bit FPU registers (the 680x0 extended precision data type), new gdbs (from a debian unstable and gdb for cross-compiled environment) don't expect this FPU registers size. But it seems like a bug in gdb, not in this implementation.
v4:
this is only a subset of v3
add a patch to move fmove CR to a function use "FPReg *" instead of FP0/FP1 temporaries fcmp/ftst take old FPSR register from parameters and return the new one
add R-b from Richard
v3:
fix fsave opcode
Add comment to define "unnormalized" number
Correctly define pickNaN()
v2:
complete rework of the series
force single precision in ColdFire mode
add "forced" precision instructions (fsmove, fdmove, fsadd, ...) fixed Fcc.
Laurent Vivier (7):
softfloat: define 680x0 specific values
target-m68k: move FPU helpers to fpu_helper.c
target-m68k: define ext_opsize
target-m68k: move fmove CR to a function
target-m68k: use floatx80 internally
target-m68k: define 96bit FP registers for gdb on 680x0
target-m68k: add FPCR and FPSR
configure | 2 +- fpu/softfloat-specialize.h | 34 +- gdb-xml/m68k-fp.xml | 21 ++ target/m68k/Makefile.objs | 2 +- target/m68k/cpu.c | 9 +- target/m68k/cpu.h | 42 ++- target/m68k/fpu_helper.c | 207 ++++++++++ target/m68k/helper.c | 165 ++++---- target/m68k/helper.h | 38 +- target/m68k/qregs.def | 2 +- target/m68k/translate.c | 918 +++++++++++++++++++++++++++++++-------------- 11 files changed, 1031 insertions(+), 409 deletions(-) create mode 100644 gdb-xml/m68k-fp.xml create mode 100644 target/m68k/fpu_helper.c
Signature · 1 line
2.9.4
PATCH v4 1/7 softfloat: define 680x0 specific values
--- fpu/softfloat-specialize.h | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-)
fpu/softfloat-specialize.h +31 -3
@@ -111,7 +111,7 @@ float16 float16_default_nan(float_status *status)*----------------------------------------------------------------------------*/ float32 float32_default_nan (float_status *status) { -#if defined(TARGET_SPARC ) +#if defined(TARGET_SPARC ) || defined(TARGET_M68K )return const_float32 (0x7FFFFFFF );#elif defined(TARGET_PPC ) || defined(TARGET_ARM ) || defined(TARGET_ALPHA ) || \ defined(TARGET_XTENSA ) || defined(TARGET_S390X ) || defined(TARGET_TRICORE )
@@ -136,7 +136,7 @@ float32 float32_default_nan(float_status *status)*----------------------------------------------------------------------------*/ float64 float64_default_nan (float_status *status) { -#if defined(TARGET_SPARC ) +#if defined(TARGET_SPARC ) || defined(TARGET_M68K )return const_float64 (LIT64 (0x7FFFFFFFFFFFFFFF ));#elif defined(TARGET_PPC ) || defined(TARGET_ARM ) || defined(TARGET_ALPHA ) || \ defined(TARGET_S390X )
@@ -162,7 +162,10 @@ float64 float64_default_nan(float_status *status)floatx80 floatx80_default_nan (float_status *status) {floatx80 r; - +#if defined(TARGET_M68K ) + r.low =LIT64 (0xFFFFFFFFFFFFFFFF ); + r.high =0x7FFF ; +#else if (status->snan_bit_is_one) { r.low =LIT64 (0xBFFFFFFFFFFFFFFF ); r.high =0x7FFF ;
@@ -170,6 +173,7 @@ floatx80 floatx80_default_nan(float_status *status) r.low =LIT64 (0xC000000000000000 ); r.high = 0xFFFF; } +#endif return r; }
@@ -502,6 +506,30 @@ static int pickNaN(flag aIsQNaN, flag aIsSNaN, flag bIsQNaN, flag bIsSNaN, return 1; } } +#elif defined(TARGET_M68K) +static int pickNaN (flag aIsQNaN,flag aIsSNaN,flag bIsQNaN,flag bIsSNaN, +flag aIsLargerSignificand) +{ +/* M68000 FAMILY PROGRAMMER'S REFERENCE MANUAL +* 3.4 FLOATING-POINT INSTRUCTION DETAILS +* If either operand, but not both operands, of an operation is a +* nonsignaling NaN, then that NaN is returned as the result. If both +* operands are nonsignaling NaNs, then the destination operand +* nonsignaling NaN is returned as the result. +* If either operand to an operation is a signaling NaN (SNaN), then the +* SNaN bit is set in the FPSR EXC byte. If the SNaN exception enable bit +* is set in the FPCR ENABLE byte, then the exception is taken and the +* destination is not modified. If the SNaN exception enable bit is not +* set, setting the SNaN bit in the operand to a one converts the SNaN to +* a nonsignaling NaN. The operation then continues as described in the +* preceding paragraph for nonsignaling NaNs. +*/ +if (aIsQNaN || aIsSNaN) {/* a is the destination operand */ +return 0 ;/* return the destination operand */ + }else { +return 1 ;/* return b */ + } +}#else static int pickNaN (flag aIsQNaN,flag aIsSNaN,flag bIsQNaN,flag bIsSNaN,flag aIsLargerSignificand)
Signature · 1 line
2.9.4
PATCH v4 2/7 target-m68k: move FPU helpers to fpu_helper.c
In reply to Laurent Vivier--- target/m68k/Makefile.objs | 2 +- target/m68k/fpu_helper.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++ target/m68k/helper.c | 88 ------------------------------------ 3 files changed, 113 insertions(+), 89 deletions(-) create mode 100644 target/m68k/fpu_helper.c
target/m68k/Makefile.objs +1 -1
@@ -1,3 +1,3 @@ obj-y += m68k-semi.o -obj-y += translate.o op_helper.o helper.o cpu.o +obj-y += translate.o op_helper.o helper.o cpu.o fpu_helper.o obj-y += gdbstub.o
target/m68k/fpu_helper.c new file +112 -0
112 lines not on this page · raw message
target/m68k/helper.c +0 -88
94 lines not on this page · raw message
Signature · 1 line
2.9.4
PATCH v4 3/7 target-m68k: define ext_opsize
In reply to Laurent Vivier--- target/m68k/translate.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-)
target/m68k/translate.c +24 -19
@@ -669,6 +669,21 @@ static inline int insn_opsize(int insn) } } +static inline int ext_opsize (int ext,int pos) +{ +switch ((ext >> pos) &7 ) { +case 0 :return OS_LONG ; +case 1 :return OS_SINGLE ; +case 2 :return OS_EXTENDED ; +case 3 :return OS_PACKED ; +case 4 :return OS_WORD ; +case 5 :return OS_DOUBLE ; +case 6 :return OS_BYTE ; +default : +g_assert_not_reached (); + } +} +/* Assign value to a register. If the width is less than the register width only the low part of the register is set. */ static void gen_partset_reg (int opsize,TCGv reg,TCGv val)
@@ -4111,20 +4126,19 @@ DISAS_INSN(fpu) tmp32 =tcg_temp_new_i32 ();/* fmove */ /* ??? TODO: Proper behavior on overflow. */ -switch ((ext >>10 ) &7 ) { -case 0 : - opsize =OS_LONG ; + + opsize =ext_opsize (ext,10 ); +switch (opsize) { +case OS_LONG :gen_helper_f64_to_i32 (tmp32, cpu_env, src);break ; -case 1 : - opsize =OS_SINGLE ; +case OS_SINGLE :gen_helper_f64_to_f32 (tmp32, cpu_env, src);break ; -case 4 : - opsize =OS_WORD ; +case OS_WORD :gen_helper_f64_to_i32 (tmp32, cpu_env, src);break ; -case 5 :/* OS_DOUBLE */ +case OS_DOUBLE :tcg_gen_mov_i32 (tmp32,AREG (insn,0 ));switch ((insn >>3 ) &7 ) {case 2 :
@@ -4153,8 +4167,7 @@ DISAS_INSN(fpu) }tcg_temp_free_i32 (tmp32);return ; -case 6 : - opsize =OS_BYTE ; +case OS_BYTE :gen_helper_f64_to_i32 (tmp32, cpu_env, src);break ;default :
@@ -4227,15 +4240,7 @@ DISAS_INSN(fpu) }if (ext & (1 <<14 )) {/* Source effective address. */ -switch ((ext >>10 ) &7 ) { -case 0 : opsize =OS_LONG ;break ; -case 1 : opsize =OS_SINGLE ;break ; -case 4 : opsize =OS_WORD ;break ; -case 5 : opsize =OS_DOUBLE ;break ; -case 6 : opsize =OS_BYTE ;break ; -default : - goto undef; - } + opsize =ext_opsize (ext,10 );if (opsize ==OS_DOUBLE ) { tmp32 =tcg_temp_new_i32 ();tcg_gen_mov_i32 (tmp32,AREG (insn,0 ));
Signature · 1 line
2.9.4
PATCH v4 4/7 target-m68k: move fmove CR to a function
In reply to Laurent VivierMove code of fmove to/from control register to a function
--- target/m68k/translate.c | 66 ++++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 25 deletions(-)
target/m68k/translate.c +41 -25
@@ -4099,6 +4099,45 @@ DISAS_INSN(trap)gen_exception (s, s->pc -2 ,EXCP_TRAP0 + (insn &0xf )); } +static void gen_op_fmove_fcr (CPUM68KState *env,DisasContext *s, +uint32_t insn,uint32_t ext) +{ +int mask = (ext >>10 ) &7 ; +int is_write = (ext >>13 ) &1 ; +TCGv val; + +if (is_write) { +switch (mask) { +case 1 :/* FPIAR */ +case 2 :/* FPSR */ +default : +cpu_abort (NULL ,"Unimplemented: fmove from control %d" , mask); + goto undef; +case 4 :/* FPCR */ + val =tcg_const_i32 (0 ); +DEST_EA (env, insn,OS_LONG , val,NULL ); +tcg_temp_free (val); +break ; + } +return ; + } +switch (mask) { +case 1 :/* FPIAR */ +case 2 :/* FPSR */ +default : +cpu_abort (NULL ,"Unimplemented: fmove to control %d" , + mask); +break ; +case 4 :/* FPCR */ +/* Not implemented. Ignore writes. */ +break ; + } +return ; +undef: + s->pc -=2 ; +disas_undef_fpu (env, s, insn); +} +/* ??? FP exceptions are not implemented. Most exceptions are deferred until immediately before the next FP instruction is executed. */ DISAS_INSN (fpu)
@@ -4177,32 +4216,9 @@ DISAS_INSN(fpu)tcg_temp_free_i32 (tmp32);return ;case 4 :/* fmove to control register. */ -switch ((ext >>10 ) &7 ) { -case 4 :/* FPCR */ -/* Not implemented. Ignore writes. */ -break ; -case 1 :/* FPIAR */ -case 2 :/* FPSR */ -default : -cpu_abort (NULL ,"Unimplemented: fmove to control %d" , - (ext >>10 ) &7 ); - } -break ;case 5 :/* fmove from control register. */ -switch ((ext >>10 ) &7 ) { -case 4 :/* FPCR */ -/* Not implemented. Always return zero. */ - tmp32 =tcg_const_i32 (0 ); -break ; -case 1 :/* FPIAR */ -case 2 :/* FPSR */ -default : -cpu_abort (NULL ,"Unimplemented: fmove from control %d" , - (ext >>10 ) &7 ); - goto undef; - } -DEST_EA (env, insn,OS_LONG , tmp32,NULL ); -break ; +gen_op_fmove_fcr (env, s, insn, ext); +return ;case 6 :/* fmovem */ case 7 : {
Signature · 1 line
2.9.4
Re: [Qemu-devel] [PATCH v4 4/7] target-m68k: move fmove CR to a function
Quoted 6 lines · Laurent Vivier
Move code of fmove to/from control register to a function
Signed-off-by Laurent Vivier <[email protected]>--- target/m68k/translate.c | 66 ++++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 25 deletions(-)
In that this is 100% code movement,
target/m68k/translate.c DISAS_INSN(trap) · line 4115
Quoted 2 lines
target/m68k/translate.c +2
-0+cpu_abort (NULL ,"Unimplemented: fmove from control %d" , mask); + goto undef;
But cpu_abort doesn't return, and will exit qemu.
This should be qemu_log_mask(LOG_UNIMP, ...).
r~
Re: [Qemu-devel] [PATCH v4 4/7] target-m68k: move fmove CR to a function
Quoted 14 lines · Richard Henderson
Quoted 7 lines · Laurent Vivier
Move code of fmove to/from control register to a function
Signed-off-by Laurent Vivier <[email protected]>--- target/m68k/translate.c | 66 ++++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 25 deletions(-)In that this is 100% code movement,
Reviewed-by Richard Henderson <[email protected]>
Quoted 6 lines
Quoted 3 lines
+ cpu_abort(NULL, "Unimplemented: fmove from control %d",
mask);
+ goto undef;But
cpu_abortdoesn't return, and will exit qemu.
This should beqemu_log_mask(LOG_UNIMP, ...).
Do you want I update the patch to fix that?
Thanks,
Laurent
Re: [Qemu-devel] [PATCH v4 4/7] target-m68k: move fmove CR to a function
Quoted 15 lines · Laurent Vivier
Quoted 14 lines · Richard Henderson
Quoted 7 lines · Laurent Vivier
Move code of fmove to/from control register to a function
Signed-off-by Laurent Vivier <[email protected]>--- target/m68k/translate.c | 66 ++++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 25 deletions(-)In that this is 100% code movement,
Reviewed-by Richard Henderson <[email protected]>
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
+ cpu_abort(NULL, "Unimplemented: fmove from control %d",
mask);
+ goto undef;But
cpu_abortdoesn't return, and will exit qemu.
This should beqemu_log_mask(LOG_UNIMP, ...).Do you want I update the patch to fix that?
Yes please.
r~
Re: [Qemu-devel] [PATCH v4 4/7] target-m68k: move fmove CR to a function
In reply to Laurent VivierHi Laurent,
Quoted 20 lines · Laurent Vivier
Move code of fmove to/from control register to a function
Signed-off-by Laurent Vivier <[email protected]>--- target/m68k/translate.c | 66 ++++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 25 deletions(-)target/m68k/translate.c +5
-0@@ -4099,6 +4099,45 @@ DISAS_INSN(trap)gen_exception (s, s->pc -2 ,EXCP_TRAP0 + (insn &0xf )); } +static void gen_op_fmove_fcr (CPUM68KState *env,DisasContext *s, +uint32_t insn,uint32_t ext) +{ +int mask = (ext >>10 ) &7 ; +int is_write = (ext >>13 ) &1 ;
target/m68k/translate.c DISAS_INSN(trap) · line 4116
Quoted 10 lines
target/m68k/translate.c +10
-0+TCGv val; + +if (is_write) { +switch (mask) { +case 1 :/* FPIAR */ +case 2 :/* FPSR */ +default : +cpu_abort (NULL ,"Unimplemented: fmove from control %d" , mask); + goto undef; +case 4 :/* FPCR */
It seems easier to move the 'if (is_write) {' check here
target/m68k/translate.c DISAS_INSN(trap) · line 4119
Quoted 3 lines
target/m68k/translate.c +3
-0+ val =tcg_const_i32 (0 ); +DEST_EA (env, insn,OS_LONG , val,NULL ); +tcg_temp_free (val);
then '}'
Quoted 60 lines
target/m68k/translate.c +23
-25+break ; + } +return ; + } +switch (mask) { +case 1 :/* FPIAR */ +case 2 :/* FPSR */ +default : +cpu_abort (NULL ,"Unimplemented: fmove to control %d" , + mask); +break ; +case 4 :/* FPCR */ +/* Not implemented. Ignore writes. */ +break ; + } +return ; +undef: + s->pc -=2 ; +disas_undef_fpu (env, s, insn); +} +/* ??? FP exceptions are not implemented. Most exceptions are deferred until immediately before the next FP instruction is executed. */ DISAS_INSN (fpu)@@ -4177,32 +4216,9 @@ DISAS_INSN(fpu)tcg_temp_free_i32 (tmp32);return ;case 4 :/* fmove to control register. */ -switch ((ext >>10 ) &7 ) { -case 4 :/* FPCR */ -/* Not implemented. Ignore writes. */ -break ; -case 1 :/* FPIAR */ -case 2 :/* FPSR */ -default : -cpu_abort (NULL ,"Unimplemented: fmove to control %d" , - (ext >>10 ) &7 ); - } -break ;case 5 :/* fmove from control register. */ -switch ((ext >>10 ) &7 ) { -case 4 :/* FPCR */ -/* Not implemented. Always return zero. */ - tmp32 =tcg_const_i32 (0 ); -break ; -case 1 :/* FPIAR */ -case 2 :/* FPSR */ -default : -cpu_abort (NULL ,"Unimplemented: fmove from control %d" , - (ext >>10 ) &7 ); - goto undef; - } -DEST_EA (env, insn,OS_LONG , tmp32,NULL ); -break ; +gen_op_fmove_fcr (env, s, insn, ext); +return ;case 6 :/* fmovem */ case 7 : {
PATCH v4 5/7 target-m68k: use floatx80 internally
In reply to Laurent VivierColdfire uses float64, but 680x0 use floatx80. This patch introduces the use of floatx80 internally and enables 680x0 80bits FPU.
--- target/m68k/cpu.c | 9 +- target/m68k/cpu.h | 6 +- target/m68k/fpu_helper.c | 85 +++---- target/m68k/helper.c | 12 +- target/m68k/helper.h | 37 +-- target/m68k/qregs.def | 1 - target/m68k/translate.c | 568 +++++++++++++++++++++++++++++++---------------- 7 files changed, 464 insertions(+), 254 deletions(-)
target/m68k/cpu.c +8 -1
@@ -49,6 +49,8 @@ static void m68k_cpu_reset(CPUState *s)M68kCPU *cpu =M68K_CPU (s);M68kCPUClass *mcc =M68K_CPU_GET_CLASS (cpu);CPUM68KState *env = &cpu->env; +floatx80 nan =floatx80_default_nan (NULL ); +int i; mcc->parent_reset (s);
@@ -57,7 +59,12 @@ static void m68k_cpu_reset(CPUState *s) env->sr =0x2700 ;#endif m68k_switch_sp (env); -/* ??? FP regs should be initialized to NaN. */ +for (i =0 ; i <8 ; i++) { + env->fregs[i].d = nan; + } + env->fpcr =0 ; + env->fpsr =0 ; +cpu_m68k_set_ccr (env,0 );/* TODO: We should set PC from the interrupt vector. */ env->pc =0 ;
target/m68k/cpu.h +4 -2
@@ -64,6 +64,8 @@#define NB_MMU_MODES 2#define TARGET_INSN_START_EXTRA_WORDS 1 +typedef CPU_LDoubleU FPReg ; + typedef struct CPUM68KState { uint32_t dregs[8]; uint32_t aregs[8];
@@ -82,8 +84,8 @@ typedef struct CPUM68KState {uint32_t cc_c;/* either 0/1, unused, or computed from cc_n and cc_v */ uint32_t cc_z;/* == 0 or unused */ -float64 fregs[8 ]; -float64 fp_result; +FPReg fregs[8 ]; +FPReg fp_result;uint32_t fpcr;uint32_t fpsr;float_status fp_status;
target/m68k/fpu_helper.c +47 -38
139 lines not on this page · raw message
target/m68k/helper.c +7 -5
@@ -73,10 +73,11 @@ void m68k_cpu_list(FILE *f, fprintf_function cpu_fprintf)g_slist_free (list); } -static int fpu_gdb_get_reg (CPUM68KState *env,uint8_t *mem_buf,int n) +static int cf_fpu_gdb_get_reg (CPUM68KState *env,uint8_t *mem_buf,int n) {if (n <8 ) { -stfq_p (mem_buf, env->fregs[n]); +float_status s; +stfq_p (mem_buf,floatx80_to_float64 (env->fregs[n].d, &s));return 8 ; }if (n <11 ) {
@@ -87,10 +88,11 @@ static int fpu_gdb_get_reg(CPUM68KState *env, uint8_t *mem_buf, int n)return 0 ; } -static int fpu_gdb_set_reg (CPUM68KState *env,uint8_t *mem_buf,int n) +static int cf_fpu_gdb_set_reg (CPUM68KState *env,uint8_t *mem_buf,int n) {if (n <8 ) { - env->fregs[n] =ldfq_p (mem_buf); +float_status s; + env->fregs[n].d =float64_to_floatx80 (ldfq_p (mem_buf), &s);return 8 ; }if (n <11 ) {
@@ -126,7 +128,7 @@ void m68k_cpu_init_gdb(M68kCPU *cpu)CPUM68KState *env = &cpu->env;if (m68k_feature (env,M68K_FEATURE_CF_FPU )) { -gdb_register_coprocessor (cs, fpu_gdb_get_reg, fpu_gdb_set_reg, +gdb_register_coprocessor (cs, cf_fpu_gdb_get_reg, cf_fpu_gdb_set_reg,11 ,"cf-fp.xml" ,18 ); }/* TODO: Add [E]MAC registers. */
target/m68k/helper.h +22 -15
@@ -12,21 +12,28 @@ DEF_HELPER_3(movec, void, env, i32, i32) DEF_HELPER_4(cas2w, void, env, i32, i32, i32) DEF_HELPER_4(cas2l, void, env, i32, i32, i32) -DEF_HELPER_2(f64_to_i32, f32, env, f64) -DEF_HELPER_2(f64_to_f32, f32, env, f64) -DEF_HELPER_2(i32_to_f64, f64, env, i32) -DEF_HELPER_2(f32_to_f64, f64, env, f32) -DEF_HELPER_2(iround_f64, f64, env, f64) -DEF_HELPER_2(itrunc_f64, f64, env, f64) -DEF_HELPER_2(sqrt_f64, f64, env, f64) -DEF_HELPER_1(abs_f64, f64, f64) -DEF_HELPER_1(chs_f64, f64, f64) -DEF_HELPER_3(add_f64, f64, env, f64, f64) -DEF_HELPER_3(sub_f64, f64, env, f64, f64) -DEF_HELPER_3(mul_f64, f64, env, f64, f64) -DEF_HELPER_3(div_f64, f64, env, f64, f64) -DEF_HELPER_3(sub_cmp_f64, f64, env, f64, f64) -DEF_HELPER_2(compare_f64, i32, env, f64) +#define dh_alias_fp ptr +#define dh_ctype_fp FPReg * +#define dh_is_signed_fp dh_is_signed_ptr + +DEF_HELPER_3(exts32, void, env, fp, s32) +DEF_HELPER_3(extf32, void, env, fp, f32) +DEF_HELPER_3(extf64, void, env, fp, f64) +DEF_HELPER_2(redf32, f32, env, fp) +DEF_HELPER_2(redf64, f64, env, fp) +DEF_HELPER_2(reds32, s32, env, fp) + +DEF_HELPER_3(firound, void, env, fp, fp) +DEF_HELPER_3(fitrunc, void, env, fp, fp) +DEF_HELPER_3(fsqrt, void, env, fp, fp) +DEF_HELPER_3(fabs, void, env, fp, fp) +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(fdiv, void, env, fp, fp, fp) +DEF_HELPER_4(fsub_cmp, void, env, fp, fp, fp) +DEF_HELPER_2(fcompare, i32, env, fp) DEF_HELPER_3(mac_move, void, env, i32, i32)DEF_HELPER_3 (macmulf, i64, env, i32, i32)
target/m68k/qregs.def +0 -1
@@ -1,4 +1,3 @@ -DEFF64(FP_RESULT, fp_result) DEFO32(PC, pc) DEFO32(SR, sr) DEFO32(CC_OP, cc_op)
target/m68k/translate.c +376 -192
774 lines not on this page · raw message
Signature · 1 line
2.9.4
Re: [Qemu-devel] [PATCH v4 5/7] target-m68k: use floatx80 internally
Quoted 29 lines · Laurent Vivier
Coldfire uses float64, but 680x0 use floatx80. This patch introduces the use of floatx80 internally and enables 680x0 80bits FPU.
Signed-off-by Laurent Vivier <[email protected]>--- target/m68k/cpu.c | 9 +- target/m68k/cpu.h | 6 +- target/m68k/fpu_helper.c | 85 +++---- target/m68k/helper.c | 12 +- target/m68k/helper.h | 37 +-- target/m68k/qregs.def | 1 - target/m68k/translate.c | 568 +++++++++++++++++++++++++++++++---------------- 7 files changed, 464 insertions(+), 254 deletions(-)target/m68k/cpu.c +2
-0@@ -49,6 +49,8 @@ static void m68k_cpu_reset(CPUState *s)M68kCPU *cpu =M68K_CPU (s);M68kCPUClass *mcc =M68K_CPU_GET_CLASS (cpu);CPUM68KState *env = &cpu->env; +floatx80 nan =floatx80_default_nan (NULL ); +int i; mcc->parent_reset (s);
target/m68k/cpu.c static void m68k_cpu_reset(CPUState *s) · line 67
Quoted 10 lines
target/m68k/cpu.c +6
-1@@ -57,7 +59,12 @@ static void m68k_cpu_reset(CPUState *s) env->sr =0x2700 ;#endif m68k_switch_sp (env); -/* ??? FP regs should be initialized to NaN. */ +for (i =0 ; i <8 ; i++) { + env->fregs[i].d = nan; + } + env->fpcr =0 ; + env->fpsr =0 ; +
Maybe move such non-related hunks to a separate patch? This patch here is already big enough...
Thomas
Re: [Qemu-devel] [PATCH v4 5/7] target-m68k: use floatx80 internally
In reply to Laurent VivierQuoted 34 lines · Laurent Vivier
target/m68k/translate.c +34
-0+static void gen_load_fp (DisasContext *s,int opsize,TCGv addr,TCGv_ptr fp) +{ +TCGv tmp; +TCGv_i64 t64; +int index =IS_USER (s); + + t64 =tcg_temp_new_i64 (); + tmp =tcg_temp_new (); +switch (opsize) { +case OS_BYTE : +tcg_gen_qemu_ld8s (tmp, addr, index); +gen_helper_exts32 (cpu_env, fp, tmp); +break ; +case OS_WORD : +tcg_gen_qemu_ld16s (tmp, addr, index); +gen_helper_exts32 (cpu_env, fp, tmp); +break ; +case OS_LONG : +tcg_gen_qemu_ld32u (tmp, addr, index); +gen_helper_exts32 (cpu_env, fp, tmp); +break ; +case OS_SINGLE : +tcg_gen_qemu_ld32u (tmp, addr, index); +gen_helper_extf32 (cpu_env, fp, tmp); +break ; +case OS_DOUBLE : +tcg_gen_qemu_ld64 (t64, addr, index); +gen_helper_extf64 (cpu_env, fp, t64); +tcg_temp_free_i64 (t64); +break ; +case OS_EXTENDED : +tcg_gen_qemu_ld32u (tmp, addr, index); +tcg_gen_shri_i32 (tmp, tmp,16 ); + tcg_gen_st16_i32(tmp, fp, offsetof(FPReg, l.upper));
target/m68k/translate.c static TCGv gen_ea(CPUM68KState *env, DisasContext *s, uint16_t insn, · line 959
Quoted 10 lines
target/m68k/translate.c +10
-0+tcg_gen_addi_i32 (tmp, addr,4 ); +tcg_gen_qemu_ld64 (t64, tmp, index); + tcg_gen_st_i64(t64, fp, offsetof(FPReg, l.lower)); +break ; +case OS_PACKED : +tcg_gen_qemu_ld32u (tmp, addr, index); + tcg_gen_st16_i32(tmp, fp, offsetof(FPReg, l.upper)); +tcg_gen_addi_i32 (tmp, addr,4 ); +tcg_gen_qemu_ld64 (t64, tmp, index); + tcg_gen_st_i64(t64, fp, offsetof(FPReg, l.lower));
I don't see how this can be correct. Doesn't the packed-decimal format use all 12 bytes (with two unaligned nibbles unused)?
It would also make me happier if we were to adjust the definition of fl0atx80 to more closely match m68k and those missing zeros. Shouldn't real hardware move instructions propagate those middle 2 bytes regardless of contents?
Perhaps something like
#ifdef TARGET_M68K
typedef struct {
uint64_t low;
union {
uin32_t high32;
struct {
#ifdef HOST_WORDS_BIGENDIAN
uint16_t high, zero;
#else
uint16_t zero, high;
#endif
};
}; } floatx80;
#else
...
#endif
(with a minor fix to make_floatx80 to use named initializers).
Then you can use full 32-bit store insns when copying data here. Which also allows you to drop some of the shifts you're needing to add.
And, in future, when you actually implement the packed decimal, you'll be able to use the high32 field to Do the Right Thing.
All of the rest of the patch looks good.
r~
Re: [Qemu-devel] [PATCH v4 5/7] target-m68k: use floatx80 internally
Quoted 41 lines · Richard Henderson
Quoted 40 lines · Laurent Vivier
+static void
gen_load_fp(DisasContext *s, int opsize, TCGv addr, TCGv_ptr fp)target/m68k/translate.c +38
-0+{ +TCGv tmp; +TCGv_i64 t64; +int index =IS_USER (s); + + t64 =tcg_temp_new_i64 (); + tmp =tcg_temp_new (); +switch (opsize) { +case OS_BYTE : +tcg_gen_qemu_ld8s (tmp, addr, index); +gen_helper_exts32 (cpu_env, fp, tmp); +break ; +case OS_WORD : +tcg_gen_qemu_ld16s (tmp, addr, index); +gen_helper_exts32 (cpu_env, fp, tmp); +break ; +case OS_LONG : +tcg_gen_qemu_ld32u (tmp, addr, index); +gen_helper_exts32 (cpu_env, fp, tmp); +break ; +case OS_SINGLE : +tcg_gen_qemu_ld32u (tmp, addr, index); +gen_helper_extf32 (cpu_env, fp, tmp); +break ; +case OS_DOUBLE : +tcg_gen_qemu_ld64 (t64, addr, index); +gen_helper_extf64 (cpu_env, fp, t64); +tcg_temp_free_i64 (t64); +break ; +case OS_EXTENDED : +tcg_gen_qemu_ld32u (tmp, addr, index); +tcg_gen_shri_i32 (tmp, tmp,16 ); + tcg_gen_st16_i32(tmp, fp, offsetof(FPReg, l.upper)); +tcg_gen_addi_i32 (tmp, addr,4 ); +tcg_gen_qemu_ld64 (t64, tmp, index); + tcg_gen_st_i64(t64, fp, offsetof(FPReg, l.lower)); +break ; +case OS_PACKED :
Quoted 8 lines
target/m68k/translate.c static TCGv gen_ea(CPUM68KState *env, DisasContext *s, uint16_t insn, · line 952
Quoted 5 lines
target/m68k/translate.c +5
-0+tcg_gen_qemu_ld32u (tmp, addr, index); + tcg_gen_st16_i32(tmp, fp, offsetof(FPReg, l.upper)); +tcg_gen_addi_i32 (tmp, addr,4 ); +tcg_gen_qemu_ld64 (t64, tmp, index); + tcg_gen_st_i64(t64, fp, offsetof(FPReg, l.lower));I don't see how this can be correct. Doesn't the packed-decimal format use all 12 bytes (with two unaligned nibbles unused)?
yes, it's totally wrong.
Quoted 26 lines
It would also make me happier if we were to adjust the definition of fl0atx80 to more closely match m68k and those missing zeros. Shouldn't real hardware move instructions propagate those middle 2 bytes regardless of contents?
Perhaps something like
#ifdef
TARGET_M68Ktypedef struct { uint64_t low; union { uin32_t high32; struct { #ifdef HOST_WORDS_BIGENDIAN uint16_t high, zero; #else uint16_t zero, high; #endif }; };} floatx80;
#else
...
#endif
Quoted 4 lines
(with a minor fix to
make_floatx80to use named initializers).Then you can use full 32-bit store insns when copying data here. Which also allows you to drop some of the shifts you're needing to add.
OK, I will.
Quoted 4 lines
And, in future, when you actually implement the packed decimal, you'll be able to use the high32 field to Do the Right Thing.
All of the rest of the patch looks good.
Thanks,
Laurent
Re: [Qemu-devel] [PATCH v4 5/7] target-m68k: use floatx80 internally
Quoted 27 lines · Laurent Vivier
Quoted 26 lines · Richard Henderson
It would also make me happier if we were to adjust the definition of fl0atx80 to more closely match m68k and those missing zeros. Shouldn't real hardware move instructions propagate those middle 2 bytes regardless of contents?
Perhaps something like
#ifdef
TARGET_M68Ktypedef struct { uint64_t low; union { uin32_t high32; struct { #ifdef HOST_WORDS_BIGENDIAN uint16_t high, zero; #else uint16_t zero, high; #endif }; };} floatx80;
#else
...
#endif
Quoted 6 lines
Quoted 4 lines
(with a minor fix to
make_floatx80to use named initializers).Then you can use full 32-bit store insns when copying data here. Which also allows you to drop some of the shifts you're needing to add.
OK, I will.
The softfloat is in the target independent code, so we can't adjust the size of floatx80 by target, TARGET_XXXX are poisoned when used in softfloat.h.
Laurent
Re: [Qemu-devel] [PATCH v4 5/7] target-m68k: use floatx80 internally
Quoted 30 lines · Laurent Vivier
Quoted 29 lines · Laurent Vivier
Quoted 28 lines · Richard Henderson
It would also make me happier if we were to adjust the definition of fl0atx80 to more closely match m68k and those missing zeros. Shouldn't real hardware move instructions propagate those middle 2 bytes regardless of contents?
Perhaps something like
#ifdef TARGET_M68K typedef struct { uint64_t low; union { uin32_t high32; struct { #ifdef HOST_WORDS_BIGENDIAN uint16_t high, zero; #else uint16_t zero, high; #endif }; }; } floatx80; #else ...#endif
(with a minor fix to
make_floatx80to use named initializers).
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Then you can use full 32-bit store insns when copying data here. Which also allows you to drop some of the shifts you're needing to add.
OK, I will.
The softfloat is in the target independent code, so we can't adjust the size of floatx80 by target,
TARGET_XXXXare poisoned when used insoftfloat.h.
Ouch. That means we'd have to add a full set of floatx96.
If you don't want to do that now, I'd understand. I'd prefer that you issue an undefined opcode exception or something for the packed decimals though, rather than just silently dropping 2 bytes of data.
I suppose a first go at floatx96 would be just to thunk the data and call to the floatx80 routines. I do seem to recall that a Proper implementation would treat m68k un-normals different from x86.
r~
PATCH v4 6/7 target-m68k: define 96bit FP registers for gdb on 680x0
In reply to Laurent Vivier--- configure | 2 +- gdb-xml/m68k-fp.xml | 21 +++++++++++++++++++++ target/m68k/helper.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 gdb-xml/m68k-fp.xml
configure +1 -1
@@ -6056,7 +6056,7 @@ case "$target_name" in ;; m68k) bflt="yes" - gdb_xml_files="cf-core.xml cf-fp.xml" + gdb_xml_files="cf-core.xml cf-fp.xml m68k-fp.xml" ;; microblaze|microblazeel) TARGET_ARCH=microblaze
gdb-xml/m68k-fp.xml new file +21 -0
@@ -0,0 +1,21 @@ +<?xml version="1.0"?> +<!-- Copyright (C) 2008 Free Software Foundation, Inc. + + Copying and distribution of this file, with or without modification, + are permitted in any medium without royalty provided the copyright + notice and this notice are preserved. --> +<!DOCTYPE feature SYSTEM "gdb-target.dtd"> +<feature name="org.gnu.gdb.coldfire.fp"> + <reg name="fp0" bitsize="96" type="float" group="float"/> + <reg name="fp1" bitsize="96" type="float" group="float"/> + <reg name="fp2" bitsize="96" type="float" group="float"/> + <reg name="fp3" bitsize="96" type="float" group="float"/> + <reg name="fp4" bitsize="96" type="float" group="float"/> + <reg name="fp5" bitsize="96" type="float" group="float"/> + <reg name="fp6" bitsize="96" type="float" group="float"/> + <reg name="fp7" bitsize="96" type="float" group="float"/> + + <reg name="fpcontrol" bitsize="32" group="float"/> + <reg name="fpstatus" bitsize="32" group="float"/>, + <reg name="fpiaddr" bitsize="32" type="code_ptr" group="float"/> +</feature>
target/m68k/helper.c +45 -0
57 lines not on this page · raw message
Signature · 1 line
2.9.4
PATCH v4 7/7 target-m68k: add FPCR and FPSR
In reply to Laurent Vivier--- target/m68k/cpu.c | 2 +- target/m68k/cpu.h | 36 ++++- target/m68k/fpu_helper.c | 118 ++++++++++++++--- target/m68k/helper.c | 20 ++- target/m68k/helper.h | 5 +- target/m68k/qregs.def | 1 + target/m68k/translate.c | 335 +++++++++++++++++++++++++++++++++-------------- 7 files changed, 395 insertions(+), 122 deletions(-)
target/m68k/cpu.c +1 -1
@@ -62,7 +62,7 @@ static void m68k_cpu_reset(CPUState *s)for (i =0 ; i <8 ; i++) { env->fregs[i].d = nan; } - env->fpcr =0 ; +cpu_m68k_set_fpcr (env,0 ); env->fpsr =0 ;cpu_m68k_set_ccr (env,0 );
target/m68k/cpu.h +32 -4
@@ -164,6 +164,7 @@ int cpu_m68k_signal_handler(int host_signum, void *pinfo, void *puc);uint32_t cpu_m68k_get_ccr (CPUM68KState *env);void cpu_m68k_set_ccr (CPUM68KState *env,uint32_t ); +void cpu_m68k_set_fpcr (CPUM68KState *env,uint32_t val);/* Instead of computing the condition codes after each m68k instruction,
@@ -208,6 +209,36 @@ typedef enum {#define M68K_SSP 0#define M68K_USP 1 +/* Floating-Point Status Register */ + +/* Condition Code */ +#define FPSR_CC_MASK 0x0f000000 +#define FPSR_CC_A 0x01000000/* Not-A-Number */ +#define FPSR_CC_I 0x02000000/* Infinity */ +#define FPSR_CC_Z 0x04000000/* Zero */ +#define FPSR_CC_N 0x08000000/* Negative */ + +/* Quotient */ + +#define FPSR_QT_MASK 0x00ff0000 + +/* Floating-Point Control Register */ +/* Rounding mode */ +#define FPCR_RND_MASK 0x0030 +#define FPCR_RND_N 0x0000 +#define FPCR_RND_Z 0x0010 +#define FPCR_RND_M 0x0020 +#define FPCR_RND_P 0x0030 + +/* Rounding precision */ +#define FPCR_PREC_MASK 0x00c0 +#define FPCR_PREC_X 0x0000 +#define FPCR_PREC_S 0x0040 +#define FPCR_PREC_D 0x0080 +#define FPCR_PREC_U 0x00c0 + +#define FPCR_EXCP_MASK 0xff00 +/* CACR fields are implementation defined, but some bits are common. */ #define M68K_CACR_EUSP 0x10
@@ -224,8 +255,6 @@ typedef enum {void m68k_set_irq_level (M68kCPU *cpu,int level,uint8_t vector);void m68k_switch_sp (CPUM68KState *env); -#define M68K_FPCR_PREC (1 << 6) -void do_m68k_semihosting (CPUM68KState *env,int nr);/* There are 4 ColdFire core ISA revisions: A, A+, B and C.
@@ -303,8 +332,7 @@ static inline void cpu_get_tb_cpu_state(CPUM68KState *env, target_ulong *pc, { *pc = env->pc; *cs_base =0 ; - *flags = (env->fpcr &M68K_FPCR_PREC )/* Bit 6 */ - | (env->sr &SR_S )/* Bit 13 */ + *flags = (env->sr &SR_S )/* Bit 13 */ | ((env->macsr >>4 ) &0xf );/* Bits 0-3 */ }
target/m68k/fpu_helper.c +102 -16
135 lines not on this page · raw message
target/m68k/helper.c +16 -4
@@ -80,8 +80,14 @@ static int cf_fpu_gdb_get_reg(CPUM68KState *env, uint8_t *mem_buf, int n)stfq_p (mem_buf,floatx80_to_float64 (env->fregs[n].d, &s));return 8 ; } -if (n <11 ) { -/* FP control registers (not implemented) */ +switch (n) { +case 8 :/* fpcontrol */ +stl_be_p (mem_buf, env->fpcr); +return 4 ; +case 9 :/* fpstatus */ +stl_be_p (mem_buf, env->fpsr); +return 4 ; +case 10 :/* fpiar, not implemented */ memset (mem_buf,0 ,4 );return 4 ; }
@@ -95,8 +101,14 @@ static int cf_fpu_gdb_set_reg(CPUM68KState *env, uint8_t *mem_buf, int n) env->fregs[n].d =float64_to_floatx80 (ldfq_p (mem_buf), &s);return 8 ; } -if (n <11 ) { -/* FP control registers (not implemented) */ +switch (n) { +case 8 :/* fpcontrol */ + env->fpcr =ldl_p (mem_buf); +return 4 ; +case 9 :/* fpstatus */ + env->fpsr =ldl_p (mem_buf); +return 4 ; +case 10 :/* fpiar, not implemented */ return 4 ; }return 0 ;
target/m68k/helper.h +3 -2
@@ -32,8 +32,9 @@ 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(fdiv, void, env, fp, fp, fp) -DEF_HELPER_4(fsub_cmp, void, env, fp, fp, fp) -DEF_HELPER_2(fcompare, i32, env, fp) +DEF_HELPER_FLAGS_4(fcmp, TCG_CALL_NO_RWG, i32, env, i32, fp, fp) +DEF_HELPER_2(set_fpcr, void, env, i32) +DEF_HELPER_FLAGS_3(ftst, TCG_CALL_NO_RWG, i32, env, i32, fp) DEF_HELPER_3(mac_move, void, env, i32, i32)DEF_HELPER_3 (macmulf, i64, env, i32, i32)
target/m68k/qregs.def +1 -0
@@ -8,3 +8,4 @@ DEFO32(CC_V, cc_v) DEFO32(CC_Z, cc_z) DEFO32(MACSR, macsr) DEFO32(MAC_MASK, mac_mask) +DEFO32(FPSR, fpsr)
target/m68k/translate.c +240 -95
454 lines not on this page · raw message
Signature · 1 line
2.9.4
Re: [Qemu-devel] [PATCH v4 7/7] target-m68k: add FPCR and FPSR
target/m68k/helper.c static int cf_fpu_gdb_set_reg(CPUM68KState *env, uint8_t *mem_buf, int n) · line 107
Quoted 10 lines · Laurent Vivier
target/m68k/helper.c +4
-2@@ -95,8 +101,14 @@ static int cf_fpu_gdb_set_reg(CPUM68KState *env, uint8_t *mem_buf, int n) env->fregs[n].d =float64_to_floatx80 (ldfq_p (mem_buf), &s);return 8 ; } -if (n <11 ) { -/* FP control registers (not implemented) */ +switch (n) { +case 8 :/* fpcontrol */ + env->fpcr =ldl_p (mem_buf); +return 4 ;
Should use cpu_m68k_set_fpcr.
target/m68k/helper.h DEF_HELPER_4(fadd, void, env, fp, fp, fp) · line 36
Quoted 1 line
target/m68k/helper.h +1
-0+DEF_HELPER_2 (set_fpcr, void, env, i32)
Hmm. I suppose the write to env->fpcr means you can't indicate TCG_CALL_NO_RWG. I wonder if it's better as
uint32_t HELPER(set_fpcr)(CPUM68KState *env, uint32_t val) {
cpu_m68k_set_fpcr(env, val);
return env->fpcr;
}
DEF_HELPER_FLAGS_2(set_fpcr, i32, env, i32)
gen_helper_set_fpcr(QEMU_FPCR, cpu_env, val);
This skirts the rules of TCG, but it'll work, since we disguise the (incorrect) write to env->fpcr with a (correct but redundant) write to QEMU_FPCR.
Any time we can avoid spilling all globals we're better off.
As an alternative, is it really that important to represent FPSR and FPCR as tcg registers? Perhaps it's better to just tcg_gen_ld/st instead?
r~