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 if (prog->statement_profile[st - cached_statements]++ == 0 && (prvm_coverage.integer & 4))
40 PRVM_StatementCoverageEvent(prog, st - cached_statements);
41 if (prog->break_statement >= 0)
42 if ((st - cached_statements) == prog->break_statement)
44 prog->xstatement = st - cached_statements;
45 PRVM_Breakpoint(prog, prog->break_stack_index, "Breakpoint hit");
52 OPC->_float = OPA->_float + OPB->_float;
55 OPC->vector[0] = OPA->vector[0] + OPB->vector[0];
56 OPC->vector[1] = OPA->vector[1] + OPB->vector[1];
57 OPC->vector[2] = OPA->vector[2] + OPB->vector[2];
60 OPC->_float = OPA->_float - OPB->_float;
63 OPC->vector[0] = OPA->vector[0] - OPB->vector[0];
64 OPC->vector[1] = OPA->vector[1] - OPB->vector[1];
65 OPC->vector[2] = OPA->vector[2] - OPB->vector[2];
68 OPC->_float = OPA->_float * OPB->_float;
71 OPC->_float = OPA->vector[0]*OPB->vector[0] + OPA->vector[1]*OPB->vector[1] + OPA->vector[2]*OPB->vector[2];
74 tempfloat = OPA->_float;
75 OPC->vector[0] = tempfloat * OPB->vector[0];
76 OPC->vector[1] = tempfloat * OPB->vector[1];
77 OPC->vector[2] = tempfloat * OPB->vector[2];
80 tempfloat = OPB->_float;
81 OPC->vector[0] = tempfloat * OPA->vector[0];
82 OPC->vector[1] = tempfloat * OPA->vector[1];
83 OPC->vector[2] = tempfloat * OPA->vector[2];
86 if( OPB->_float != 0.0f )
88 OPC->_float = OPA->_float / OPB->_float;
92 if (developer.integer)
94 prog->xfunction->profile += (st - startst);
96 prog->xstatement = st - cached_statements;
97 VM_Warning(prog, "Attempted division by zero in %s\n", prog->name );
103 OPC->_float = (prvm_int_t)OPA->_float & (prvm_int_t)OPB->_float;
106 OPC->_float = (prvm_int_t)OPA->_float | (prvm_int_t)OPB->_float;
109 OPC->_float = OPA->_float >= OPB->_float;
112 OPC->_float = OPA->_float <= OPB->_float;
115 OPC->_float = OPA->_float > OPB->_float;
118 OPC->_float = OPA->_float < OPB->_float;
121 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
124 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
127 OPC->_float = !FLOAT_IS_TRUE_FOR_INT(OPA->_int);
130 OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2];
133 OPC->_float = !OPA->string || !*PRVM_GetString(prog, OPA->string);
136 OPC->_float = !OPA->function;
139 OPC->_float = (OPA->edict == 0);
142 OPC->_float = OPA->_float == OPB->_float;
145 OPC->_float = (OPA->vector[0] == OPB->vector[0]) && (OPA->vector[1] == OPB->vector[1]) && (OPA->vector[2] == OPB->vector[2]);
148 OPC->_float = !strcmp(PRVM_GetString(prog, OPA->string),PRVM_GetString(prog, OPB->string));
151 OPC->_float = OPA->_int == OPB->_int;
154 OPC->_float = OPA->function == OPB->function;
157 OPC->_float = OPA->_float != OPB->_float;
160 OPC->_float = (OPA->vector[0] != OPB->vector[0]) || (OPA->vector[1] != OPB->vector[1]) || (OPA->vector[2] != OPB->vector[2]);
163 OPC->_float = strcmp(PRVM_GetString(prog, OPA->string),PRVM_GetString(prog, OPB->string));
166 OPC->_float = OPA->_int != OPB->_int;
169 OPC->_float = OPA->function != OPB->function;
175 case OP_STORE_FLD: // integers
177 case OP_STORE_FNC: // pointers
178 OPB->_int = OPA->_int;
181 OPB->ivector[0] = OPA->ivector[0];
182 OPB->ivector[1] = OPA->ivector[1];
183 OPB->ivector[2] = OPA->ivector[2];
188 case OP_STOREP_FLD: // integers
190 case OP_STOREP_FNC: // pointers
191 if ((prvm_uint_t)OPB->_int - cached_entityfields >= cached_entityfieldsarea_entityfields)
193 if ((prvm_uint_t)OPB->_int >= cached_entityfieldsarea)
196 prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
199 if ((prvm_uint_t)OPB->_int < cached_entityfields && !cached_allowworldwrites)
201 prog->xstatement = st - cached_statements;
202 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);
205 ptr = (prvm_eval_t *)(cached_edictsfields + OPB->_int);
206 ptr->_int = OPA->_int;
209 if ((prvm_uint_t)OPB->_int - cached_entityfields > (prvm_uint_t)cached_entityfieldsarea_entityfields_3)
211 if ((prvm_uint_t)OPB->_int > cached_entityfieldsarea_3)
214 prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
217 if ((prvm_uint_t)OPB->_int < cached_entityfields && !cached_allowworldwrites)
219 prog->xstatement = st - cached_statements;
220 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);
223 ptr = (prvm_eval_t *)(cached_edictsfields + OPB->_int);
224 ptr->ivector[0] = OPA->ivector[0];
225 ptr->ivector[1] = OPA->ivector[1];
226 ptr->ivector[2] = OPA->ivector[2];
230 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
233 prog->error_cmd("%s Progs attempted to address an out of bounds edict number", prog->name);
236 if ((prvm_uint_t)OPB->_int >= cached_entityfields)
239 prog->error_cmd("%s attempted to address an invalid field (%i) in an edict", prog->name, (int)OPB->_int);
243 if (OPA->edict == 0 && !cached_allowworldwrites)
246 prog->error_cmd("forbidden assignment to null/world entity in %s", prog->name);
250 OPC->_int = OPA->edict * cached_entityfields + OPB->_int;
258 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
261 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
264 if ((prvm_uint_t)OPB->_int >= cached_entityfields)
267 prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
270 ed = PRVM_PROG_TO_EDICT(OPA->edict);
271 OPC->_int = ((prvm_eval_t *)(ed->fields.ip + OPB->_int))->_int;
275 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
278 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
281 if ((prvm_uint_t)OPB->_int > cached_entityfields_3)
284 prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
287 ed = PRVM_PROG_TO_EDICT(OPA->edict);
288 ptr = (prvm_eval_t *)(ed->fields.ip + OPB->_int);
289 OPC->ivector[0] = ptr->ivector[0];
290 OPC->ivector[1] = ptr->ivector[1];
291 OPC->ivector[2] = ptr->ivector[2];
297 if(!FLOAT_IS_TRUE_FOR_INT(OPA->_int))
298 // TODO add an "int-if", and change this one to OPA->_float
299 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
300 // and entity, string, field values can never have that value
302 prog->xfunction->profile += (st - startst);
303 st = cached_statements + st->jumpabsolute - 1; // offset the st++
305 // no bounds check needed, it is done when loading progs
306 if (++jumpcount == 10000000 && prvm_runawaycheck)
308 prog->xstatement = st - cached_statements;
309 PRVM_Profile(prog, 1<<30, 1000000, 0);
310 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
316 if(FLOAT_IS_TRUE_FOR_INT(OPA->_int))
317 // TODO add an "int-if", and change this one, as well as the FLOAT_IS_TRUE_FOR_INT usages, to OPA->_float
318 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
319 // and entity, string, field values can never have that value
321 prog->xfunction->profile += (st - startst);
322 st = cached_statements + st->jumpabsolute - 1; // offset the st++
324 // no bounds check needed, it is done when loading progs
325 if (++jumpcount == 10000000 && prvm_runawaycheck)
327 prog->xstatement = st - cached_statements;
328 PRVM_Profile(prog, 1<<30, 0.01, 0);
329 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
335 prog->xfunction->profile += (st - startst);
336 st = cached_statements + st->jumpabsolute - 1; // offset the st++
338 // no bounds check needed, it is done when loading progs
339 if (++jumpcount == 10000000 && prvm_runawaycheck)
341 prog->xstatement = st - cached_statements;
342 PRVM_Profile(prog, 1<<30, 0.01, 0);
343 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
356 #ifdef PRVMTIMEPROFILING
357 tm = Sys_DirtyTime();
358 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
361 prog->xfunction->profile += (st - startst);
363 prog->xstatement = st - cached_statements;
364 prog->argc = st->op - OP_CALL0;
366 prog->error_cmd("NULL function in %s", prog->name);
368 if(!OPA->function || OPA->function < 0 || OPA->function >= prog->numfunctions)
371 prog->error_cmd("%s CALL outside the program", prog->name);
375 newf = &prog->functions[OPA->function];
376 if (newf->callcount++ == 0 && (prvm_coverage.integer & 1))
377 PRVM_FunctionCoverageEvent(prog, newf);
379 if (newf->first_statement < 0)
381 // negative first_statement values are built in functions
382 int builtinnumber = -newf->first_statement;
383 prog->xfunction->builtinsprofile++;
384 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
386 prog->builtins[builtinnumber](prog);
387 #ifdef PRVMTIMEPROFILING
388 tm = Sys_DirtyTime();
389 newf->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
390 prog->xfunction->tbprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
393 // builtins may cause ED_Alloc() to be called, update cached variables
394 cached_edictsfields = prog->edictsfields;
395 cached_entityfields = prog->entityfields;
396 cached_entityfields_3 = prog->entityfields - 3;
397 cached_entityfieldsarea = prog->entityfieldsarea;
398 cached_entityfieldsarea_entityfields = prog->entityfieldsarea - prog->entityfields;
399 cached_entityfieldsarea_3 = prog->entityfieldsarea - 3;
400 cached_entityfieldsarea_entityfields_3 = prog->entityfieldsarea - prog->entityfields - 3;
401 cached_max_edicts = prog->max_edicts;
402 // these do not change
403 //cached_statements = prog->statements;
404 //cached_allowworldwrites = prog->allowworldwrites;
405 //cached_flag = prog->flag;
406 // if prog->trace changed we need to change interpreter path
407 if (prog->trace != cachedpr_trace)
408 goto chooseexecprogram;
411 prog->error_cmd("No such builtin #%i in %s; most likely cause: outdated engine build. Try updating!", builtinnumber, prog->name);
414 st = cached_statements + PRVM_EnterFunction(prog, newf);
420 #ifdef PRVMTIMEPROFILING
421 tm = Sys_DirtyTime();
422 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
425 prog->xfunction->profile += (st - startst);
426 prog->xstatement = st - cached_statements;
428 prog->globals.ip[OFS_RETURN ] = prog->globals.ip[st->operand[0] ];
429 prog->globals.ip[OFS_RETURN+1] = prog->globals.ip[st->operand[0]+1];
430 prog->globals.ip[OFS_RETURN+2] = prog->globals.ip[st->operand[0]+2];
432 st = cached_statements + PRVM_LeaveFunction(prog);
434 if (prog->depth <= exitdepth)
435 goto cleanup; // all done
439 if(cached_flag & PRVM_OP_STATE)
441 ed = PRVM_PROG_TO_EDICT(PRVM_gameglobaledict(self));
442 PRVM_gameedictfloat(ed,nextthink) = PRVM_gameglobalfloat(time) + 0.1;
443 PRVM_gameedictfloat(ed,frame) = OPA->_float;
444 PRVM_gameedictfunction(ed,think) = OPB->function;
449 prog->xstatement = st - cached_statements;
450 prog->error_cmd("OP_STATE not supported by %s", prog->name);
454 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
457 OPC->_int = OPA->_int + OPB->_int;
460 OPC->_int = OPA->_int + (prvm_int_t) OPB->_float;
463 OPC->_float = OPA->_float + (prvm_vec_t) OPB->_int;
466 OPC->_int = OPA->_int - OPB->_int;
469 OPC->_int = OPA->_int - (prvm_int_t) OPB->_float;
472 OPC->_float = OPA->_float - (prvm_vec_t) OPB->_int;
475 OPC->_int = OPA->_int * OPB->_int;
478 OPC->_int = OPA->_int * (prvm_int_t) OPB->_float;
481 OPC->_float = OPA->_float * (prvm_vec_t) OPB->_int;
484 OPC->vector[0] = (prvm_vec_t) OPB->_int * OPA->vector[0];
485 OPC->vector[1] = (prvm_vec_t) OPB->_int * OPA->vector[1];
486 OPC->vector[2] = (prvm_vec_t) OPB->_int * OPA->vector[2];
490 float temp = 1.0f / OPB->_float;
491 OPC->vector[0] = temp * OPA->vector[0];
492 OPC->vector[1] = temp * OPA->vector[1];
493 OPC->vector[2] = temp * OPA->vector[2];
497 OPC->_int = OPA->_int / OPB->_int;
500 OPC->_int = OPA->_int / (prvm_int_t) OPB->_float;
503 OPC->_float = OPA->_float / (prvm_vec_t) OPB->_int;
506 OPC->_float = OPA->_int;
509 OPC->_int = OPA->_float;
512 OPC->_int = OPA->_int & OPB->_int;
515 OPC->_int = OPA->_int | OPB->_int;
518 OPC->_int = OPA->_int & (prvm_int_t)OPB->_float;
521 OPC->_int = OPA->_int | (prvm_int_t)OPB->_float;
524 OPC->_float = (prvm_int_t)OPA->_float & OPB->_int;
527 OPC->_float = (prvm_int_t)OPA->_float | OPB->_int;
530 OPC->_float = OPA->_int >= OPB->_int;
533 OPC->_float = OPA->_int <= OPB->_int;
536 OPC->_float = OPA->_int > OPB->_int;
539 OPC->_float = OPA->_int < OPB->_int;
542 OPC->_float = OPA->_int && OPB->_int;
545 OPC->_float = OPA->_int || OPB->_int;
548 OPC->_float = (prvm_vec_t)OPA->_int >= OPB->_float;
551 OPC->_float = (prvm_vec_t)OPA->_int <= OPB->_float;
554 OPC->_float = (prvm_vec_t)OPA->_int > OPB->_float;
557 OPC->_float = (prvm_vec_t)OPA->_int < OPB->_float;
560 OPC->_float = (prvm_vec_t)OPA->_int && OPB->_float;
563 OPC->_float = (prvm_vec_t)OPA->_int || OPB->_float;
566 OPC->_float = OPA->_float >= (prvm_vec_t)OPB->_int;
569 OPC->_float = OPA->_float <= (prvm_vec_t)OPB->_int;
572 OPC->_float = OPA->_float > (prvm_vec_t)OPB->_int;
575 OPC->_float = OPA->_float < (prvm_vec_t)OPB->_int;
578 OPC->_float = OPA->_float && (prvm_vec_t)OPB->_int;
581 OPC->_float = OPA->_float || (prvm_vec_t)OPB->_int;
584 OPC->_float = !OPA->_int;
587 OPC->_float = OPA->_int == OPB->_int;
590 OPC->_float = (prvm_vec_t)OPA->_int == OPB->_float;
593 OPC->_float = OPA->_float == (prvm_vec_t)OPB->_int;
596 OPC->_float = OPA->_int != OPB->_int;
599 OPC->_float = (prvm_vec_t)OPA->_int != OPB->_float;
602 OPC->_float = OPA->_float != (prvm_vec_t)OPB->_int;
605 OPB->_int = OPA->_int;
609 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
612 prog->error_cmd("%s Progs attempted to write to an out of bounds edict", prog->name);
616 ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
617 ptr->_int = OPA->_int;
621 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
624 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
627 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
630 prog->error_cmd("%s Progs attempted to read an invalid field in an edict", prog->name);
634 ed = PRVM_PROG_TO_EDICT(OPA->edict);
635 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
641 case OP_GSTOREP_FLD: // integers
643 case OP_GSTOREP_FNC: // pointers
645 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
648 prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name);
652 pr_iglobals[OPB->_int] = OPA->_int;
656 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
659 prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name);
663 pr_iglobals[OPB->_int ] = OPA->ivector[0];
664 pr_iglobals[OPB->_int+1] = OPA->ivector[1];
665 pr_iglobals[OPB->_int+2] = OPA->ivector[2];
669 i = OPA->_int + (prvm_int_t) OPB->_float;
671 if (i < 0 || i >= pr_globaldefs)
674 prog->error_cmd("%s Progs attempted to address an out of bounds global", prog->name);
678 OPC->_int = pr_iglobals[i];
688 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
691 prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name);
695 OPC->_int = pr_iglobals[OPA->_int];
700 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
703 prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name);
707 OPC->ivector[0] = pr_iglobals[OPA->_int ];
708 OPC->ivector[1] = pr_iglobals[OPA->_int+1];
709 OPC->ivector[2] = pr_iglobals[OPA->_int+2];
713 if (OPA->_int < 0 || OPA->_int >= st->b)
716 prog->error_cmd("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", prog->name, st->b, st->c);
725 prog->error_cmd("Bad opcode %i in %s", st->op, prog->name);
728 #if PRVMSLOWINTERPRETER
730 if (prog->watch_global_type != ev_void)
732 prvm_eval_t *f = PRVM_GLOBALFIELDVALUE(prog->watch_global);
733 prog->xstatement = st - cached_statements;
734 PRVM_Watchpoint(prog, 0, "Global watchpoint hit", prog->watch_global_type, &prog->watch_global_value, f);
736 if (prog->watch_field_type != ev_void && prog->watch_edict < prog->max_edicts)
738 prvm_eval_t *f = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field);
739 prog->xstatement = st - cached_statements;
740 PRVM_Watchpoint(prog, 0, "Entityfield watchpoint hit", prog->watch_field_type, &prog->watch_edictfield_value, f);