1 #ifdef PRVMTIMEPROFILING
3 prog->xstatement = st - cached_statements; \
4 tm = Sys_DirtyTime(); \
5 prog->xfunction->profile += (st - startst); \
6 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
9 prog->xstatement = st - cached_statements; \
10 prog->xfunction->profile += (st - startst);
13 // This code isn't #ifdef/#define protectable, don't try.
15 #if PRVMSLOWINTERPRETER
17 if (prog->watch_global_type != ev_void)
19 prvm_eval_t *f = PRVM_GLOBALFIELDVALUE(prog->watch_global);
20 prog->xstatement = st + 1 - cached_statements;
21 PRVM_Watchpoint(prog, 1, "Global watchpoint hit by engine", prog->watch_global_type, &prog->watch_global_value, f);
23 if (prog->watch_field_type != ev_void && prog->watch_edict < prog->max_edicts)
25 prvm_eval_t *f = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field);
26 prog->xstatement = st + 1 - cached_statements;
27 PRVM_Watchpoint(prog, 1, "Entityfield watchpoint hit by engine", prog->watch_field_type, &prog->watch_edictfield_value, f);
36 #if PRVMSLOWINTERPRETER
38 PRVM_PrintStatement(prog, st);
39 prog->statement_profile[st - cached_statements]++;
40 if (prog->break_statement >= 0)
41 if ((st - cached_statements) == prog->break_statement)
43 prog->xstatement = st - cached_statements;
44 PRVM_Breakpoint(prog, prog->break_stack_index, "Breakpoint hit");
51 OPC->_float = OPA->_float + OPB->_float;
54 OPC->vector[0] = OPA->vector[0] + OPB->vector[0];
55 OPC->vector[1] = OPA->vector[1] + OPB->vector[1];
56 OPC->vector[2] = OPA->vector[2] + OPB->vector[2];
59 OPC->_float = OPA->_float - OPB->_float;
62 OPC->vector[0] = OPA->vector[0] - OPB->vector[0];
63 OPC->vector[1] = OPA->vector[1] - OPB->vector[1];
64 OPC->vector[2] = OPA->vector[2] - OPB->vector[2];
67 OPC->_float = OPA->_float * OPB->_float;
70 OPC->_float = OPA->vector[0]*OPB->vector[0] + OPA->vector[1]*OPB->vector[1] + OPA->vector[2]*OPB->vector[2];
73 tempfloat = OPA->_float;
74 OPC->vector[0] = tempfloat * OPB->vector[0];
75 OPC->vector[1] = tempfloat * OPB->vector[1];
76 OPC->vector[2] = tempfloat * OPB->vector[2];
79 tempfloat = OPB->_float;
80 OPC->vector[0] = tempfloat * OPA->vector[0];
81 OPC->vector[1] = tempfloat * OPA->vector[1];
82 OPC->vector[2] = tempfloat * OPA->vector[2];
85 if( OPB->_float != 0.0f )
87 OPC->_float = OPA->_float / OPB->_float;
91 if (developer.integer)
93 prog->xfunction->profile += (st - startst);
95 prog->xstatement = st - cached_statements;
96 VM_Warning(prog, "Attempted division by zero in %s\n", prog->name );
102 OPC->_float = (prvm_int_t)OPA->_float & (prvm_int_t)OPB->_float;
105 OPC->_float = (prvm_int_t)OPA->_float | (prvm_int_t)OPB->_float;
108 OPC->_float = OPA->_float >= OPB->_float;
111 OPC->_float = OPA->_float <= OPB->_float;
114 OPC->_float = OPA->_float > OPB->_float;
117 OPC->_float = OPA->_float < OPB->_float;
120 OPC->_float = FLOAT_IS_TRUE_FOR_INT(OPA->_int) && FLOAT_IS_TRUE_FOR_INT(OPB->_int); // TODO change this back to float, and add AND_I to be used by fteqcc for anything not a float
123 OPC->_float = FLOAT_IS_TRUE_FOR_INT(OPA->_int) || FLOAT_IS_TRUE_FOR_INT(OPB->_int); // TODO change this back to float, and add OR_I to be used by fteqcc for anything not a float
126 OPC->_float = !FLOAT_IS_TRUE_FOR_INT(OPA->_int);
129 OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2];
132 OPC->_float = !OPA->string || !*PRVM_GetString(prog, OPA->string);
135 OPC->_float = !OPA->function;
138 OPC->_float = (OPA->edict == 0);
141 OPC->_float = OPA->_float == OPB->_float;
144 OPC->_float = (OPA->vector[0] == OPB->vector[0]) && (OPA->vector[1] == OPB->vector[1]) && (OPA->vector[2] == OPB->vector[2]);
147 OPC->_float = !strcmp(PRVM_GetString(prog, OPA->string),PRVM_GetString(prog, OPB->string));
150 OPC->_float = OPA->_int == OPB->_int;
153 OPC->_float = OPA->function == OPB->function;
156 OPC->_float = OPA->_float != OPB->_float;
159 OPC->_float = (OPA->vector[0] != OPB->vector[0]) || (OPA->vector[1] != OPB->vector[1]) || (OPA->vector[2] != OPB->vector[2]);
162 OPC->_float = strcmp(PRVM_GetString(prog, OPA->string),PRVM_GetString(prog, OPB->string));
165 OPC->_float = OPA->_int != OPB->_int;
168 OPC->_float = OPA->function != OPB->function;
174 case OP_STORE_FLD: // integers
176 case OP_STORE_FNC: // pointers
177 OPB->_int = OPA->_int;
180 OPB->ivector[0] = OPA->ivector[0];
181 OPB->ivector[1] = OPA->ivector[1];
182 OPB->ivector[2] = OPA->ivector[2];
187 case OP_STOREP_FLD: // integers
189 case OP_STOREP_FNC: // pointers
190 if ((prvm_uint_t)OPB->_int - cached_entityfields >= cached_entityfieldsarea_entityfields)
192 if ((prvm_uint_t)OPB->_int >= cached_entityfieldsarea)
195 prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
198 if ((prvm_uint_t)OPB->_int < cached_entityfields && !cached_allowworldwrites)
200 prog->xstatement = st - cached_statements;
201 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);
204 ptr = (prvm_eval_t *)(cached_edictsfields + OPB->_int);
205 ptr->_int = OPA->_int;
208 if ((prvm_uint_t)OPB->_int - cached_entityfields > (prvm_uint_t)cached_entityfieldsarea_entityfields_3)
210 if ((prvm_uint_t)OPB->_int > cached_entityfieldsarea_3)
213 prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
216 if ((prvm_uint_t)OPB->_int < cached_entityfields && !cached_allowworldwrites)
218 prog->xstatement = st - cached_statements;
219 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);
222 ptr = (prvm_eval_t *)(cached_edictsfields + OPB->_int);
223 ptr->ivector[0] = OPA->ivector[0];
224 ptr->ivector[1] = OPA->ivector[1];
225 ptr->ivector[2] = OPA->ivector[2];
229 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
232 prog->error_cmd("%s Progs attempted to address an out of bounds edict number", prog->name);
235 if ((prvm_uint_t)OPB->_int >= cached_entityfields)
238 prog->error_cmd("%s attempted to address an invalid field (%i) in an edict", prog->name, (int)OPB->_int);
242 if (OPA->edict == 0 && !cached_allowworldwrites)
245 prog->error_cmd("forbidden assignment to null/world entity in %s", prog->name);
249 OPC->_int = OPA->edict * cached_entityfields + OPB->_int;
257 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
260 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
263 if ((prvm_uint_t)OPB->_int >= cached_entityfields)
266 prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
269 ed = PRVM_PROG_TO_EDICT(OPA->edict);
270 OPC->_int = ((prvm_eval_t *)(ed->fields.ip + OPB->_int))->_int;
274 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
277 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
280 if ((prvm_uint_t)OPB->_int > cached_entityfields_3)
283 prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
286 ed = PRVM_PROG_TO_EDICT(OPA->edict);
287 ptr = (prvm_eval_t *)(ed->fields.ip + OPB->_int);
288 OPC->ivector[0] = ptr->ivector[0];
289 OPC->ivector[1] = ptr->ivector[1];
290 OPC->ivector[2] = ptr->ivector[2];
296 if(!FLOAT_IS_TRUE_FOR_INT(OPA->_int))
297 // TODO add an "int-if", and change this one to OPA->_float
298 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
299 // and entity, string, field values can never have that value
301 prog->xfunction->profile += (st - startst);
302 st = cached_statements + st->jumpabsolute - 1; // offset the st++
304 // no bounds check needed, it is done when loading progs
305 if (++jumpcount == 10000000 && prvm_runawaycheck)
307 prog->xstatement = st - cached_statements;
308 PRVM_Profile(prog, 1<<30, 1000000, 0);
309 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
315 if(FLOAT_IS_TRUE_FOR_INT(OPA->_int))
316 // TODO add an "int-if", and change this one, as well as the FLOAT_IS_TRUE_FOR_INT usages, to OPA->_float
317 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
318 // and entity, string, field values can never have that value
320 prog->xfunction->profile += (st - startst);
321 st = cached_statements + st->jumpabsolute - 1; // offset the st++
323 // no bounds check needed, it is done when loading progs
324 if (++jumpcount == 10000000 && prvm_runawaycheck)
326 prog->xstatement = st - cached_statements;
327 PRVM_Profile(prog, 1<<30, 0.01, 0);
328 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
334 prog->xfunction->profile += (st - startst);
335 st = cached_statements + st->jumpabsolute - 1; // offset the st++
337 // no bounds check needed, it is done when loading progs
338 if (++jumpcount == 10000000 && prvm_runawaycheck)
340 prog->xstatement = st - cached_statements;
341 PRVM_Profile(prog, 1<<30, 0.01, 0);
342 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
355 #ifdef PRVMTIMEPROFILING
356 tm = Sys_DirtyTime();
357 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
360 prog->xfunction->profile += (st - startst);
362 prog->xstatement = st - cached_statements;
363 prog->argc = st->op - OP_CALL0;
365 prog->error_cmd("NULL function in %s", prog->name);
367 if(!OPA->function || OPA->function < 0 || OPA->function >= prog->numfunctions)
370 prog->error_cmd("%s CALL outside the program", prog->name);
374 newf = &prog->functions[OPA->function];
377 if (newf->first_statement < 0)
379 // negative first_statement values are built in functions
380 int builtinnumber = -newf->first_statement;
381 prog->xfunction->builtinsprofile++;
382 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
384 prog->builtins[builtinnumber](prog);
385 #ifdef PRVMTIMEPROFILING
386 tm = Sys_DirtyTime();
387 newf->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
388 prog->xfunction->tbprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
391 // builtins may cause ED_Alloc() to be called, update cached variables
392 cached_edictsfields = prog->edictsfields;
393 cached_entityfields = prog->entityfields;
394 cached_entityfields_3 = prog->entityfields - 3;
395 cached_entityfieldsarea = prog->entityfieldsarea;
396 cached_entityfieldsarea_entityfields = prog->entityfieldsarea - prog->entityfields;
397 cached_entityfieldsarea_3 = prog->entityfieldsarea - 3;
398 cached_entityfieldsarea_entityfields_3 = prog->entityfieldsarea - prog->entityfields - 3;
399 cached_max_edicts = prog->max_edicts;
400 // these do not change
401 //cached_statements = prog->statements;
402 //cached_allowworldwrites = prog->allowworldwrites;
403 //cached_flag = prog->flag;
404 // if prog->trace changed we need to change interpreter path
405 if (prog->trace != cachedpr_trace)
406 goto chooseexecprogram;
409 prog->error_cmd("No such builtin #%i in %s; most likely cause: outdated engine build. Try updating!", builtinnumber, prog->name);
412 st = cached_statements + PRVM_EnterFunction(prog, newf);
418 #ifdef PRVMTIMEPROFILING
419 tm = Sys_DirtyTime();
420 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
423 prog->xfunction->profile += (st - startst);
424 prog->xstatement = st - cached_statements;
426 prog->globals.ip[OFS_RETURN ] = prog->globals.ip[st->operand[0] ];
427 prog->globals.ip[OFS_RETURN+1] = prog->globals.ip[st->operand[0]+1];
428 prog->globals.ip[OFS_RETURN+2] = prog->globals.ip[st->operand[0]+2];
430 st = cached_statements + PRVM_LeaveFunction(prog);
432 if (prog->depth <= exitdepth)
433 goto cleanup; // all done
437 if(cached_flag & PRVM_OP_STATE)
439 ed = PRVM_PROG_TO_EDICT(PRVM_gameglobaledict(self));
440 PRVM_gameedictfloat(ed,nextthink) = PRVM_gameglobalfloat(time) + 0.1;
441 PRVM_gameedictfloat(ed,frame) = OPA->_float;
442 PRVM_gameedictfunction(ed,think) = OPB->function;
447 prog->xstatement = st - cached_statements;
448 prog->error_cmd("OP_STATE not supported by %s", prog->name);
452 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
455 OPC->_int = OPA->_int + OPB->_int;
458 OPC->_int = OPA->_int + (prvm_int_t) OPB->_float;
461 OPC->_float = OPA->_float + (prvm_vec_t) OPB->_int;
464 OPC->_int = OPA->_int - OPB->_int;
467 OPC->_int = OPA->_int - (prvm_int_t) OPB->_float;
470 OPC->_float = OPA->_float - (prvm_vec_t) OPB->_int;
473 OPC->_int = OPA->_int * OPB->_int;
476 OPC->_int = OPA->_int * (prvm_int_t) OPB->_float;
479 OPC->_float = OPA->_float * (prvm_vec_t) OPB->_int;
482 OPC->vector[0] = (prvm_vec_t) OPB->_int * OPA->vector[0];
483 OPC->vector[1] = (prvm_vec_t) OPB->_int * OPA->vector[1];
484 OPC->vector[2] = (prvm_vec_t) OPB->_int * OPA->vector[2];
488 float temp = 1.0f / OPB->_float;
489 OPC->vector[0] = temp * OPA->vector[0];
490 OPC->vector[1] = temp * OPA->vector[1];
491 OPC->vector[2] = temp * OPA->vector[2];
495 OPC->_int = OPA->_int / OPB->_int;
498 OPC->_int = OPA->_int / (prvm_int_t) OPB->_float;
501 OPC->_float = OPA->_float / (prvm_vec_t) OPB->_int;
504 OPC->_float = OPA->_int;
507 OPC->_int = OPA->_float;
510 OPC->_int = OPA->_int & OPB->_int;
513 OPC->_int = OPA->_int | OPB->_int;
516 OPC->_int = OPA->_int & (prvm_int_t)OPB->_float;
519 OPC->_int = OPA->_int | (prvm_int_t)OPB->_float;
522 OPC->_float = (prvm_int_t)OPA->_float & OPB->_int;
525 OPC->_float = (prvm_int_t)OPA->_float | OPB->_int;
528 OPC->_float = OPA->_int >= OPB->_int;
531 OPC->_float = OPA->_int <= OPB->_int;
534 OPC->_float = OPA->_int > OPB->_int;
537 OPC->_float = OPA->_int < OPB->_int;
540 OPC->_float = OPA->_int && OPB->_int;
543 OPC->_float = OPA->_int || OPB->_int;
546 OPC->_float = (prvm_vec_t)OPA->_int >= OPB->_float;
549 OPC->_float = (prvm_vec_t)OPA->_int <= OPB->_float;
552 OPC->_float = (prvm_vec_t)OPA->_int > OPB->_float;
555 OPC->_float = (prvm_vec_t)OPA->_int < OPB->_float;
558 OPC->_float = (prvm_vec_t)OPA->_int && OPB->_float;
561 OPC->_float = (prvm_vec_t)OPA->_int || OPB->_float;
564 OPC->_float = OPA->_float >= (prvm_vec_t)OPB->_int;
567 OPC->_float = OPA->_float <= (prvm_vec_t)OPB->_int;
570 OPC->_float = OPA->_float > (prvm_vec_t)OPB->_int;
573 OPC->_float = OPA->_float < (prvm_vec_t)OPB->_int;
576 OPC->_float = OPA->_float && (prvm_vec_t)OPB->_int;
579 OPC->_float = OPA->_float || (prvm_vec_t)OPB->_int;
582 OPC->_float = !OPA->_int;
585 OPC->_float = OPA->_int == OPB->_int;
588 OPC->_float = (prvm_vec_t)OPA->_int == OPB->_float;
591 OPC->_float = OPA->_float == (prvm_vec_t)OPB->_int;
594 OPC->_float = OPA->_int != OPB->_int;
597 OPC->_float = (prvm_vec_t)OPA->_int != OPB->_float;
600 OPC->_float = OPA->_float != (prvm_vec_t)OPB->_int;
603 OPB->_int = OPA->_int;
607 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
610 prog->error_cmd("%s Progs attempted to write to an out of bounds edict", prog->name);
614 ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
615 ptr->_int = OPA->_int;
619 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
622 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
625 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
628 prog->error_cmd("%s Progs attempted to read an invalid field in an edict", prog->name);
632 ed = PRVM_PROG_TO_EDICT(OPA->edict);
633 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
639 case OP_GSTOREP_FLD: // integers
641 case OP_GSTOREP_FNC: // pointers
643 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
646 prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name);
650 pr_iglobals[OPB->_int] = OPA->_int;
654 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
657 prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name);
661 pr_iglobals[OPB->_int ] = OPA->ivector[0];
662 pr_iglobals[OPB->_int+1] = OPA->ivector[1];
663 pr_iglobals[OPB->_int+2] = OPA->ivector[2];
667 i = OPA->_int + (prvm_int_t) OPB->_float;
669 if (i < 0 || i >= pr_globaldefs)
672 prog->error_cmd("%s Progs attempted to address an out of bounds global", prog->name);
676 OPC->_int = pr_iglobals[i];
686 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
689 prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name);
693 OPC->_int = pr_iglobals[OPA->_int];
698 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
701 prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name);
705 OPC->ivector[0] = pr_iglobals[OPA->_int ];
706 OPC->ivector[1] = pr_iglobals[OPA->_int+1];
707 OPC->ivector[2] = pr_iglobals[OPA->_int+2];
711 if (OPA->_int < 0 || OPA->_int >= st->b)
714 prog->error_cmd("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", prog->name, st->b, st->c);
723 prog->error_cmd("Bad opcode %i in %s", st->op, prog->name);
726 #if PRVMSLOWINTERPRETER
728 if (prog->watch_global_type != ev_void)
730 prvm_eval_t *f = PRVM_GLOBALFIELDVALUE(prog->watch_global);
731 prog->xstatement = st - cached_statements;
732 PRVM_Watchpoint(prog, 0, "Global watchpoint hit", prog->watch_global_type, &prog->watch_global_value, f);
734 if (prog->watch_field_type != ev_void && prog->watch_edict < prog->max_edicts)
736 prvm_eval_t *f = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field);
737 prog->xstatement = st - cached_statements;
738 PRVM_Watchpoint(prog, 0, "Entityfield watchpoint hit", prog->watch_field_type, &prog->watch_edictfield_value, f);