FPU support for MIPS
PATCH 1/1 FPU support for MIPS
Hi All,
a new version of my FPU patch, now actually doing some math. Known issues include, but may not be limited to:
- only support .d format, that is IEEE 64bit
- no proper float exception handling. If someone gets CONFIG_SOFTFLOAT to compile, this should be quite easy to improve. Most of the infrastructure required is in place.
Feedback welcome!
Cheers,
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 +46 -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,48 @@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) \ + (((cpu)->CP0_Status & (1<<CP0St_FR)) ? \ + ((fpr_t*)&(cpu)->fpr[(n) & 0x1f]) : \ + ((fmt) == 1 ? \ + ((fpr_t*)&(cpu)->fpr[(n) & 0x1e]) : \ + ((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 +106,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 +174,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 +21 -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,14 @@void do_tlbwr (void );void do_tlbp (void );void do_tlbr (void ); +#ifdef MIPS_USES_FPU +int do_cmp_d (void ); +void dump_fpu (void ); +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 +261 -0
273 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 +109 -0
121 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 +31 -0
@@ -61,6 +61,12 @@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 +124,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 +457 -6
572 lines not on this page · raw message
fop_template.c new file +134 -0
134 lines not on this page · raw message
A few remarks:
1) Why do you use 3 temporaries ? Maybe two suffice in most cases.
2) do_cmp_d() should be completely decoded at translation time.
3) I suspect the macro FPR() does too many things at runtime which gives an important performance loss. CP0St_FR should be known at translation time.
You should use CONFIG_SOFTFLOAT to validate your code. The ARM target does it, so it works (see the configure script).
Fabrice.
Quoted 13 lines · Marius Groeger
Hi All,
a new version of my FPU patch, now actually doing some math. Known issues include, but may not be limited to:
- only support .d format, that is IEEE 64bit
- no proper float exception handling. If someone getsCONFIG_SOFTFLOATto compile, this should be quite easy to improve. Most of the infrastructure required is in place.Feedback welcome!
Cheers,
Marius
Hi Fabrice,
thanks for the review.
Quoted 1 line · Fabrice Bellard
1) Why do you use 3 temporaries ? Maybe two suffice in most cases.
Well, I less temporaries don't gain performance, while a
FDT2 = FDT0 * FDT1
fpu_dump_state()
allows for easier debugging. Therefore I'd rather keep three temps, but I can change that if you think it's too much bloat.
Quoted 1 line
2)
do_cmp_d()should be completely decoded at translation time.
Hm. Yeah. I just don't quite now about the limitations of generated code. In the !CONFIG_SOFTFLOAT case, the softfloat-native will use compiler/libc defined stuff like isgreater(), libm, whatever. Is is really safe to assume all that code can be generated? I felt better with a CALL_FROM_TB(). Maybe you can enlighten me a bit there.
Also, is a call really that much slower? It might even benefit from the called function being in the host cpu cache already. Any figures on that available?
Quoted 1 line
3) I suspect the macro
FPR()does too many things at runtime which gives an important performance loss.CP0St_FRshould be known at translation time.
I'll see what I can do.
Quoted 1 line
You should use
CONFIG_SOFTFLOATto validate your code. The ARM target does it, so it works (see the configure script).
Ok, I got pretty weird errors in the floatx80 area and it kind of looked like this is broken. I must have missed something then.
While there: I noticed it's very difficult at best to properly emulate floating point states and exceptions when using native float; the softfloat has a nice interface for that stuff. How's the world order to handle this?
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
Re: [Qemu-devel] [PATCH][MIPS]
Hi!
The current CVS QEMU Makefile builds "qemu-system-mips" binary which really emulates a little-endian system and should be renamed to the "qemu-system-mipsel"
[alec@ilias qemu/bin]$ ls
qemu qemu-i386 qemu-mipsel qemu-sparc qemu-system-ppc qemu-arm qemu-img qemu-ppc qemu-system-arm qemu-system-sparc qemu-armeb qemu-mips qemu-sh4 qemu-system-mips qemu-system-x86_64
Is it possible to build _both_ "qemu-system-mips*" for LE and BE support like userspace does ?
--
-=AV=-
Re: [Qemu-devel] [PATCH][MIPS]
Quoted 3 lines · Alexander Voropay
The current CVS QEMU
Makefilebuilds "qemu-system-mips" binary which really emulates a little-endian system and should be renamed to the "qemu-system-mipsel"
With configure --target-list you can select mips-softmmu or mipsel-softmmu. So I think it's a good idea to extend build system to generate
mips-softmmu -> qemu-system-mips (big endian) mipsel-softmmu -> qemu-system-mipsel (little endian)
Has anybody a patch for this?
Quoted 2 lines
Is it possible to build _both_ "qemu-system-mips*" for LE and BE support like userspace does ?
I don't think so at the moment. I'm not sure what happens if both (little and big endian) targets are selected by configure.
Dirk