1 #ifdef PRVMTIMEPROFILING
3 prog->xstatement = st - prog->statements; \
4 tm = Sys_DoubleTime(); \
5 prog->xfunction->profile += (st - startst); \
6 prog->xfunction->tprofile += (tm - starttm);
9 prog->xstatement = st - prog->statements; \
10 prog->xfunction->profile += (st - startst);
13 // This code isn't #ifdef/#define protectable, don't try.
19 #if PRVMSLOWINTERPRETER
21 PRVM_PrintStatement(st);
22 prog->statement_profile[st - prog->statements]++;
28 OPC->_float = OPA->_float + OPB->_float;
31 OPC->vector[0] = OPA->vector[0] + OPB->vector[0];
32 OPC->vector[1] = OPA->vector[1] + OPB->vector[1];
33 OPC->vector[2] = OPA->vector[2] + OPB->vector[2];
36 OPC->_float = OPA->_float - OPB->_float;
39 OPC->vector[0] = OPA->vector[0] - OPB->vector[0];
40 OPC->vector[1] = OPA->vector[1] - OPB->vector[1];
41 OPC->vector[2] = OPA->vector[2] - OPB->vector[2];
44 OPC->_float = OPA->_float * OPB->_float;
47 OPC->_float = OPA->vector[0]*OPB->vector[0] + OPA->vector[1]*OPB->vector[1] + OPA->vector[2]*OPB->vector[2];
50 OPC->vector[0] = OPA->_float * OPB->vector[0];
51 OPC->vector[1] = OPA->_float * OPB->vector[1];
52 OPC->vector[2] = OPA->_float * OPB->vector[2];
55 OPC->vector[0] = OPB->_float * OPA->vector[0];
56 OPC->vector[1] = OPB->_float * OPA->vector[1];
57 OPC->vector[2] = OPB->_float * OPA->vector[2];
60 if( OPB->_float != 0.0f )
62 OPC->_float = OPA->_float / OPB->_float;
66 if (developer.integer)
68 prog->xfunction->profile += (st - startst);
70 prog->xstatement = st - prog->statements;
71 VM_Warning( "Attempted division by zero in %s\n", PRVM_NAME );
77 OPC->_float = (int)OPA->_float & (int)OPB->_float;
80 OPC->_float = (int)OPA->_float | (int)OPB->_float;
83 OPC->_float = OPA->_float >= OPB->_float;
86 OPC->_float = OPA->_float <= OPB->_float;
89 OPC->_float = OPA->_float > OPB->_float;
92 OPC->_float = OPA->_float < OPB->_float;
95 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
98 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
101 OPC->_float = !FLOAT_IS_TRUE_FOR_INT(OPA->_int);
104 OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2];
107 OPC->_float = !OPA->string || !*PRVM_GetString(OPA->string);
110 OPC->_float = !OPA->function;
113 OPC->_float = (OPA->edict == 0);
116 OPC->_float = OPA->_float == OPB->_float;
119 OPC->_float = (OPA->vector[0] == OPB->vector[0]) && (OPA->vector[1] == OPB->vector[1]) && (OPA->vector[2] == OPB->vector[2]);
122 OPC->_float = !strcmp(PRVM_GetString(OPA->string),PRVM_GetString(OPB->string));
125 OPC->_float = OPA->_int == OPB->_int;
128 OPC->_float = OPA->function == OPB->function;
131 OPC->_float = OPA->_float != OPB->_float;
134 OPC->_float = (OPA->vector[0] != OPB->vector[0]) || (OPA->vector[1] != OPB->vector[1]) || (OPA->vector[2] != OPB->vector[2]);
137 OPC->_float = strcmp(PRVM_GetString(OPA->string),PRVM_GetString(OPB->string));
140 OPC->_float = OPA->_int != OPB->_int;
143 OPC->_float = OPA->function != OPB->function;
149 case OP_STORE_FLD: // integers
151 case OP_STORE_FNC: // pointers
152 OPB->_int = OPA->_int;
155 OPB->ivector[0] = OPA->ivector[0];
156 OPB->ivector[1] = OPA->ivector[1];
157 OPB->ivector[2] = OPA->ivector[2];
162 case OP_STOREP_FLD: // integers
164 case OP_STOREP_FNC: // pointers
165 if (OPB->_int < 0 || OPB->_int + 1 > prog->entityfieldsarea)
168 PRVM_ERROR("%s attempted to write to an out of bounds edict (%i)", PRVM_NAME, OPB->_int);
171 if (OPB->_int < prog->progs->entityfields && !prog->allowworldwrites)
173 prog->xstatement = st - prog->statements;
174 VM_Warning("assignment to world.%s (field %i) in %s\n", PRVM_GetString(PRVM_ED_FieldAtOfs(OPB->_int)->s_name), OPB->_int, PRVM_NAME);
176 ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
177 ptr->_int = OPA->_int;
180 if (OPB->_int < 0 || OPB->_int + 3 > prog->entityfieldsarea)
183 PRVM_ERROR("%s attempted to write to an out of bounds edict (%i)", PRVM_NAME, OPB->_int);
186 if (OPB->_int < prog->progs->entityfields && !prog->allowworldwrites)
188 prog->xstatement = st - prog->statements;
189 VM_Warning("assignment to world.%s (field %i) in %s\n", PRVM_GetString(PRVM_ED_FieldAtOfs(OPB->_int)->s_name), OPB->_int, PRVM_NAME);
191 ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
192 ptr->ivector[0] = OPA->ivector[0];
193 ptr->ivector[1] = OPA->ivector[1];
194 ptr->ivector[2] = OPA->ivector[2];
198 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
201 PRVM_ERROR ("%s Progs attempted to address an out of bounds edict number", PRVM_NAME);
204 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->progs->entityfields))
207 PRVM_ERROR("%s attempted to address an invalid field (%i) in an edict", PRVM_NAME, OPB->_int);
211 if (OPA->edict == 0 && !prog->allowworldwrites)
214 PRVM_ERROR("forbidden assignment to null/world entity in %s", PRVM_NAME);
218 ed = PRVM_PROG_TO_EDICT(OPA->edict);
219 OPC->_int = ed->fields.vp - prog->edictsfields + OPB->_int;
227 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
230 PRVM_ERROR ("%s Progs attempted to read an out of bounds edict number", PRVM_NAME);
233 if ((unsigned int)(OPB->_int) >= (unsigned int)(prog->progs->entityfields))
236 PRVM_ERROR("%s attempted to read an invalid field in an edict (%i)", PRVM_NAME, OPB->_int);
239 ed = PRVM_PROG_TO_EDICT(OPA->edict);
240 OPC->_int = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->_int;
244 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
247 PRVM_ERROR ("%s Progs attempted to read an out of bounds edict number", PRVM_NAME);
250 if (OPB->_int < 0 || OPB->_int + 2 >= prog->progs->entityfields)
253 PRVM_ERROR("%s attempted to read an invalid field in an edict (%i)", PRVM_NAME, OPB->_int);
256 ed = PRVM_PROG_TO_EDICT(OPA->edict);
257 OPC->ivector[0] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[0];
258 OPC->ivector[1] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[1];
259 OPC->ivector[2] = ((prvm_eval_t *)((int *)ed->fields.vp + OPB->_int))->ivector[2];
265 if(!FLOAT_IS_TRUE_FOR_INT(OPA->_int))
266 // TODO add an "int-if", and change this one to OPA->_float
267 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
268 // and entity, string, field values can never have that value
270 prog->xfunction->profile += (st - startst);
271 st += st->b - 1; // offset the s++
273 // no bounds check needed, it is done when loading progs
274 if (++jumpcount == 10000000 && prvm_runawaycheck)
276 prog->xstatement = st - prog->statements;
277 PRVM_Profile(1<<30, 1000000, 0);
278 PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
284 if(FLOAT_IS_TRUE_FOR_INT(OPA->_int))
285 // TODO add an "int-if", and change this one, as well as the FLOAT_IS_TRUE_FOR_INT usages, to OPA->_float
286 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
287 // and entity, string, field values can never have that value
289 prog->xfunction->profile += (st - startst);
290 st += st->b - 1; // offset the s++
292 // no bounds check needed, it is done when loading progs
293 if (++jumpcount == 10000000 && prvm_runawaycheck)
295 prog->xstatement = st - prog->statements;
296 PRVM_Profile(1<<30, 0.01, 0);
297 PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
303 prog->xfunction->profile += (st - startst);
304 st += st->a - 1; // offset the s++
306 // no bounds check needed, it is done when loading progs
307 if (++jumpcount == 10000000 && prvm_runawaycheck)
309 prog->xstatement = st - prog->statements;
310 PRVM_Profile(1<<30, 0.01, 0);
311 PRVM_ERROR("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", PRVM_NAME, jumpcount);
324 #ifdef PRVMTIMEPROFILING
325 tm = Sys_DoubleTime();
326 prog->xfunction->tprofile += (tm - starttm);
329 prog->xfunction->profile += (st - startst);
331 prog->xstatement = st - prog->statements;
332 prog->argc = st->op - OP_CALL0;
334 PRVM_ERROR("NULL function in %s", PRVM_NAME);
336 if(!OPA->function || OPA->function >= (unsigned int)prog->progs->numfunctions)
339 PRVM_ERROR("%s CALL outside the program", PRVM_NAME);
343 newf = &prog->functions[OPA->function];
346 if (newf->first_statement < 0)
348 // negative statements are built in functions
349 int builtinnumber = -newf->first_statement;
350 prog->xfunction->builtinsprofile++;
351 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
353 prog->builtins[builtinnumber]();
354 #ifdef PRVMTIMEPROFILING
355 tm = Sys_DoubleTime();
356 newf->tprofile += (tm - starttm);
357 prog->xfunction->tbprofile += (tm - starttm);
362 PRVM_ERROR("No such builtin #%i in %s; most likely cause: outdated engine build. Try updating!", builtinnumber, PRVM_NAME);
365 st = prog->statements + PRVM_EnterFunction(newf);
371 #ifdef PRVMTIMEPROFILING
372 tm = Sys_DoubleTime();
373 prog->xfunction->tprofile += (tm - starttm);
376 prog->xfunction->profile += (st - startst);
377 prog->xstatement = st - prog->statements;
379 prog->globals.generic[OFS_RETURN] = prog->globals.generic[(unsigned short) st->a];
380 prog->globals.generic[OFS_RETURN+1] = prog->globals.generic[(unsigned short) st->a+1];
381 prog->globals.generic[OFS_RETURN+2] = prog->globals.generic[(unsigned short) st->a+2];
383 st = prog->statements + PRVM_LeaveFunction();
385 if (prog->depth <= exitdepth)
386 goto cleanup; // all done
387 if (prog->trace != cachedpr_trace)
388 goto chooseexecprogram;
392 if(prog->flag & PRVM_OP_STATE)
394 ed = PRVM_PROG_TO_EDICT(PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict);
395 PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.nextthink)->_float = PRVM_GLOBALFIELDVALUE(prog->globaloffsets.time)->_float + 0.1;
396 PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.frame)->_float = OPA->_float;
397 PRVM_EDICTFIELDVALUE(ed,prog->fieldoffsets.think)->function = OPB->function;
402 prog->xstatement = st - prog->statements;
403 PRVM_ERROR("OP_STATE not supported by %s", PRVM_NAME);
407 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
410 OPC->_int = OPA->_int + OPB->_int;
413 OPC->_int = OPA->_int + (int) OPB->_float;
416 OPC->_float = OPA->_float + (float) OPB->_int;
419 OPC->_int = OPA->_int - OPB->_int;
422 OPC->_int = OPA->_int - (int) OPB->_float;
425 OPC->_float = OPA->_float - (float) OPB->_int;
428 OPC->_int = OPA->_int * OPB->_int;
431 OPC->_int = OPA->_int * (int) OPB->_float;
434 OPC->_float = OPA->_float * (float) OPB->_int;
437 OPC->vector[0] = (float) OPB->_int * OPA->vector[0];
438 OPC->vector[1] = (float) OPB->_int * OPA->vector[1];
439 OPC->vector[2] = (float) OPB->_int * OPA->vector[2];
443 float temp = 1.0f / OPB->_float;
444 OPC->vector[0] = temp * OPA->vector[0];
445 OPC->vector[1] = temp * OPA->vector[1];
446 OPC->vector[2] = temp * OPA->vector[2];
450 OPC->_int = OPA->_int / OPB->_int;
453 OPC->_int = OPA->_int / (int) OPB->_float;
456 OPC->_float = OPA->_float / (float) OPB->_int;
459 OPC->_float = OPA->_int;
462 OPC->_int = OPA->_float;
465 OPC->_int = OPA->_int & OPB->_int;
468 OPC->_int = OPA->_int | OPB->_int;
471 OPC->_int = OPA->_int & (int)OPB->_float;
474 OPC->_int = OPA->_int | (int)OPB->_float;
477 OPC->_float = (int)OPA->_float & OPB->_int;
480 OPC->_float = (int)OPA->_float | OPB->_int;
483 OPC->_float = OPA->_int >= OPB->_int;
486 OPC->_float = OPA->_int <= OPB->_int;
489 OPC->_float = OPA->_int > OPB->_int;
492 OPC->_float = OPA->_int < OPB->_int;
495 OPC->_float = OPA->_int && OPB->_int;
498 OPC->_float = OPA->_int || OPB->_int;
501 OPC->_float = (float)OPA->_int >= OPB->_float;
504 OPC->_float = (float)OPA->_int <= OPB->_float;
507 OPC->_float = (float)OPA->_int > OPB->_float;
510 OPC->_float = (float)OPA->_int < OPB->_float;
513 OPC->_float = (float)OPA->_int && OPB->_float;
516 OPC->_float = (float)OPA->_int || OPB->_float;
519 OPC->_float = OPA->_float >= (float)OPB->_int;
522 OPC->_float = OPA->_float <= (float)OPB->_int;
525 OPC->_float = OPA->_float > (float)OPB->_int;
528 OPC->_float = OPA->_float < (float)OPB->_int;
531 OPC->_float = OPA->_float && (float)OPB->_int;
534 OPC->_float = OPA->_float || (float)OPB->_int;
537 OPC->_float = !OPA->_int;
540 OPC->_float = OPA->_int == OPB->_int;
543 OPC->_float = (float)OPA->_int == OPB->_float;
546 OPC->_float = OPA->_float == (float)OPB->_int;
549 OPC->_float = OPA->_int != OPB->_int;
552 OPC->_float = (float)OPA->_int != OPB->_float;
555 OPC->_float = OPA->_float != (float)OPB->_int;
558 OPB->_int = OPA->_int;
562 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
565 PRVM_ERROR ("%s Progs attempted to write to an out of bounds edict", PRVM_NAME);
569 ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
570 ptr->_int = OPA->_int;
574 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
577 PRVM_ERROR ("%s Progs attempted to read an out of bounds edict number", PRVM_NAME);
580 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
583 PRVM_ERROR ("%s Progs attempted to read an invalid field in an edict", PRVM_NAME);
587 ed = PRVM_PROG_TO_EDICT(OPA->edict);
588 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
594 case OP_GSTOREP_FLD: // integers
596 case OP_GSTOREP_FNC: // pointers
598 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
601 PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
605 pr_iglobals[OPB->_int] = OPA->_int;
609 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
612 PRVM_ERROR ("%s Progs attempted to write to an invalid indexed global", PRVM_NAME);
616 pr_iglobals[OPB->_int ] = OPA->ivector[0];
617 pr_iglobals[OPB->_int+1] = OPA->ivector[1];
618 pr_iglobals[OPB->_int+2] = OPA->ivector[2];
622 i = OPA->_int + (int) OPB->_float;
624 if (i < 0 || i >= pr_globaldefs)
627 PRVM_ERROR ("%s Progs attempted to address an out of bounds global", PRVM_NAME);
631 OPC->_int = pr_iglobals[i];
641 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
644 PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
648 OPC->_int = pr_iglobals[OPA->_int];
653 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
656 PRVM_ERROR ("%s Progs attempted to read an invalid indexed global", PRVM_NAME);
660 OPC->ivector[0] = pr_iglobals[OPA->_int ];
661 OPC->ivector[1] = pr_iglobals[OPA->_int+1];
662 OPC->ivector[2] = pr_iglobals[OPA->_int+2];
666 if (OPA->_int < 0 || OPA->_int >= st->b)
669 PRVM_ERROR ("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", PRVM_NAME, st->b, st->c);
678 PRVM_ERROR ("Bad opcode %i in %s", st->op, PRVM_NAME);