1 #ifdef PRVMTIMEPROFILING
3 prog->xstatement = st - prog->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 - prog->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 - prog->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 - prog->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 - prog->statements]++;
40 if (prog->break_statement >= 0)
41 if ((st - prog->statements) == prog->break_statement)
43 prog->xstatement = st - prog->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 - prog->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 - prog->entityfields >= (prvm_uint_t)prog->entityfieldsarea - prog->entityfields)
192 if (OPB->_int < 0 || OPB->_int >= prog->entityfieldsarea)
195 prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
198 if (OPB->_int < prog->entityfields && !prog->allowworldwrites)
200 prog->xstatement = st - prog->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 *)(prog->edictsfields + OPB->_int);
205 ptr->_int = OPA->_int;
208 if ((prvm_uint_t)OPB->_int - prog->entityfields > (prvm_uint_t)prog->entityfieldsarea - prog->entityfields - 3)
210 if (OPB->_int < 0 || OPB->_int > prog->entityfieldsarea - 3)
213 prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
216 if (OPB->_int < prog->entityfields && !prog->allowworldwrites)
218 prog->xstatement = st - prog->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 *)(prog->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 >= (prvm_uint_t)prog->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) >= (prvm_uint_t)(prog->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 && !prog->allowworldwrites)
245 prog->error_cmd("forbidden assignment to null/world entity in %s", prog->name);
249 ed = PRVM_PROG_TO_EDICT(OPA->edict);
250 OPC->_int = ed->fields.fp - prog->edictsfields + OPB->_int;
258 if ((prvm_uint_t)OPA->edict >= (prvm_uint_t)prog->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) >= (prvm_uint_t)(prog->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 >= (prvm_uint_t)prog->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 > (prvm_uint_t)prog->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 = prog->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 - prog->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 = prog->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 - prog->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 = prog->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 - prog->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 - prog->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];
378 if (newf->first_statement < 0)
380 // negative statements are built in functions
381 int builtinnumber = -newf->first_statement;
382 prog->xfunction->builtinsprofile++;
383 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
385 prog->builtins[builtinnumber](prog);
386 #ifdef PRVMTIMEPROFILING
387 tm = Sys_DirtyTime();
388 newf->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
389 prog->xfunction->tbprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
394 prog->error_cmd("No such builtin #%i in %s; most likely cause: outdated engine build. Try updating!", builtinnumber, prog->name);
396 if (prog->trace != cachedpr_trace)
397 goto chooseexecprogram;
400 st = prog->statements + PRVM_EnterFunction(prog, newf);
406 #ifdef PRVMTIMEPROFILING
407 tm = Sys_DirtyTime();
408 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
411 prog->xfunction->profile += (st - startst);
412 prog->xstatement = st - prog->statements;
414 prog->globals.ip[OFS_RETURN ] = prog->globals.ip[st->operand[0] ];
415 prog->globals.ip[OFS_RETURN+1] = prog->globals.ip[st->operand[0]+1];
416 prog->globals.ip[OFS_RETURN+2] = prog->globals.ip[st->operand[0]+2];
418 st = prog->statements + PRVM_LeaveFunction(prog);
420 if (prog->depth <= exitdepth)
421 goto cleanup; // all done
425 if(prog->flag & PRVM_OP_STATE)
427 ed = PRVM_PROG_TO_EDICT(PRVM_gameglobaledict(self));
428 PRVM_gameedictfloat(ed,nextthink) = PRVM_gameglobalfloat(time) + 0.1;
429 PRVM_gameedictfloat(ed,frame) = OPA->_float;
430 PRVM_gameedictfunction(ed,think) = OPB->function;
435 prog->xstatement = st - prog->statements;
436 prog->error_cmd("OP_STATE not supported by %s", prog->name);
440 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
443 OPC->_int = OPA->_int + OPB->_int;
446 OPC->_int = OPA->_int + (prvm_int_t) OPB->_float;
449 OPC->_float = OPA->_float + (prvm_vec_t) OPB->_int;
452 OPC->_int = OPA->_int - OPB->_int;
455 OPC->_int = OPA->_int - (prvm_int_t) OPB->_float;
458 OPC->_float = OPA->_float - (prvm_vec_t) OPB->_int;
461 OPC->_int = OPA->_int * OPB->_int;
464 OPC->_int = OPA->_int * (prvm_int_t) OPB->_float;
467 OPC->_float = OPA->_float * (prvm_vec_t) OPB->_int;
470 OPC->vector[0] = (prvm_vec_t) OPB->_int * OPA->vector[0];
471 OPC->vector[1] = (prvm_vec_t) OPB->_int * OPA->vector[1];
472 OPC->vector[2] = (prvm_vec_t) OPB->_int * OPA->vector[2];
476 float temp = 1.0f / OPB->_float;
477 OPC->vector[0] = temp * OPA->vector[0];
478 OPC->vector[1] = temp * OPA->vector[1];
479 OPC->vector[2] = temp * OPA->vector[2];
483 OPC->_int = OPA->_int / OPB->_int;
486 OPC->_int = OPA->_int / (prvm_int_t) OPB->_float;
489 OPC->_float = OPA->_float / (prvm_vec_t) OPB->_int;
492 OPC->_float = OPA->_int;
495 OPC->_int = OPA->_float;
498 OPC->_int = OPA->_int & OPB->_int;
501 OPC->_int = OPA->_int | OPB->_int;
504 OPC->_int = OPA->_int & (prvm_int_t)OPB->_float;
507 OPC->_int = OPA->_int | (prvm_int_t)OPB->_float;
510 OPC->_float = (prvm_int_t)OPA->_float & OPB->_int;
513 OPC->_float = (prvm_int_t)OPA->_float | OPB->_int;
516 OPC->_float = OPA->_int >= OPB->_int;
519 OPC->_float = OPA->_int <= OPB->_int;
522 OPC->_float = OPA->_int > OPB->_int;
525 OPC->_float = OPA->_int < OPB->_int;
528 OPC->_float = OPA->_int && OPB->_int;
531 OPC->_float = OPA->_int || OPB->_int;
534 OPC->_float = (prvm_vec_t)OPA->_int >= OPB->_float;
537 OPC->_float = (prvm_vec_t)OPA->_int <= OPB->_float;
540 OPC->_float = (prvm_vec_t)OPA->_int > OPB->_float;
543 OPC->_float = (prvm_vec_t)OPA->_int < OPB->_float;
546 OPC->_float = (prvm_vec_t)OPA->_int && OPB->_float;
549 OPC->_float = (prvm_vec_t)OPA->_int || OPB->_float;
552 OPC->_float = OPA->_float >= (prvm_vec_t)OPB->_int;
555 OPC->_float = OPA->_float <= (prvm_vec_t)OPB->_int;
558 OPC->_float = OPA->_float > (prvm_vec_t)OPB->_int;
561 OPC->_float = OPA->_float < (prvm_vec_t)OPB->_int;
564 OPC->_float = OPA->_float && (prvm_vec_t)OPB->_int;
567 OPC->_float = OPA->_float || (prvm_vec_t)OPB->_int;
570 OPC->_float = !OPA->_int;
573 OPC->_float = OPA->_int == OPB->_int;
576 OPC->_float = (prvm_vec_t)OPA->_int == OPB->_float;
579 OPC->_float = OPA->_float == (prvm_vec_t)OPB->_int;
582 OPC->_float = OPA->_int != OPB->_int;
585 OPC->_float = (prvm_vec_t)OPA->_int != OPB->_float;
588 OPC->_float = OPA->_float != (prvm_vec_t)OPB->_int;
591 OPB->_int = OPA->_int;
595 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
598 prog->error_cmd("%s Progs attempted to write to an out of bounds edict", prog->name);
602 ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
603 ptr->_int = OPA->_int;
607 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
610 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
613 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
616 prog->error_cmd("%s Progs attempted to read an invalid field in an edict", prog->name);
620 ed = PRVM_PROG_TO_EDICT(OPA->edict);
621 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
627 case OP_GSTOREP_FLD: // integers
629 case OP_GSTOREP_FNC: // pointers
631 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
634 prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name);
638 pr_iglobals[OPB->_int] = OPA->_int;
642 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
645 prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name);
649 pr_iglobals[OPB->_int ] = OPA->ivector[0];
650 pr_iglobals[OPB->_int+1] = OPA->ivector[1];
651 pr_iglobals[OPB->_int+2] = OPA->ivector[2];
655 i = OPA->_int + (prvm_int_t) OPB->_float;
657 if (i < 0 || i >= pr_globaldefs)
660 prog->error_cmd("%s Progs attempted to address an out of bounds global", prog->name);
664 OPC->_int = pr_iglobals[i];
674 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
677 prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name);
681 OPC->_int = pr_iglobals[OPA->_int];
686 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
689 prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name);
693 OPC->ivector[0] = pr_iglobals[OPA->_int ];
694 OPC->ivector[1] = pr_iglobals[OPA->_int+1];
695 OPC->ivector[2] = pr_iglobals[OPA->_int+2];
699 if (OPA->_int < 0 || OPA->_int >= st->b)
702 prog->error_cmd("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", prog->name, st->b, st->c);
711 prog->error_cmd("Bad opcode %i in %s", st->op, prog->name);
714 #if PRVMSLOWINTERPRETER
716 if (prog->watch_global_type != ev_void)
718 prvm_eval_t *f = PRVM_GLOBALFIELDVALUE(prog->watch_global);
719 prog->xstatement = st - prog->statements;
720 PRVM_Watchpoint(prog, 0, "Global watchpoint hit", prog->watch_global_type, &prog->watch_global_value, f);
722 if (prog->watch_field_type != ev_void && prog->watch_edict < prog->max_edicts)
724 prvm_eval_t *f = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field);
725 prog->xstatement = st - prog->statements;
726 PRVM_Watchpoint(prog, 0, "Entityfield watchpoint hit", prog->watch_field_type, &prog->watch_edictfield_value, f);