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
18 if (prog->watch_global >= 0)
20 prvm_vec_t f = PRVM_GLOBALFIELDFLOAT(prog->watch_global);
21 if (memcmp(&f, &prog->watch_global_value, sizeof(f)))
23 prog->xstatement = st + 1 - prog->statements;
24 PRVM_Breakpoint(prog, 1, va(vabuf, sizeof(vabuf), "Global watchpoint hit by engine: " FLOAT_LOSSLESS_FORMAT " -> " FLOAT_LOSSLESS_FORMAT, prog->watch_global_value, f));
25 prog->watch_global_value = f;
28 if (prog->watch_edict >= 0 && prog->watch_edict < prog->max_edicts)
30 prvm_vec_t f = PRVM_EDICTFIELDFLOAT(prog->edicts + prog->watch_edict, prog->watch_field);
31 if (memcmp(&f, &prog->watch_edictfield_value, sizeof(f)))
33 prog->xstatement = st + 1 - prog->statements;
34 PRVM_Breakpoint(prog, 1, va(vabuf, sizeof(vabuf), "Entityfield watchpoint hit by engine: " FLOAT_LOSSLESS_FORMAT " -> " FLOAT_LOSSLESS_FORMAT, prog->watch_edictfield_value, f));
35 prog->watch_edictfield_value = f;
45 #if PRVMSLOWINTERPRETER
47 PRVM_PrintStatement(prog, st);
48 prog->statement_profile[st - prog->statements]++;
49 if (prog->break_statement >= 0)
50 if ((st - prog->statements) == prog->break_statement)
52 prog->xstatement = st - prog->statements;
53 PRVM_Breakpoint(prog, prog->break_stack_index, "Breakpoint hit");
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->vector[0] = OPA->vector[0] - OPB->vector[0];
72 OPC->vector[1] = OPA->vector[1] - OPB->vector[1];
73 OPC->vector[2] = OPA->vector[2] - OPB->vector[2];
76 OPC->_float = OPA->_float * OPB->_float;
79 OPC->_float = OPA->vector[0]*OPB->vector[0] + OPA->vector[1]*OPB->vector[1] + OPA->vector[2]*OPB->vector[2];
82 OPC->vector[0] = OPA->_float * OPB->vector[0];
83 OPC->vector[1] = OPA->_float * OPB->vector[1];
84 OPC->vector[2] = OPA->_float * OPB->vector[2];
87 OPC->vector[0] = OPB->_float * OPA->vector[0];
88 OPC->vector[1] = OPB->_float * OPA->vector[1];
89 OPC->vector[2] = OPB->_float * OPA->vector[2];
92 if( OPB->_float != 0.0f )
94 OPC->_float = OPA->_float / OPB->_float;
98 if (developer.integer)
100 prog->xfunction->profile += (st - startst);
102 prog->xstatement = st - prog->statements;
103 VM_Warning(prog, "Attempted division by zero in %s\n", prog->name );
109 OPC->_float = (prvm_int_t)OPA->_float & (prvm_int_t)OPB->_float;
112 OPC->_float = (prvm_int_t)OPA->_float | (prvm_int_t)OPB->_float;
115 OPC->_float = OPA->_float >= OPB->_float;
118 OPC->_float = OPA->_float <= OPB->_float;
121 OPC->_float = OPA->_float > OPB->_float;
124 OPC->_float = OPA->_float < OPB->_float;
127 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
130 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
133 OPC->_float = !FLOAT_IS_TRUE_FOR_INT(OPA->_int);
136 OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2];
139 OPC->_float = !OPA->string || !*PRVM_GetString(prog, OPA->string);
142 OPC->_float = !OPA->function;
145 OPC->_float = (OPA->edict == 0);
148 OPC->_float = OPA->_float == OPB->_float;
151 OPC->_float = (OPA->vector[0] == OPB->vector[0]) && (OPA->vector[1] == OPB->vector[1]) && (OPA->vector[2] == OPB->vector[2]);
154 OPC->_float = !strcmp(PRVM_GetString(prog, OPA->string),PRVM_GetString(prog, OPB->string));
157 OPC->_float = OPA->_int == OPB->_int;
160 OPC->_float = OPA->function == OPB->function;
163 OPC->_float = OPA->_float != OPB->_float;
166 OPC->_float = (OPA->vector[0] != OPB->vector[0]) || (OPA->vector[1] != OPB->vector[1]) || (OPA->vector[2] != OPB->vector[2]);
169 OPC->_float = strcmp(PRVM_GetString(prog, OPA->string),PRVM_GetString(prog, OPB->string));
172 OPC->_float = OPA->_int != OPB->_int;
175 OPC->_float = OPA->function != OPB->function;
181 case OP_STORE_FLD: // integers
183 case OP_STORE_FNC: // pointers
184 OPB->_int = OPA->_int;
187 OPB->ivector[0] = OPA->ivector[0];
188 OPB->ivector[1] = OPA->ivector[1];
189 OPB->ivector[2] = OPA->ivector[2];
194 case OP_STOREP_FLD: // integers
196 case OP_STOREP_FNC: // pointers
197 if (OPB->_int < 0 || OPB->_int + 1 > prog->entityfieldsarea)
200 prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
203 if (OPB->_int < prog->entityfields && !prog->allowworldwrites)
205 prog->xstatement = st - prog->statements;
206 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);
208 ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
209 ptr->_int = OPA->_int;
212 if (OPB->_int < 0 || OPB->_int + 3 > prog->entityfieldsarea)
215 prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
218 if (OPB->_int < prog->entityfields && !prog->allowworldwrites)
220 prog->xstatement = st - prog->statements;
221 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 *)(prog->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 (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
233 prog->error_cmd("%s Progs attempted to address an out of bounds edict number", prog->name);
236 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->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 && !prog->allowworldwrites)
246 prog->error_cmd("forbidden assignment to null/world entity in %s", prog->name);
250 ed = PRVM_PROG_TO_EDICT(OPA->edict);
251 OPC->_int = ed->fields.fp - prog->edictsfields + OPB->_int;
259 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
262 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
265 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->entityfields))
268 prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
271 ed = PRVM_PROG_TO_EDICT(OPA->edict);
272 OPC->_int = ((prvm_eval_t *)(ed->fields.ip + OPB->_int))->_int;
276 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
279 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
282 if (OPB->_int < 0 || OPB->_int + 2 >= prog->entityfields)
285 prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
288 ed = PRVM_PROG_TO_EDICT(OPA->edict);
289 OPC->ivector[0] = ((prvm_eval_t *)(ed->fields.ip + OPB->_int))->ivector[0];
290 OPC->ivector[1] = ((prvm_eval_t *)(ed->fields.ip + OPB->_int))->ivector[1];
291 OPC->ivector[2] = ((prvm_eval_t *)(ed->fields.ip + OPB->_int))->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
717 if (prog->watch_global >= 0)
719 prvm_vec_t f = PRVM_GLOBALFIELDFLOAT(prog->watch_global);
720 if (memcmp(&f, &prog->watch_global_value, sizeof(f)))
722 prog->xstatement = st - prog->statements;
723 PRVM_Breakpoint(prog, 0, va(vabuf, sizeof(vabuf), "Global watchpoint hit: " FLOAT_LOSSLESS_FORMAT " -> " FLOAT_LOSSLESS_FORMAT, prog->watch_global_value, f));
724 prog->watch_global_value = f;
727 if (prog->watch_edict >= 0 && prog->watch_edict < prog->max_edicts)
729 prvm_vec_t f = PRVM_EDICTFIELDFLOAT(prog->edicts + prog->watch_edict, prog->watch_field);
730 if (memcmp(&f, &prog->watch_edictfield_value, sizeof(f)))
732 prog->xstatement = st - prog->statements;
733 PRVM_Breakpoint(prog, 0, va(vabuf, sizeof(vabuf), "Entityfield watchpoint hit: " FLOAT_LOSSLESS_FORMAT " -> " FLOAT_LOSSLESS_FORMAT, prog->watch_edictfield_value, f));
734 prog->watch_edictfield_value = f;