1 extern cvar_t prvm_garbagecollection_enable;
2 // NEED to reset startst after calling this! startst may or may not be clobbered!
3 #define ADVANCE_PROFILE_BEFORE_JUMP() \
4 prog->xfunction->profile += (st - startst); \
5 if (prvm_statementprofiling.integer || (prvm_coverage.integer & 4)) { \
6 /* All statements from startst+1 to st have been hit. */ \
7 while (++startst <= st) { \
8 if (prog->statement_profile[startst - cached_statements]++ == 0 && (prvm_coverage.integer & 4)) \
9 PRVM_StatementCoverageEvent(prog, prog->xfunction, startst - cached_statements); \
11 /* Observe: startst now is clobbered (now at st+1)! */ \
14 #ifdef PRVMTIMEPROFILING
16 ADVANCE_PROFILE_BEFORE_JUMP(); \
17 prog->xstatement = st - cached_statements; \
18 tm = Sys_DirtyTime(); \
19 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0; \
24 ADVANCE_PROFILE_BEFORE_JUMP(); \
25 prog->xstatement = st - cached_statements; \
29 // This code isn't #ifdef/#define protectable, don't try.
31 #if HAVE_COMPUTED_GOTOS && !(PRVMSLOWINTERPRETER || PRVMTIMEPROFILING)
32 // NOTE: Due to otherwise duplicate labels, only ONE interpreter path may
34 # define USE_COMPUTED_GOTOS 1
37 #if USE_COMPUTED_GOTOS
38 // Must exactly match opcode_e enum in pr_comp.h
39 const static void *dispatchtable[] = {
80 &&handle_OP_STORE_ENT,
81 &&handle_OP_STORE_FLD,
82 &&handle_OP_STORE_FNC,
87 &&handle_OP_STOREP_ENT,
88 &&handle_OP_STOREP_FLD,
89 &&handle_OP_STOREP_FNC,
116 #define DISPATCH_OPCODE() \
117 goto *dispatchtable[(++st)->op]
118 #define HANDLE_OPCODE(opcode) handle_##opcode
120 DISPATCH_OPCODE(); // jump to first opcode
121 #else // USE_COMPUTED_GOTOS
122 #define DISPATCH_OPCODE() break
123 #define HANDLE_OPCODE(opcode) case opcode
125 #if PRVMSLOWINTERPRETER
127 if (prog->watch_global_type != ev_void)
129 prvm_eval_t *g = PRVM_GLOBALFIELDVALUE(prog->watch_global);
130 prog->xstatement = st + 1 - cached_statements;
131 PRVM_Watchpoint(prog, 1, "Global watchpoint hit by engine", prog->watch_global_type, &prog->watch_global_value, g);
133 if (prog->watch_field_type != ev_void && prog->watch_edict < prog->max_edicts)
135 prvm_eval_t *g = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field);
136 prog->xstatement = st + 1 - cached_statements;
137 PRVM_Watchpoint(prog, 1, "Entityfield watchpoint hit by engine", prog->watch_field_type, &prog->watch_edictfield_value, g);
145 #endif // USE_COMPUTED_GOTOS
147 #if !USE_COMPUTED_GOTOS
149 #if PRVMSLOWINTERPRETER
151 PRVM_PrintStatement(prog, st);
152 if (prog->break_statement >= 0)
153 if ((st - cached_statements) == prog->break_statement)
155 prog->xstatement = st - cached_statements;
156 PRVM_Breakpoint(prog, prog->break_stack_index, "Breakpoint hit");
162 HANDLE_OPCODE(OP_ADD_F):
163 OPC->_float = OPA->_float + OPB->_float;
165 HANDLE_OPCODE(OP_ADD_V):
166 OPC->vector[0] = OPA->vector[0] + OPB->vector[0];
167 OPC->vector[1] = OPA->vector[1] + OPB->vector[1];
168 OPC->vector[2] = OPA->vector[2] + OPB->vector[2];
170 HANDLE_OPCODE(OP_SUB_F):
171 OPC->_float = OPA->_float - OPB->_float;
173 HANDLE_OPCODE(OP_SUB_V):
174 OPC->vector[0] = OPA->vector[0] - OPB->vector[0];
175 OPC->vector[1] = OPA->vector[1] - OPB->vector[1];
176 OPC->vector[2] = OPA->vector[2] - OPB->vector[2];
178 HANDLE_OPCODE(OP_MUL_F):
179 OPC->_float = OPA->_float * OPB->_float;
181 HANDLE_OPCODE(OP_MUL_V):
182 OPC->_float = OPA->vector[0]*OPB->vector[0] + OPA->vector[1]*OPB->vector[1] + OPA->vector[2]*OPB->vector[2];
184 HANDLE_OPCODE(OP_MUL_FV):
185 tempfloat = OPA->_float;
186 OPC->vector[0] = tempfloat * OPB->vector[0];
187 OPC->vector[1] = tempfloat * OPB->vector[1];
188 OPC->vector[2] = tempfloat * OPB->vector[2];
190 HANDLE_OPCODE(OP_MUL_VF):
191 tempfloat = OPB->_float;
192 OPC->vector[0] = tempfloat * OPA->vector[0];
193 OPC->vector[1] = tempfloat * OPA->vector[1];
194 OPC->vector[2] = tempfloat * OPA->vector[2];
196 HANDLE_OPCODE(OP_DIV_F):
197 if( OPB->_float != 0.0f )
199 OPC->_float = OPA->_float / OPB->_float;
203 if (developer.integer)
206 VM_Warning(prog, "Attempted division by zero in %s\n", prog->name );
211 HANDLE_OPCODE(OP_BITAND):
212 OPC->_float = (prvm_int_t)OPA->_float & (prvm_int_t)OPB->_float;
214 HANDLE_OPCODE(OP_BITOR):
215 OPC->_float = (prvm_int_t)OPA->_float | (prvm_int_t)OPB->_float;
217 HANDLE_OPCODE(OP_GE):
218 OPC->_float = OPA->_float >= OPB->_float;
220 HANDLE_OPCODE(OP_LE):
221 OPC->_float = OPA->_float <= OPB->_float;
223 HANDLE_OPCODE(OP_GT):
224 OPC->_float = OPA->_float > OPB->_float;
226 HANDLE_OPCODE(OP_LT):
227 OPC->_float = OPA->_float < OPB->_float;
229 HANDLE_OPCODE(OP_AND):
230 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
232 HANDLE_OPCODE(OP_OR):
233 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
235 HANDLE_OPCODE(OP_NOT_F):
236 OPC->_float = !FLOAT_IS_TRUE_FOR_INT(OPA->_int);
238 HANDLE_OPCODE(OP_NOT_V):
239 OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2];
241 HANDLE_OPCODE(OP_NOT_S):
242 OPC->_float = !OPA->string || !*PRVM_GetString(prog, OPA->string);
244 HANDLE_OPCODE(OP_NOT_FNC):
245 OPC->_float = !OPA->function;
247 HANDLE_OPCODE(OP_NOT_ENT):
248 OPC->_float = (OPA->edict == 0);
250 HANDLE_OPCODE(OP_EQ_F):
251 OPC->_float = OPA->_float == OPB->_float;
253 HANDLE_OPCODE(OP_EQ_V):
254 OPC->_float = (OPA->vector[0] == OPB->vector[0]) && (OPA->vector[1] == OPB->vector[1]) && (OPA->vector[2] == OPB->vector[2]);
256 HANDLE_OPCODE(OP_EQ_S):
257 OPC->_float = !strcmp(PRVM_GetString(prog, OPA->string),PRVM_GetString(prog, OPB->string));
259 HANDLE_OPCODE(OP_EQ_E):
260 OPC->_float = OPA->_int == OPB->_int;
262 HANDLE_OPCODE(OP_EQ_FNC):
263 OPC->_float = OPA->function == OPB->function;
265 HANDLE_OPCODE(OP_NE_F):
266 OPC->_float = OPA->_float != OPB->_float;
268 HANDLE_OPCODE(OP_NE_V):
269 OPC->_float = (OPA->vector[0] != OPB->vector[0]) || (OPA->vector[1] != OPB->vector[1]) || (OPA->vector[2] != OPB->vector[2]);
271 HANDLE_OPCODE(OP_NE_S):
272 OPC->_float = strcmp(PRVM_GetString(prog, OPA->string),PRVM_GetString(prog, OPB->string));
274 HANDLE_OPCODE(OP_NE_E):
275 OPC->_float = OPA->_int != OPB->_int;
277 HANDLE_OPCODE(OP_NE_FNC):
278 OPC->_float = OPA->function != OPB->function;
282 HANDLE_OPCODE(OP_STORE_F):
283 HANDLE_OPCODE(OP_STORE_ENT):
284 HANDLE_OPCODE(OP_STORE_FLD): // integers
285 HANDLE_OPCODE(OP_STORE_FNC): // pointers
286 OPB->_int = OPA->_int;
288 HANDLE_OPCODE(OP_STORE_S):
289 // refresh the garbage collection on the string - this guards
290 // against a certain sort of repeated migration to earlier
291 // points in the scan that could otherwise result in the string
292 // being freed for being unused
293 if(prvm_garbagecollection_enable.integer)
294 PRVM_GetString(prog, OPA->_int);
295 OPB->_int = OPA->_int;
297 HANDLE_OPCODE(OP_STORE_V):
298 OPB->ivector[0] = OPA->ivector[0];
299 OPB->ivector[1] = OPA->ivector[1];
300 OPB->ivector[2] = OPA->ivector[2];
303 HANDLE_OPCODE(OP_STOREP_F):
304 HANDLE_OPCODE(OP_STOREP_ENT):
305 HANDLE_OPCODE(OP_STOREP_FLD): // integers
306 HANDLE_OPCODE(OP_STOREP_FNC): // pointers
307 if ((prvm_uint_t)OPB->_int - cached_entityfields >= cached_entityfieldsarea_entityfields)
309 if ((prvm_uint_t)OPB->_int >= cached_entityfieldsarea)
312 prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
315 if ((prvm_uint_t)OPB->_int < cached_entityfields && !cached_allowworldwrites)
318 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);
321 ptr = (prvm_eval_t *)(cached_edictsfields + OPB->_int);
322 ptr->_int = OPA->_int;
324 HANDLE_OPCODE(OP_STOREP_S):
325 if ((prvm_uint_t)OPB->_int - cached_entityfields >= cached_entityfieldsarea_entityfields)
327 if ((prvm_uint_t)OPB->_int >= cached_entityfieldsarea)
330 prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
333 if ((prvm_uint_t)OPB->_int < cached_entityfields && !cached_allowworldwrites)
336 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);
339 // refresh the garbage collection on the string - this guards
340 // against a certain sort of repeated migration to earlier
341 // points in the scan that could otherwise result in the string
342 // being freed for being unused
343 if(prvm_garbagecollection_enable.integer)
344 PRVM_GetString(prog, OPA->_int);
345 ptr = (prvm_eval_t *)(cached_edictsfields + OPB->_int);
346 ptr->_int = OPA->_int;
348 HANDLE_OPCODE(OP_STOREP_V):
349 if ((prvm_uint_t)OPB->_int - cached_entityfields > (prvm_uint_t)cached_entityfieldsarea_entityfields_3)
351 if ((prvm_uint_t)OPB->_int > cached_entityfieldsarea_3)
354 prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
357 if ((prvm_uint_t)OPB->_int < cached_entityfields && !cached_allowworldwrites)
360 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);
363 ptr = (prvm_eval_t *)(cached_edictsfields + OPB->_int);
364 ptr->ivector[0] = OPA->ivector[0];
365 ptr->ivector[1] = OPA->ivector[1];
366 ptr->ivector[2] = OPA->ivector[2];
369 HANDLE_OPCODE(OP_ADDRESS):
370 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
373 prog->error_cmd("%s Progs attempted to address an out of bounds edict number", prog->name);
376 if ((prvm_uint_t)OPB->_int >= cached_entityfields)
379 prog->error_cmd("%s attempted to address an invalid field (%i) in an edict", prog->name, (int)OPB->_int);
383 if (OPA->edict == 0 && !cached_allowworldwrites)
386 prog->error_cmd("forbidden assignment to null/world entity in %s", prog->name);
390 OPC->_int = OPA->edict * cached_entityfields + OPB->_int;
393 HANDLE_OPCODE(OP_LOAD_F):
394 HANDLE_OPCODE(OP_LOAD_FLD):
395 HANDLE_OPCODE(OP_LOAD_ENT):
396 HANDLE_OPCODE(OP_LOAD_FNC):
397 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
400 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
403 if ((prvm_uint_t)OPB->_int >= cached_entityfields)
406 prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
409 ed = PRVM_PROG_TO_EDICT(OPA->edict);
410 OPC->_int = ((prvm_eval_t *)(ed->fields.ip + OPB->_int))->_int;
412 HANDLE_OPCODE(OP_LOAD_S):
413 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
416 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
419 if ((prvm_uint_t)OPB->_int >= cached_entityfields)
422 prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
425 ed = PRVM_PROG_TO_EDICT(OPA->edict);
426 OPC->_int = ((prvm_eval_t *)(ed->fields.ip + OPB->_int))->_int;
427 // refresh the garbage collection on the string - this guards
428 // against a certain sort of repeated migration to earlier
429 // points in the scan that could otherwise result in the string
430 // being freed for being unused
431 if(prvm_garbagecollection_enable.integer)
432 PRVM_GetString(prog, OPC->_int);
435 HANDLE_OPCODE(OP_LOAD_V):
436 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
439 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
442 if ((prvm_uint_t)OPB->_int > cached_entityfields_3)
445 prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
448 ed = PRVM_PROG_TO_EDICT(OPA->edict);
449 ptr = (prvm_eval_t *)(ed->fields.ip + OPB->_int);
450 OPC->ivector[0] = ptr->ivector[0];
451 OPC->ivector[1] = ptr->ivector[1];
452 OPC->ivector[2] = ptr->ivector[2];
457 HANDLE_OPCODE(OP_IFNOT):
458 if(!FLOAT_IS_TRUE_FOR_INT(OPA->_int))
459 // TODO add an "int-if", and change this one to OPA->_float
460 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
461 // and entity, string, field values can never have that value
463 ADVANCE_PROFILE_BEFORE_JUMP();
464 st = cached_statements + st->jumpabsolute - 1; // offset the st++
466 // no bounds check needed, it is done when loading progs
467 if (++jumpcount == 10000000 && prvm_runawaycheck)
469 prog->xstatement = st - cached_statements;
470 PRVM_Profile(prog, 1<<30, 1000000, 0);
471 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
476 HANDLE_OPCODE(OP_IF):
477 if(FLOAT_IS_TRUE_FOR_INT(OPA->_int))
478 // TODO add an "int-if", and change this one, as well as the FLOAT_IS_TRUE_FOR_INT usages, to OPA->_float
479 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
480 // and entity, string, field values can never have that value
482 ADVANCE_PROFILE_BEFORE_JUMP();
483 st = cached_statements + st->jumpabsolute - 1; // offset the st++
485 // no bounds check needed, it is done when loading progs
486 if (++jumpcount == 10000000 && prvm_runawaycheck)
488 prog->xstatement = st - cached_statements;
489 PRVM_Profile(prog, 1<<30, 0.01, 0);
490 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
495 HANDLE_OPCODE(OP_GOTO):
496 ADVANCE_PROFILE_BEFORE_JUMP();
497 st = cached_statements + st->jumpabsolute - 1; // offset the st++
499 // no bounds check needed, it is done when loading progs
500 if (++jumpcount == 10000000 && prvm_runawaycheck)
502 prog->xstatement = st - cached_statements;
503 PRVM_Profile(prog, 1<<30, 0.01, 0);
504 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
508 HANDLE_OPCODE(OP_CALL0):
509 HANDLE_OPCODE(OP_CALL1):
510 HANDLE_OPCODE(OP_CALL2):
511 HANDLE_OPCODE(OP_CALL3):
512 HANDLE_OPCODE(OP_CALL4):
513 HANDLE_OPCODE(OP_CALL5):
514 HANDLE_OPCODE(OP_CALL6):
515 HANDLE_OPCODE(OP_CALL7):
516 HANDLE_OPCODE(OP_CALL8):
517 #ifdef PRVMTIMEPROFILING
518 tm = Sys_DirtyTime();
519 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
522 ADVANCE_PROFILE_BEFORE_JUMP();
524 prog->xstatement = st - cached_statements;
525 prog->argc = st->op - OP_CALL0;
528 prog->error_cmd("NULL function in %s", prog->name);
531 if(!OPA->function || OPA->function < 0 || OPA->function >= prog->numfunctions)
534 prog->error_cmd("%s CALL outside the program", prog->name);
538 enterfunc = &prog->functions[OPA->function];
539 if (enterfunc->callcount++ == 0 && (prvm_coverage.integer & 1))
540 PRVM_FunctionCoverageEvent(prog, enterfunc);
542 if (enterfunc->first_statement < 0)
544 // negative first_statement values are built in functions
545 int builtinnumber = -enterfunc->first_statement;
546 prog->xfunction->builtinsprofile++;
547 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
549 prog->builtins[builtinnumber](prog);
550 #ifdef PRVMTIMEPROFILING
551 tm = Sys_DirtyTime();
552 enterfunc->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
553 prog->xfunction->tbprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
556 // builtins may cause ED_Alloc() to be called, update cached variables
557 cached_edictsfields = prog->edictsfields.fp;
558 cached_entityfields = prog->entityfields;
559 cached_entityfields_3 = prog->entityfields - 3;
560 cached_entityfieldsarea = prog->entityfieldsarea;
561 cached_entityfieldsarea_entityfields = prog->entityfieldsarea - prog->entityfields;
562 cached_entityfieldsarea_3 = prog->entityfieldsarea - 3;
563 cached_entityfieldsarea_entityfields_3 = prog->entityfieldsarea - prog->entityfields - 3;
564 cached_max_edicts = prog->max_edicts;
565 // these do not change
566 //cached_statements = prog->statements;
567 //cached_allowworldwrites = prog->allowworldwrites;
568 //cached_flag = prog->flag;
569 // if prog->trace changed we need to change interpreter path
570 if (prog->trace != cachedpr_trace)
571 goto chooseexecprogram;
574 prog->error_cmd("No such builtin #%i in %s; most likely cause: outdated engine build. Try updating!", builtinnumber, prog->name);
577 st = cached_statements + PRVM_EnterFunction(prog, enterfunc);
581 HANDLE_OPCODE(OP_DONE):
582 HANDLE_OPCODE(OP_RETURN):
583 #ifdef PRVMTIMEPROFILING
584 tm = Sys_DirtyTime();
585 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
588 ADVANCE_PROFILE_BEFORE_JUMP();
589 prog->xstatement = st - cached_statements;
591 prog->globals.ip[OFS_RETURN ] = prog->globals.ip[st->operand[0] ];
592 prog->globals.ip[OFS_RETURN+1] = prog->globals.ip[st->operand[0]+1];
593 prog->globals.ip[OFS_RETURN+2] = prog->globals.ip[st->operand[0]+2];
595 st = cached_statements + PRVM_LeaveFunction(prog);
597 if (prog->depth <= exitdepth)
598 goto cleanup; // all done
601 HANDLE_OPCODE(OP_STATE):
602 if(cached_flag & PRVM_OP_STATE)
604 ed = PRVM_PROG_TO_EDICT(PRVM_gameglobaledict(self));
605 PRVM_gameedictfloat(ed,nextthink) = PRVM_gameglobalfloat(time) + 0.1;
606 PRVM_gameedictfloat(ed,frame) = OPA->_float;
607 PRVM_gameedictfunction(ed,think) = OPB->function;
612 prog->xstatement = st - cached_statements;
613 prog->error_cmd("OP_STATE not supported by %s", prog->name);
617 // LadyHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
619 HANDLE_OPCODE(OP_ADD_I):
620 OPC->_int = OPA->_int + OPB->_int;
622 HANDLE_OPCODE(OP_ADD_IF):
623 OPC->_int = OPA->_int + (prvm_int_t) OPB->_float;
625 HANDLE_OPCODE(OP_ADD_FI):
626 OPC->_float = OPA->_float + (prvm_vec_t) OPB->_int;
628 HANDLE_OPCODE(OP_SUB_I):
629 OPC->_int = OPA->_int - OPB->_int;
631 HANDLE_OPCODE(OP_SUB_IF):
632 OPC->_int = OPA->_int - (prvm_int_t) OPB->_float;
634 HANDLE_OPCODE(OP_SUB_FI):
635 OPC->_float = OPA->_float - (prvm_vec_t) OPB->_int;
637 HANDLE_OPCODE(OP_MUL_I):
638 OPC->_int = OPA->_int * OPB->_int;
640 HANDLE_OPCODE(OP_MUL_IF):
641 OPC->_int = OPA->_int * (prvm_int_t) OPB->_float;
643 HANDLE_OPCODE(OP_MUL_FI):
644 OPC->_float = OPA->_float * (prvm_vec_t) OPB->_int;
646 HANDLE_OPCODE(OP_MUL_VI):
647 OPC->vector[0] = (prvm_vec_t) OPB->_int * OPA->vector[0];
648 OPC->vector[1] = (prvm_vec_t) OPB->_int * OPA->vector[1];
649 OPC->vector[2] = (prvm_vec_t) OPB->_int * OPA->vector[2];
651 HANDLE_OPCODE(OP_DIV_VF):
653 float temp = 1.0f / OPB->_float;
654 OPC->vector[0] = temp * OPA->vector[0];
655 OPC->vector[1] = temp * OPA->vector[1];
656 OPC->vector[2] = temp * OPA->vector[2];
659 HANDLE_OPCODE(OP_DIV_I):
660 OPC->_int = OPA->_int / OPB->_int;
662 HANDLE_OPCODE(OP_DIV_IF):
663 OPC->_int = OPA->_int / (prvm_int_t) OPB->_float;
665 HANDLE_OPCODE(OP_DIV_FI):
666 OPC->_float = OPA->_float / (prvm_vec_t) OPB->_int;
668 HANDLE_OPCODE(OP_CONV_IF):
669 OPC->_float = OPA->_int;
671 HANDLE_OPCODE(OP_CONV_FI):
672 OPC->_int = OPA->_float;
674 HANDLE_OPCODE(OP_BITAND_I):
675 OPC->_int = OPA->_int & OPB->_int;
677 HANDLE_OPCODE(OP_BITOR_I):
678 OPC->_int = OPA->_int | OPB->_int;
680 HANDLE_OPCODE(OP_BITAND_IF):
681 OPC->_int = OPA->_int & (prvm_int_t)OPB->_float;
683 HANDLE_OPCODE(OP_BITOR_IF):
684 OPC->_int = OPA->_int | (prvm_int_t)OPB->_float;
686 HANDLE_OPCODE(OP_BITAND_FI):
687 OPC->_float = (prvm_int_t)OPA->_float & OPB->_int;
689 HANDLE_OPCODE(OP_BITOR_FI):
690 OPC->_float = (prvm_int_t)OPA->_float | OPB->_int;
692 HANDLE_OPCODE(OP_GE_I):
693 OPC->_float = OPA->_int >= OPB->_int;
695 HANDLE_OPCODE(OP_LE_I):
696 OPC->_float = OPA->_int <= OPB->_int;
698 HANDLE_OPCODE(OP_GT_I):
699 OPC->_float = OPA->_int > OPB->_int;
701 HANDLE_OPCODE(OP_LT_I):
702 OPC->_float = OPA->_int < OPB->_int;
704 HANDLE_OPCODE(OP_AND_I):
705 OPC->_float = OPA->_int && OPB->_int;
707 HANDLE_OPCODE(OP_OR_I):
708 OPC->_float = OPA->_int || OPB->_int;
710 HANDLE_OPCODE(OP_GE_IF):
711 OPC->_float = (prvm_vec_t)OPA->_int >= OPB->_float;
713 HANDLE_OPCODE(OP_LE_IF):
714 OPC->_float = (prvm_vec_t)OPA->_int <= OPB->_float;
716 HANDLE_OPCODE(OP_GT_IF):
717 OPC->_float = (prvm_vec_t)OPA->_int > OPB->_float;
719 HANDLE_OPCODE(OP_LT_IF):
720 OPC->_float = (prvm_vec_t)OPA->_int < OPB->_float;
722 HANDLE_OPCODE(OP_AND_IF):
723 OPC->_float = (prvm_vec_t)OPA->_int && OPB->_float;
725 HANDLE_OPCODE(OP_OR_IF):
726 OPC->_float = (prvm_vec_t)OPA->_int || OPB->_float;
728 HANDLE_OPCODE(OP_GE_FI):
729 OPC->_float = OPA->_float >= (prvm_vec_t)OPB->_int;
731 HANDLE_OPCODE(OP_LE_FI):
732 OPC->_float = OPA->_float <= (prvm_vec_t)OPB->_int;
734 HANDLE_OPCODE(OP_GT_FI):
735 OPC->_float = OPA->_float > (prvm_vec_t)OPB->_int;
737 HANDLE_OPCODE(OP_LT_FI):
738 OPC->_float = OPA->_float < (prvm_vec_t)OPB->_int;
740 HANDLE_OPCODE(OP_AND_FI):
741 OPC->_float = OPA->_float && (prvm_vec_t)OPB->_int;
743 HANDLE_OPCODE(OP_OR_FI):
744 OPC->_float = OPA->_float || (prvm_vec_t)OPB->_int;
746 HANDLE_OPCODE(OP_NOT_I):
747 OPC->_float = !OPA->_int;
749 HANDLE_OPCODE(OP_EQ_I):
750 OPC->_float = OPA->_int == OPB->_int;
752 HANDLE_OPCODE(OP_EQ_IF):
753 OPC->_float = (prvm_vec_t)OPA->_int == OPB->_float;
755 HANDLE_OPCODE(OP_EQ_FI):
756 OPC->_float = OPA->_float == (prvm_vec_t)OPB->_int;
758 HANDLE_OPCODE(OP_NE_I):
759 OPC->_float = OPA->_int != OPB->_int;
761 HANDLE_OPCODE(OP_NE_IF):
762 OPC->_float = (prvm_vec_t)OPA->_int != OPB->_float;
764 HANDLE_OPCODE(OP_NE_FI):
765 OPC->_float = OPA->_float != (prvm_vec_t)OPB->_int;
767 HANDLE_OPCODE(OP_STORE_I):
768 OPB->_int = OPA->_int;
770 HANDLE_OPCODE(OP_STOREP_I):
772 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
775 prog->error_cmd("%s Progs attempted to write to an out of bounds edict", prog->name);
779 ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
780 ptr->_int = OPA->_int;
782 HANDLE_OPCODE(OP_LOAD_I):
784 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
787 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
790 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
793 prog->error_cmd("%s Progs attempted to read an invalid field in an edict", prog->name);
797 ed = PRVM_PROG_TO_EDICT(OPA->edict);
798 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
801 HANDLE_OPCODE(OP_GSTOREP_I):
802 HANDLE_OPCODE(OP_GSTOREP_F):
803 HANDLE_OPCODE(OP_GSTOREP_ENT):
804 HANDLE_OPCODE(OP_GSTOREP_FLD): // integers
805 HANDLE_OPCODE(OP_GSTOREP_S):
806 HANDLE_OPCODE(OP_GSTOREP_FNC): // pointers
808 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
811 prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name);
815 pr_iglobals[OPB->_int] = OPA->_int;
817 HANDLE_OPCODE(OP_GSTOREP_V):
819 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
822 prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name);
826 pr_iglobals[OPB->_int ] = OPA->ivector[0];
827 pr_iglobals[OPB->_int+1] = OPA->ivector[1];
828 pr_iglobals[OPB->_int+2] = OPA->ivector[2];
831 HANDLE_OPCODE(OP_GADDRESS):
832 i = OPA->_int + (prvm_int_t) OPB->_float;
834 if (i < 0 || i >= pr_globaldefs)
837 prog->error_cmd("%s Progs attempted to address an out of bounds global", prog->name);
841 OPC->_int = pr_iglobals[i];
844 HANDLE_OPCODE(OP_GLOAD_I):
845 HANDLE_OPCODE(OP_GLOAD_F):
846 HANDLE_OPCODE(OP_GLOAD_FLD):
847 HANDLE_OPCODE(OP_GLOAD_ENT):
848 HANDLE_OPCODE(OP_GLOAD_S):
849 HANDLE_OPCODE(OP_GLOAD_FNC):
851 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
854 prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name);
858 OPC->_int = pr_iglobals[OPA->_int];
861 HANDLE_OPCODE(OP_GLOAD_V):
863 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
866 prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name);
870 OPC->ivector[0] = pr_iglobals[OPA->_int ];
871 OPC->ivector[1] = pr_iglobals[OPA->_int+1];
872 OPC->ivector[2] = pr_iglobals[OPA->_int+2];
875 HANDLE_OPCODE(OP_BOUNDCHECK):
876 if (OPA->_int < 0 || OPA->_int >= st->b)
879 prog->error_cmd("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", prog->name, st->b, st->c);
886 #if !USE_COMPUTED_GOTOS
889 prog->error_cmd("Bad opcode %i in %s", st->op, prog->name);
892 #if PRVMSLOWINTERPRETER
894 if (prog->watch_global_type != ev_void)
896 prvm_eval_t *g = PRVM_GLOBALFIELDVALUE(prog->watch_global);
897 prog->xstatement = st - cached_statements;
898 PRVM_Watchpoint(prog, 0, "Global watchpoint hit", prog->watch_global_type, &prog->watch_global_value, g);
900 if (prog->watch_field_type != ev_void && prog->watch_edict < prog->max_edicts)
902 prvm_eval_t *g = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field);
903 prog->xstatement = st - cached_statements;
904 PRVM_Watchpoint(prog, 0, "Entityfield watchpoint hit", prog->watch_field_type, &prog->watch_edictfield_value, g);
909 #endif // !USE_COMPUTED_GOTOS
911 #undef DISPATCH_OPCODE
913 #undef USE_COMPUTED_GOTOS
915 #undef ADVANCE_PROFILE_BEFORE_JUMP