From 066033e4c600bc1f01ffc88edce077dbcf23a0c1 Mon Sep 17 00:00:00 2001 From: Frode Solheim Date: Fri, 18 Sep 2015 18:19:14 +0200 Subject: [PATCH] JIT: use COMP_OPCODE_* constants, (partially) support runtime fpu option --- include/newcpu.h | 7 +++ jit/compemu.h | 4 ++ jit/compemu_support.cpp | 21 ++++++-- jit/gencomp.cpp | 107 ++++++++++++++++++++++++++-------------- 4 files changed, 99 insertions(+), 40 deletions(-) diff --git a/include/newcpu.h b/include/newcpu.h index 37adf067..37d7031c 100644 --- a/include/newcpu.h +++ b/include/newcpu.h @@ -70,6 +70,13 @@ struct cputbl { #ifdef JIT typedef uae_u32 REGPARAM3 compop_func (uae_u32) REGPARAM; +#define COMP_OPCODE_ISJUMP 0x0001 +#define COMP_OPCODE_LONG_OPCODE 0x0002 +#define COMP_OPCODE_CMOV 0x0004 +#define COMP_OPCODE_ISADDX 0x0008 +#define COMP_OPCODE_ISCJUMP 0x0010 +#define COMP_OPCODE_USES_FPU 0x0020 + struct comptbl { compop_func *handler; uae_u32 opcode; diff --git a/jit/compemu.h b/jit/compemu.h index b183ae40..2561bb14 100644 --- a/jit/compemu.h +++ b/jit/compemu.h @@ -41,6 +41,9 @@ typedef uae_u64 uintptr; typedef uae_u32 uintptr; #endif #define USE_JIT +#ifdef CPU_i386 +#define USE_JIT_FPU +#endif #endif #ifdef USE_JIT @@ -359,6 +362,7 @@ extern void calc_disp_ea_020(int base, uae_u32 dp, int target, int tmp); /* Set native Z flag only if register is zero */ extern void set_zero(int r, int tmp); extern int kill_rodent(int r); +#define SYNC_PC_OFFSET 100 extern void sync_m68k_pc(void); extern uae_u32 get_const(int r); extern int is_const(int r); diff --git a/jit/compemu_support.cpp b/jit/compemu_support.cpp index b9bd3b40..e5362b1f 100644 --- a/jit/compemu_support.cpp +++ b/jit/compemu_support.cpp @@ -3847,15 +3847,28 @@ void build_comp(void) } for (i = 0; tbl[i].opcode < 65536; i++) { - int isjmp = (tbl[i].specific & 1); - int isaddx = (tbl[i].specific & 8); - int iscjmp = (tbl[i].specific & 16); + int isjmp = (tbl[i].specific & COMP_OPCODE_ISJUMP); + int isaddx = (tbl[i].specific & COMP_OPCODE_ISADDX); + int iscjmp = (tbl[i].specific & COMP_OPCODE_ISCJUMP); prop[cft_map(tbl[i].opcode)].is_jump = isjmp; prop[cft_map(tbl[i].opcode)].is_const_jump = iscjmp; prop[cft_map(tbl[i].opcode)].is_addx = isaddx; - compfunctbl[cft_map(tbl[i].opcode)] = tbl[i].handler; + + bool uses_fpu = (tbl[i].specific & COMP_OPCODE_USES_FPU) != 0; +#ifdef UAE +#ifdef USE_JIT_FPU + avoid_fpu = false; +#else + avoid_fpu = true; +#endif +#endif + if (uses_fpu && avoid_fpu) + compfunctbl[cft_map(tbl[i].opcode)] = NULL; + else + compfunctbl[cft_map(tbl[i].opcode)] = tbl[i].handler; } + for (i = 0; nftbl[i].opcode < 65536; i++) { nfcompfunctbl[cft_map(nftbl[i].opcode)] = nftbl[i].handler; #ifdef NOFLAGS_SUPPORT diff --git a/jit/gencomp.cpp b/jit/gencomp.cpp index 98711839..356673d4 100644 --- a/jit/gencomp.cpp +++ b/jit/gencomp.cpp @@ -27,7 +27,12 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifdef UAE #include "sysconfig.h" +#else +#define CC_FOR_BUILD 1 +#endif + #include "sysdeps.h" #include "readcpu.h" @@ -37,6 +42,7 @@ #include #include #include +#undef abort #ifdef UAE /* @@ -88,10 +94,6 @@ #define DISABLE_I_FSCC #define DISABLE_I_MOVE16 */ - -#ifdef CPU_x86_64 -#define DISABLE_I_FPP -#endif #endif /* UAE */ #ifdef UAE @@ -129,11 +131,7 @@ static char endstr[1000]; static char lines[100000]; static int comp_index=0; -#if defined(CPU_arm) -# include "flags_arm.h" -#else -# include "flags_x86.h" -#endif +#include "flags_x86.h" static int cond_codes[]={-1,-1, NATIVE_CC_HI,NATIVE_CC_LS, @@ -324,10 +322,25 @@ gen_nextibyte (void) return buffer; } + +static void +swap_opcode (void) +{ +#ifdef UAE + /* no-op */ +#else + comprintf("#ifdef USE_JIT_FPU\n"); + comprintf("#if defined(HAVE_GET_WORD_UNSWAPPED) && !defined(FULLMMU)\n"); + comprintf("\topcode = do_byteswap_16(opcode);\n"); + comprintf("#endif\n"); + comprintf("#endif\n"); +#endif +} + static void sync_m68k_pc (void) { - comprintf("\t if (m68k_pc_offset>100) sync_m68k_pc();\n"); + comprintf("\t if (m68k_pc_offset > SYNC_PC_OFFSET) sync_m68k_pc();\n"); } @@ -1280,7 +1293,7 @@ genflags (flagtypes type, wordsizes size, const char *value, const char *src, co } static int /* returns zero for success, non-zero for failure */ -gen_opcode (unsigned long int opcode) +gen_opcode (unsigned int opcode) { struct instr *curi = table68k + opcode; const char* ssize=NULL; @@ -2949,9 +2962,15 @@ case i_TAS: #ifdef DISABLE_I_FPP failure; #endif + uses_fpu; mayfail; + comprintf("#ifdef USE_JIT_FPU\n"); comprintf("\tuae_u16 extra=%s;\n",gen_nextiword()); + swap_opcode(); comprintf("\tcomp_fpp_opp(opcode,extra);\n"); + comprintf("#else\n"); + comprintf("\tfailure = 1;\n"); + comprintf("#endif\n"); break; case i_FBcc: @@ -2961,10 +2980,16 @@ case i_TAS: isjump; uses_cmov; mayfail; + comprintf("#ifdef USE_JIT_FPU\n"); + swap_opcode(); comprintf("\tcomp_fbcc_opp(opcode);\n"); + comprintf("#else\n"); + comprintf("\tfailure = 1;\n"); + comprintf("#endif\n"); break; case i_FDBcc: + uses_fpu; isjump; failure; break; @@ -2975,20 +3000,28 @@ case i_TAS: #endif mayfail; uses_cmov; + comprintf("#ifdef USE_JIT_FPU\n"); comprintf("\tuae_u16 extra=%s;\n",gen_nextiword()); + swap_opcode(); comprintf("\tcomp_fscc_opp(opcode,extra);\n"); + comprintf("#else\n"); + comprintf("\tfailure = 1;\n"); + comprintf("#endif\n"); break; case i_FTRAPcc: + uses_fpu; isjump; failure; break; case i_FSAVE: + uses_fpu; failure; break; case i_FRESTORE: + uses_fpu; failure; break; @@ -3053,11 +3086,12 @@ generate_includes (FILE * f) fprintf (f, "#include \"memory.h\"\n"); #else fprintf (f, "#include \"m68k.h\"\n"); - fprintf (f, "#include \"memory.h\"\n"); + fprintf (f, "#include \"memory-uae.h\"\n"); #endif fprintf (f, "#include \"readcpu.h\"\n"); fprintf (f, "#include \"newcpu.h\"\n"); fprintf (f, "#include \"comptbl.h\"\n"); + fprintf (f, "#include \"debug.h\"\n"); } static int postfix; @@ -3175,7 +3209,7 @@ generate_one_opcode (int rp, int noflags) { int i; uae_u16 smsk, dmsk; - long int opcode = opcode_map[rp]; + unsigned int opcode = opcode_map[rp]; int aborted=0; int have_srcreg=0; int have_dstreg=0; @@ -3304,32 +3338,31 @@ generate_one_opcode (int rp, int noflags) aborted=gen_opcode (opcode); { - int flags=0; - if (global_isjump) flags|=1; - if (long_opcode) flags|=2; - if (global_cmov) flags|=4; - if (global_isaddx) flags|=8; - if (global_iscjump) flags|=16; -#ifdef UAE - comprintf ("return 0;\n"); -#endif + char flags[64 * 6]; + *flags = '\0'; + if (global_isjump) strcat(flags, "COMP_OPCODE_ISJUMP|"); + if (long_opcode) strcat(flags, "COMP_OPCODE_LONG_OPCODE|"); + if (global_cmov) strcat(flags, "COMP_OPCODE_CMOV|"); + if (global_isaddx) strcat(flags, "COMP_OPCODE_ISADDX|"); + if (global_iscjump) strcat(flags, "COMP_OPCODE_ISCJUMP|"); + if (global_fpu) strcat(flags, "COMP_OPCODE_USES_FPU|"); + if (*flags) + flags[strlen(flags) - 1] = '\0'; + else + strcpy(flags, "0"); + comprintf ("}\n"); char *name = ua (lookuptab[i].name); if (aborted) { - fprintf (stblfile, "{ NULL, %ld, 0x%08x }, /* %s */\n", opcode, flags, name); + fprintf (stblfile, "{ NULL, %u, %s }, /* %s */\n", opcode, flags, name); com_discard(); } else { + const char *tbl = noflags ? "nf" : "ff"; printf ("/* %s */\n", outopcode (opcode)); - if (noflags) { - fprintf (stblfile, "{ op_%lx_%d_comp_nf, %ld, 0x%08x }, /* %s */\n", opcode, postfix, opcode, flags, name); - fprintf (headerfile, "extern compop_func op_%lx_%d_comp_nf;\n", opcode, postfix); - printf ("uae_u32 REGPARAM2 op_%lx_%d_comp_nf(uae_u32 opcode)\n{\n", opcode, postfix); - } else { - fprintf (stblfile, "{ op_%lx_%d_comp_ff, %ld, 0x%08x }, /* %s */\n", opcode, postfix, opcode, flags, name); - fprintf (headerfile, "extern compop_func op_%lx_%d_comp_ff;\n", opcode, postfix); - printf ("uae_u32 REGPARAM2 op_%lx_%d_comp_ff(uae_u32 opcode)\n{\n", opcode, postfix); - } + fprintf (stblfile, "{ op_%x_%d_comp_%s, %u, %s }, /* %s */\n", opcode, postfix, tbl, opcode, flags, name); + fprintf (headerfile, "extern compop_func op_%x_%d_comp_%s;\n", opcode, postfix, tbl); + printf ("uae_u32 REGPARAM2 op_%x_%d_comp_%s(uae_u32 opcode)\n{\n", opcode, postfix, tbl); com_flush(); } xfree (name); @@ -3371,10 +3404,12 @@ generate_func (int noflags) "#define PART_6 1\n" "#define PART_7 1\n" "#define PART_8 1\n" - "#endif\n\n" - "extern void comp_fpp_opp();\n" - "extern void comp_fscc_opp();\n" - "extern void comp_fbcc_opp();\n\n"); + "#endif\n\n"); +#ifdef UAE + printf ("extern void comp_fpp_opp();\n" + "extern void comp_fscc_opp();\n" + "extern void comp_fbcc_opp();\n\n"); +#endif rp = 0; for (j = 1; j <= 8; ++j) -- 2.47.3