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 PRVM_GetString(prog, OPC->_int);
434 HANDLE_OPCODE(OP_LOAD_V):
435 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
438 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
441 if ((prvm_uint_t)OPB->_int > cached_entityfields_3)
444 prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
447 ed = PRVM_PROG_TO_EDICT(OPA->edict);
448 ptr = (prvm_eval_t *)(ed->fields.ip + OPB->_int);
449 OPC->ivector[0] = ptr->ivector[0];
450 OPC->ivector[1] = ptr->ivector[1];
451 OPC->ivector[2] = ptr->ivector[2];
456 HANDLE_OPCODE(OP_IFNOT):
457 if(!FLOAT_IS_TRUE_FOR_INT(OPA->_int))
458 // TODO add an "int-if", and change this one to OPA->_float
459 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
460 // and entity, string, field values can never have that value
462 ADVANCE_PROFILE_BEFORE_JUMP();
463 st = cached_statements + st->jumpabsolute - 1; // offset the st++
465 // no bounds check needed, it is done when loading progs
466 if (++jumpcount == 10000000 && prvm_runawaycheck)
468 prog->xstatement = st - cached_statements;
469 PRVM_Profile(prog, 1<<30, 1000000, 0);
470 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
475 HANDLE_OPCODE(OP_IF):
476 if(FLOAT_IS_TRUE_FOR_INT(OPA->_int))
477 // TODO add an "int-if", and change this one, as well as the FLOAT_IS_TRUE_FOR_INT usages, to OPA->_float
478 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
479 // and entity, string, field values can never have that value
481 ADVANCE_PROFILE_BEFORE_JUMP();
482 st = cached_statements + st->jumpabsolute - 1; // offset the st++
484 // no bounds check needed, it is done when loading progs
485 if (++jumpcount == 10000000 && prvm_runawaycheck)
487 prog->xstatement = st - cached_statements;
488 PRVM_Profile(prog, 1<<30, 0.01, 0);
489 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
494 HANDLE_OPCODE(OP_GOTO):
495 ADVANCE_PROFILE_BEFORE_JUMP();
496 st = cached_statements + st->jumpabsolute - 1; // offset the st++
498 // no bounds check needed, it is done when loading progs
499 if (++jumpcount == 10000000 && prvm_runawaycheck)
501 prog->xstatement = st - cached_statements;
502 PRVM_Profile(prog, 1<<30, 0.01, 0);
503 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
507 HANDLE_OPCODE(OP_CALL0):
508 HANDLE_OPCODE(OP_CALL1):
509 HANDLE_OPCODE(OP_CALL2):
510 HANDLE_OPCODE(OP_CALL3):
511 HANDLE_OPCODE(OP_CALL4):
512 HANDLE_OPCODE(OP_CALL5):
513 HANDLE_OPCODE(OP_CALL6):
514 HANDLE_OPCODE(OP_CALL7):
515 HANDLE_OPCODE(OP_CALL8):
516 #ifdef PRVMTIMEPROFILING
517 tm = Sys_DirtyTime();
518 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
521 ADVANCE_PROFILE_BEFORE_JUMP();
523 prog->xstatement = st - cached_statements;
524 prog->argc = st->op - OP_CALL0;
527 prog->error_cmd("NULL function in %s", prog->name);
530 if(!OPA->function || OPA->function < 0 || OPA->function >= prog->numfunctions)
533 prog->error_cmd("%s CALL outside the program", prog->name);
537 enterfunc = &prog->functions[OPA->function];
538 if (enterfunc->callcount++ == 0 && (prvm_coverage.integer & 1))
539 PRVM_FunctionCoverageEvent(prog, enterfunc);
541 if (enterfunc->first_statement < 0)
543 // negative first_statement values are built in functions
544 int builtinnumber = -enterfunc->first_statement;
545 prog->xfunction->builtinsprofile++;
546 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
548 prog->builtins[builtinnumber](prog);
549 #ifdef PRVMTIMEPROFILING
550 tm = Sys_DirtyTime();
551 enterfunc->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
552 prog->xfunction->tbprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
555 // builtins may cause ED_Alloc() to be called, update cached variables
556 cached_edictsfields = prog->edictsfields.fp;
557 cached_entityfields = prog->entityfields;
558 cached_entityfields_3 = prog->entityfields - 3;
559 cached_entityfieldsarea = prog->entityfieldsarea;
560 cached_entityfieldsarea_entityfields = prog->entityfieldsarea - prog->entityfields;
561 cached_entityfieldsarea_3 = prog->entityfieldsarea - 3;
562 cached_entityfieldsarea_entityfields_3 = prog->entityfieldsarea - prog->entityfields - 3;
563 cached_max_edicts = prog->max_edicts;
564 // these do not change
565 //cached_statements = prog->statements;
566 //cached_allowworldwrites = prog->allowworldwrites;
567 //cached_flag = prog->flag;
568 // if prog->trace changed we need to change interpreter path
569 if (prog->trace != cachedpr_trace)
570 goto chooseexecprogram;
573 prog->error_cmd("No such builtin #%i in %s; most likely cause: outdated engine build. Try updating!", builtinnumber, prog->name);
576 st = cached_statements + PRVM_EnterFunction(prog, enterfunc);
580 HANDLE_OPCODE(OP_DONE):
581 HANDLE_OPCODE(OP_RETURN):
582 #ifdef PRVMTIMEPROFILING
583 tm = Sys_DirtyTime();
584 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
587 ADVANCE_PROFILE_BEFORE_JUMP();
588 prog->xstatement = st - cached_statements;
590 prog->globals.ip[OFS_RETURN ] = prog->globals.ip[st->operand[0] ];
591 prog->globals.ip[OFS_RETURN+1] = prog->globals.ip[st->operand[0]+1];
592 prog->globals.ip[OFS_RETURN+2] = prog->globals.ip[st->operand[0]+2];
594 st = cached_statements + PRVM_LeaveFunction(prog);
596 if (prog->depth <= exitdepth)
597 goto cleanup; // all done
600 HANDLE_OPCODE(OP_STATE):
601 if(cached_flag & PRVM_OP_STATE)
603 ed = PRVM_PROG_TO_EDICT(PRVM_gameglobaledict(self));
604 PRVM_gameedictfloat(ed,nextthink) = PRVM_gameglobalfloat(time) + 0.1;
605 PRVM_gameedictfloat(ed,frame) = OPA->_float;
606 PRVM_gameedictfunction(ed,think) = OPB->function;
611 prog->xstatement = st - cached_statements;
612 prog->error_cmd("OP_STATE not supported by %s", prog->name);
616 // LadyHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
618 HANDLE_OPCODE(OP_ADD_I):
619 OPC->_int = OPA->_int + OPB->_int;
621 HANDLE_OPCODE(OP_ADD_IF):
622 OPC->_int = OPA->_int + (prvm_int_t) OPB->_float;
624 HANDLE_OPCODE(OP_ADD_FI):
625 OPC->_float = OPA->_float + (prvm_vec_t) OPB->_int;
627 HANDLE_OPCODE(OP_SUB_I):
628 OPC->_int = OPA->_int - OPB->_int;
630 HANDLE_OPCODE(OP_SUB_IF):
631 OPC->_int = OPA->_int - (prvm_int_t) OPB->_float;
633 HANDLE_OPCODE(OP_SUB_FI):
634 OPC->_float = OPA->_float - (prvm_vec_t) OPB->_int;
636 HANDLE_OPCODE(OP_MUL_I):
637 OPC->_int = OPA->_int * OPB->_int;
639 HANDLE_OPCODE(OP_MUL_IF):
640 OPC->_int = OPA->_int * (prvm_int_t) OPB->_float;
642 HANDLE_OPCODE(OP_MUL_FI):
643 OPC->_float = OPA->_float * (prvm_vec_t) OPB->_int;
645 HANDLE_OPCODE(OP_MUL_VI):
646 OPC->vector[0] = (prvm_vec_t) OPB->_int * OPA->vector[0];
647 OPC->vector[1] = (prvm_vec_t) OPB->_int * OPA->vector[1];
648 OPC->vector[2] = (prvm_vec_t) OPB->_int * OPA->vector[2];
650 HANDLE_OPCODE(OP_DIV_VF):
652 float temp = 1.0f / OPB->_float;
653 OPC->vector[0] = temp * OPA->vector[0];
654 OPC->vector[1] = temp * OPA->vector[1];
655 OPC->vector[2] = temp * OPA->vector[2];
658 HANDLE_OPCODE(OP_DIV_I):
659 OPC->_int = OPA->_int / OPB->_int;
661 HANDLE_OPCODE(OP_DIV_IF):
662 OPC->_int = OPA->_int / (prvm_int_t) OPB->_float;
664 HANDLE_OPCODE(OP_DIV_FI):
665 OPC->_float = OPA->_float / (prvm_vec_t) OPB->_int;
667 HANDLE_OPCODE(OP_CONV_IF):
668 OPC->_float = OPA->_int;
670 HANDLE_OPCODE(OP_CONV_FI):
671 OPC->_int = OPA->_float;
673 HANDLE_OPCODE(OP_BITAND_I):
674 OPC->_int = OPA->_int & OPB->_int;
676 HANDLE_OPCODE(OP_BITOR_I):
677 OPC->_int = OPA->_int | OPB->_int;
679 HANDLE_OPCODE(OP_BITAND_IF):
680 OPC->_int = OPA->_int & (prvm_int_t)OPB->_float;
682 HANDLE_OPCODE(OP_BITOR_IF):
683 OPC->_int = OPA->_int | (prvm_int_t)OPB->_float;
685 HANDLE_OPCODE(OP_BITAND_FI):
686 OPC->_float = (prvm_int_t)OPA->_float & OPB->_int;
688 HANDLE_OPCODE(OP_BITOR_FI):
689 OPC->_float = (prvm_int_t)OPA->_float | OPB->_int;
691 HANDLE_OPCODE(OP_GE_I):
692 OPC->_float = OPA->_int >= OPB->_int;
694 HANDLE_OPCODE(OP_LE_I):
695 OPC->_float = OPA->_int <= OPB->_int;
697 HANDLE_OPCODE(OP_GT_I):
698 OPC->_float = OPA->_int > OPB->_int;
700 HANDLE_OPCODE(OP_LT_I):
701 OPC->_float = OPA->_int < OPB->_int;
703 HANDLE_OPCODE(OP_AND_I):
704 OPC->_float = OPA->_int && OPB->_int;
706 HANDLE_OPCODE(OP_OR_I):
707 OPC->_float = OPA->_int || OPB->_int;
709 HANDLE_OPCODE(OP_GE_IF):
710 OPC->_float = (prvm_vec_t)OPA->_int >= OPB->_float;
712 HANDLE_OPCODE(OP_LE_IF):
713 OPC->_float = (prvm_vec_t)OPA->_int <= OPB->_float;
715 HANDLE_OPCODE(OP_GT_IF):
716 OPC->_float = (prvm_vec_t)OPA->_int > OPB->_float;
718 HANDLE_OPCODE(OP_LT_IF):
719 OPC->_float = (prvm_vec_t)OPA->_int < OPB->_float;
721 HANDLE_OPCODE(OP_AND_IF):
722 OPC->_float = (prvm_vec_t)OPA->_int && OPB->_float;
724 HANDLE_OPCODE(OP_OR_IF):
725 OPC->_float = (prvm_vec_t)OPA->_int || OPB->_float;
727 HANDLE_OPCODE(OP_GE_FI):
728 OPC->_float = OPA->_float >= (prvm_vec_t)OPB->_int;
730 HANDLE_OPCODE(OP_LE_FI):
731 OPC->_float = OPA->_float <= (prvm_vec_t)OPB->_int;
733 HANDLE_OPCODE(OP_GT_FI):
734 OPC->_float = OPA->_float > (prvm_vec_t)OPB->_int;
736 HANDLE_OPCODE(OP_LT_FI):
737 OPC->_float = OPA->_float < (prvm_vec_t)OPB->_int;
739 HANDLE_OPCODE(OP_AND_FI):
740 OPC->_float = OPA->_float && (prvm_vec_t)OPB->_int;
742 HANDLE_OPCODE(OP_OR_FI):
743 OPC->_float = OPA->_float || (prvm_vec_t)OPB->_int;
745 HANDLE_OPCODE(OP_NOT_I):
746 OPC->_float = !OPA->_int;
748 HANDLE_OPCODE(OP_EQ_I):
749 OPC->_float = OPA->_int == OPB->_int;
751 HANDLE_OPCODE(OP_EQ_IF):
752 OPC->_float = (prvm_vec_t)OPA->_int == OPB->_float;
754 HANDLE_OPCODE(OP_EQ_FI):
755 OPC->_float = OPA->_float == (prvm_vec_t)OPB->_int;
757 HANDLE_OPCODE(OP_NE_I):
758 OPC->_float = OPA->_int != OPB->_int;
760 HANDLE_OPCODE(OP_NE_IF):
761 OPC->_float = (prvm_vec_t)OPA->_int != OPB->_float;
763 HANDLE_OPCODE(OP_NE_FI):
764 OPC->_float = OPA->_float != (prvm_vec_t)OPB->_int;
766 HANDLE_OPCODE(OP_STORE_I):
767 OPB->_int = OPA->_int;
769 HANDLE_OPCODE(OP_STOREP_I):
771 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
774 prog->error_cmd("%s Progs attempted to write to an out of bounds edict", prog->name);
778 ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
779 ptr->_int = OPA->_int;
781 HANDLE_OPCODE(OP_LOAD_I):
783 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
786 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
789 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
792 prog->error_cmd("%s Progs attempted to read an invalid field in an edict", prog->name);
796 ed = PRVM_PROG_TO_EDICT(OPA->edict);
797 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
800 HANDLE_OPCODE(OP_GSTOREP_I):
801 HANDLE_OPCODE(OP_GSTOREP_F):
802 HANDLE_OPCODE(OP_GSTOREP_ENT):
803 HANDLE_OPCODE(OP_GSTOREP_FLD): // integers
804 HANDLE_OPCODE(OP_GSTOREP_S):
805 HANDLE_OPCODE(OP_GSTOREP_FNC): // pointers
807 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
810 prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name);
814 pr_iglobals[OPB->_int] = OPA->_int;
816 HANDLE_OPCODE(OP_GSTOREP_V):
818 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
821 prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name);
825 pr_iglobals[OPB->_int ] = OPA->ivector[0];
826 pr_iglobals[OPB->_int+1] = OPA->ivector[1];
827 pr_iglobals[OPB->_int+2] = OPA->ivector[2];
830 HANDLE_OPCODE(OP_GADDRESS):
831 i = OPA->_int + (prvm_int_t) OPB->_float;
833 if (i < 0 || i >= pr_globaldefs)
836 prog->error_cmd("%s Progs attempted to address an out of bounds global", prog->name);
840 OPC->_int = pr_iglobals[i];
843 HANDLE_OPCODE(OP_GLOAD_I):
844 HANDLE_OPCODE(OP_GLOAD_F):
845 HANDLE_OPCODE(OP_GLOAD_FLD):
846 HANDLE_OPCODE(OP_GLOAD_ENT):
847 HANDLE_OPCODE(OP_GLOAD_S):
848 HANDLE_OPCODE(OP_GLOAD_FNC):
850 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
853 prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name);
857 OPC->_int = pr_iglobals[OPA->_int];
860 HANDLE_OPCODE(OP_GLOAD_V):
862 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
865 prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name);
869 OPC->ivector[0] = pr_iglobals[OPA->_int ];
870 OPC->ivector[1] = pr_iglobals[OPA->_int+1];
871 OPC->ivector[2] = pr_iglobals[OPA->_int+2];
874 HANDLE_OPCODE(OP_BOUNDCHECK):
875 if (OPA->_int < 0 || OPA->_int >= st->b)
878 prog->error_cmd("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", prog->name, st->b, st->c);
885 #if !USE_COMPUTED_GOTOS
888 prog->error_cmd("Bad opcode %i in %s", st->op, prog->name);
891 #if PRVMSLOWINTERPRETER
893 if (prog->watch_global_type != ev_void)
895 prvm_eval_t *g = PRVM_GLOBALFIELDVALUE(prog->watch_global);
896 prog->xstatement = st - cached_statements;
897 PRVM_Watchpoint(prog, 0, "Global watchpoint hit", prog->watch_global_type, &prog->watch_global_value, g);
899 if (prog->watch_field_type != ev_void && prog->watch_edict < prog->max_edicts)
901 prvm_eval_t *g = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field);
902 prog->xstatement = st - cached_statements;
903 PRVM_Watchpoint(prog, 0, "Entityfield watchpoint hit", prog->watch_field_type, &prog->watch_edictfield_value, g);
908 #endif // !USE_COMPUTED_GOTOS
910 #undef DISPATCH_OPCODE
912 #undef USE_COMPUTED_GOTOS
914 #undef ADVANCE_PROFILE_BEFORE_JUMP