]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
Restructure profiling to allow easier statement coverage later.
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 8 Jan 2014 16:02:01 +0000 (16:02 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 8 Jan 2014 16:02:01 +0000 (16:02 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12046 d7cf8633-e32d-0410-b094-e92efae38249

prvm_execprogram.h

index 3e3ceef0bac2fa0cae57da2d436b2e6eb628bdf7..b87cfcf91b3fb0e74cb822addd1122754391194b 100644 (file)
@@ -1,15 +1,19 @@
-#ifdef PRVMTIMEPROFILING 
-#define PreError() \
+// NEED to reset startst after calling this!
+#define ADVANCE_PROFILE_BEFORE_JUMP() \
+       prog->xfunction->profile += (st - startst)
+
+#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
 
                                {
                                        if (developer.integer)
                                        {
-                                               PreError();
+                                               PRE_ERROR();
                                                VM_Warning(prog, "Attempted division by zero in %s\n", prog->name );
                                        }
                                        OPC->_float = 0.0f;
                                {
                                        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);
                                        }
                                }
                                {
                                        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);
                                        }
                                }
                        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;
                                }
                        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;
                                }
                        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;
                                }
                                // 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
                                // 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
                                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
                                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;
                                }
                                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]  ];
                                }
                                else
                                {
-                                       PreError();
+                                       PRE_ERROR();
                                        prog->xstatement = st - cached_statements;
                                        prog->error_cmd("OP_STATE not supported by %s", prog->name);
                                }
 #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;
                                }
 #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;
                                }
 #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;
                                }
 #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;
                                }
 #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;
                                }
 #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;
                                }
 #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;
                                }
                        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;
                                }
 
 #if !USE_COMPUTED_GOTOS
                        default:
-                               PreError();
+                               PRE_ERROR();
                                prog->error_cmd("Bad opcode %i in %s", st->op, prog->name);
                                goto cleanup;
                        }
 #undef DISPATCH_OPCODE
 #undef HANDLE_OPCODE
 #undef USE_COMPUTED_GOTOS
-
-
-#undef PreError
+#undef PRE_ERROR
+#undef ADVANCE_PROFILE_BEFORE_JUMP