FPU support for MIPS
PATCH 1/1 FPU support for MIPS
Hi again,
again, a current version of my FPU patch for MIPS. Fabrice, I tried to implement all your suggestions you made for the previous version. The patch seems now a lot cleaner to me, easier to extend, and will now also handle IEEE single floating point (.s) format. Also, the exception handling of unimplemented arith operations/formats is now more constistent. I also verified the implementation with CONFIG_SOFTFLOAT.
Regards,
Marius
Signature · 4 lines
Marius Groeger <[email protected]> SYSGO AG Embedded and Real-Time Software Voice: +49 6136 9948 0 FAX: +49 6136 9948 10 www.sysgo.com | www.elinos.com | www.osek.de | www.pikeos.com
Index: target-mips/cpu.h
===================================================================
RCS file: /sources/qemu/qemu/target-mips/cpu.h,v
retrieving revision 1.6
cpu.h +39 -13
@@ -9,10 +9,13 @@#include "softfloat.h" typedef union fpr_t fpr_t ; +union fpr_t { -double d; -float f; -uint32_t u[2 ]; +float64 fd;/* ieee double precision */ +float32 fs;/* ieee single precision */ +int64_t d;/* binary single fixed-point */ +int32_t w;/* binary single fixed-point */ +uint32_t u32[2 ]; };#if defined(MIPS_USES_R4K_TLB )
@@ -43,16 +46,41 @@uint32_t DCR ;/* ? */ #if defined(MIPS_USES_FPU )/* Floating point registers */ -fpr_t fpr[16 ]; -/* Floating point special purpose registers */ +uint32_t fpr[2 *32 ]; +#define FPR (cpu, n, fmt) ((fpr_t*)&(cpu)->fpr[(n) & 0x1f]) + +#ifndef USE_HOST_FLOAT_REGS +fpr_t ft0; +fpr_t ft1; +fpr_t ft2; +#endif +float_status fp_status; +/* fpu implementation/revision register */ uint32_t fcr0; -uint32_t fcr25; -uint32_t fcr26; -uint32_t fcr28; -uint32_t fcsr; +/* fcsr */ +uint32_t fcr31; +/* set condition, "c" must be 0 or 1 */ +#define SET_FP_COND (reg, c) do { \ +/*assert(c == 0 || c == 1);*/ \ + (reg) = ((reg) & ~(1 <<23 )) | ((c)<<23 ); \ + } while(0) +#define IS_FP_COND_SET (reg) (((reg) & (1<<23)) != 0) +#define GET_FP_CAUSE (reg) (((reg) >> 12) & 0x3f) +#define GET_FP_ENABLE (reg) (((reg) >> 7) & 0x1f) +#define GET_FP_FLAGS (reg) (((reg) >> 2) & 0x1f) +#define SET_FP_CAUSE (reg,v) do { (reg) = ((reg) & ~(0x3f << 12)) | ((v) << 12); } while(0) +#define SET_FP_ENABLE (reg,v) do { (reg) = ((reg) & ~(0x1f << 7)) | ((v) << 7); } while(0) +#define SET_FP_FLAGS (reg,v) do { (reg) = ((reg) & ~(0x1f << 2)) | ((v) << 2); } while(0) +#define FP_INEXACT 1 +#define FP_UNDERFLOW 2 +#define FP_OVERFLOW 4 +#define FP_DIV0 8 +#define FP_INVALID 16 +#define FP_UNIMPLEMENTED 32 +#endif #if defined(MIPS_USES_R4K_TLB ) -tlb_t tlb[16 ]; +tlb_t tlb[MIPS_TLB_NB ];#endif uint32_t CP0_index;uint32_t CP0_random;
@@ -71,6 +99,7 @@#define CP0St_CU1 29#define CP0St_CU0 28#define CP0St_RP 27 +#define CP0St_FR 26#define CP0St_RE 25#define CP0St_BEV 22#define CP0St_TS 21
@@ -138,9 +167,6 @@uint32_t CP0_ErrorEPC;uint32_t CP0_DESAVE ;/* Qemu */ -#if defined (USE_HOST_FLOAT_REGS ) && defined(MIPS_USES_FPU ) -double ft0, ft1, ft2; -#endif struct QEMUTimer *timer;/* Internal timer */ int interrupt_request;jmp_buf jmp_env;
Index: target-mips/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-mips/exec.h,v
retrieving revision 1.7
exec.h +20 -6
@@ -21,13 +21,20 @@ register host_uint_t T2 asm(AREG3);#if defined (USE_HOST_FLOAT_REGS ) -register double FT0 asm(FREG0); -register double FT1 asm(FREG1); -register double FT2 asm(FREG2); +#error "implement me."#else -#define FT0 (env->ft0.d) -#define FT1 (env->ft1.d) -#define FT2 (env->ft2.d) +#define FDT0 (env->ft0.fd) +#define FDT1 (env->ft1.fd) +#define FDT2 (env->ft2.fd) +#define FST0 (env->ft0.fs) +#define FST1 (env->ft1.fs) +#define FST2 (env->ft2.fs) +#define DT0 (env->ft0.d) +#define DT1 (env->ft1.d) +#define DT2 (env->ft2.d) +#define WT0 (env->ft0.w) +#define WT1 (env->ft1.w) +#define WT2 (env->ft2.w)#endif #if defined (DEBUG_OP )
@@ -65,6 +72,13 @@void do_tlbwr (void );void do_tlbp (void );void do_tlbr (void ); +#ifdef MIPS_USES_FPU +void dump_fpu (CPUState *env); +void fpu_dump_state (CPUState *env,FILE *f, +int (*fpu_fprintf)(FILE *f,const char *fmt, ...), +int flags); +#endif +void dump_sc (void );void do_lwl_raw (uint32_t );void do_lwr_raw (uint32_t );uint32_t do_swl_raw (uint32_t );
Index: target-mips/mips-defs.h
===================================================================
RCS file: /sources/qemu/qemu/target-mips/mips-defs.h,v retrieving revision 1.1
mips-defs.h +3 -1
@@ -24,6 +24,8 @@/* Uses MIPS R4Kc TLB model */ #define MIPS_USES_R4K_TLB #define MIPS_TLB_NB 16 +/* basic FPU register support */ +#define MIPS_USES_FPU /* Have config1, runs in big-endian mode, uses TLB */ #define MIPS_CONFIG0 \ ((1 << CP0C0_M) | (0x000 << CP0C0_K23) | (0x000 << CP0C0_KU) | \
@@ -52,7 +54,7 @@#error "MIPS CPU not defined"/* Remainder for other flags */ //#define TARGET_MIPS64 -//define MIPS_USES_FPU +//#define MIPS_USES_FPU #endif #endif /* !defined (__QEMU_MIPS_DEFS_H__) */
Index: target-mips/op.c
===================================================================
RCS file: /sources/qemu/qemu/target-mips/op.c,v
retrieving revision 1.7
op.c +359 -0
377 lines not on this page · raw message
Index: target-mips/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-mips/op_helper.c,v retrieving revision 1.11
op_helper.c +41 -0
47 lines not on this page · raw message
Index: target-mips/op_mem.c
===================================================================
RCS file: /sources/qemu/qemu/target-mips/op_mem.c,v retrieving revision 1.2
op_mem.c +37 -0
@@ -61,6 +61,18 @@RETURN (); } +void glue (op_lwu ,MEMSUFFIX ) (void ) +{ +T0 =glue (ldl,MEMSUFFIX )(T0 ); +RETURN (); +} + +void glue (op_lwu ,MEMSUFFIX ) (void ) +{ +T0 =glue (ldl,MEMSUFFIX )(T0 ); +RETURN (); +} +void glue (op_sw ,MEMSUFFIX ) (void ) {glue (stl,MEMSUFFIX )(T0 ,T1 );
@@ -118,3 +130,28 @@ }RETURN (); } + +#ifdef MIPS_USES_FPU +void glue (op_lwc1 ,MEMSUFFIX ) (void ) +{ +WT0 =glue (ldl,MEMSUFFIX )(T0 ); +RETURN (); +} +void glue (op_swc1 ,MEMSUFFIX ) (void ) +{ +glue (stl,MEMSUFFIX )(T0 ,WT0 ); +RETURN (); +} +void glue (op_ldc1 ,MEMSUFFIX ) (void ) +{ +DT0 =glue (ldq,MEMSUFFIX )(T0 ); +//CALL_FROM_TB0(dump_fpu); +RETURN (); +} +void glue (op_sdc1 ,MEMSUFFIX ) (void ) +{ +//CALL_FROM_TB0(dump_fpu); +glue (stq,MEMSUFFIX )(T0 ,DT0 ); +RETURN (); +} +#endif
Index: target-mips/translate.c
===================================================================
RCS file: /sources/qemu/qemu/target-mips/translate.c,v retrieving revision 1.12
translate.c +602 -4
697 lines not on this page · raw message
fop_template.c new file +81 -0
81 lines not on this page · raw message
Quoted 1 line · Marius Groeger
again, a current version of my FPU patch for MIPS. Fabrice, I tried to
Sorry, hunk #1 of the target-mips/op_mem.c patch got out wrong. (I wanted to remove other feature patches[1] first and seemed to have messed up in doing so.) Just delete this hunk before appling the patch.
Sorry and Best Regards
Marius
[1] qemu-0.8.0-mips-cp0.patch,
qemu-0.8.0-mips-lwu.patch,
qemu-0.8.0-mips-aligned-pc.patchSignature · 4 lines
Marius Groeger <[email protected]> SYSGO AG Embedded and Real-Time Software Voice: +49 6136 9948 0 FAX: +49 6136 9948 10 www.sysgo.com | www.elinos.com | www.osek.de | www.pikeos.com
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 8 lines · Flavien
Quoted 1 line
Sorry, hunk #1 of the
target-mips/op_mem.cpatch got out wrong.Please re-diff against CVS and re-send it to the list.
BTW, fix the indentation to be consistent with the rest of the code. One level is 4 spaces. Not 8, not tab.
That'll be easier for everyone. Thanks !
Here's the patch again, rediffed and untabified as requested.
Thanks,
Marius
Signature · 4 lines
Marius Groeger <[email protected]> SYSGO AG Embedded and Real-Time Software Voice: +49 6136 9948 0 FAX: +49 6136 9948 10 www.sysgo.com | www.elinos.com | www.osek.de | www.pikeos.com
Index: target-mips/cpu.h
===================================================================
RCS file: /sources/qemu/qemu/target-mips/cpu.h,v
retrieving revision 1.6
cpu.h +38 -13
@@ -10,9 +10,11 @@typedef union fpr_t fpr_t ;union fpr_t { -double d; -float f; -uint32_t u[2 ]; +float64 fd;/* ieee double precision */ +float32 fs;/* ieee single precision */ +int64_t d;/* binary single fixed-point */ +int32_t w;/* binary single fixed-point */ +uint32_t u32[2 ]; };#if defined(MIPS_USES_R4K_TLB )
@@ -43,16 +45,41 @@uint32_t DCR ;/* ? */ #if defined(MIPS_USES_FPU )/* Floating point registers */ -fpr_t fpr[16 ]; -/* Floating point special purpose registers */ +uint32_t fpr[2 *32 ]; +#define FPR (cpu, n, fmt) ((fpr_t*)&(cpu)->fpr[(n) & 0x1f]) + +#ifndef USE_HOST_FLOAT_REGS +fpr_t ft0; +fpr_t ft1; +fpr_t ft2; +#endif +float_status fp_status; +/* fpu implementation/revision register */ uint32_t fcr0; -uint32_t fcr25; -uint32_t fcr26; -uint32_t fcr28; -uint32_t fcsr; +/* fcsr */ +uint32_t fcr31; +/* set condition, "c" must be 0 or 1 */ +#define SET_FP_COND (reg, c) do { \ +/*assert(c == 0 || c == 1);*/ \ + (reg) = ((reg) & ~(1 <<23 )) | ((c)<<23 ); \ + } while(0) +#define IS_FP_COND_SET (reg) (((reg) & (1<<23)) != 0) +#define GET_FP_CAUSE (reg) (((reg) >> 12) & 0x3f) +#define GET_FP_ENABLE (reg) (((reg) >> 7) & 0x1f) +#define GET_FP_FLAGS (reg) (((reg) >> 2) & 0x1f) +#define SET_FP_CAUSE (reg,v) do { (reg) = ((reg) & ~(0x3f << 12)) | ((v) << 12); } while(0) +#define SET_FP_ENABLE (reg,v) do { (reg) = ((reg) & ~(0x1f << 7)) | ((v) << 7); } while(0) +#define SET_FP_FLAGS (reg,v) do { (reg) = ((reg) & ~(0x1f << 2)) | ((v) << 2); } while(0) +#define FP_INEXACT 1 +#define FP_UNDERFLOW 2 +#define FP_OVERFLOW 4 +#define FP_DIV0 8 +#define FP_INVALID 16 +#define FP_UNIMPLEMENTED 32 +#endif #if defined(MIPS_USES_R4K_TLB ) -tlb_t tlb[16 ]; +tlb_t tlb[MIPS_TLB_NB ];#endif uint32_t CP0_index;uint32_t CP0_random;
@@ -71,6 +98,7 @@#define CP0St_CU1 29#define CP0St_CU0 28#define CP0St_RP 27 +#define CP0St_FR 26#define CP0St_RE 25#define CP0St_BEV 22#define CP0St_TS 21
@@ -138,9 +166,6 @@uint32_t CP0_ErrorEPC;uint32_t CP0_DESAVE ;/* Qemu */ -#if defined (USE_HOST_FLOAT_REGS ) && defined(MIPS_USES_FPU ) -double ft0, ft1, ft2; -#endif struct QEMUTimer *timer;/* Internal timer */ int interrupt_request;jmp_buf jmp_env;
Index: target-mips/exec.h
===================================================================
RCS file: /sources/qemu/qemu/target-mips/exec.h,v
retrieving revision 1.7
exec.h +20 -6
@@ -21,13 +21,20 @@ register host_uint_t T2 asm(AREG3);#if defined (USE_HOST_FLOAT_REGS ) -register double FT0 asm(FREG0); -register double FT1 asm(FREG1); -register double FT2 asm(FREG2); +#error "implement me."#else -#define FT0 (env->ft0.d) -#define FT1 (env->ft1.d) -#define FT2 (env->ft2.d) +#define FDT0 (env->ft0.fd) +#define FDT1 (env->ft1.fd) +#define FDT2 (env->ft2.fd) +#define FST0 (env->ft0.fs) +#define FST1 (env->ft1.fs) +#define FST2 (env->ft2.fs) +#define DT0 (env->ft0.d) +#define DT1 (env->ft1.d) +#define DT2 (env->ft2.d) +#define WT0 (env->ft0.w) +#define WT1 (env->ft1.w) +#define WT2 (env->ft2.w)#endif #if defined (DEBUG_OP )
@@ -65,6 +72,13 @@void do_tlbwr (void );void do_tlbp (void );void do_tlbr (void ); +#ifdef MIPS_USES_FPU +void dump_fpu (CPUState *env); +void fpu_dump_state (CPUState *env,FILE *f, +int (*fpu_fprintf)(FILE *f,const char *fmt, ...), +int flags); +#endif +void dump_sc (void );void do_lwl_raw (uint32_t );void do_lwr_raw (uint32_t );uint32_t do_swl_raw (uint32_t );
Index: target-mips/mips-defs.h
===================================================================
RCS file: /sources/qemu/qemu/target-mips/mips-defs.h,v retrieving revision 1.1
mips-defs.h +3 -1
@@ -24,6 +24,8 @@/* Uses MIPS R4Kc TLB model */ #define MIPS_USES_R4K_TLB #define MIPS_TLB_NB 16 +/* basic FPU register support */ +#define MIPS_USES_FPU /* Have config1, runs in big-endian mode, uses TLB */ #define MIPS_CONFIG0 \ ((1 << CP0C0_M) | (0x000 << CP0C0_K23) | (0x000 << CP0C0_KU) | \
@@ -52,7 +54,7 @@#error "MIPS CPU not defined"/* Remainder for other flags */ //#define TARGET_MIPS64 -//define MIPS_USES_FPU +//#define MIPS_USES_FPU #endif #endif /* !defined (__QEMU_MIPS_DEFS_H__) */
Index: target-mips/op.c
===================================================================
RCS file: /sources/qemu/qemu/target-mips/op.c,v
retrieving revision 1.7
op.c +359 -0
377 lines not on this page · raw message
Index: target-mips/op_helper.c
===================================================================
RCS file: /sources/qemu/qemu/target-mips/op_helper.c,v retrieving revision 1.11
op_helper.c +41 -0
47 lines not on this page · raw message
Index: target-mips/op_mem.c
===================================================================
RCS file: /sources/qemu/qemu/target-mips/op_mem.c,v retrieving revision 1.2
op_mem.c +23 -0
@@ -118,3 +118,26 @@ }RETURN (); } + +#ifdef MIPS_USES_FPU +void glue (op_lwc1 ,MEMSUFFIX ) (void ) +{ +WT0 =glue (ldl,MEMSUFFIX )(T0 ); +RETURN (); +} +void glue (op_swc1 ,MEMSUFFIX ) (void ) +{ +glue (stl,MEMSUFFIX )(T0 ,WT0 ); +RETURN (); +} +void glue (op_ldc1 ,MEMSUFFIX ) (void ) +{ +DT0 =glue (ldq,MEMSUFFIX )(T0 ); +RETURN (); +} +void glue (op_sdc1 ,MEMSUFFIX ) (void ) +{ +glue (stq,MEMSUFFIX )(T0 ,DT0 ); +RETURN (); +} +#endif
Index: target-mips/translate.c
===================================================================
RCS file: /sources/qemu/qemu/target-mips/translate.c,v retrieving revision 1.12
translate.c +596 -2
665 lines not on this page · raw message
fop_template.c new file +81 -0
81 lines not on this page · raw message