target-m68k: implement 680x0 FPU
v2 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 and several floating point instructions.
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.
After this series is applied, qemu-m68k can run a debian etch-m68k or a debian unstable chroot.
v2:
complete rework of the series
force single precision in ColdFire mode
add "forced" precision instructions (fsmove, fdmove, fsadd, ...) fixed Fcc.
Laurent Vivier (16):
softfloat: define 680x0 specific values
softloat: disable floatx80_invalid_encoding() for m68k
target-m68k: move FPU helpers to fpu_helper.c
target-m68k: define ext_opsize
target-m68k: use floatx80 internally
target-m68k: add FPCR and FPSR
target-m68k: manage FPU exceptions
target-m68k: define 96bit FP registers for gdb on 680x0
target-m68k: add fmovem
target-m68k: add fscc.
target-m68k: add fmovecr
target-m68k: add fscale, fgetman, fgetexp and fmod
target-m68k: add fsglmul and fsgldiv
target-m68k: add explicit single and double precision operations
target-m68k: add more FPU instructions
target-m68k: add fsincos
configure | 2 +- fpu/softfloat-specialize.h | 30 +- fpu/softfloat.c | 20 + gdb-xml/m68k-fp.xml | 21 + include/fpu/softfloat.h | 15 - target/m68k/Makefile.objs | 2 +- target/m68k/cpu.c | 13 +- target/m68k/cpu.h | 75 ++- target/m68k/fpu_helper.c | 972 ++++++++++++++++++++++++++++++++ target/m68k/helper.c | 165 +++--- target/m68k/helper.h | 73 ++- target/m68k/qregs.def | 4 +- target/m68k/translate.c | 1316 +++++++++++++++++++++++++++++++++----------- 13 files changed, 2238 insertions(+), 470 deletions(-) create mode 100644 gdb-xml/m68k-fp.xml create mode 100644 target/m68k/fpu_helper.c
Signature · 1 line
2.9.3
PATCH v2 1/16 softfloat: define 680x0 specific values
--- fpu/softfloat-specialize.h | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-)
fpu/softfloat-specialize.h +27 -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,26 @@ 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) +{ +/* 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 (aIsSNaN) { +return 0 ; + }else if (bIsSNaN) { +return 1 ; + }else if (bIsQNaN) { +return 1 ; + }else { +return 0 ; + } +}#else static int pickNaN (flag aIsQNaN,flag aIsSNaN,flag bIsQNaN,flag bIsSNaN,flag aIsLargerSignificand)
Signature · 1 line
2.9.3
Re: [Qemu-devel] [PATCH v2 01/16] softfloat: define 680x0 specific values
Quoted 11 lines · Laurent Vivier
Signed-off-by Laurent Vivier <[email protected]>fpu/softfloat-specialize.h +10
-0+#elif defined(TARGET_M68K ) +static int pickNaN (flag aIsQNaN,flag aIsSNaN,flag bIsQNaN,flag bIsSNaN, +flag aIsLargerSignificand) +{ +/* 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. +*/ +
fpu/softfloat-specialize.h static int pickNaN(flag aIsQNaN, flag aIsSNaN, flag bIsQNaN, flag bIsSNaN, · line 528
Quoted 10 lines
fpu/softfloat-specialize.h +10
-0+if (aIsSNaN) { +return 0 ; + }else if (bIsSNaN) { +return 1 ; + }else if (bIsQNaN) { +return 1 ; + }else { +return 0 ; + } +}
This function doesn't seem to quite do what the comment says (in particular the comment doesn't say anything about handling of signaling NaNs but the code makes decisions based on which inputs are signaling).
PS: NaN is conventionally capitalized with a lowercase 'a'.
thanks
-- PMM
PATCH v2 2/16 softloat: disable floatx80_invalid_encoding() for m68k
In reply to Laurent VivierAccording to the comment, this definition of invalid encoding is given by intel developer's manual, and doesn't work with the behavior of 680x0 FPU.
--- fpu/softfloat.c | 20 ++++++++++++++++++++ include/fpu/softfloat.h | 15 --------------- 2 files changed, 20 insertions(+), 15 deletions(-)
fpu/softfloat.c +20 -0
@@ -4799,6 +4799,26 @@ int float64_unordered_quiet(float64 a, float64 b, float_status *status) }/*---------------------------------------------------------------------------- +| Return whether the given value is an invalid floatx80 encoding. +| Invalid floatx80 encodings arise when the integer bit is not set, but +| the exponent is not zero. The only times the integer bit is permitted to +| be zero is in subnormal numbers and the value zero. +| This includes what the Intel software developer's manual calls pseudo-NaNs, +| pseudo-infinities and un-normal numbers. It does not include +| pseudo-denormals, which must still be correctly handled as inputs even +| if they are never generated as outputs. +*----------------------------------------------------------------------------*/ +static inline bool floatx80_invalid_encoding (floatx80 a) +{ +#if defined(TARGET_M68K ) +return 0 ; +#else +return (a.low & (1ULL <<63 )) ==0 && (a.high &0x7FFF ) !=0 ; +#endif +} + + +/*---------------------------------------------------------------------------- | Returns the result of converting the extended double-precision floating- | point value `a' to the 32-bit two's complement integer format. The | conversion is performed according to the IEC/IEEE Standard for Binary
include/fpu/softfloat.h +0 -15
@@ -658,21 +658,6 @@ static inline int floatx80_is_any_nan(floatx80 a)return ((a.high &0x7fff ) ==0x7fff ) && (a.low<<1 ); } -/*---------------------------------------------------------------------------- -| Return whether the given value is an invalid floatx80 encoding. -| Invalid floatx80 encodings arise when the integer bit is not set, but -| the exponent is not zero. The only times the integer bit is permitted to -| be zero is in subnormal numbers and the value zero. -| This includes what the Intel software developer's manual calls pseudo-NaNs, -| pseudo-infinities and un-normal numbers. It does not include -| pseudo-denormals, which must still be correctly handled as inputs even -| if they are never generated as outputs. -*----------------------------------------------------------------------------*/ -static inline bool floatx80_invalid_encoding (floatx80 a) -{ -return (a.low & (1ULL <<63 )) ==0 && (a.high &0x7FFF ) !=0 ; -} -#define floatx80_zero make_floatx80(0x0000, 0x0000000000000000LL)#define floatx80_one make_floatx80(0x3fff, 0x8000000000000000LL)#define floatx80_ln2 make_floatx80(0x3ffe, 0xb17217f7d1cf79acLL)
Signature · 1 line
2.9.3
Re: [Qemu-devel] [PATCH v2 02/16] softloat: disable floatx80_invalid_encoding() for m68k
Quoted 5 lines · Laurent Vivier
According to the comment, this definition of invalid encoding is given by intel developer's manual, and doesn't work with the behavior of 680x0 FPU.
Signed-off-by Laurent Vivier <[email protected]>
Part of the reason these checks are here is that the code behind them doesn't always cope nicely with the invalid encodings.
https://lists.nongnu.org/archive/html/qemu-devel/2016-08/msg01991.html
has an x86 test case for certain sqrt inputs that cause the floatx80_sqrt() function to go into an infinite loop, for instance.
I guess we need to look more carefully at exactly what the m68k does for these encodings (maybe have a 'normalize value' function which squashes them down to whatever the equivalent non-weird encoding is?).
thanks
-- PMM
Re: [Qemu-devel] [PATCH v2 02/16] softloat: disable floatx80_invalid_encoding() for m68k
Quoted 4 lines · Peter Maydell
I guess we need to look more carefully at exactly what the m68k does for these encodings (maybe have a 'normalize value' function which squashes them down to whatever the equivalent non-weird encoding is?).
On the m68k, the concept of pseudo-inf/nan doesn't exist, because the integer bit is don't-care for inf and nan. The combination of a zero integer bit with other non-zero biased exponents is called unnormal, and the 68881/2 will always convert them to normal/denormal/zero on input. (The 68040/60 don't support denormal/unnormal in hardware and lets the support library handle them, which presumably works the same way as the 68881/2.)
Andreas.
Signature · 3 lines
Andreas Schwab, [email protected] GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."
PATCH v2 3/16 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.3
PATCH v2 4/16 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)
@@ -4101,20 +4116,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 :
@@ -4143,8 +4157,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 :
@@ -4217,15 +4230,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.3
PATCH v2 5/16 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 | 13 +- target/m68k/cpu.h | 10 +- target/m68k/fpu_helper.c | 202 +++++++++++++--- target/m68k/helper.c | 12 +- target/m68k/helper.h | 32 +-- target/m68k/qregs.def | 3 +- target/m68k/translate.c | 615 +++++++++++++++++++++++++++++++---------------- 7 files changed, 615 insertions(+), 272 deletions(-)
target/m68k/cpu.c +12 -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,16 @@ 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->fp0h = nan.high; + env->fp0l = nan.low; + env->fp1h = nan.high; + env->fp1l = nan.low; + 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 +8 -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,12 +84,16 @@ 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 ];uint32_t fpcr;uint32_t fpsr;float_status fp_status; +uint32_t fp0h; +uint64_t fp0l; +uint32_t fp1h; +uint64_t fp1l; +uint64_t mactmp;/* EMAC Hardware deals with 48-bit values composed of one 32-bit and two 8-bit parts. We store a single 64-bit value and
target/m68k/fpu_helper.c +163 -39
261 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 +17 -15
@@ -12,21 +12,23 @@ 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) +DEF_HELPER_1(exts32_FP0, void, env) +DEF_HELPER_1(extf32_FP0, void, env) +DEF_HELPER_1(extf64_FP0, void, env) +DEF_HELPER_1(redf32_FP0, void, env) +DEF_HELPER_1(redf64_FP0, void, env) +DEF_HELPER_1(reds32_FP0, void, env) +DEF_HELPER_1(iround_FP0, void, env) +DEF_HELPER_1(itrunc_FP0, void, env) +DEF_HELPER_1(sqrt_FP0, void, env) +DEF_HELPER_1(abs_FP0, void, env) +DEF_HELPER_1(chs_FP0, void, env) +DEF_HELPER_1(add_FP0_FP1, void, env) +DEF_HELPER_1(sub_FP0_FP1, void, env) +DEF_HELPER_1(mul_FP0_FP1, void, env) +DEF_HELPER_1(div_FP0_FP1, void, env) +DEF_HELPER_1(cmp_FP0_FP1, void, env) +DEF_HELPER_1(compare_FP0, i32, env) DEF_HELPER_3(mac_move, void, env, i32, i32)DEF_HELPER_3 (macmulf, i64, env, i32, i32)
target/m68k/qregs.def +2 -1
@@ -1,4 +1,5 @@ -DEFF64(FP_RESULT, fp_result) +DEFF96(FP0, fp0) +DEFF96(FP1, fp1) DEFO32(PC, pc) DEFO32(SR, sr) DEFO32(CC_OP, cc_op)
target/m68k/translate.c +406 -209
813 lines not on this page · raw message
Signature · 1 line
2.9.3
PATCH v2 6/16 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 | 116 +++++++++++++++--- target/m68k/helper.c | 20 ++- target/m68k/helper.h | 3 +- target/m68k/qregs.def | 1 + target/m68k/translate.c | 311 +++++++++++++++++++++++++++++++++++------------ 7 files changed, 381 insertions(+), 108 deletions(-)
target/m68k/cpu.c +1 -1
@@ -66,7 +66,7 @@ static void m68k_cpu_reset(CPUState *s) env->fp0l = nan.low; env->fp1h = nan.high; env->fp1l = nan.low; - env->fpcr =0 ; +cpu_m68k_set_fpcr (env,0 ); env->fpsr =0 ;cpu_m68k_set_ccr (env,0 );
target/m68k/cpu.h +32 -4
@@ -168,6 +168,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,
@@ -212,6 +213,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
@@ -228,8 +259,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.
@@ -306,8 +335,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 +99 -17
139 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 +2 -1
@@ -28,7 +28,8 @@ DEF_HELPER_1(sub_FP0_FP1, void, env) DEF_HELPER_1(mul_FP0_FP1, void, env) DEF_HELPER_1(div_FP0_FP1, void, env) DEF_HELPER_1(cmp_FP0_FP1, void, env) -DEF_HELPER_1(compare_FP0, i32, env) +DEF_HELPER_2(set_fpcr, void, env, i32) +DEF_HELPER_1(tst_FP0, void, env) DEF_HELPER_3(mac_move, void, env, i32, i32)DEF_HELPER_3 (macmulf, i64, env, i32, i32)
target/m68k/qregs.def +1 -0
@@ -10,3 +10,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 +230 -81
436 lines not on this page · raw message
Signature · 1 line
2.9.3
PATCH v2 7/16 target-m68k: manage FPU exceptions
In reply to Laurent Vivier--- target/m68k/cpu.h | 28 +++++++++++++ target/m68k/fpu_helper.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++- target/m68k/helper.h | 1 + target/m68k/translate.c | 27 ++++++++++++ 4 files changed, 162 insertions(+), 1 deletion(-)
target/m68k/cpu.h +28 -0
@@ -57,6 +57,15 @@#define EXCP_TRAP15 47/* User trap #15. */ #define EXCP_UNSUPPORTED 61#define EXCP_ICE 13 +#define EXCP_FP_BSUN 48/* Branch Set on Unordered */ +#define EXCP_FP_INEX 49/* Inexact result */ +#define EXCP_FP_DZ 50/* Divide by Zero */ +#define EXCP_FP_UNFL 51/* Underflow */ +#define EXCP_FP_OPERR 52/* Operand Error */ +#define EXCP_FP_OVFL 53/* Overflow */ +#define EXCP_FP_SNAN 54/* Signaling Not-A-Number */ +#define EXCP_FP_UNIMP 55/* Unimplemented Data type */ +#define EXCP_RTE 0x100#define EXCP_HALT_INSN 0x101
@@ -222,6 +231,25 @@ typedef enum {#define FPSR_CC_Z 0x04000000/* Zero */ #define FPSR_CC_N 0x08000000/* Negative */ +/* Exception Status */ +#define FPSR_ES_MASK 0x0000ff00 +#define FPSR_ES_BSUN 0x00008000/* Branch Set on Unordered */ +#define FPSR_ES_SNAN 0x00004000/* Signaling Not-A-Number */ +#define FPSR_ES_OPERR 0x00002000/* Operand Error */ +#define FPSR_ES_OVFL 0x00001000/* Overflow */ +#define FPSR_ES_UNFL 0x00000800/* Underflow */ +#define FPSR_ES_DZ 0x00000400/* Divide by Zero */ +#define FPSR_ES_INEX2 0x00000200/* Inexact operation */ +#define FPSR_ES_INEX 0x00000100/* Inexact decimal input */ + +/* Accrued Exception */ +#define FPSR_AE_MASK 0x000000ff +#define FPSR_AE_IOP 0x00000080/* Invalid Operation */ +#define FPSR_AE_OVFL 0x00000040/* Overflow */ +#define FPSR_AE_UNFL 0x00000020/* Underflow */ +#define FPSR_AE_DZ 0x00000010/* Divide by Zero */ +#define FPSR_AE_INEX 0x00000008/* Inexact */ +/* Quotient */ #define FPSR_QT_MASK 0x00ff0000
target/m68k/fpu_helper.c +106 -1
126 lines not on this page · raw message
target/m68k/helper.h +1 -0
@@ -30,6 +30,7 @@ DEF_HELPER_1(div_FP0_FP1, void, env) DEF_HELPER_1(cmp_FP0_FP1, void, env) DEF_HELPER_2(set_fpcr, void, env, i32) DEF_HELPER_1(tst_FP0, void, env) +DEF_HELPER_1(update_fpstatus, void, env) DEF_HELPER_3(mac_move, void, env, i32, i32)DEF_HELPER_3 (macmulf, i64, env, i32, i32)
target/m68k/translate.c +27 -0
@@ -4388,6 +4388,7 @@ static void gen_load_fcr(DisasContext *s, TCGv addr, int reg)switch (reg) {case 0 :/* FPSR */ tcg_gen_qemu_ld32u (QEMU_FPSR , addr, index); +gen_helper_update_fpstatus (cpu_env);break ;case 1 :/* FPIAR */ break ;
@@ -4431,6 +4432,7 @@ static void gen_op_fmove_fcr(CPUM68KState *env, DisasContext *s,case 2 :/* FPSR */ SRC_EA (env, val,OS_LONG ,0 ,NULL );tcg_gen_mov_i32 (QEMU_FPSR , val); +gen_helper_update_fpstatus (cpu_env);break ;case 4 :/* FPCR */ SRC_EA (env, val,OS_LONG ,0 ,NULL );
@@ -5481,6 +5483,21 @@ void m68k_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf, (env->fpsr &FPSR_CC_I ) ?'I' :'-' , (env->fpsr &FPSR_CC_Z ) ?'Z' :'-' , (env->fpsr & FPSR_CC_N) ? 'N' : '-'); +cpu_fprintf (f,"%c%c%c%c%c%c%c%c " , + (env->fpsr &FPSR_ES_BSUN ) ?'B' :'-' , + (env->fpsr &FPSR_ES_SNAN ) ?'A' :'-' , + (env->fpsr &FPSR_ES_OPERR ) ?'O' :'-' , + (env->fpsr &FPSR_ES_OVFL ) ?'V' :'-' , + (env->fpsr &FPSR_ES_UNFL ) ?'U' :'-' , + (env->fpsr &FPSR_ES_DZ ) ?'Z' :'-' , + (env->fpsr &FPSR_ES_INEX2 ) ?'2' :'-' , + (env->fpcr &FPSR_ES_INEX ) ?'I' :'-' ); +cpu_fprintf (f,"%c%c%c%c%c" , + (env->fpsr &FPSR_AE_IOP ) ?'O' :'-' , + (env->fpsr &FPSR_AE_OVFL ) ?'V' :'-' , + (env->fpsr &FPSR_AE_UNFL ) ?'U' :'-' , + (env->fpsr &FPSR_AE_DZ ) ?'Z' :'-' , + (env->fpcr &FPSR_ES_INEX ) ?'I' :'-' );cpu_fprintf (f,"\n " "FPCR = %04x " , env->fpcr);switch (env->fpcr &FPCR_PREC_MASK ) {
@@ -5508,6 +5525,16 @@ void m68k_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,cpu_fprintf (f,"RP " );break ; } +/* FPCR exception mask uses the same bitmask as FPSR */ +cpu_fprintf (f,"%c%c%c%c%c%c%c%c\n" , + (env->fpcr &FPSR_ES_BSUN ) ?'B' :'-' , + (env->fpcr &FPSR_ES_SNAN ) ?'A' :'-' , + (env->fpcr &FPSR_ES_OPERR ) ?'O' :'-' , + (env->fpcr &FPSR_ES_OVFL ) ?'V' :'-' , + (env->fpcr &FPSR_ES_UNFL ) ?'U' :'-' , + (env->fpcr &FPSR_ES_DZ ) ?'Z' :'-' , + (env->fpcr &FPSR_ES_INEX2 ) ?'2' :'-' , + (env->fpcr &FPSR_ES_INEX ) ?'I' :'-' ); } void restore_state_to_opc(CPUM68KState *env, TranslationBlock *tb,
Signature · 1 line
2.9.3
PATCH v2 8/16 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
@@ -5912,7 +5912,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.3
PATCH v2 9/16 target-m68k: add fmovem
In reply to Laurent Vivier--- target/m68k/fpu_helper.c | 6 +++ target/m68k/helper.h | 1 + target/m68k/translate.c | 99 +++++++++++++++++++++++++++++++++++------------- 3 files changed, 80 insertions(+), 26 deletions(-)
target/m68k/fpu_helper.c +6 -0
@@ -421,3 +421,9 @@ void HELPER(update_fpstatus)(CPUM68KState *env)set_float_exception_flags (flags, &env->fp_status); } + +void HELPER (fmovem )(CPUM68KState *env,uint32_t opsize, +uint32_t mode,uint32_t mask) +{ +fprintf (stderr,"MISSING HELPER fmovem\n" ); +}
target/m68k/helper.h +1 -0
@@ -31,6 +31,7 @@ DEF_HELPER_1(cmp_FP0_FP1, void, env) DEF_HELPER_2(set_fpcr, void, env, i32) DEF_HELPER_1(tst_FP0, void, env) DEF_HELPER_1(update_fpstatus, void, env) +DEF_HELPER_4(fmovem, void, env, i32, i32, i32) DEF_HELPER_3(mac_move, void, env, i32, i32)DEF_HELPER_3 (macmulf, i64, env, i32, i32)
target/m68k/translate.c +73 -26
118 lines not on this page · raw message
Signature · 1 line
2.9.3
PATCH v2 10/16 target-m68k: add fscc.
In reply to Laurent Vivieruse DisasCompare with FPU conditions in fscc and fbcc.
--- target/m68k/translate.c | 228 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 153 insertions(+), 75 deletions(-)
target/m68k/translate.c +153 -75
@@ -4654,139 +4654,215 @@ undef:disas_undef_fpu (env, s, insn); } -DISAS_INSN (fbcc) +static void gen_fcc_cond (DisasCompare *c,DisasContext *s,int cond) { -uint32_t offset; -uint32_t addr; -TCGLabel *l1; -TCGv tmp; - - addr = s->pc; - offset =cpu_ldsw_code (env, s->pc); - s->pc +=2 ; -if (insn & (1 <<6 )) { - offset = (offset <<16 ) |read_im16 (env, s); - } - - l1 =gen_new_label (); + c->g1 =0 ; + c->v2 =tcg_const_i32 (0 ); + c->g2 =1 ;/* TODO: Raise BSUN exception. */ -/* Jump to l1 if condition is true. */ -switch (insn &0x3f ) { +switch (cond) {case 0 :/* False */ case 16 :/* Signaling False */ + c->v1 = c->v2; + c->tcond =TCG_COND_NEVER ;break ;case 1 :/* EQual Z */ case 17 :/* Signaling EQual Z */ - tmp =tcg_temp_new (); -tcg_gen_andi_i32 (tmp,QREG_FPSR ,FPSR_CC_Z ); -tcg_gen_brcondi_i32 (TCG_COND_NE , tmp,0 , l1); + c->v1 =tcg_temp_new (); + c->g1 =1 ; +tcg_gen_andi_i32 (c->v1,QREG_FPSR ,FPSR_CC_Z ); + c->tcond =TCG_COND_NE ;break ;case 2 :/* Ordered Greater Than !(A || Z || N) */ case 18 :/* Greater Than !(A || Z || N) */ - tmp =tcg_temp_new (); -tcg_gen_andi_i32 (tmp,QREG_FPSR , + c->v1 =tcg_temp_new (); + c->g1 =1 ; +tcg_gen_andi_i32 (c->v1,QREG_FPSR ,FPSR_CC_A |FPSR_CC_Z |FPSR_CC_N ); -tcg_gen_brcondi_i32 (TCG_COND_EQ , tmp,0 , l1); + c->tcond =TCG_COND_EQ ;break ;case 3 :/* Ordered Greater than or Equal Z || !(A || N) */ case 19 :/* Greater than or Equal Z || !(A || N) */ assert (FPSR_CC_A == (FPSR_CC_N >>3 )); - tmp =tcg_temp_new (); -tcg_gen_shli_i32 (tmp,QREG_FPSR ,3 ); -tcg_gen_or_i32 (tmp, tmp,QREG_FPSR ); -tcg_gen_xori_i32 (tmp, tmp,FPSR_CC_N ); -tcg_gen_andi_i32 (tmp, tmp,FPSR_CC_N |FPSR_CC_Z ); -tcg_gen_brcondi_i32 (TCG_COND_NE , tmp,0 , l1); + c->v1 =tcg_temp_new (); + c->g1 =1 ; +tcg_gen_shli_i32 (c->v1,QREG_FPSR ,3 ); +tcg_gen_or_i32 (c->v1, c->v1,QREG_FPSR ); +tcg_gen_xori_i32 (c->v1, c->v1,FPSR_CC_N ); +tcg_gen_andi_i32 (c->v1, c->v1,FPSR_CC_N |FPSR_CC_Z ); + c->tcond =TCG_COND_NE ;break ;case 4 :/* Ordered Less Than !(!N || A || Z); */ case 20 :/* Less Than !(!N || A || Z); */ - tmp =tcg_temp_new (); -tcg_gen_xori_i32 (tmp,QREG_FPSR ,FPSR_CC_N ); -tcg_gen_andi_i32 (tmp, tmp,FPSR_CC_N |FPSR_CC_A |FPSR_CC_Z ); -tcg_gen_brcondi_i32 (TCG_COND_EQ , tmp,0 , l1); + c->v1 =tcg_temp_new (); + c->g1 =1 ; +tcg_gen_xori_i32 (c->v1,QREG_FPSR ,FPSR_CC_N ); +tcg_gen_andi_i32 (c->v1, c->v1,FPSR_CC_N |FPSR_CC_A |FPSR_CC_Z ); + c->tcond =TCG_COND_EQ ;break ;case 5 :/* Ordered Less than or Equal Z || (N && !A) */ case 21 :/* Less than or Equal Z || (N && !A) */ assert (FPSR_CC_A == (FPSR_CC_N >>3 )); - tmp =tcg_temp_new (); -tcg_gen_xori_i32 (tmp,QREG_FPSR ,FPSR_CC_A ); -tcg_gen_shli_i32 (tmp, tmp,3 ); -tcg_gen_ori_i32 (tmp, tmp,FPSR_CC_Z ); -tcg_gen_and_i32 (tmp, tmp,QREG_FPSR ); -tcg_gen_brcondi_i32 (TCG_COND_NE , tmp,0 , l1); + c->v1 =tcg_temp_new (); + c->g1 =1 ; +tcg_gen_xori_i32 (c->v1,QREG_FPSR ,FPSR_CC_A ); +tcg_gen_shli_i32 (c->v1, c->v1,3 ); +tcg_gen_ori_i32 (c->v1, c->v1,FPSR_CC_Z ); +tcg_gen_and_i32 (c->v1, c->v1,QREG_FPSR ); + c->tcond =TCG_COND_NE ;break ;case 6 :/* Ordered Greater or Less than !(A || Z) */ case 22 :/* Greater or Less than !(A || Z) */ - tmp =tcg_temp_new (); -tcg_gen_andi_i32 (tmp,QREG_FPSR ,FPSR_CC_A |FPSR_CC_Z ); -tcg_gen_brcondi_i32 (TCG_COND_EQ , tmp,0 , l1); + c->v1 =tcg_temp_new (); + c->g1 =1 ; +tcg_gen_andi_i32 (c->v1,QREG_FPSR ,FPSR_CC_A |FPSR_CC_Z ); + c->tcond =TCG_COND_EQ ;break ;case 7 :/* Ordered !A */ case 23 :/* Greater, Less or Equal !A */ - tmp =tcg_temp_new (); -tcg_gen_andi_i32 (tmp,QREG_FPSR ,FPSR_CC_A ); -tcg_gen_brcondi_i32 (TCG_COND_EQ , tmp,0 , l1); + c->v1 =tcg_temp_new (); + c->g1 =1 ; +tcg_gen_andi_i32 (c->v1,QREG_FPSR ,FPSR_CC_A ); + c->tcond =TCG_COND_EQ ;break ;case 8 :/* Unordered A */ case 24 :/* Not Greater, Less or Equal A */ - tmp =tcg_temp_new (); -tcg_gen_andi_i32 (tmp,QREG_FPSR ,FPSR_CC_A ); -tcg_gen_brcondi_i32 (TCG_COND_NE , tmp,0 , l1); + c->v1 =tcg_temp_new (); + c->g1 =1 ; +tcg_gen_andi_i32 (c->v1,QREG_FPSR ,FPSR_CC_A ); + c->tcond =TCG_COND_NE ;break ;case 9 :/* Unordered or Equal A || Z */ case 25 :/* Not Greater or Less then A || Z */ - tmp =tcg_temp_new (); -tcg_gen_andi_i32 (tmp,QREG_FPSR ,FPSR_CC_A |FPSR_CC_Z ); -tcg_gen_brcondi_i32 (TCG_COND_NE , tmp,0 , l1); + c->v1 =tcg_temp_new (); + c->g1 =1 ; +tcg_gen_andi_i32 (c->v1,QREG_FPSR ,FPSR_CC_A |FPSR_CC_Z ); + c->tcond =TCG_COND_NE ;break ;case 10 :/* Unordered or Greater Than A || !(N || Z)) */ case 26 :/* Not Less or Equal A || !(N || Z)) */ assert (FPSR_CC_Z == (FPSR_CC_N >>1 )); - tmp =tcg_temp_new (); -tcg_gen_shli_i32 (tmp,QREG_FPSR ,1 ); -tcg_gen_or_i32 (tmp, tmp,QREG_FPSR ); -tcg_gen_xori_i32 (tmp, tmp,FPSR_CC_N ); -tcg_gen_andi_i32 (tmp, tmp,FPSR_CC_N |FPSR_CC_A ); -tcg_gen_brcondi_i32 (TCG_COND_NE , tmp,0 , l1); + c->v1 =tcg_temp_new (); + c->g1 =1 ; +tcg_gen_shli_i32 (c->v1,QREG_FPSR ,1 ); +tcg_gen_or_i32 (c->v1, c->v1,QREG_FPSR ); +tcg_gen_xori_i32 (c->v1, c->v1,FPSR_CC_N ); +tcg_gen_andi_i32 (c->v1, c->v1,FPSR_CC_N |FPSR_CC_A ); + c->tcond =TCG_COND_NE ;break ;case 11 :/* Unordered or Greater or Equal A || Z || !N */ case 27 :/* Not Less Than A || Z || !N */ - tmp =tcg_temp_new (); -tcg_gen_andi_i32 (tmp,QREG_FPSR ,FPSR_CC_A |FPSR_CC_Z |FPSR_CC_N ); -tcg_gen_xori_i32 (tmp, tmp,FPSR_CC_N ); -tcg_gen_brcondi_i32 (TCG_COND_NE , tmp,0 , l1); + c->v1 =tcg_temp_new (); + c->g1 =1 ; +tcg_gen_andi_i32 (c->v1,QREG_FPSR ,FPSR_CC_A |FPSR_CC_Z |FPSR_CC_N ); +tcg_gen_xori_i32 (c->v1, c->v1,FPSR_CC_N ); + c->tcond =TCG_COND_NE ;break ;case 12 :/* Unordered or Less Than A || (N && !Z) */ case 28 :/* Not Greater than or Equal A || (N && !Z) */ assert (FPSR_CC_Z == (FPSR_CC_N >>1 )); - tmp =tcg_temp_new (); -tcg_gen_xori_i32 (tmp,QREG_FPSR ,FPSR_CC_Z ); -tcg_gen_shli_i32 (tmp, tmp,1 ); -tcg_gen_ori_i32 (tmp, tmp,FPSR_CC_A ); -tcg_gen_and_i32 (tmp, tmp,QREG_FPSR ); -tcg_gen_andi_i32 (tmp, tmp,FPSR_CC_A |FPSR_CC_N ); -tcg_gen_brcondi_i32 (TCG_COND_NE , tmp,0 , l1); + c->v1 =tcg_temp_new (); + c->g1 =1 ; +tcg_gen_xori_i32 (c->v1,QREG_FPSR ,FPSR_CC_Z ); +tcg_gen_shli_i32 (c->v1, c->v1,1 ); +tcg_gen_ori_i32 (c->v1, c->v1,FPSR_CC_A ); +tcg_gen_and_i32 (c->v1, c->v1,QREG_FPSR ); +tcg_gen_andi_i32 (c->v1, c->v1,FPSR_CC_A |FPSR_CC_N ); + c->tcond =TCG_COND_NE ;break ;case 13 :/* Unordered or Less or Equal A || Z || N */ case 29 :/* Not Greater Than A || Z || N */ - tmp =tcg_temp_new (); -tcg_gen_andi_i32 (tmp,QREG_FPSR ,FPSR_CC_A |FPSR_CC_Z |FPSR_CC_N ); -tcg_gen_brcondi_i32 (TCG_COND_NE , tmp,0 , l1); + c->v1 =tcg_temp_new (); + c->g1 =1 ; +tcg_gen_andi_i32 (c->v1,QREG_FPSR ,FPSR_CC_A |FPSR_CC_Z |FPSR_CC_N ); + c->tcond =TCG_COND_NE ;break ;case 14 :/* Not Equal !Z */ case 30 :/* Signaling Not Equal !Z */ - tmp =tcg_temp_new (); -tcg_gen_andi_i32 (tmp,QREG_FPSR ,FPSR_CC_Z ); -tcg_gen_brcondi_i32 (TCG_COND_EQ , tmp,0 , l1); + c->v1 =tcg_temp_new (); + c->g1 =1 ; +tcg_gen_andi_i32 (c->v1,QREG_FPSR ,FPSR_CC_Z ); + c->tcond =TCG_COND_EQ ;break ;case 15 :/* True */ case 31 :/* Signaling True */ -tcg_gen_br (l1); + c->v1 = c->v2; + c->tcond =TCG_COND_ALWAYS ;break ; } +} + +static void gen_fjmpcc (DisasContext *s,int cond,TCGLabel *l1) +{ +DisasCompare c; + +gen_fcc_cond (&c, s, cond); +tcg_gen_brcond_i32 (c.tcond, c.v1, c.v2, l1); +free_cond (&c); +} + +DISAS_INSN (fbcc) +{ +uint32_t offset; +uint32_t base; +TCGLabel *l1; + + base = s->pc; + offset = (int16_t )read_im16 (env, s); +if (insn & (1 <<6 )) { + offset = (offset <<16 ) |read_im16 (env, s); + } + + l1 =gen_new_label (); +update_cc_op (s); +gen_fjmpcc (s, insn &0x3f , l1);gen_jmp_tb (s,0 , s->pc);gen_set_label (l1); -gen_jmp_tb (s,1 , addr + offset); +gen_jmp_tb (s,1 , base + offset); +} + +DISAS_INSN (fscc_mem) +{ +TCGLabel *l1, *l2; +TCGv taddr; +TCGv addr; +uint16_t ext; + + ext =read_im16 (env, s); + + taddr =gen_lea (env, s, insn,OS_BYTE ); +if (IS_NULL_QREG (taddr)) { +gen_addr_fault (s); +return ; + } + addr =tcg_temp_local_new (); +tcg_gen_mov_i32 (addr, taddr); + l1 =gen_new_label (); + l2 =gen_new_label (); +gen_fjmpcc (s, ext &0x3f , l1); +gen_store (s,OS_BYTE , addr,tcg_const_i32 (0x00 )); +tcg_gen_br (l2); +gen_set_label (l1); +gen_store (s,OS_BYTE , addr,tcg_const_i32 (0xff )); +gen_set_label (l2); +tcg_temp_free (addr); +} + +DISAS_INSN (fscc_reg) +{ +TCGLabel *l1; +TCGv reg; +uint16_t ext; + + ext =read_im16 (env, s); + + reg =DREG (insn,0 ); + + l1 =gen_new_label (); +tcg_gen_ori_i32 (reg, reg,0x000000ff ); +gen_fjmpcc (s, ext &0x3f , l1); +tcg_gen_andi_i32 (reg, reg,0xffffff00 ); +gen_set_label (l1); }DISAS_INSN (frestore)
@@ -5366,6 +5442,8 @@ void register_m68k_insns (CPUM68KState *env)INSN (frestore, f340, ffc0,CF_FPU );INSN (fsave, f340, ffc0,CF_FPU );INSN (fpu, f200, ffc0,FPU ); +INSN (fscc_mem, f240, ffc0,FPU ); +INSN (fscc_reg, f240, fff8,FPU );INSN (fbcc, f280, ff80,FPU );INSN (frestore, f340, ffc0,FPU );INSN (fsave, f340, ffc0,FPU );
Signature · 1 line
2.9.3
PATCH v2 11/16 target-m68k: add fmovecr
In reply to Laurent Vivierfmovecr moves a floating point constant from the
FPU ROM to a floating point register.
--- target/m68k/fpu_helper.c | 31 +++++++++++++++++++++++++++++++ target/m68k/helper.h | 1 + target/m68k/translate.c | 12 +++++++++++- 3 files changed, 43 insertions(+), 1 deletion(-)
target/m68k/fpu_helper.c +31 -0
@@ -24,6 +24,31 @@#include "exec/helper-proto.h" #include "exec/exec-all.h" +static const floatx80 fpu_rom[128 ] = { + [0x00 ] = floatx80_pi,/* Pi */ + [0x0b ] =make_floatx80 (0x3ffd ,0x9a209a84fbcff798ULL ),/* Log10(2) */ + [0x0c ] =make_floatx80 (0x4000 ,0xadf85458a2bb4a9aULL ),/* e */ + [0x0d ] =make_floatx80 (0x3fff ,0xb8aa3b295c17f0bcULL ),/* Log2(e) */ + [0x0e ] =make_floatx80 (0x3ffd ,0xde5bd8a937287195ULL ),/* Log10(e) */ + [0x0f ] = floatx80_zero,/* Zero */ + [0x30 ] = floatx80_ln2,/* ln(2) */ + [0x31 ] =make_floatx80 (0x4000 ,0x935d8dddaaa8ac17ULL ),/* ln(10) */ + [0x32 ] = floatx80_one,/* 10^0 */ + [0x33 ] =make_floatx80 (0x4002 ,0xa000000000000000ULL ),/* 10^1 */ + [0x34 ] =make_floatx80 (0x4005 ,0xc800000000000000ULL ),/* 10^2 */ + [0x35 ] =make_floatx80 (0x400c ,0x9c40000000000000ULL ),/* 10^4 */ + [0x36 ] =make_floatx80 (0x4019 ,0xbebc200000000000ULL ),/* 10^8 */ + [0x37 ] =make_floatx80 (0x4034 ,0x8e1bc9bf04000000ULL ),/* 10^16 */ + [0x38 ] =make_floatx80 (0x4069 ,0x9dc5ada82b70b59eULL ),/* 10^32 */ + [0x39 ] =make_floatx80 (0x40d3 ,0xc2781f49ffcfa6d5ULL ),/* 10^64 */ + [0x3a ] =make_floatx80 (0x41a8 ,0x93ba47c980e98ce0ULL ),/* 10^128 */ + [0x3b ] =make_floatx80 (0x4351 ,0xaa7eebfb9df9de8eULL ),/* 10^256 */ + [0x3c ] =make_floatx80 (0x46a3 ,0xe319a0aea60e91c7ULL ),/* 10^512 */ + [0x3d ] =make_floatx80 (0x4d48 ,0xc976758681750c17ULL ),/* 10^1024 */ + [0x3e ] =make_floatx80 (0x5a92 ,0x9e8b3b5dc53d5de5ULL ),/* 10^2048 */ + [0x3f ] =make_floatx80 (0x7525 ,0xc46052028a20979bULL ),/* 10^4096 */ +}; +static floatx80 FP0_to_floatx80 (CPUM68KState *env) {return (floatx80 ){ .low = env->fp0l, .high = env->fp0h };
@@ -427,3 +452,9 @@ void HELPER(fmovem)(CPUM68KState *env, uint32_t opsize, {fprintf (stderr,"MISSING HELPER fmovem\n" ); } + +void HELPER (const_FP0 )(CPUM68KState *env,uint32_t offset) +{ + env->fp0l = fpu_rom[offset].low; + env->fp0h = fpu_rom[offset].high; +}
target/m68k/helper.h +1 -0
@@ -32,6 +32,7 @@ DEF_HELPER_2(set_fpcr, void, env, i32) DEF_HELPER_1(tst_FP0, void, env) DEF_HELPER_1(update_fpstatus, void, env) DEF_HELPER_4(fmovem, void, env, i32, i32, i32) +DEF_HELPER_2(const_FP0, void, env, i32) DEF_HELPER_3(mac_move, void, env, i32, i32)DEF_HELPER_3 (macmulf, i64, env, i32, i32)
target/m68k/translate.c +11 -1
@@ -4555,16 +4555,26 @@ static void gen_op_fmovem(CPUM68KState *env, DisasContext *s,DISAS_INSN (fpu) {uint16_t ext; +uint8_t rom_offset;int opmode;int opsize; ext =read_im16 (env, s); opmode = ext &0x7f ;switch ((ext >>13 ) &7 ) { -case 0 :case 2 : +case 0 :break ;case 1 : goto undef; +case 2 : +if (insn ==0xf200 && (ext &0xfc00 ) ==0x5c00 ) { +/* fmovecr */ + rom_offset = ext &0x7f ; +gen_helper_const_FP0 (cpu_env,tcg_const_i32 (rom_offset)); +gen_op_store_fpr_FP0 (REG (ext,7 )); +return ; + } +break ;case 3 :/* fmove out */ gen_op_load_fpr_FP0 (REG (ext,7 )); opsize =ext_opsize (ext,10 );
Signature · 1 line
2.9.3
PATCH v2 12/16 target-m68k: add fscale, fgetman, fgetexp and fmod
In reply to Laurent Vivier--- target/m68k/cpu.h | 1 + target/m68k/fpu_helper.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ target/m68k/helper.h | 4 ++++ target/m68k/translate.c | 14 ++++++++++++ 4 files changed, 75 insertions(+)
target/m68k/cpu.h +1 -0
@@ -253,6 +253,7 @@ typedef enum {/* Quotient */ #define FPSR_QT_MASK 0x00ff0000 +#define FPSR_QT_SHIFT 16/* Floating-Point Control Register */ /* Rounding mode */
target/m68k/fpu_helper.c +56 -0
59 lines not on this page · raw message
target/m68k/helper.h +4 -0
@@ -33,6 +33,10 @@ DEF_HELPER_1(tst_FP0, void, env) DEF_HELPER_1(update_fpstatus, void, env) DEF_HELPER_4(fmovem, void, env, i32, i32, i32) DEF_HELPER_2(const_FP0, void, env, i32) +DEF_HELPER_1(getexp_FP0, void, env) +DEF_HELPER_1(getman_FP0, void, env) +DEF_HELPER_1(scale_FP0_FP1, void, env) +DEF_HELPER_1(mod_FP0_FP1, void, env) DEF_HELPER_3(mac_move, void, env, i32, i32)DEF_HELPER_3 (macmulf, i64, env, i32, i32)
target/m68k/translate.c +14 -0
@@ -4629,10 +4629,20 @@ DISAS_INSN(fpu)case 0x1a :case 0x5a :case 0x5e :/* fneg */ gen_helper_chs_FP0 (cpu_env);break ; +case 0x1e :/* fgetexp */ +gen_helper_getexp_FP0 (cpu_env); +break ; +case 0x1f :/* fgetman */ +gen_helper_getman_FP0 (cpu_env); +break ;case 0x20 :case 0x60 :case 0x64 :/* fdiv */ gen_op_load_fpr_FP1 (REG (ext,7 ));gen_helper_div_FP0_FP1 (cpu_env);break ; +case 0x21 :/* fmod */ +gen_op_load_fpr_FP1 (REG (ext,7 )); +gen_helper_mod_FP0_FP1 (cpu_env); +break ;case 0x22 :case 0x62 :case 0x66 :/* fadd */ gen_op_load_fpr_FP1 (REG (ext,7 ));gen_helper_add_FP0_FP1 (cpu_env);
@@ -4641,6 +4651,10 @@ DISAS_INSN(fpu)gen_op_load_fpr_FP1 (REG (ext,7 ));gen_helper_mul_FP0_FP1 (cpu_env);break ; +case 0x26 :/* fscale */ +gen_op_load_fpr_FP1 (REG (ext,7 )); +gen_helper_scale_FP0_FP1 (cpu_env); +break ;case 0x28 :case 0x68 :case 0x6c :/* fsub */ gen_op_load_fpr_FP1 (REG (ext,7 ));gen_helper_sub_FP0_FP1 (cpu_env);
Signature · 1 line
2.9.3
PATCH v2 13/16 target-m68k: add fsglmul and fsgldiv
In reply to Laurent Vivierfsglmul and fsgldiv truncate data to single precision before computing results.
--- target/m68k/fpu_helper.c | 22 ++++++++++++++++++++++ target/m68k/helper.h | 2 ++ target/m68k/translate.c | 8 ++++++++ 3 files changed, 32 insertions(+)
target/m68k/fpu_helper.c +22 -0
@@ -351,6 +351,17 @@ void HELPER(mul_FP0_FP1)(CPUM68KState *env)floatx80_to_FP0 (env, res); } +void HELPER (sglmul_FP0_FP1 )(CPUM68KState *env) +{ +float64 a, b, res; + + a =floatx80_to_float64 (FP0_to_floatx80 (env), &env->fp_status); + b =floatx80_to_float64 (FP1_to_floatx80 (env), &env->fp_status); + res =float64_mul (a, b, &env->fp_status); + +floatx80_to_FP0 (env,float64_to_floatx80 (res, &env->fp_status)); +} +void HELPER (div_FP0_FP1 )(CPUM68KState *env) {floatx80 res;
@@ -361,6 +372,17 @@ void HELPER(div_FP0_FP1)(CPUM68KState *env)floatx80_to_FP0 (env, res); } +void HELPER (sgldiv_FP0_FP1 )(CPUM68KState *env) +{ +float64 a, b, res; + + a =floatx80_to_float64 (FP1_to_floatx80 (env), &env->fp_status); + b =floatx80_to_float64 (FP0_to_floatx80 (env), &env->fp_status); + res =float64_div (a, b, &env->fp_status); + +floatx80_to_FP0 (env,float64_to_floatx80 (res, &env->fp_status)); +} +static int float_comp_to_cc (int float_compare) {switch (float_compare) {
target/m68k/helper.h +2 -0
@@ -26,7 +26,9 @@ DEF_HELPER_1(chs_FP0, void, env) DEF_HELPER_1(add_FP0_FP1, void, env) DEF_HELPER_1(sub_FP0_FP1, void, env) DEF_HELPER_1(mul_FP0_FP1, void, env) +DEF_HELPER_1(sglmul_FP0_FP1, void, env) DEF_HELPER_1(div_FP0_FP1, void, env) +DEF_HELPER_1(sgldiv_FP0_FP1, void, env) DEF_HELPER_1(cmp_FP0_FP1, void, env) DEF_HELPER_2(set_fpcr, void, env, i32)DEF_HELPER_1 (tst_FP0, void, env)
target/m68k/translate.c +8 -0
@@ -4651,10 +4651,18 @@ DISAS_INSN(fpu)gen_op_load_fpr_FP1 (REG (ext,7 ));gen_helper_mul_FP0_FP1 (cpu_env);break ; +case 0x24 :/* fsgldiv */ +gen_op_load_fpr_FP1 (REG (ext,7 )); +gen_helper_sgldiv_FP0_FP1 (cpu_env); +break ;case 0x26 :/* fscale */ gen_op_load_fpr_FP1 (REG (ext,7 ));gen_helper_scale_FP0_FP1 (cpu_env);break ; +case 0x27 :/* fsglmul */ +gen_op_load_fpr_FP1 (REG (ext,7 )); +gen_helper_sglmul_FP0_FP1 (cpu_env); +break ;case 0x28 :case 0x68 :case 0x6c :/* fsub */ gen_op_load_fpr_FP1 (REG (ext,7 ));gen_helper_sub_FP0_FP1 (cpu_env);
Signature · 1 line
2.9.3
PATCH v2 14/16 target-m68k: add explicit single and double precision operations
In reply to Laurent VivierAdd fssqrt, fdsqrt, fsabs, fdabs, fsneg, fdneg, fsadd, fdadd, fssub, fdsub, fsmul, fdmul, fsdiv, fddiv, fsmove and fdmove.
The precision is managed using set_floatx80_rounding_precision(), except for fsmove, fdmove, fsneg, fdneg, fsabs and fdabs:
the value is converted manually to the given precision and converted back to floatx80.
--- target/m68k/fpu_helper.c | 178 ++++++++++++++++++++++++++++++++++++++++++++++- target/m68k/helper.h | 16 ++++- target/m68k/translate.c | 76 +++++++++++++++++--- 3 files changed, 259 insertions(+), 11 deletions(-)
target/m68k/fpu_helper.c +177 -1
@@ -294,6 +294,16 @@ void HELPER(itrunc_FP0)(CPUM68KState *env)floatx80_to_FP0 (env, res); } +#define PREC_BEGIN (prec) \ + do { \ + int old; \ + old = get_floatx80_rounding_precision(&env->fp_status); \ + set_floatx80_rounding_precision(prec, &env->fp_status) \ + +#define PREC_END () \ + set_floatx80_rounding_precision(old, &env->fp_status); \ + } while (0) +void HELPER (sqrt_FP0 )(CPUM68KState *env) {floatx80 res;
@@ -303,6 +313,28 @@ void HELPER(sqrt_FP0)(CPUM68KState *env)floatx80_to_FP0 (env, res); } +void HELPER (ssqrt_FP0 )(CPUM68KState *env) +{ +floatx80 res; + +PREC_BEGIN (32 ); + res =floatx80_sqrt (FP0_to_floatx80 (env), &env->fp_status); +PREC_END (); + +floatx80_to_FP0 (env, res); +} + +void HELPER (dsqrt_FP0 )(CPUM68KState *env) +{ +floatx80 res; + +PREC_BEGIN (64 ); + res =floatx80_sqrt (FP0_to_floatx80 (env), &env->fp_status); +PREC_END (); + +floatx80_to_FP0 (env, res); +} +void HELPER (abs_FP0 )(CPUM68KState *env) {floatx80 res;
@@ -312,11 +344,59 @@ void HELPER(abs_FP0)(CPUM68KState *env)floatx80_to_FP0 (env, res); } -void HELPER (chs_FP0 )(CPUM68KState *env) +void HELPER (sabs_FP0 )(CPUM68KState *env) {floatx80 res; +float32 f32; + + res =floatx80_abs (FP0_to_floatx80 (env)); + f32 =floatx80_to_float32 (res, &env->fp_status); + res =float32_to_floatx80 (f32, &env->fp_status); + +floatx80_to_FP0 (env, res); +} + +void HELPER (dabs_FP0 )(CPUM68KState *env) +{ +floatx80 res; +float64 f64; + + res =floatx80_abs (FP0_to_floatx80 (env)); + f64 =floatx80_to_float64 (res, &env->fp_status); + res =float64_to_floatx80 (f64, &env->fp_status); + +floatx80_to_FP0 (env, res); +} + +void HELPER (neg_FP0 )(CPUM68KState *env) +{ +floatx80 res; + + res =floatx80_chs (FP0_to_floatx80 (env)); + +floatx80_to_FP0 (env, res); +} + +void HELPER (sneg_FP0 )(CPUM68KState *env) +{ +floatx80 res; +float32 f32; + + res =floatx80_chs (FP0_to_floatx80 (env)); + f32 =floatx80_to_float32 (res, &env->fp_status); + res =float32_to_floatx80 (f32, &env->fp_status); + +floatx80_to_FP0 (env, res); +} + +void HELPER (dneg_FP0 )(CPUM68KState *env) +{ +floatx80 res; +float64 f64; res =floatx80_chs (FP0_to_floatx80 (env)); + f64 =floatx80_to_float64 (res, &env->fp_status); + res =float64_to_floatx80 (f64, &env->fp_status);floatx80_to_FP0 (env, res); }
@@ -331,6 +411,30 @@ void HELPER(add_FP0_FP1)(CPUM68KState *env)floatx80_to_FP0 (env, res); } +void HELPER (sadd_FP0_FP1 )(CPUM68KState *env) +{ +floatx80 res; + +PREC_BEGIN (32 ); + res =floatx80_add (FP0_to_floatx80 (env),FP1_to_floatx80 (env), + &env->fp_status); +PREC_END (); + +floatx80_to_FP0 (env, res); +} + +void HELPER (dadd_FP0_FP1 )(CPUM68KState *env) +{ +floatx80 res; + +PREC_BEGIN (64 ); + res =floatx80_add (FP0_to_floatx80 (env),FP1_to_floatx80 (env), + &env->fp_status); +PREC_END (); + +floatx80_to_FP0 (env, res); +} +void HELPER (sub_FP0_FP1 )(CPUM68KState *env) {floatx80 res;
@@ -341,6 +445,30 @@ void HELPER(sub_FP0_FP1)(CPUM68KState *env)floatx80_to_FP0 (env, res); } +void HELPER (ssub_FP0_FP1 )(CPUM68KState *env) +{ +floatx80 res; + +PREC_BEGIN (32 ); + res =floatx80_sub (FP1_to_floatx80 (env),FP0_to_floatx80 (env), + &env->fp_status); +PREC_END (); + +floatx80_to_FP0 (env, res); +} + +void HELPER (dsub_FP0_FP1 )(CPUM68KState *env) +{ +floatx80 res; + +PREC_BEGIN (64 ); + res =floatx80_sub (FP1_to_floatx80 (env),FP0_to_floatx80 (env), + &env->fp_status); +PREC_END (); + +floatx80_to_FP0 (env, res); +} +void HELPER (mul_FP0_FP1 )(CPUM68KState *env) {floatx80 res;
@@ -351,6 +479,30 @@ void HELPER(mul_FP0_FP1)(CPUM68KState *env)floatx80_to_FP0 (env, res); } +void HELPER (smul_FP0_FP1 )(CPUM68KState *env) +{ +floatx80 res; + +PREC_BEGIN (32 ); + res =floatx80_mul (FP0_to_floatx80 (env),FP1_to_floatx80 (env), + &env->fp_status); +PREC_END (); + +floatx80_to_FP0 (env, res); +} + +void HELPER (dmul_FP0_FP1 )(CPUM68KState *env) +{ +floatx80 res; + +PREC_BEGIN (64 ); + res =floatx80_mul (FP0_to_floatx80 (env),FP1_to_floatx80 (env), + &env->fp_status); +PREC_END (); + +floatx80_to_FP0 (env, res); +} +void HELPER (sglmul_FP0_FP1 )(CPUM68KState *env) {float64 a, b, res;
@@ -372,6 +524,30 @@ void HELPER(div_FP0_FP1)(CPUM68KState *env)floatx80_to_FP0 (env, res); } +void HELPER (sdiv_FP0_FP1 )(CPUM68KState *env) +{ +floatx80 res; + +PREC_BEGIN (32 ); + res =floatx80_div (FP1_to_floatx80 (env),FP0_to_floatx80 (env), + &env->fp_status); +PREC_END (); + +floatx80_to_FP0 (env, res); +} + +void HELPER (ddiv_FP0_FP1 )(CPUM68KState *env) +{ +floatx80 res; + +PREC_BEGIN (64 ); + res =floatx80_div (FP1_to_floatx80 (env),FP0_to_floatx80 (env), + &env->fp_status); +PREC_END (); + +floatx80_to_FP0 (env, res); +} +void HELPER (sgldiv_FP0_FP1 )(CPUM68KState *env) {float64 a, b, res;
target/m68k/helper.h +15 -1
@@ -21,13 +21,27 @@ DEF_HELPER_1(reds32_FP0, void, env) DEF_HELPER_1(iround_FP0, void, env) DEF_HELPER_1(itrunc_FP0, void, env) DEF_HELPER_1(sqrt_FP0, void, env) +DEF_HELPER_1(ssqrt_FP0, void, env) +DEF_HELPER_1(dsqrt_FP0, void, env) DEF_HELPER_1(abs_FP0, void, env) -DEF_HELPER_1(chs_FP0, void, env) +DEF_HELPER_1(sabs_FP0, void, env) +DEF_HELPER_1(dabs_FP0, void, env) +DEF_HELPER_1(neg_FP0, void, env) +DEF_HELPER_1(sneg_FP0, void, env) +DEF_HELPER_1(dneg_FP0, void, env) DEF_HELPER_1(add_FP0_FP1, void, env) +DEF_HELPER_1(sadd_FP0_FP1, void, env) +DEF_HELPER_1(dadd_FP0_FP1, void, env) DEF_HELPER_1(sub_FP0_FP1, void, env) +DEF_HELPER_1(ssub_FP0_FP1, void, env) +DEF_HELPER_1(dsub_FP0_FP1, void, env) DEF_HELPER_1(mul_FP0_FP1, void, env) +DEF_HELPER_1(smul_FP0_FP1, void, env) +DEF_HELPER_1(dmul_FP0_FP1, void, env) DEF_HELPER_1(sglmul_FP0_FP1, void, env) DEF_HELPER_1(div_FP0_FP1, void, env) +DEF_HELPER_1(sdiv_FP0_FP1, void, env) +DEF_HELPER_1(ddiv_FP0_FP1, void, env) DEF_HELPER_1(sgldiv_FP0_FP1, void, env) DEF_HELPER_1(cmp_FP0_FP1, void, env)DEF_HELPER_2 (set_fpcr, void, env, i32)
target/m68k/translate.c +67 -9
120 lines not on this page · raw message
Signature · 1 line
2.9.3
PATCH v2 15/16 target-m68k: add more FPU instructions
In reply to Laurent VivierAdd fsinh, flognp1, ftanh, fatan, fasin, fatanh, fsin, ftan, fetox, ftwotox, ftentox, flogn, flog10, facos, fcos.
As softfloat library does not provide these functions, we us the libm of the host.
--- target/m68k/fpu_helper.c | 237 +++++++++++++++++++++++++++++++++++++++++++++++ target/m68k/helper.h | 16 ++++ target/m68k/translate.c | 48 ++++++++++ 3 files changed, 301 insertions(+)
target/m68k/fpu_helper.c +237 -0
@@ -23,6 +23,7 @@#include "cpu.h" #include "exec/helper-proto.h" #include "exec/exec-all.h" +#include <math.h> static const floatx80 fpu_rom[128 ] = { [0x00 ] = floatx80_pi,/* Pi */
@@ -712,3 +713,239 @@ void HELPER(mod_FP0_FP1)(CPUM68KState *env)floatx80_to_FP0 (env, res); } + +static long double floatx80_to_ldouble (floatx80 val) +{ +if (floatx80_is_infinity (val)) { +if (floatx80_is_neg (val)) { +return -__builtin_infl (); + } +return __builtin_infl (); + } +if (floatx80_is_any_nan (val)) { +char low[20 ]; +sprintf (low,"0x%016" PRIx64, val.low); + +return nanl (low); + } + +return *(long double *)&val; +} + +static floatx80 ldouble_to_floatx80 (long double val) +{ +floatx80 res; + +if (isinf (val)) { + res.high =floatx80_default_nan (NULL ).high; + res.low =0 ; + } +if (isinf (val) <0 ) { + res.high |=0x8000 ; + } +if (isnan (val)) { + res.high =floatx80_default_nan (NULL ).high; + res.low = *(uint64_t *)((char *)&val +4 ); + } +return *(floatx80 *)&val; +} + +void HELPER (sinh_FP0 )(CPUM68KState *env) +{ +floatx80 res; +long double val; + + val =sinhl (floatx80_to_ldouble (FP0_to_floatx80 (env))); + res =ldouble_to_floatx80 (val); + +floatx80_to_FP0 (env, res); +} + +void HELPER (lognp1_FP0 )(CPUM68KState *env) +{ +floatx80 val; +long double res; + + val =FP0_to_floatx80 (env); + res =logl (floatx80_to_ldouble (val) +1.0 ); + +floatx80_to_FP0 (env,ldouble_to_floatx80 (res)); +} + +void HELPER (ln_FP0 )(CPUM68KState *env) +{ +floatx80 val; +long double res; + + val =FP0_to_floatx80 (env); + res =logl (floatx80_to_ldouble (val)); + +floatx80_to_FP0 (env,ldouble_to_floatx80 (res)); +} + +void HELPER (log10_FP0 )(CPUM68KState *env) +{ +floatx80 val; +long double res; + + val =FP0_to_floatx80 (env); + res =log10l (floatx80_to_ldouble (val)); + +floatx80_to_FP0 (env,ldouble_to_floatx80 (res)); +} + +void HELPER (atan_FP0 )(CPUM68KState *env) +{ +floatx80 res; +long double val; + + val =floatx80_to_ldouble (FP0_to_floatx80 (env)); + + val =atanl (val); + res =ldouble_to_floatx80 (val); +floatx80_to_FP0 (env, res); +} + +void HELPER (asin_FP0 )(CPUM68KState *env) +{ +floatx80 res; +long double val; + + val =floatx80_to_ldouble (FP0_to_floatx80 (env)); +if (val <-1.0 || val >1.0 ) { +floatx80_to_FP0 (env,floatx80_default_nan (NULL )); +return ; + } + + val =asinl (val); + res =ldouble_to_floatx80 (val); +floatx80_to_FP0 (env, res); +} + +void HELPER (atanh_FP0 )(CPUM68KState *env) +{ +floatx80 res; +long double val; + + val =floatx80_to_ldouble (FP0_to_floatx80 (env)); +if (val <-1.0 || val >1.0 ) { +floatx80_to_FP0 (env,floatx80_default_nan (NULL )); +return ; + } + + val =atanhl (val); + res =ldouble_to_floatx80 (val); +floatx80_to_FP0 (env, res); +} + +void HELPER (sin_FP0 )(CPUM68KState *env) +{ +floatx80 res; +long double val; + + val =floatx80_to_ldouble (FP0_to_floatx80 (env)); + + val =sinl (val); + res =ldouble_to_floatx80 (val); +floatx80_to_FP0 (env, res); +} + +void HELPER (tanh_FP0 )(CPUM68KState *env) +{ +floatx80 res; +long double val; + + val =floatx80_to_ldouble (FP0_to_floatx80 (env)); + + val =tanhl (val); + res =ldouble_to_floatx80 (val); +floatx80_to_FP0 (env, res); +} + +void HELPER (tan_FP0 )(CPUM68KState *env) +{ +floatx80 res; +long double val; + + val =floatx80_to_ldouble (FP0_to_floatx80 (env)); + + val =tanl (val); + res =ldouble_to_floatx80 (val); +floatx80_to_FP0 (env, res); +} + +void HELPER (exp_FP0 )(CPUM68KState *env) +{ +floatx80 f; +long double res; + + f =FP0_to_floatx80 (env); + + res =expl (floatx80_to_ldouble (f)); + +floatx80_to_FP0 (env,ldouble_to_floatx80 (res)); +} + +void HELPER (exp2_FP0 )(CPUM68KState *env) +{ +floatx80 f; +long double res; + + f =FP0_to_floatx80 (env); + + res =exp2l (floatx80_to_ldouble (f)); + +floatx80_to_FP0 (env,ldouble_to_floatx80 (res)); +} + +void HELPER (exp10_FP0 )(CPUM68KState *env) +{ +floatx80 res; +long double val; + + val =floatx80_to_ldouble (FP0_to_floatx80 (env)); + + val =exp10l (val); + res =ldouble_to_floatx80 (val); +floatx80_to_FP0 (env, res); +} + +void HELPER (cosh_FP0 )(CPUM68KState *env) +{ +floatx80 res; +long double val; + + val =floatx80_to_ldouble (FP0_to_floatx80 (env)); + + val =coshl (val); + res =ldouble_to_floatx80 (val); +floatx80_to_FP0 (env, res); +} + +void HELPER (acos_FP0 )(CPUM68KState *env) +{ +floatx80 res; +long double val; + + val =floatx80_to_ldouble (FP0_to_floatx80 (env)); +if (val <-1.0 || val >1.0 ) { +floatx80_to_FP0 (env,floatx80_default_nan (NULL )); +return ; + } + + val =acosl (val); + res =ldouble_to_floatx80 (val); +floatx80_to_FP0 (env, res); +} + +void HELPER (cos_FP0 )(CPUM68KState *env) +{ +floatx80 res; +long double val; + + val =floatx80_to_ldouble (FP0_to_floatx80 (env)); + + val =cosl (val); + res =ldouble_to_floatx80 (val); +floatx80_to_FP0 (env, res); +}
target/m68k/helper.h +16 -0
@@ -53,6 +53,22 @@ DEF_HELPER_1(getexp_FP0, void, env) DEF_HELPER_1(getman_FP0, void, env) DEF_HELPER_1(scale_FP0_FP1, void, env) DEF_HELPER_1(mod_FP0_FP1, void, env) +DEF_HELPER_1(sinh_FP0, void, env) +DEF_HELPER_1(lognp1_FP0, void, env) +DEF_HELPER_1(atan_FP0, void, env) +DEF_HELPER_1(asin_FP0, void, env) +DEF_HELPER_1(atanh_FP0, void, env) +DEF_HELPER_1(sin_FP0, void, env) +DEF_HELPER_1(tanh_FP0, void, env) +DEF_HELPER_1(tan_FP0, void, env) +DEF_HELPER_1(exp_FP0, void, env) +DEF_HELPER_1(exp2_FP0, void, env) +DEF_HELPER_1(exp10_FP0, void, env) +DEF_HELPER_1(ln_FP0, void, env) +DEF_HELPER_1(log10_FP0, void, env) +DEF_HELPER_1(cosh_FP0, void, env) +DEF_HELPER_1(acos_FP0, void, env) +DEF_HELPER_1(cos_FP0, void, env) DEF_HELPER_3(mac_move, void, env, i32, i32)DEF_HELPER_3 (macmulf, i64, env, i32, i32)
target/m68k/translate.c +48 -0
72 lines not on this page · raw message
Signature · 1 line
2.9.3
PATCH v2 16/16 target-m68k: add fsincos
In reply to Laurent Vivier--- target/m68k/fpu_helper.c | 21 +++++++++++++++++++++ target/m68k/helper.h | 1 + target/m68k/translate.c | 15 +++++++++++++++ 3 files changed, 37 insertions(+)
target/m68k/fpu_helper.c +21 -0
@@ -95,6 +95,12 @@ static floatx80 FP1_to_floatx80(CPUM68KState *env)return (floatx80 ){ .low = env->fp1l, .high = env->fp1h }; } +static void floatx80_to_FP1 (CPUM68KState *env,floatx80 res) +{ + env->fp1l = res.low; + env->fp1h = res.high; +} +void HELPER (exts32_FP0 )(CPUM68KState *env) {floatx80 res;
@@ -949,3 +955,18 @@ void HELPER(cos_FP0)(CPUM68KState *env) res =ldouble_to_floatx80 (val);floatx80_to_FP0 (env, res); } + +void HELPER (sincos_FP0_FP1 )(CPUM68KState *env) +{ +floatx80 res; +long double val, valsin, valcos; + + val =floatx80_to_ldouble (FP0_to_floatx80 (env)); + +sincosl (val, &valsin, &valcos); + res =ldouble_to_floatx80 (valsin); +floatx80_to_FP0 (env, res); + res =ldouble_to_floatx80 (valcos); +floatx80_to_FP1 (env, res); + +}
target/m68k/helper.h +1 -0
@@ -69,6 +69,7 @@ DEF_HELPER_1(log10_FP0, void, env) DEF_HELPER_1(cosh_FP0, void, env) DEF_HELPER_1(acos_FP0, void, env) DEF_HELPER_1(cos_FP0, void, env) +DEF_HELPER_1(sincos_FP0_FP1, void, env) DEF_HELPER_3(mac_move, void, env, i32, i32)DEF_HELPER_3 (macmulf, i64, env, i32, i32)
target/m68k/translate.c +15 -0
@@ -923,6 +923,14 @@ static void gen_op_load_fpr_FP1(int freg) offsetof(CPUM68KState, fregs[freg].l.lower)); } +static void gen_op_store_fpr_FP1 (int freg) +{ +tcg_gen_st16_i32 (QREG_FP1H , cpu_env, + offsetof(CPUM68KState, fregs[freg].l.upper)); +tcg_gen_st_i64 (QREG_FP1L , cpu_env, + offsetof(CPUM68KState, fregs[freg].l.lower)); +} +static void gen_extend_FP0 (int opsize) {switch (opsize) {
@@ -4773,6 +4781,13 @@ DISAS_INSN(fpu)gen_op_load_fpr_FP1 (REG (ext,7 ));gen_helper_dsub_FP0_FP1 (cpu_env);break ; +case 0x30 :case 0x31 :case 0x32 : +case 0x33 :case 0x34 :case 0x35 : +case 0x36 :case 0x37 : +gen_helper_sincos_FP0_FP1 (cpu_env); +gen_op_store_fpr_FP0 (REG (ext,7 ));/* sin */ +gen_op_store_fpr_FP1 (REG (ext,0 ));/* cos */ +break ;case 0x38 :/* fcmp */ gen_op_load_fpr_FP1 (REG (ext,7 ));gen_helper_cmp_FP0_FP1 (cpu_env);
Signature · 1 line
2.9.3
Quoted 4 lines · Laurent Vivier
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.
An Intel Extended also has a different exponent bias than a Motorola Extended in the denormal range. In other words, for the latter the bias doesn't change between normal and denormal numbers.
Andreas.
Signature · 3 lines
Andreas Schwab, [email protected] GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."
Your series seems to have some coding style problems. See output below for more information:
Hi,
Your series seems to have some coding style problems. See output below for more information:
Type: series
Subject: [Qemu-devel] [PATCH v2 00/16] target-m68k: implement 680x0 FPU
Message-id: [email protected]
=== TEST SCRIPT BEGIN ===
#!/bin/bash
BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0
# Useful git options
git config --local diff.renamelimit 0
git config --local diff.renames True
commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))done
exit $failed
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
dbe6dbe target-m68k: add fsincos
ab31de0 target-m68k: add more FPU instructions
034d842 target-m68k: add explicit single and double precision operations 6c8776d target-m68k: add fsglmul and fsgldiv
541e299 target-m68k: add fscale, fgetman, fgetexp and fmod 9dfe1c1 target-m68k: add fmovecr
e028b28 target-m68k: add fscc.
aea92d1 target-m68k: add fmovem
5eb013e target-m68k: define 96bit FP registers for gdb on 680x0 9e4f1b4 target-m68k: manage FPU exceptions
baadbd9 target-m68k: add FPCR and FPSR
20f7380 target-m68k: use floatx80 internally
a47c018 target-m68k: define ext_opsize
0770d33 target-m68k: move FPU helpers to fpu_helper.c 4132de8 softloat: disable floatx80_invalid_encoding() for m68k d714fec softfloat: define 680x0 specific values
=== OUTPUT BEGIN ===
Checking PATCH 1/16: softfloat: define 680x0 specific values... Checking PATCH 2/16: softloat: disable floatx80_invalid_encoding() for m68k... Checking PATCH 3/16: target-m68k: move FPU helpers to fpu_helper.c... Checking PATCH 4/16: target-m68k: define ext_opsize...
Checking PATCH 5/16: target-m68k: use floatx80 internally...
ERROR: storage class should be at the beginning of the declaration #457: FILE: target/m68k/translate.c:39:
+#define DEFF96(name, offset) static TCGv_i32 QREG_##name##H; \
total: 1 errors, 0 warnings, 1203 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 6/16: target-m68k: add FPCR and FPSR...
Checking PATCH 7/16: target-m68k: manage FPU exceptions...
Checking PATCH 8/16: target-m68k: define 96bit FP registers for gdb on 680x0... Checking PATCH 9/16: target-m68k: add fmovem...
Checking PATCH 10/16: target-m68k: add fscc....
Checking PATCH 11/16: target-m68k: add fmovecr...
Checking PATCH 12/16: target-m68k: add fscale, fgetman, fgetexp and fmod... Checking PATCH 13/16: target-m68k: add fsglmul and fsgldiv...
Checking PATCH 14/16: target-m68k: add explicit single and double precision operations... Checking PATCH 15/16: target-m68k: add more FPU instructions...
Checking PATCH 16/16: target-m68k: add fsincos...
=== OUTPUT END ===
Test command exited with code: 1
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]