X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=prvm_exec.c;h=8fb0d69254722617045db75231ebb23c047bbf99;hb=1a606ca4c462e8a9a76cd5e7e085efbecbe90009;hp=a4f529c27c379f423cd470861899885f4db1d451;hpb=2f311cc6db562c4a78e216f914fdbeab4227aa69;p=xonotic%2Fdarkplaces.git diff --git a/prvm_exec.c b/prvm_exec.c index a4f529c2..8fb0d692 100644 --- a/prvm_exec.c +++ b/prvm_exec.c @@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include "progsvm.h" -char *prvm_opnames[] = +const char *prvm_opnames[] = { "^5DONE", @@ -112,6 +112,7 @@ char *prvm_opnames[] = char *PRVM_GlobalString (int ofs); char *PRVM_GlobalStringNoContents (int ofs); +extern ddef_t *PRVM_ED_FieldAtOfs(int ofs); //============================================================================= @@ -122,7 +123,8 @@ PRVM_PrintStatement ================= */ extern cvar_t prvm_statementprofiling; -void PRVM_PrintStatement (dstatement_t *s) +extern cvar_t prvm_timeprofiling; +void PRVM_PrintStatement(mstatement_t *s) { size_t i; int opnum = (int)(s - prog->statements); @@ -144,46 +146,10 @@ void PRVM_PrintStatement (dstatement_t *s) for ( ; i<10 ; i++) Con_Print(" "); } - if (s->op == OP_IF || s->op == OP_IFNOT) - Con_Printf("%s, s%i",PRVM_GlobalString((unsigned short) s->a),(signed short)s->b + opnum); - else if (s->op == OP_GOTO) - Con_Printf("s%i",(signed short)s->a + opnum); - else if ( (unsigned)(s->op - OP_STORE_F) < 6) - { - Con_Print(PRVM_GlobalString((unsigned short) s->a)); - Con_Print(", "); - Con_Print(PRVM_GlobalStringNoContents((unsigned short) s->b)); - } - else if (s->op == OP_ADDRESS || (unsigned)(s->op - OP_LOAD_F) < 6) - { - if (s->a) - Con_Print(PRVM_GlobalString((unsigned short) s->a)); - if (s->b) - { - Con_Print(", "); - Con_Print(PRVM_GlobalStringNoContents((unsigned short) s->b)); - } - if (s->c) - { - Con_Print(", "); - Con_Print(PRVM_GlobalStringNoContents((unsigned short) s->c)); - } - } - else - { - if (s->a) - Con_Print(PRVM_GlobalString((unsigned short) s->a)); - if (s->b) - { - Con_Print(", "); - Con_Print(PRVM_GlobalString((unsigned short) s->b)); - } - if (s->c) - { - Con_Print(", "); - Con_Print(PRVM_GlobalStringNoContents((unsigned short) s->c)); - } - } + if (s->operand[0] >= 0) Con_Printf( "%s", PRVM_GlobalString(s->operand[0])); + if (s->operand[1] >= 0) Con_Printf(", %s", PRVM_GlobalString(s->operand[1])); + if (s->operand[2] >= 0) Con_Printf(", %s", PRVM_GlobalString(s->operand[2])); + if (s->jumpabsolute >= 0) Con_Printf(", statement %i", s->jumpabsolute); Con_Print("\n"); } @@ -205,13 +171,13 @@ void PRVM_PrintFunctionStatements (const char *name) } // find the end statement - endstatement = prog->progs->numstatements; - for (i = 0;i < prog->progs->numfunctions;i++) + endstatement = prog->numstatements; + for (i = 0;i < prog->numfunctions;i++) if (endstatement > prog->functions[i].first_statement && firststatement < prog->functions[i].first_statement) endstatement = prog->functions[i].first_statement; // now print the range of statements - Con_Printf("%s progs: disassembly of function %s (statements %i-%i):\n", PRVM_NAME, name, firststatement, endstatement); + Con_Printf("%s progs: disassembly of function %s (statements %i-%i, locals %i-%i):\n", PRVM_NAME, name, firststatement, endstatement, func->parm_start, func->parm_start + func->locals - 1); for (i = firststatement;i < endstatement;i++) { PRVM_PrintStatement(prog->statements + i); @@ -311,7 +277,7 @@ void PRVM_CallProfile (void) { max = 0; best = NULL; - for (i=0 ; iprogs->numfunctions ; i++) + for (i=0 ; inumfunctions ; i++) { f = &prog->functions[i]; if (max < f->totaltime) @@ -334,54 +300,108 @@ void PRVM_CallProfile (void) prog->starttime = Sys_DoubleTime(); } -void PRVM_Profile (int maxfunctions, int mininstructions, int sortby) +void PRVM_Profile (int maxfunctions, double mintime, int sortby) { mfunction_t *f, *best; int i, num; double max; - Con_Printf( "%s Profile:\n[CallCount] [Statement] [BuiltinCt] [StmtTotal] [BltnTotal] [self]\n", PRVM_NAME ); - // 12345678901 12345678901 12345678901 12345678901 12345678901 123.45% + if(!prvm_timeprofiling.integer) + mintime *= 10000000; // count each statement as about 0.1µs + + if(prvm_timeprofiling.integer) + Con_Printf( "%s Profile:\n[CallCount] [Time] [BuiltinTm] [Statement] [BuiltinCt] [TimeTotal] [StmtTotal] [BltnTotal] [self]\n", PRVM_NAME ); + // 12345678901 12345678901 12345678901 12345678901 12345678901 12345678901 12345678901 123.45% + else + Con_Printf( "%s Profile:\n[CallCount] [Statement] [BuiltinCt] [StmtTotal] [BltnTotal] [self]\n", PRVM_NAME ); + // 12345678901 12345678901 12345678901 12345678901 12345678901 123.45% num = 0; do { max = 0; best = NULL; - for (i=0 ; iprogs->numfunctions ; i++) + for (i=0 ; inumfunctions ; i++) { f = &prog->functions[i]; - if(sortby) + if(prvm_timeprofiling.integer) { - if (max < f->profile_total + f->builtinsprofile_total + f->callcount) + if(sortby) + { + if(f->first_statement < 0) + { + if (max < f->tprofile) + { + max = f->tprofile; + best = f; + } + } + else + { + if (max < f->tprofile_total) + { + max = f->tprofile_total; + best = f; + } + } + } + else { - max = f->profile_total + f->builtinsprofile_total + f->callcount; - best = f; + if (max < f->tprofile + f->tbprofile) + { + max = f->tprofile + f->tbprofile; + best = f; + } } } else { - if (max < f->profile + f->builtinsprofile + f->callcount) + if(sortby) + { + if (max < f->profile_total + f->builtinsprofile_total + f->callcount) + { + max = f->profile_total + f->builtinsprofile_total + f->callcount; + best = f; + } + } + else { - max = f->profile + f->builtinsprofile + f->callcount; - best = f; + if (max < f->profile + f->builtinsprofile + f->callcount) + { + max = f->profile + f->builtinsprofile + f->callcount; + best = f; + } } } } if (best) { - if (num < maxfunctions && max >= mininstructions) + if (num < maxfunctions && max > mintime) { - if (best->first_statement < 0) - Con_Printf("%11.0f ----------------------- builtin ----------------------- %s\n", best->callcount, PRVM_GetString(best->s_name)); - // 12345678901 12345678901 12345678901 12345678901 123.45% + if(prvm_timeprofiling.integer) + { + if (best->first_statement < 0) + Con_Printf("%11.0f %11.6f ------------- builtin ------------- %11.6f ----------- builtin ----------- %s\n", best->callcount, best->tprofile, best->tprofile, PRVM_GetString(best->s_name)); + // %11.6f 12345678901 12345678901 12345678901 %11.6f 12345678901 12345678901 123.45% + else + Con_Printf("%11.0f %11.6f %11.6f %11.0f %11.0f %11.6f %11.0f %11.0f %6.2f%% %s\n", best->callcount, best->tprofile, best->tbprofile, best->profile, best->builtinsprofile, best->tprofile_total, best->profile_total, best->builtinsprofile_total, (best->tprofile_total > 0) ? ((best->tprofile) * 100.0 / (best->tprofile_total)) : -99.99, PRVM_GetString(best->s_name)); + } else - Con_Printf("%11.0f %11.0f %11.0f %11.0f %11.0f %6.2f%% %s\n", best->callcount, best->profile, best->builtinsprofile, best->profile_total, best->builtinsprofile_total, (best->profile + best->builtinsprofile) * 100.0 / (best->profile_total + best->builtinsprofile_total), PRVM_GetString(best->s_name)); + { + if (best->first_statement < 0) + Con_Printf("%11.0f ----------------------- builtin ----------------------- %s\n", best->callcount, PRVM_GetString(best->s_name)); + // 12345678901 12345678901 12345678901 12345678901 123.45% + else + Con_Printf("%11.0f %11.0f %11.0f %11.0f %11.0f %6.2f%% %s\n", best->callcount, best->profile, best->builtinsprofile, best->profile_total, best->builtinsprofile_total, (best->profile + best->builtinsprofile) * 100.0 / (best->profile_total + best->builtinsprofile_total), PRVM_GetString(best->s_name)); + } } num++; best->profile = 0; + best->tprofile = 0; + best->tbprofile = 0; best->builtinsprofile = 0; best->profile_total = 0; + best->tprofile_total = 0; best->builtinsprofile_total = 0; best->callcount = 0; } @@ -434,7 +454,7 @@ void PRVM_Profile_f (void) if(!PRVM_SetProgFromString(Cmd_Argv(1))) return; - PRVM_Profile(howmany, 1, 0); + PRVM_Profile(howmany, 0, 0); PRVM_End; } @@ -456,7 +476,7 @@ void PRVM_ChildProfile_f (void) if(!PRVM_SetProgFromString(Cmd_Argv(1))) return; - PRVM_Profile(howmany, 1, 1); + PRVM_Profile(howmany, 0, 1); PRVM_End; } @@ -503,7 +523,7 @@ void PRVM_Crash(void) if (prog == NULL) return; - prog->funcoffsets.SV_Shutdown = 0; // don't call SV_Shutdown on crash + PRVM_serverfunction(SV_Shutdown) = 0; // don't call SV_Shutdown on crash if( prog->depth > 0 ) { @@ -553,6 +573,7 @@ int PRVM_EnterFunction (mfunction_t *f) prog->stack[prog->depth].s = prog->xstatement; prog->stack[prog->depth].f = prog->xfunction; prog->stack[prog->depth].profile_acc = -f->profile; + prog->stack[prog->depth].tprofile_acc = -f->tprofile + -f->tbprofile; prog->stack[prog->depth].builtinsprofile_acc = -f->builtinsprofile; prog->depth++; if (prog->depth >=PRVM_MAX_STACK_DEPTH) @@ -613,10 +634,12 @@ int PRVM_LeaveFunction (void) --f->recursion; prog->xfunction = prog->stack[prog->depth].f; prog->stack[prog->depth].profile_acc += f->profile; + prog->stack[prog->depth].tprofile_acc += f->tprofile + f->tbprofile; prog->stack[prog->depth].builtinsprofile_acc += f->builtinsprofile; if(prog->depth > 0) { prog->stack[prog->depth-1].profile_acc += prog->stack[prog->depth].profile_acc; + prog->stack[prog->depth-1].tprofile_acc += prog->stack[prog->depth].tprofile_acc; prog->stack[prog->depth-1].builtinsprofile_acc += prog->stack[prog->depth].builtinsprofile_acc; } if(!f->recursion) @@ -626,6 +649,7 @@ int PRVM_LeaveFunction (void) // or we would add it more than once // so, let's only add to the function's profile if it is the outermost call f->profile_total += prog->stack[prog->depth].profile_acc; + f->tprofile_total += prog->stack[prog->depth].tprofile_acc; f->builtinsprofile_total += prog->stack[prog->depth].builtinsprofile_acc; } @@ -641,36 +665,37 @@ void PRVM_Init_Exec(void) // nothing here yet } +#define OPA ((prvm_eval_t *)&prog->globals.generic[st->operand[0]]) +#define OPB ((prvm_eval_t *)&prog->globals.generic[st->operand[1]]) +#define OPC ((prvm_eval_t *)&prog->globals.generic[st->operand[2]]) +extern cvar_t prvm_traceqc; +extern cvar_t prvm_statementprofiling; +extern sizebuf_t vm_tempstringsbuf; +extern qboolean prvm_runawaycheck; + +#ifdef PROFILING /* ==================== MVM_ExecuteProgram ==================== */ -// LordHavoc: optimized -#define OPA ((prvm_eval_t *)&prog->globals.generic[(unsigned short) st->a]) -#define OPB ((prvm_eval_t *)&prog->globals.generic[(unsigned short) st->b]) -#define OPC ((prvm_eval_t *)&prog->globals.generic[(unsigned short) st->c]) -extern cvar_t prvm_traceqc; -extern cvar_t prvm_statementprofiling; -extern sizebuf_t vm_tempstringsbuf; -extern qboolean prvm_runawaycheck; -extern qboolean prvm_boundscheck; void MVM_ExecuteProgram (func_t fnum, const char *errormessage) { - dstatement_t *st, *startst; + mstatement_t *st, *startst; mfunction_t *f, *newf; prvm_edict_t *ed; prvm_eval_t *ptr; int jumpcount, cachedpr_trace, exitdepth; int restorevm_tempstringsbuf_cursize; double calltime; + double tm, starttm; calltime = Sys_DoubleTime(); - if (!fnum || fnum >= (unsigned int)prog->progs->numfunctions) + if (!fnum || fnum >= (unsigned int)prog->numfunctions) { - if (prog->globaloffsets.self >= 0 && PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict) - PRVM_ED_Print(PRVM_PROG_TO_EDICT(PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict), NULL); + if (PRVM_allglobaledict(self)) + PRVM_ED_Print(PRVM_PROG_TO_EDICT(PRVM_allglobaledict(self)), NULL); PRVM_ERROR ("MVM_ExecuteProgram: %s", errormessage); } @@ -690,6 +715,7 @@ void MVM_ExecuteProgram (func_t fnum, const char *errormessage) // (when the function exits or jumps, the (st - startst) integer value is // added to the function's profile counter) startst = st; + starttm = calltime; // instead of counting instructions, we count jumps jumpcount = 0; // add one to the callcount of this function because otherwise engine-called functions aren't counted @@ -697,146 +723,38 @@ void MVM_ExecuteProgram (func_t fnum, const char *errormessage) chooseexecprogram: cachedpr_trace = prog->trace; - if (prvm_runawaycheck) + if (prvm_statementprofiling.integer || prog->trace) { -#define PRVMRUNAWAYCHECK 1 - if (prvm_statementprofiling.integer) +#define PRVMSLOWINTERPRETER 1 + if (prvm_timeprofiling.integer) { -#define PRVMSTATEMENTPROFILING 1 - if (prvm_boundscheck) - { -#define PRVMBOUNDSCHECK 1 - if (prog->trace) - { -#define PRVMTRACE 1 +#define PRVMTIMEPROFILING 1 #include "prvm_execprogram.h" -#undef PRVMTRACE - } - else - { -#include "prvm_execprogram.h" - } -#undef PRVMBOUNDSCHECK - } - else - { - if (prog->trace) - { -#define PRVMTRACE 1 -#include "prvm_execprogram.h" -#undef PRVMTRACE - } - else - { -#include "prvm_execprogram.h" - } - } -#undef PRVMSTATEMENTPROFILING +#undef PRVMTIMEPROFILING } else { - if (prvm_boundscheck) - { -#define PRVMBOUNDSCHECK 1 - if (prog->trace) - { -#define PRVMTRACE 1 -#include "prvm_execprogram.h" -#undef PRVMTRACE - } - else - { #include "prvm_execprogram.h" - } -#undef PRVMBOUNDSCHECK - } - else - { - if (prog->trace) - { -#define PRVMTRACE 1 -#include "prvm_execprogram.h" -#undef PRVMTRACE - } - else - { -#include "prvm_execprogram.h" - } - } } -#undef PRVMRUNAWAYCHECK +#undef PRVMSLOWINTERPRETER } else { - if (prvm_statementprofiling.integer) + if (prvm_timeprofiling.integer) { -#define PRVMSTATEMENTPROFILING 1 - if (prvm_boundscheck) - { -#define PRVMBOUNDSCHECK 1 - if (prog->trace) - { -#define PRVMTRACE 1 +#define PRVMTIMEPROFILING 1 #include "prvm_execprogram.h" -#undef PRVMTRACE - } - else - { -#include "prvm_execprogram.h" - } -#undef PRVMBOUNDSCHECK - } - else - { - if (prog->trace) - { -#define PRVMTRACE 1 -#include "prvm_execprogram.h" -#undef PRVMTRACE - } - else - { -#include "prvm_execprogram.h" - } - } -#undef PRVMSTATEMENTPROFILING +#undef PRVMTIMEPROFILING } else { - if (prvm_boundscheck) - { -#define PRVMBOUNDSCHECK 1 - if (prog->trace) - { -#define PRVMTRACE 1 -#include "prvm_execprogram.h" -#undef PRVMTRACE - } - else - { #include "prvm_execprogram.h" - } -#undef PRVMBOUNDSCHECK - } - else - { - if (prog->trace) - { -#define PRVMTRACE 1 -#include "prvm_execprogram.h" -#undef PRVMTRACE - } - else - { -#include "prvm_execprogram.h" - } - } } } cleanup: - if (developer.integer >= 200 && vm_tempstringsbuf.cursize > restorevm_tempstringsbuf_cursize) - Con_Printf("MVM_ExecuteProgram: %s used %i bytes of tempstrings\n", PRVM_GetString(prog->functions[fnum].s_name), vm_tempstringsbuf.cursize - restorevm_tempstringsbuf_cursize); + if (developer_insane.integer && vm_tempstringsbuf.cursize > restorevm_tempstringsbuf_cursize) + Con_DPrintf("MVM_ExecuteProgram: %s used %i bytes of tempstrings\n", PRVM_GetString(prog->functions[fnum].s_name), vm_tempstringsbuf.cursize - restorevm_tempstringsbuf_cursize); // delete tempstrings created by this function vm_tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize; @@ -850,31 +768,23 @@ cleanup: CLVM_ExecuteProgram ==================== */ -// LordHavoc: optimized -#define OPA ((prvm_eval_t *)&prog->globals.generic[(unsigned short) st->a]) -#define OPB ((prvm_eval_t *)&prog->globals.generic[(unsigned short) st->b]) -#define OPC ((prvm_eval_t *)&prog->globals.generic[(unsigned short) st->c]) -extern cvar_t prvm_traceqc; -extern cvar_t prvm_statementprofiling; -extern sizebuf_t vm_tempstringsbuf; -extern qboolean prvm_runawaycheck; -extern qboolean prvm_boundscheck; void CLVM_ExecuteProgram (func_t fnum, const char *errormessage) { - dstatement_t *st, *startst; + mstatement_t *st, *startst; mfunction_t *f, *newf; prvm_edict_t *ed; prvm_eval_t *ptr; int jumpcount, cachedpr_trace, exitdepth; int restorevm_tempstringsbuf_cursize; double calltime; + double tm, starttm; calltime = Sys_DoubleTime(); - if (!fnum || fnum >= (unsigned int)prog->progs->numfunctions) + if (!fnum || fnum >= (unsigned int)prog->numfunctions) { - if (prog->globaloffsets.self >= 0 && PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict) - PRVM_ED_Print(PRVM_PROG_TO_EDICT(PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict), NULL); + if (PRVM_allglobaledict(self)) + PRVM_ED_Print(PRVM_PROG_TO_EDICT(PRVM_allglobaledict(self)), NULL); PRVM_ERROR ("CLVM_ExecuteProgram: %s", errormessage); } @@ -894,6 +804,7 @@ void CLVM_ExecuteProgram (func_t fnum, const char *errormessage) // (when the function exits or jumps, the (st - startst) integer value is // added to the function's profile counter) startst = st; + starttm = calltime; // instead of counting instructions, we count jumps jumpcount = 0; // add one to the callcount of this function because otherwise engine-called functions aren't counted @@ -901,146 +812,38 @@ void CLVM_ExecuteProgram (func_t fnum, const char *errormessage) chooseexecprogram: cachedpr_trace = prog->trace; - if (prvm_runawaycheck) + if (prvm_statementprofiling.integer || prog->trace) { -#define PRVMRUNAWAYCHECK 1 - if (prvm_statementprofiling.integer) +#define PRVMSLOWINTERPRETER 1 + if (prvm_timeprofiling.integer) { -#define PRVMSTATEMENTPROFILING 1 - if (prvm_boundscheck) - { -#define PRVMBOUNDSCHECK 1 - if (prog->trace) - { -#define PRVMTRACE 1 +#define PRVMTIMEPROFILING 1 #include "prvm_execprogram.h" -#undef PRVMTRACE - } - else - { -#include "prvm_execprogram.h" - } -#undef PRVMBOUNDSCHECK - } - else - { - if (prog->trace) - { -#define PRVMTRACE 1 -#include "prvm_execprogram.h" -#undef PRVMTRACE - } - else - { -#include "prvm_execprogram.h" - } - } -#undef PRVMSTATEMENTPROFILING +#undef PRVMTIMEPROFILING } else { - if (prvm_boundscheck) - { -#define PRVMBOUNDSCHECK 1 - if (prog->trace) - { -#define PRVMTRACE 1 #include "prvm_execprogram.h" -#undef PRVMTRACE - } - else - { -#include "prvm_execprogram.h" - } -#undef PRVMBOUNDSCHECK - } - else - { - if (prog->trace) - { -#define PRVMTRACE 1 -#include "prvm_execprogram.h" -#undef PRVMTRACE - } - else - { -#include "prvm_execprogram.h" - } - } } -#undef PRVMRUNAWAYCHECK +#undef PRVMSLOWINTERPRETER } else { - if (prvm_statementprofiling.integer) + if (prvm_timeprofiling.integer) { -#define PRVMSTATEMENTPROFILING 1 - if (prvm_boundscheck) - { -#define PRVMBOUNDSCHECK 1 - if (prog->trace) - { -#define PRVMTRACE 1 -#include "prvm_execprogram.h" -#undef PRVMTRACE - } - else - { -#include "prvm_execprogram.h" - } -#undef PRVMBOUNDSCHECK - } - else - { - if (prog->trace) - { -#define PRVMTRACE 1 +#define PRVMTIMEPROFILING 1 #include "prvm_execprogram.h" -#undef PRVMTRACE - } - else - { -#include "prvm_execprogram.h" - } - } -#undef PRVMSTATEMENTPROFILING +#undef PRVMTIMEPROFILING } else { - if (prvm_boundscheck) - { -#define PRVMBOUNDSCHECK 1 - if (prog->trace) - { -#define PRVMTRACE 1 -#include "prvm_execprogram.h" -#undef PRVMTRACE - } - else - { -#include "prvm_execprogram.h" - } -#undef PRVMBOUNDSCHECK - } - else - { - if (prog->trace) - { -#define PRVMTRACE 1 -#include "prvm_execprogram.h" -#undef PRVMTRACE - } - else - { #include "prvm_execprogram.h" - } - } } } cleanup: - if (developer.integer >= 200 && vm_tempstringsbuf.cursize > restorevm_tempstringsbuf_cursize) - Con_Printf("CLVM_ExecuteProgram: %s used %i bytes of tempstrings\n", PRVM_GetString(prog->functions[fnum].s_name), vm_tempstringsbuf.cursize - restorevm_tempstringsbuf_cursize); + if (developer_insane.integer && vm_tempstringsbuf.cursize > restorevm_tempstringsbuf_cursize) + Con_DPrintf("CLVM_ExecuteProgram: %s used %i bytes of tempstrings\n", PRVM_GetString(prog->functions[fnum].s_name), vm_tempstringsbuf.cursize - restorevm_tempstringsbuf_cursize); // delete tempstrings created by this function vm_tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize; @@ -1048,37 +851,30 @@ cleanup: SV_FlushBroadcastMessages(); } +#endif /* ==================== SVVM_ExecuteProgram ==================== */ -// LordHavoc: optimized -#define OPA ((prvm_eval_t *)&prog->globals.generic[(unsigned short) st->a]) -#define OPB ((prvm_eval_t *)&prog->globals.generic[(unsigned short) st->b]) -#define OPC ((prvm_eval_t *)&prog->globals.generic[(unsigned short) st->c]) -extern cvar_t prvm_traceqc; -extern cvar_t prvm_statementprofiling; -extern sizebuf_t vm_tempstringsbuf; -extern qboolean prvm_runawaycheck; -extern qboolean prvm_boundscheck; void SVVM_ExecuteProgram (func_t fnum, const char *errormessage) { - dstatement_t *st, *startst; + mstatement_t *st, *startst; mfunction_t *f, *newf; prvm_edict_t *ed; prvm_eval_t *ptr; int jumpcount, cachedpr_trace, exitdepth; int restorevm_tempstringsbuf_cursize; double calltime; + double tm, starttm; calltime = Sys_DoubleTime(); - if (!fnum || fnum >= (unsigned int)prog->progs->numfunctions) + if (!fnum || fnum >= (unsigned int)prog->numfunctions) { - if (prog->globaloffsets.self >= 0 && PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict) - PRVM_ED_Print(PRVM_PROG_TO_EDICT(PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict), NULL); + if (PRVM_allglobaledict(self)) + PRVM_ED_Print(PRVM_PROG_TO_EDICT(PRVM_allglobaledict(self)), NULL); PRVM_ERROR ("SVVM_ExecuteProgram: %s", errormessage); } @@ -1098,6 +894,7 @@ void SVVM_ExecuteProgram (func_t fnum, const char *errormessage) // (when the function exits or jumps, the (st - startst) integer value is // added to the function's profile counter) startst = st; + starttm = calltime; // instead of counting instructions, we count jumps jumpcount = 0; // add one to the callcount of this function because otherwise engine-called functions aren't counted @@ -1105,146 +902,38 @@ void SVVM_ExecuteProgram (func_t fnum, const char *errormessage) chooseexecprogram: cachedpr_trace = prog->trace; - if (prvm_runawaycheck) + if (prvm_statementprofiling.integer || prog->trace) { -#define PRVMRUNAWAYCHECK 1 - if (prvm_statementprofiling.integer) +#define PRVMSLOWINTERPRETER 1 + if (prvm_timeprofiling.integer) { -#define PRVMSTATEMENTPROFILING 1 - if (prvm_boundscheck) - { -#define PRVMBOUNDSCHECK 1 - if (prog->trace) - { -#define PRVMTRACE 1 -#include "prvm_execprogram.h" -#undef PRVMTRACE - } - else - { -#include "prvm_execprogram.h" - } -#undef PRVMBOUNDSCHECK - } - else - { - if (prog->trace) - { -#define PRVMTRACE 1 -#include "prvm_execprogram.h" -#undef PRVMTRACE - } - else - { +#define PRVMTIMEPROFILING 1 #include "prvm_execprogram.h" - } - } -#undef PRVMSTATEMENTPROFILING +#undef PRVMTIMEPROFILING } else { - if (prvm_boundscheck) - { -#define PRVMBOUNDSCHECK 1 - if (prog->trace) - { -#define PRVMTRACE 1 -#include "prvm_execprogram.h" -#undef PRVMTRACE - } - else - { #include "prvm_execprogram.h" - } -#undef PRVMBOUNDSCHECK - } - else - { - if (prog->trace) - { -#define PRVMTRACE 1 -#include "prvm_execprogram.h" -#undef PRVMTRACE - } - else - { -#include "prvm_execprogram.h" - } - } } -#undef PRVMRUNAWAYCHECK +#undef PRVMSLOWINTERPRETER } else { - if (prvm_statementprofiling.integer) + if (prvm_timeprofiling.integer) { -#define PRVMSTATEMENTPROFILING 1 - if (prvm_boundscheck) - { -#define PRVMBOUNDSCHECK 1 - if (prog->trace) - { -#define PRVMTRACE 1 +#define PRVMTIMEPROFILING 1 #include "prvm_execprogram.h" -#undef PRVMTRACE - } - else - { -#include "prvm_execprogram.h" - } -#undef PRVMBOUNDSCHECK - } - else - { - if (prog->trace) - { -#define PRVMTRACE 1 -#include "prvm_execprogram.h" -#undef PRVMTRACE - } - else - { -#include "prvm_execprogram.h" - } - } -#undef PRVMSTATEMENTPROFILING +#undef PRVMTIMEPROFILING } else { - if (prvm_boundscheck) - { -#define PRVMBOUNDSCHECK 1 - if (prog->trace) - { -#define PRVMTRACE 1 #include "prvm_execprogram.h" -#undef PRVMTRACE - } - else - { -#include "prvm_execprogram.h" - } -#undef PRVMBOUNDSCHECK - } - else - { - if (prog->trace) - { -#define PRVMTRACE 1 -#include "prvm_execprogram.h" -#undef PRVMTRACE - } - else - { -#include "prvm_execprogram.h" - } - } } } cleanup: - if (developer.integer >= 200 && vm_tempstringsbuf.cursize > restorevm_tempstringsbuf_cursize) - Con_Printf("SVVM_ExecuteProgram: %s used %i bytes of tempstrings\n", PRVM_GetString(prog->functions[fnum].s_name), vm_tempstringsbuf.cursize - restorevm_tempstringsbuf_cursize); + if (developer_insane.integer && vm_tempstringsbuf.cursize > restorevm_tempstringsbuf_cursize) + Con_DPrintf("SVVM_ExecuteProgram: %s used %i bytes of tempstrings\n", PRVM_GetString(prog->functions[fnum].s_name), vm_tempstringsbuf.cursize - restorevm_tempstringsbuf_cursize); // delete tempstrings created by this function vm_tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;