X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=prvm_execprogram.h;h=6578d78902de24c88a91ea591cf09366eaeaa7f6;hp=3e3ceef0bac2fa0cae57da2d436b2e6eb628bdf7;hb=e47d52795a830dd0bee4f3c2dd83b4540128f0d8;hpb=a98016316992f6daad635aba23295bee1ebeb3fb diff --git a/prvm_execprogram.h b/prvm_execprogram.h index 3e3ceef0..6578d789 100644 --- a/prvm_execprogram.h +++ b/prvm_execprogram.h @@ -1,15 +1,27 @@ -#ifdef PRVMTIMEPROFILING -#define PreError() \ +// NEED to reset startst after calling this! startst may or may not be clobbered! +#define ADVANCE_PROFILE_BEFORE_JUMP() \ + prog->xfunction->profile += (st - startst); \ + if (prvm_statementprofiling.integer || (prvm_coverage.integer & 4)) { \ + /* All statements from startst+1 to st have been hit. */ \ + while (++startst <= st) { \ + if (prog->statement_profile[startst - cached_statements]++ == 0 && (prvm_coverage.integer & 4)) \ + PRVM_StatementCoverageEvent(prog, prog->xfunction, startst - cached_statements); \ + } \ + /* Observe: startst now is clobbered (now at st+1)! */ \ + } + +#ifdef PRVMTIMEPROFILING +#define PRE_ERROR() \ + ADVANCE_PROFILE_BEFORE_JUMP(); \ prog->xstatement = st - cached_statements; \ tm = Sys_DirtyTime(); \ - prog->xfunction->profile += (st - startst); \ prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0; \ startst = st; \ starttm = tm #else -#define PreError() \ +#define PRE_ERROR() \ + ADVANCE_PROFILE_BEFORE_JUMP(); \ prog->xstatement = st - cached_statements; \ - prog->xfunction->profile += (st - startst); \ startst = st #endif @@ -113,15 +125,15 @@ { if (prog->watch_global_type != ev_void) { - prvm_eval_t *f = PRVM_GLOBALFIELDVALUE(prog->watch_global); + prvm_eval_t *g = PRVM_GLOBALFIELDVALUE(prog->watch_global); prog->xstatement = st + 1 - cached_statements; - PRVM_Watchpoint(prog, 1, "Global watchpoint hit by engine", prog->watch_global_type, &prog->watch_global_value, f); + PRVM_Watchpoint(prog, 1, "Global watchpoint hit by engine", prog->watch_global_type, &prog->watch_global_value, g); } if (prog->watch_field_type != ev_void && prog->watch_edict < prog->max_edicts) { - prvm_eval_t *f = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field); + prvm_eval_t *g = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field); prog->xstatement = st + 1 - cached_statements; - PRVM_Watchpoint(prog, 1, "Entityfield watchpoint hit by engine", prog->watch_field_type, &prog->watch_edictfield_value, f); + PRVM_Watchpoint(prog, 1, "Entityfield watchpoint hit by engine", prog->watch_field_type, &prog->watch_edictfield_value, g); } } #endif @@ -136,8 +148,6 @@ #if PRVMSLOWINTERPRETER if (prog->trace) PRVM_PrintStatement(prog, st); - if (prog->statement_profile[st - cached_statements]++ == 0 && (prvm_coverage.integer & 4)) - PRVM_StatementCoverageEvent(prog, prog->xfunction, st - cached_statements); if (prog->break_statement >= 0) if ((st - cached_statements) == prog->break_statement) { @@ -191,7 +201,7 @@ { if (developer.integer) { - PreError(); + PRE_ERROR(); VM_Warning(prog, "Attempted division by zero in %s\n", prog->name ); } OPC->_float = 0.0f; @@ -290,13 +300,13 @@ { if ((prvm_uint_t)OPB->_int >= cached_entityfieldsarea) { - PreError(); + PRE_ERROR(); prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int); goto cleanup; } if ((prvm_uint_t)OPB->_int < cached_entityfields && !cached_allowworldwrites) { - PreError(); + PRE_ERROR(); VM_Warning(prog, "assignment to world.%s (field %i) in %s\n", PRVM_GetString(prog, PRVM_ED_FieldAtOfs(prog, OPB->_int)->s_name), (int)OPB->_int, prog->name); } } @@ -308,13 +318,13 @@ { if ((prvm_uint_t)OPB->_int > cached_entityfieldsarea_3) { - PreError(); + PRE_ERROR(); prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int); goto cleanup; } if ((prvm_uint_t)OPB->_int < cached_entityfields && !cached_allowworldwrites) { - PreError(); + PRE_ERROR(); VM_Warning(prog, "assignment to world.%s (field %i) in %s\n", PRVM_GetString(prog, PRVM_ED_FieldAtOfs(prog, OPB->_int)->s_name), (int)OPB->_int, prog->name); } } @@ -327,20 +337,20 @@ HANDLE_OPCODE(OP_ADDRESS): if ((prvm_uint_t)OPA->edict >= cached_max_edicts) { - PreError(); + PRE_ERROR(); prog->error_cmd("%s Progs attempted to address an out of bounds edict number", prog->name); goto cleanup; } if ((prvm_uint_t)OPB->_int >= cached_entityfields) { - PreError(); + PRE_ERROR(); prog->error_cmd("%s attempted to address an invalid field (%i) in an edict", prog->name, (int)OPB->_int); goto cleanup; } #if 0 if (OPA->edict == 0 && !cached_allowworldwrites) { - PreError(); + PRE_ERROR(); prog->error_cmd("forbidden assignment to null/world entity in %s", prog->name); goto cleanup; } @@ -355,13 +365,13 @@ HANDLE_OPCODE(OP_LOAD_FNC): if ((prvm_uint_t)OPA->edict >= cached_max_edicts) { - PreError(); + PRE_ERROR(); prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name); goto cleanup; } if ((prvm_uint_t)OPB->_int >= cached_entityfields) { - PreError(); + PRE_ERROR(); prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int); goto cleanup; } @@ -372,13 +382,13 @@ HANDLE_OPCODE(OP_LOAD_V): if ((prvm_uint_t)OPA->edict >= cached_max_edicts) { - PreError(); + PRE_ERROR(); prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name); goto cleanup; } if ((prvm_uint_t)OPB->_int > cached_entityfields_3) { - PreError(); + PRE_ERROR(); prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int); goto cleanup; } @@ -397,7 +407,7 @@ // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero) // and entity, string, field values can never have that value { - prog->xfunction->profile += (st - startst); + ADVANCE_PROFILE_BEFORE_JUMP(); st = cached_statements + st->jumpabsolute - 1; // offset the st++ startst = st; // no bounds check needed, it is done when loading progs @@ -416,7 +426,7 @@ // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero) // and entity, string, field values can never have that value { - prog->xfunction->profile += (st - startst); + ADVANCE_PROFILE_BEFORE_JUMP(); st = cached_statements + st->jumpabsolute - 1; // offset the st++ startst = st; // no bounds check needed, it is done when loading progs @@ -430,7 +440,7 @@ DISPATCH_OPCODE(); HANDLE_OPCODE(OP_GOTO): - prog->xfunction->profile += (st - startst); + ADVANCE_PROFILE_BEFORE_JUMP(); st = cached_statements + st->jumpabsolute - 1; // offset the st++ startst = st; // no bounds check needed, it is done when loading progs @@ -456,35 +466,37 @@ prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0; starttm = tm; #endif - prog->xfunction->profile += (st - startst); + ADVANCE_PROFILE_BEFORE_JUMP(); startst = st; prog->xstatement = st - cached_statements; prog->argc = st->op - OP_CALL0; if (!OPA->function) + { prog->error_cmd("NULL function in %s", prog->name); + } if(!OPA->function || OPA->function < 0 || OPA->function >= prog->numfunctions) { - PreError(); + PRE_ERROR(); prog->error_cmd("%s CALL outside the program", prog->name); goto cleanup; } - newf = &prog->functions[OPA->function]; - if (newf->callcount++ == 0 && (prvm_coverage.integer & 1)) - PRVM_FunctionCoverageEvent(prog, newf); + enterfunc = &prog->functions[OPA->function]; + if (enterfunc->callcount++ == 0 && (prvm_coverage.integer & 1)) + PRVM_FunctionCoverageEvent(prog, enterfunc); - if (newf->first_statement < 0) + if (enterfunc->first_statement < 0) { // negative first_statement values are built in functions - int builtinnumber = -newf->first_statement; + int builtinnumber = -enterfunc->first_statement; prog->xfunction->builtinsprofile++; if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber]) { prog->builtins[builtinnumber](prog); #ifdef PRVMTIMEPROFILING tm = Sys_DirtyTime(); - newf->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0; + enterfunc->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0; prog->xfunction->tbprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0; starttm = tm; #endif @@ -509,7 +521,7 @@ prog->error_cmd("No such builtin #%i in %s; most likely cause: outdated engine build. Try updating!", builtinnumber, prog->name); } else - st = cached_statements + PRVM_EnterFunction(prog, newf); + st = cached_statements + PRVM_EnterFunction(prog, enterfunc); startst = st; DISPATCH_OPCODE(); @@ -520,7 +532,7 @@ prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0; starttm = tm; #endif - prog->xfunction->profile += (st - startst); + ADVANCE_PROFILE_BEFORE_JUMP(); prog->xstatement = st - cached_statements; prog->globals.ip[OFS_RETURN ] = prog->globals.ip[st->operand[0] ]; @@ -543,7 +555,7 @@ } else { - PreError(); + PRE_ERROR(); prog->xstatement = st - cached_statements; prog->error_cmd("OP_STATE not supported by %s", prog->name); } @@ -706,7 +718,7 @@ #if PRBOUNDSCHECK if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize) { - PreError(); + PRE_ERROR(); prog->error_cmd("%s Progs attempted to write to an out of bounds edict", prog->name); goto cleanup; } @@ -718,13 +730,13 @@ #if PRBOUNDSCHECK if (OPA->edict < 0 || OPA->edict >= prog->max_edicts) { - PreError(); + PRE_ERROR(); prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name); goto cleanup; } if (OPB->_int < 0 || OPB->_int >= progs->entityfields) { - PreError(); + PRE_ERROR(); prog->error_cmd("%s Progs attempted to read an invalid field in an edict", prog->name); goto cleanup; } @@ -742,7 +754,7 @@ #if PRBOUNDSCHECK if (OPB->_int < 0 || OPB->_int >= pr_globaldefs) { - PreError(); + PRE_ERROR(); prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name); goto cleanup; } @@ -753,7 +765,7 @@ #if PRBOUNDSCHECK if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs) { - PreError(); + PRE_ERROR(); prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name); goto cleanup; } @@ -768,7 +780,7 @@ #if PRBOUNDSCHECK if (i < 0 || i >= pr_globaldefs) { - PreError(); + PRE_ERROR(); prog->error_cmd("%s Progs attempted to address an out of bounds global", prog->name); goto cleanup; } @@ -785,7 +797,7 @@ #if PRBOUNDSCHECK if (OPA->_int < 0 || OPA->_int >= pr_globaldefs) { - PreError(); + PRE_ERROR(); prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name); goto cleanup; } @@ -797,7 +809,7 @@ #if PRBOUNDSCHECK if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs) { - PreError(); + PRE_ERROR(); prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name); goto cleanup; } @@ -810,7 +822,7 @@ HANDLE_OPCODE(OP_BOUNDCHECK): if (OPA->_int < 0 || OPA->_int >= st->b) { - PreError(); + PRE_ERROR(); prog->error_cmd("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", prog->name, st->b, st->c); goto cleanup; } @@ -820,7 +832,7 @@ #if !USE_COMPUTED_GOTOS default: - PreError(); + PRE_ERROR(); prog->error_cmd("Bad opcode %i in %s", st->op, prog->name); goto cleanup; } @@ -828,15 +840,15 @@ { if (prog->watch_global_type != ev_void) { - prvm_eval_t *f = PRVM_GLOBALFIELDVALUE(prog->watch_global); + prvm_eval_t *g = PRVM_GLOBALFIELDVALUE(prog->watch_global); prog->xstatement = st - cached_statements; - PRVM_Watchpoint(prog, 0, "Global watchpoint hit", prog->watch_global_type, &prog->watch_global_value, f); + PRVM_Watchpoint(prog, 0, "Global watchpoint hit", prog->watch_global_type, &prog->watch_global_value, g); } if (prog->watch_field_type != ev_void && prog->watch_edict < prog->max_edicts) { - prvm_eval_t *f = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field); + prvm_eval_t *g = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field); prog->xstatement = st - cached_statements; - PRVM_Watchpoint(prog, 0, "Entityfield watchpoint hit", prog->watch_field_type, &prog->watch_edictfield_value, f); + PRVM_Watchpoint(prog, 0, "Entityfield watchpoint hit", prog->watch_field_type, &prog->watch_edictfield_value, g); } } #endif @@ -846,6 +858,5 @@ #undef DISPATCH_OPCODE #undef HANDLE_OPCODE #undef USE_COMPUTED_GOTOS - - -#undef PreError +#undef PRE_ERROR +#undef ADVANCE_PROFILE_BEFORE_JUMP