1 // NEED to reset startst after calling this! startst may or may not be clobbered!
2 #define ADVANCE_PROFILE_BEFORE_JUMP() \
3 prog->xfunction->profile += (st - startst); \
4 if (prvm_statementprofiling.integer || (prvm_coverage.integer & 4)) { \
5 /* All statements from startst+1 to st have been hit. */ \
6 while (++startst <= st) { \
7 if (prog->statement_profile[startst - cached_statements]++ == 0 && (prvm_coverage.integer & 4)) \
8 PRVM_StatementCoverageEvent(prog, prog->xfunction, startst - cached_statements); \
10 /* Observe: startst now is clobbered (now at st+1)! */ \
13 #ifdef PRVMTIMEPROFILING
15 ADVANCE_PROFILE_BEFORE_JUMP(); \
16 prog->xstatement = st - cached_statements; \
17 tm = Sys_DirtyTime(); \
18 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0; \
23 ADVANCE_PROFILE_BEFORE_JUMP(); \
24 prog->xstatement = st - cached_statements; \
28 // This code isn't #ifdef/#define protectable, don't try.
30 #if HAVE_COMPUTED_GOTOS && !(PRVMSLOWINTERPRETER || PRVMTIMEPROFILING)
31 // NOTE: Due to otherwise duplicate labels, only ONE interpreter path may
33 # define USE_COMPUTED_GOTOS 1
36 #if USE_COMPUTED_GOTOS
37 // Must exactly match opcode_e enum in pr_comp.h
38 const static void *dispatchtable[] = {
79 &&handle_OP_STORE_ENT,
80 &&handle_OP_STORE_FLD,
81 &&handle_OP_STORE_FNC,
86 &&handle_OP_STOREP_ENT,
87 &&handle_OP_STOREP_FLD,
88 &&handle_OP_STOREP_FNC,
115 #define DISPATCH_OPCODE() \
116 goto *dispatchtable[(++st)->op]
117 #define HANDLE_OPCODE(opcode) handle_##opcode
119 DISPATCH_OPCODE(); // jump to first opcode
120 #else // USE_COMPUTED_GOTOS
121 #define DISPATCH_OPCODE() break
122 #define HANDLE_OPCODE(opcode) case opcode
124 #if PRVMSLOWINTERPRETER
126 if (prog->watch_global_type != ev_void)
128 prvm_eval_t *g = PRVM_GLOBALFIELDVALUE(prog->watch_global);
129 prog->xstatement = st + 1 - cached_statements;
130 PRVM_Watchpoint(prog, 1, "Global watchpoint hit by engine", prog->watch_global_type, &prog->watch_global_value, g);
132 if (prog->watch_field_type != ev_void && prog->watch_edict < prog->max_edicts)
134 prvm_eval_t *g = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field);
135 prog->xstatement = st + 1 - cached_statements;
136 PRVM_Watchpoint(prog, 1, "Entityfield watchpoint hit by engine", prog->watch_field_type, &prog->watch_edictfield_value, g);
144 #endif // USE_COMPUTED_GOTOS
146 #if !USE_COMPUTED_GOTOS
148 #if PRVMSLOWINTERPRETER
150 PRVM_PrintStatement(prog, st);
151 if (prog->break_statement >= 0)
152 if ((st - cached_statements) == prog->break_statement)
154 prog->xstatement = st - cached_statements;
155 PRVM_Breakpoint(prog, prog->break_stack_index, "Breakpoint hit");
161 HANDLE_OPCODE(OP_ADD_F):
162 OPC->_float = OPA->_float + OPB->_float;
164 HANDLE_OPCODE(OP_ADD_V):
165 OPC->vector[0] = OPA->vector[0] + OPB->vector[0];
166 OPC->vector[1] = OPA->vector[1] + OPB->vector[1];
167 OPC->vector[2] = OPA->vector[2] + OPB->vector[2];
169 HANDLE_OPCODE(OP_SUB_F):
170 OPC->_float = OPA->_float - OPB->_float;
172 HANDLE_OPCODE(OP_SUB_V):
173 OPC->vector[0] = OPA->vector[0] - OPB->vector[0];
174 OPC->vector[1] = OPA->vector[1] - OPB->vector[1];
175 OPC->vector[2] = OPA->vector[2] - OPB->vector[2];
177 HANDLE_OPCODE(OP_MUL_F):
178 OPC->_float = OPA->_float * OPB->_float;
180 HANDLE_OPCODE(OP_MUL_V):
181 OPC->_float = OPA->vector[0]*OPB->vector[0] + OPA->vector[1]*OPB->vector[1] + OPA->vector[2]*OPB->vector[2];
183 HANDLE_OPCODE(OP_MUL_FV):
184 tempfloat = OPA->_float;
185 OPC->vector[0] = tempfloat * OPB->vector[0];
186 OPC->vector[1] = tempfloat * OPB->vector[1];
187 OPC->vector[2] = tempfloat * OPB->vector[2];
189 HANDLE_OPCODE(OP_MUL_VF):
190 tempfloat = OPB->_float;
191 OPC->vector[0] = tempfloat * OPA->vector[0];
192 OPC->vector[1] = tempfloat * OPA->vector[1];
193 OPC->vector[2] = tempfloat * OPA->vector[2];
195 HANDLE_OPCODE(OP_DIV_F):
196 if( OPB->_float != 0.0f )
198 OPC->_float = OPA->_float / OPB->_float;
202 if (developer.integer)
205 VM_Warning(prog, "Attempted division by zero in %s\n", prog->name );
210 HANDLE_OPCODE(OP_BITAND):
211 OPC->_float = (prvm_int_t)OPA->_float & (prvm_int_t)OPB->_float;
213 HANDLE_OPCODE(OP_BITOR):
214 OPC->_float = (prvm_int_t)OPA->_float | (prvm_int_t)OPB->_float;
216 HANDLE_OPCODE(OP_GE):
217 OPC->_float = OPA->_float >= OPB->_float;
219 HANDLE_OPCODE(OP_LE):
220 OPC->_float = OPA->_float <= OPB->_float;
222 HANDLE_OPCODE(OP_GT):
223 OPC->_float = OPA->_float > OPB->_float;
225 HANDLE_OPCODE(OP_LT):
226 OPC->_float = OPA->_float < OPB->_float;
228 HANDLE_OPCODE(OP_AND):
229 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
231 HANDLE_OPCODE(OP_OR):
232 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
234 HANDLE_OPCODE(OP_NOT_F):
235 OPC->_float = !FLOAT_IS_TRUE_FOR_INT(OPA->_int);
237 HANDLE_OPCODE(OP_NOT_V):
238 OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2];
240 HANDLE_OPCODE(OP_NOT_S):
241 OPC->_float = !OPA->string || !*PRVM_GetString(prog, OPA->string);
243 HANDLE_OPCODE(OP_NOT_FNC):
244 OPC->_float = !OPA->function;
246 HANDLE_OPCODE(OP_NOT_ENT):
247 OPC->_float = (OPA->edict == 0);
249 HANDLE_OPCODE(OP_EQ_F):
250 OPC->_float = OPA->_float == OPB->_float;
252 HANDLE_OPCODE(OP_EQ_V):
253 OPC->_float = (OPA->vector[0] == OPB->vector[0]) && (OPA->vector[1] == OPB->vector[1]) && (OPA->vector[2] == OPB->vector[2]);
255 HANDLE_OPCODE(OP_EQ_S):
256 OPC->_float = !strcmp(PRVM_GetString(prog, OPA->string),PRVM_GetString(prog, OPB->string));
258 HANDLE_OPCODE(OP_EQ_E):
259 OPC->_float = OPA->_int == OPB->_int;
261 HANDLE_OPCODE(OP_EQ_FNC):
262 OPC->_float = OPA->function == OPB->function;
264 HANDLE_OPCODE(OP_NE_F):
265 OPC->_float = OPA->_float != OPB->_float;
267 HANDLE_OPCODE(OP_NE_V):
268 OPC->_float = (OPA->vector[0] != OPB->vector[0]) || (OPA->vector[1] != OPB->vector[1]) || (OPA->vector[2] != OPB->vector[2]);
270 HANDLE_OPCODE(OP_NE_S):
271 OPC->_float = strcmp(PRVM_GetString(prog, OPA->string),PRVM_GetString(prog, OPB->string));
273 HANDLE_OPCODE(OP_NE_E):
274 OPC->_float = OPA->_int != OPB->_int;
276 HANDLE_OPCODE(OP_NE_FNC):
277 OPC->_float = OPA->function != OPB->function;
281 HANDLE_OPCODE(OP_STORE_F):
282 HANDLE_OPCODE(OP_STORE_ENT):
283 HANDLE_OPCODE(OP_STORE_FLD): // integers
284 HANDLE_OPCODE(OP_STORE_FNC): // pointers
285 OPB->_int = OPA->_int;
287 HANDLE_OPCODE(OP_STORE_S):
288 // refresh the garbage collection on the string - this guards
289 // against a certain sort of repeated migration to earlier
290 // points in the scan that could otherwise result in the string
291 // being freed for being unused
292 PRVM_GetString(prog, OPA->_int);
293 OPB->_int = OPA->_int;
295 HANDLE_OPCODE(OP_STORE_V):
296 OPB->ivector[0] = OPA->ivector[0];
297 OPB->ivector[1] = OPA->ivector[1];
298 OPB->ivector[2] = OPA->ivector[2];
301 HANDLE_OPCODE(OP_STOREP_F):
302 HANDLE_OPCODE(OP_STOREP_ENT):
303 HANDLE_OPCODE(OP_STOREP_FLD): // integers
304 HANDLE_OPCODE(OP_STOREP_FNC): // pointers
305 if ((prvm_uint_t)OPB->_int - cached_entityfields >= cached_entityfieldsarea_entityfields)
307 if ((prvm_uint_t)OPB->_int >= cached_entityfieldsarea)
310 prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
313 if ((prvm_uint_t)OPB->_int < cached_entityfields && !cached_allowworldwrites)
316 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);
319 ptr = (prvm_eval_t *)(cached_edictsfields + OPB->_int);
320 ptr->_int = OPA->_int;
322 HANDLE_OPCODE(OP_STOREP_S):
323 if ((prvm_uint_t)OPB->_int - cached_entityfields >= cached_entityfieldsarea_entityfields)
325 if ((prvm_uint_t)OPB->_int >= cached_entityfieldsarea)
328 prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
331 if ((prvm_uint_t)OPB->_int < cached_entityfields && !cached_allowworldwrites)
334 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);
337 // refresh the garbage collection on the string - this guards
338 // against a certain sort of repeated migration to earlier
339 // points in the scan that could otherwise result in the string
340 // being freed for being unused
341 PRVM_GetString(prog, OPA->_int);
342 ptr = (prvm_eval_t *)(cached_edictsfields + OPB->_int);
343 ptr->_int = OPA->_int;
345 HANDLE_OPCODE(OP_STOREP_V):
346 if ((prvm_uint_t)OPB->_int - cached_entityfields > (prvm_uint_t)cached_entityfieldsarea_entityfields_3)
348 if ((prvm_uint_t)OPB->_int > cached_entityfieldsarea_3)
351 prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
354 if ((prvm_uint_t)OPB->_int < cached_entityfields && !cached_allowworldwrites)
357 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);
360 ptr = (prvm_eval_t *)(cached_edictsfields + OPB->_int);
361 ptr->ivector[0] = OPA->ivector[0];
362 ptr->ivector[1] = OPA->ivector[1];
363 ptr->ivector[2] = OPA->ivector[2];
366 HANDLE_OPCODE(OP_ADDRESS):
367 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
370 prog->error_cmd("%s Progs attempted to address an out of bounds edict number", prog->name);
373 if ((prvm_uint_t)OPB->_int >= cached_entityfields)
376 prog->error_cmd("%s attempted to address an invalid field (%i) in an edict", prog->name, (int)OPB->_int);
380 if (OPA->edict == 0 && !cached_allowworldwrites)
383 prog->error_cmd("forbidden assignment to null/world entity in %s", prog->name);
387 OPC->_int = OPA->edict * cached_entityfields + OPB->_int;
390 HANDLE_OPCODE(OP_LOAD_F):
391 HANDLE_OPCODE(OP_LOAD_FLD):
392 HANDLE_OPCODE(OP_LOAD_ENT):
393 HANDLE_OPCODE(OP_LOAD_FNC):
394 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
397 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
400 if ((prvm_uint_t)OPB->_int >= cached_entityfields)
403 prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
406 ed = PRVM_PROG_TO_EDICT(OPA->edict);
407 OPC->_int = ((prvm_eval_t *)(ed->fields.ip + OPB->_int))->_int;
409 HANDLE_OPCODE(OP_LOAD_S):
410 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
413 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
416 if ((prvm_uint_t)OPB->_int >= cached_entityfields)
419 prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
422 ed = PRVM_PROG_TO_EDICT(OPA->edict);
423 OPC->_int = ((prvm_eval_t *)(ed->fields.ip + OPB->_int))->_int;
424 // refresh the garbage collection on the string - this guards
425 // against a certain sort of repeated migration to earlier
426 // points in the scan that could otherwise result in the string
427 // being freed for being unused
428 PRVM_GetString(prog, OPC->_int);
431 HANDLE_OPCODE(OP_LOAD_V):
432 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
435 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
438 if ((prvm_uint_t)OPB->_int > cached_entityfields_3)
441 prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
444 ed = PRVM_PROG_TO_EDICT(OPA->edict);
445 ptr = (prvm_eval_t *)(ed->fields.ip + OPB->_int);
446 OPC->ivector[0] = ptr->ivector[0];
447 OPC->ivector[1] = ptr->ivector[1];
448 OPC->ivector[2] = ptr->ivector[2];
453 HANDLE_OPCODE(OP_IFNOT):
454 if(!FLOAT_IS_TRUE_FOR_INT(OPA->_int))
455 // TODO add an "int-if", and change this one to OPA->_float
456 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
457 // and entity, string, field values can never have that value
459 ADVANCE_PROFILE_BEFORE_JUMP();
460 st = cached_statements + st->jumpabsolute - 1; // offset the st++
462 // no bounds check needed, it is done when loading progs
463 if (++jumpcount == 10000000 && prvm_runawaycheck)
465 prog->xstatement = st - cached_statements;
466 PRVM_Profile(prog, 1<<30, 1000000, 0);
467 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
472 HANDLE_OPCODE(OP_IF):
473 if(FLOAT_IS_TRUE_FOR_INT(OPA->_int))
474 // TODO add an "int-if", and change this one, as well as the FLOAT_IS_TRUE_FOR_INT usages, to OPA->_float
475 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
476 // and entity, string, field values can never have that value
478 ADVANCE_PROFILE_BEFORE_JUMP();
479 st = cached_statements + st->jumpabsolute - 1; // offset the st++
481 // no bounds check needed, it is done when loading progs
482 if (++jumpcount == 10000000 && prvm_runawaycheck)
484 prog->xstatement = st - cached_statements;
485 PRVM_Profile(prog, 1<<30, 0.01, 0);
486 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
491 HANDLE_OPCODE(OP_GOTO):
492 ADVANCE_PROFILE_BEFORE_JUMP();
493 st = cached_statements + st->jumpabsolute - 1; // offset the st++
495 // no bounds check needed, it is done when loading progs
496 if (++jumpcount == 10000000 && prvm_runawaycheck)
498 prog->xstatement = st - cached_statements;
499 PRVM_Profile(prog, 1<<30, 0.01, 0);
500 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
504 HANDLE_OPCODE(OP_CALL0):
505 HANDLE_OPCODE(OP_CALL1):
506 HANDLE_OPCODE(OP_CALL2):
507 HANDLE_OPCODE(OP_CALL3):
508 HANDLE_OPCODE(OP_CALL4):
509 HANDLE_OPCODE(OP_CALL5):
510 HANDLE_OPCODE(OP_CALL6):
511 HANDLE_OPCODE(OP_CALL7):
512 HANDLE_OPCODE(OP_CALL8):
513 #ifdef PRVMTIMEPROFILING
514 tm = Sys_DirtyTime();
515 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
518 ADVANCE_PROFILE_BEFORE_JUMP();
520 prog->xstatement = st - cached_statements;
521 prog->argc = st->op - OP_CALL0;
524 prog->error_cmd("NULL function in %s", prog->name);
527 if(!OPA->function || OPA->function < 0 || OPA->function >= prog->numfunctions)
530 prog->error_cmd("%s CALL outside the program", prog->name);
534 enterfunc = &prog->functions[OPA->function];
535 if (enterfunc->callcount++ == 0 && (prvm_coverage.integer & 1))
536 PRVM_FunctionCoverageEvent(prog, enterfunc);
538 if (enterfunc->first_statement < 0)
540 // negative first_statement values are built in functions
541 int builtinnumber = -enterfunc->first_statement;
542 prog->xfunction->builtinsprofile++;
543 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
545 prog->builtins[builtinnumber](prog);
546 #ifdef PRVMTIMEPROFILING
547 tm = Sys_DirtyTime();
548 enterfunc->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
549 prog->xfunction->tbprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
552 // builtins may cause ED_Alloc() to be called, update cached variables
553 cached_edictsfields = prog->edictsfields.fp;
554 cached_entityfields = prog->entityfields;
555 cached_entityfields_3 = prog->entityfields - 3;
556 cached_entityfieldsarea = prog->entityfieldsarea;
557 cached_entityfieldsarea_entityfields = prog->entityfieldsarea - prog->entityfields;
558 cached_entityfieldsarea_3 = prog->entityfieldsarea - 3;
559 cached_entityfieldsarea_entityfields_3 = prog->entityfieldsarea - prog->entityfields - 3;
560 cached_max_edicts = prog->max_edicts;
561 // these do not change
562 //cached_statements = prog->statements;
563 //cached_allowworldwrites = prog->allowworldwrites;
564 //cached_flag = prog->flag;
565 // if prog->trace changed we need to change interpreter path
566 if (prog->trace != cachedpr_trace)
567 goto chooseexecprogram;
570 prog->error_cmd("No such builtin #%i in %s; most likely cause: outdated engine build. Try updating!", builtinnumber, prog->name);
573 st = cached_statements + PRVM_EnterFunction(prog, enterfunc);
577 HANDLE_OPCODE(OP_DONE):
578 HANDLE_OPCODE(OP_RETURN):
579 #ifdef PRVMTIMEPROFILING
580 tm = Sys_DirtyTime();
581 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
584 ADVANCE_PROFILE_BEFORE_JUMP();
585 prog->xstatement = st - cached_statements;
587 prog->globals.ip[OFS_RETURN ] = prog->globals.ip[st->operand[0] ];
588 prog->globals.ip[OFS_RETURN+1] = prog->globals.ip[st->operand[0]+1];
589 prog->globals.ip[OFS_RETURN+2] = prog->globals.ip[st->operand[0]+2];
591 st = cached_statements + PRVM_LeaveFunction(prog);
593 if (prog->depth <= exitdepth)
594 goto cleanup; // all done
597 HANDLE_OPCODE(OP_STATE):
598 if(cached_flag & PRVM_OP_STATE)
600 ed = PRVM_PROG_TO_EDICT(PRVM_gameglobaledict(self));
601 PRVM_gameedictfloat(ed,nextthink) = PRVM_gameglobalfloat(time) + 0.1;
602 PRVM_gameedictfloat(ed,frame) = OPA->_float;
603 PRVM_gameedictfunction(ed,think) = OPB->function;
608 prog->xstatement = st - cached_statements;
609 prog->error_cmd("OP_STATE not supported by %s", prog->name);
613 // LadyHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
615 HANDLE_OPCODE(OP_ADD_I):
616 OPC->_int = OPA->_int + OPB->_int;
618 HANDLE_OPCODE(OP_ADD_IF):
619 OPC->_int = OPA->_int + (prvm_int_t) OPB->_float;
621 HANDLE_OPCODE(OP_ADD_FI):
622 OPC->_float = OPA->_float + (prvm_vec_t) OPB->_int;
624 HANDLE_OPCODE(OP_SUB_I):
625 OPC->_int = OPA->_int - OPB->_int;
627 HANDLE_OPCODE(OP_SUB_IF):
628 OPC->_int = OPA->_int - (prvm_int_t) OPB->_float;
630 HANDLE_OPCODE(OP_SUB_FI):
631 OPC->_float = OPA->_float - (prvm_vec_t) OPB->_int;
633 HANDLE_OPCODE(OP_MUL_I):
634 OPC->_int = OPA->_int * OPB->_int;
636 HANDLE_OPCODE(OP_MUL_IF):
637 OPC->_int = OPA->_int * (prvm_int_t) OPB->_float;
639 HANDLE_OPCODE(OP_MUL_FI):
640 OPC->_float = OPA->_float * (prvm_vec_t) OPB->_int;
642 HANDLE_OPCODE(OP_MUL_VI):
643 OPC->vector[0] = (prvm_vec_t) OPB->_int * OPA->vector[0];
644 OPC->vector[1] = (prvm_vec_t) OPB->_int * OPA->vector[1];
645 OPC->vector[2] = (prvm_vec_t) OPB->_int * OPA->vector[2];
647 HANDLE_OPCODE(OP_DIV_VF):
649 float temp = 1.0f / OPB->_float;
650 OPC->vector[0] = temp * OPA->vector[0];
651 OPC->vector[1] = temp * OPA->vector[1];
652 OPC->vector[2] = temp * OPA->vector[2];
655 HANDLE_OPCODE(OP_DIV_I):
656 OPC->_int = OPA->_int / OPB->_int;
658 HANDLE_OPCODE(OP_DIV_IF):
659 OPC->_int = OPA->_int / (prvm_int_t) OPB->_float;
661 HANDLE_OPCODE(OP_DIV_FI):
662 OPC->_float = OPA->_float / (prvm_vec_t) OPB->_int;
664 HANDLE_OPCODE(OP_CONV_IF):
665 OPC->_float = OPA->_int;
667 HANDLE_OPCODE(OP_CONV_FI):
668 OPC->_int = OPA->_float;
670 HANDLE_OPCODE(OP_BITAND_I):
671 OPC->_int = OPA->_int & OPB->_int;
673 HANDLE_OPCODE(OP_BITOR_I):
674 OPC->_int = OPA->_int | OPB->_int;
676 HANDLE_OPCODE(OP_BITAND_IF):
677 OPC->_int = OPA->_int & (prvm_int_t)OPB->_float;
679 HANDLE_OPCODE(OP_BITOR_IF):
680 OPC->_int = OPA->_int | (prvm_int_t)OPB->_float;
682 HANDLE_OPCODE(OP_BITAND_FI):
683 OPC->_float = (prvm_int_t)OPA->_float & OPB->_int;
685 HANDLE_OPCODE(OP_BITOR_FI):
686 OPC->_float = (prvm_int_t)OPA->_float | OPB->_int;
688 HANDLE_OPCODE(OP_GE_I):
689 OPC->_float = OPA->_int >= OPB->_int;
691 HANDLE_OPCODE(OP_LE_I):
692 OPC->_float = OPA->_int <= OPB->_int;
694 HANDLE_OPCODE(OP_GT_I):
695 OPC->_float = OPA->_int > OPB->_int;
697 HANDLE_OPCODE(OP_LT_I):
698 OPC->_float = OPA->_int < OPB->_int;
700 HANDLE_OPCODE(OP_AND_I):
701 OPC->_float = OPA->_int && OPB->_int;
703 HANDLE_OPCODE(OP_OR_I):
704 OPC->_float = OPA->_int || OPB->_int;
706 HANDLE_OPCODE(OP_GE_IF):
707 OPC->_float = (prvm_vec_t)OPA->_int >= OPB->_float;
709 HANDLE_OPCODE(OP_LE_IF):
710 OPC->_float = (prvm_vec_t)OPA->_int <= OPB->_float;
712 HANDLE_OPCODE(OP_GT_IF):
713 OPC->_float = (prvm_vec_t)OPA->_int > OPB->_float;
715 HANDLE_OPCODE(OP_LT_IF):
716 OPC->_float = (prvm_vec_t)OPA->_int < OPB->_float;
718 HANDLE_OPCODE(OP_AND_IF):
719 OPC->_float = (prvm_vec_t)OPA->_int && OPB->_float;
721 HANDLE_OPCODE(OP_OR_IF):
722 OPC->_float = (prvm_vec_t)OPA->_int || OPB->_float;
724 HANDLE_OPCODE(OP_GE_FI):
725 OPC->_float = OPA->_float >= (prvm_vec_t)OPB->_int;
727 HANDLE_OPCODE(OP_LE_FI):
728 OPC->_float = OPA->_float <= (prvm_vec_t)OPB->_int;
730 HANDLE_OPCODE(OP_GT_FI):
731 OPC->_float = OPA->_float > (prvm_vec_t)OPB->_int;
733 HANDLE_OPCODE(OP_LT_FI):
734 OPC->_float = OPA->_float < (prvm_vec_t)OPB->_int;
736 HANDLE_OPCODE(OP_AND_FI):
737 OPC->_float = OPA->_float && (prvm_vec_t)OPB->_int;
739 HANDLE_OPCODE(OP_OR_FI):
740 OPC->_float = OPA->_float || (prvm_vec_t)OPB->_int;
742 HANDLE_OPCODE(OP_NOT_I):
743 OPC->_float = !OPA->_int;
745 HANDLE_OPCODE(OP_EQ_I):
746 OPC->_float = OPA->_int == OPB->_int;
748 HANDLE_OPCODE(OP_EQ_IF):
749 OPC->_float = (prvm_vec_t)OPA->_int == OPB->_float;
751 HANDLE_OPCODE(OP_EQ_FI):
752 OPC->_float = OPA->_float == (prvm_vec_t)OPB->_int;
754 HANDLE_OPCODE(OP_NE_I):
755 OPC->_float = OPA->_int != OPB->_int;
757 HANDLE_OPCODE(OP_NE_IF):
758 OPC->_float = (prvm_vec_t)OPA->_int != OPB->_float;
760 HANDLE_OPCODE(OP_NE_FI):
761 OPC->_float = OPA->_float != (prvm_vec_t)OPB->_int;
763 HANDLE_OPCODE(OP_STORE_I):
764 OPB->_int = OPA->_int;
766 HANDLE_OPCODE(OP_STOREP_I):
768 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
771 prog->error_cmd("%s Progs attempted to write to an out of bounds edict", prog->name);
775 ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
776 ptr->_int = OPA->_int;
778 HANDLE_OPCODE(OP_LOAD_I):
780 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
783 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
786 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
789 prog->error_cmd("%s Progs attempted to read an invalid field in an edict", prog->name);
793 ed = PRVM_PROG_TO_EDICT(OPA->edict);
794 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
797 HANDLE_OPCODE(OP_GSTOREP_I):
798 HANDLE_OPCODE(OP_GSTOREP_F):
799 HANDLE_OPCODE(OP_GSTOREP_ENT):
800 HANDLE_OPCODE(OP_GSTOREP_FLD): // integers
801 HANDLE_OPCODE(OP_GSTOREP_S):
802 HANDLE_OPCODE(OP_GSTOREP_FNC): // pointers
804 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
807 prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name);
811 pr_iglobals[OPB->_int] = OPA->_int;
813 HANDLE_OPCODE(OP_GSTOREP_V):
815 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
818 prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name);
822 pr_iglobals[OPB->_int ] = OPA->ivector[0];
823 pr_iglobals[OPB->_int+1] = OPA->ivector[1];
824 pr_iglobals[OPB->_int+2] = OPA->ivector[2];
827 HANDLE_OPCODE(OP_GADDRESS):
828 i = OPA->_int + (prvm_int_t) OPB->_float;
830 if (i < 0 || i >= pr_globaldefs)
833 prog->error_cmd("%s Progs attempted to address an out of bounds global", prog->name);
837 OPC->_int = pr_iglobals[i];
840 HANDLE_OPCODE(OP_GLOAD_I):
841 HANDLE_OPCODE(OP_GLOAD_F):
842 HANDLE_OPCODE(OP_GLOAD_FLD):
843 HANDLE_OPCODE(OP_GLOAD_ENT):
844 HANDLE_OPCODE(OP_GLOAD_S):
845 HANDLE_OPCODE(OP_GLOAD_FNC):
847 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
850 prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name);
854 OPC->_int = pr_iglobals[OPA->_int];
857 HANDLE_OPCODE(OP_GLOAD_V):
859 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
862 prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name);
866 OPC->ivector[0] = pr_iglobals[OPA->_int ];
867 OPC->ivector[1] = pr_iglobals[OPA->_int+1];
868 OPC->ivector[2] = pr_iglobals[OPA->_int+2];
871 HANDLE_OPCODE(OP_BOUNDCHECK):
872 if (OPA->_int < 0 || OPA->_int >= st->b)
875 prog->error_cmd("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", prog->name, st->b, st->c);
882 #if !USE_COMPUTED_GOTOS
885 prog->error_cmd("Bad opcode %i in %s", st->op, prog->name);
888 #if PRVMSLOWINTERPRETER
890 if (prog->watch_global_type != ev_void)
892 prvm_eval_t *g = PRVM_GLOBALFIELDVALUE(prog->watch_global);
893 prog->xstatement = st - cached_statements;
894 PRVM_Watchpoint(prog, 0, "Global watchpoint hit", prog->watch_global_type, &prog->watch_global_value, g);
896 if (prog->watch_field_type != ev_void && prog->watch_edict < prog->max_edicts)
898 prvm_eval_t *g = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field);
899 prog->xstatement = st - cached_statements;
900 PRVM_Watchpoint(prog, 0, "Entityfield watchpoint hit", prog->watch_field_type, &prog->watch_edictfield_value, g);
905 #endif // !USE_COMPUTED_GOTOS
907 #undef DISPATCH_OPCODE
909 #undef USE_COMPUTED_GOTOS
911 #undef ADVANCE_PROFILE_BEFORE_JUMP