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_S):
285 HANDLE_OPCODE(OP_STORE_FNC): // pointers
286 OPB->_int = OPA->_int;
288 HANDLE_OPCODE(OP_STORE_V):
289 OPB->ivector[0] = OPA->ivector[0];
290 OPB->ivector[1] = OPA->ivector[1];
291 OPB->ivector[2] = OPA->ivector[2];
294 HANDLE_OPCODE(OP_STOREP_F):
295 HANDLE_OPCODE(OP_STOREP_ENT):
296 HANDLE_OPCODE(OP_STOREP_FLD): // integers
297 HANDLE_OPCODE(OP_STOREP_S):
298 HANDLE_OPCODE(OP_STOREP_FNC): // pointers
299 if ((prvm_uint_t)OPB->_int - cached_entityfields >= cached_entityfieldsarea_entityfields)
301 if ((prvm_uint_t)OPB->_int >= cached_entityfieldsarea)
304 prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
307 if ((prvm_uint_t)OPB->_int < cached_entityfields && !cached_allowworldwrites)
310 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);
313 ptr = (prvm_eval_t *)(cached_edictsfields + OPB->_int);
314 ptr->_int = OPA->_int;
316 HANDLE_OPCODE(OP_STOREP_V):
317 if ((prvm_uint_t)OPB->_int - cached_entityfields > (prvm_uint_t)cached_entityfieldsarea_entityfields_3)
319 if ((prvm_uint_t)OPB->_int > cached_entityfieldsarea_3)
322 prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
325 if ((prvm_uint_t)OPB->_int < cached_entityfields && !cached_allowworldwrites)
328 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);
331 ptr = (prvm_eval_t *)(cached_edictsfields + OPB->_int);
332 ptr->ivector[0] = OPA->ivector[0];
333 ptr->ivector[1] = OPA->ivector[1];
334 ptr->ivector[2] = OPA->ivector[2];
337 HANDLE_OPCODE(OP_ADDRESS):
338 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
341 prog->error_cmd("%s Progs attempted to address an out of bounds edict number", prog->name);
344 if ((prvm_uint_t)OPB->_int >= cached_entityfields)
347 prog->error_cmd("%s attempted to address an invalid field (%i) in an edict", prog->name, (int)OPB->_int);
351 if (OPA->edict == 0 && !cached_allowworldwrites)
354 prog->error_cmd("forbidden assignment to null/world entity in %s", prog->name);
358 OPC->_int = OPA->edict * cached_entityfields + OPB->_int;
361 HANDLE_OPCODE(OP_LOAD_F):
362 HANDLE_OPCODE(OP_LOAD_FLD):
363 HANDLE_OPCODE(OP_LOAD_ENT):
364 HANDLE_OPCODE(OP_LOAD_S):
365 HANDLE_OPCODE(OP_LOAD_FNC):
366 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
369 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
372 if ((prvm_uint_t)OPB->_int >= cached_entityfields)
375 prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
378 ed = PRVM_PROG_TO_EDICT(OPA->edict);
379 OPC->_int = ((prvm_eval_t *)(ed->fields.ip + OPB->_int))->_int;
382 HANDLE_OPCODE(OP_LOAD_V):
383 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
386 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
389 if ((prvm_uint_t)OPB->_int > cached_entityfields_3)
392 prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
395 ed = PRVM_PROG_TO_EDICT(OPA->edict);
396 ptr = (prvm_eval_t *)(ed->fields.ip + OPB->_int);
397 OPC->ivector[0] = ptr->ivector[0];
398 OPC->ivector[1] = ptr->ivector[1];
399 OPC->ivector[2] = ptr->ivector[2];
404 HANDLE_OPCODE(OP_IFNOT):
405 if(!FLOAT_IS_TRUE_FOR_INT(OPA->_int))
406 // TODO add an "int-if", and change this one to OPA->_float
407 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
408 // and entity, string, field values can never have that value
410 ADVANCE_PROFILE_BEFORE_JUMP();
411 st = cached_statements + st->jumpabsolute - 1; // offset the st++
413 // no bounds check needed, it is done when loading progs
414 if (++jumpcount == 10000000 && prvm_runawaycheck)
416 prog->xstatement = st - cached_statements;
417 PRVM_Profile(prog, 1<<30, 1000000, 0);
418 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
423 HANDLE_OPCODE(OP_IF):
424 if(FLOAT_IS_TRUE_FOR_INT(OPA->_int))
425 // TODO add an "int-if", and change this one, as well as the FLOAT_IS_TRUE_FOR_INT usages, to OPA->_float
426 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
427 // and entity, string, field values can never have that value
429 ADVANCE_PROFILE_BEFORE_JUMP();
430 st = cached_statements + st->jumpabsolute - 1; // offset the st++
432 // no bounds check needed, it is done when loading progs
433 if (++jumpcount == 10000000 && prvm_runawaycheck)
435 prog->xstatement = st - cached_statements;
436 PRVM_Profile(prog, 1<<30, 0.01, 0);
437 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
442 HANDLE_OPCODE(OP_GOTO):
443 ADVANCE_PROFILE_BEFORE_JUMP();
444 st = cached_statements + st->jumpabsolute - 1; // offset the st++
446 // no bounds check needed, it is done when loading progs
447 if (++jumpcount == 10000000 && prvm_runawaycheck)
449 prog->xstatement = st - cached_statements;
450 PRVM_Profile(prog, 1<<30, 0.01, 0);
451 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
455 HANDLE_OPCODE(OP_CALL0):
456 HANDLE_OPCODE(OP_CALL1):
457 HANDLE_OPCODE(OP_CALL2):
458 HANDLE_OPCODE(OP_CALL3):
459 HANDLE_OPCODE(OP_CALL4):
460 HANDLE_OPCODE(OP_CALL5):
461 HANDLE_OPCODE(OP_CALL6):
462 HANDLE_OPCODE(OP_CALL7):
463 HANDLE_OPCODE(OP_CALL8):
464 #ifdef PRVMTIMEPROFILING
465 tm = Sys_DirtyTime();
466 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
469 ADVANCE_PROFILE_BEFORE_JUMP();
471 prog->xstatement = st - cached_statements;
472 prog->argc = st->op - OP_CALL0;
475 prog->error_cmd("NULL function in %s", prog->name);
478 if(!OPA->function || OPA->function < 0 || OPA->function >= prog->numfunctions)
481 prog->error_cmd("%s CALL outside the program", prog->name);
485 enterfunc = &prog->functions[OPA->function];
486 if (enterfunc->callcount++ == 0 && (prvm_coverage.integer & 1))
487 PRVM_FunctionCoverageEvent(prog, enterfunc);
489 if (enterfunc->first_statement < 0)
491 // negative first_statement values are built in functions
492 int builtinnumber = -enterfunc->first_statement;
493 prog->xfunction->builtinsprofile++;
494 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
496 prog->builtins[builtinnumber](prog);
497 #ifdef PRVMTIMEPROFILING
498 tm = Sys_DirtyTime();
499 enterfunc->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
500 prog->xfunction->tbprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
503 // builtins may cause ED_Alloc() to be called, update cached variables
504 cached_edictsfields = prog->edictsfields;
505 cached_entityfields = prog->entityfields;
506 cached_entityfields_3 = prog->entityfields - 3;
507 cached_entityfieldsarea = prog->entityfieldsarea;
508 cached_entityfieldsarea_entityfields = prog->entityfieldsarea - prog->entityfields;
509 cached_entityfieldsarea_3 = prog->entityfieldsarea - 3;
510 cached_entityfieldsarea_entityfields_3 = prog->entityfieldsarea - prog->entityfields - 3;
511 cached_max_edicts = prog->max_edicts;
512 // these do not change
513 //cached_statements = prog->statements;
514 //cached_allowworldwrites = prog->allowworldwrites;
515 //cached_flag = prog->flag;
516 // if prog->trace changed we need to change interpreter path
517 if (prog->trace != cachedpr_trace)
518 goto chooseexecprogram;
521 prog->error_cmd("No such builtin #%i in %s; most likely cause: outdated engine build. Try updating!", builtinnumber, prog->name);
524 st = cached_statements + PRVM_EnterFunction(prog, enterfunc);
528 HANDLE_OPCODE(OP_DONE):
529 HANDLE_OPCODE(OP_RETURN):
530 #ifdef PRVMTIMEPROFILING
531 tm = Sys_DirtyTime();
532 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
535 ADVANCE_PROFILE_BEFORE_JUMP();
536 prog->xstatement = st - cached_statements;
538 prog->globals.ip[OFS_RETURN ] = prog->globals.ip[st->operand[0] ];
539 prog->globals.ip[OFS_RETURN+1] = prog->globals.ip[st->operand[0]+1];
540 prog->globals.ip[OFS_RETURN+2] = prog->globals.ip[st->operand[0]+2];
542 st = cached_statements + PRVM_LeaveFunction(prog);
544 if (prog->depth <= exitdepth)
545 goto cleanup; // all done
548 HANDLE_OPCODE(OP_STATE):
549 if(cached_flag & PRVM_OP_STATE)
551 ed = PRVM_PROG_TO_EDICT(PRVM_gameglobaledict(self));
552 PRVM_gameedictfloat(ed,nextthink) = PRVM_gameglobalfloat(time) + 0.1;
553 PRVM_gameedictfloat(ed,frame) = OPA->_float;
554 PRVM_gameedictfunction(ed,think) = OPB->function;
559 prog->xstatement = st - cached_statements;
560 prog->error_cmd("OP_STATE not supported by %s", prog->name);
564 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
566 HANDLE_OPCODE(OP_ADD_I):
567 OPC->_int = OPA->_int + OPB->_int;
569 HANDLE_OPCODE(OP_ADD_IF):
570 OPC->_int = OPA->_int + (prvm_int_t) OPB->_float;
572 HANDLE_OPCODE(OP_ADD_FI):
573 OPC->_float = OPA->_float + (prvm_vec_t) OPB->_int;
575 HANDLE_OPCODE(OP_SUB_I):
576 OPC->_int = OPA->_int - OPB->_int;
578 HANDLE_OPCODE(OP_SUB_IF):
579 OPC->_int = OPA->_int - (prvm_int_t) OPB->_float;
581 HANDLE_OPCODE(OP_SUB_FI):
582 OPC->_float = OPA->_float - (prvm_vec_t) OPB->_int;
584 HANDLE_OPCODE(OP_MUL_I):
585 OPC->_int = OPA->_int * OPB->_int;
587 HANDLE_OPCODE(OP_MUL_IF):
588 OPC->_int = OPA->_int * (prvm_int_t) OPB->_float;
590 HANDLE_OPCODE(OP_MUL_FI):
591 OPC->_float = OPA->_float * (prvm_vec_t) OPB->_int;
593 HANDLE_OPCODE(OP_MUL_VI):
594 OPC->vector[0] = (prvm_vec_t) OPB->_int * OPA->vector[0];
595 OPC->vector[1] = (prvm_vec_t) OPB->_int * OPA->vector[1];
596 OPC->vector[2] = (prvm_vec_t) OPB->_int * OPA->vector[2];
598 HANDLE_OPCODE(OP_DIV_VF):
600 float temp = 1.0f / OPB->_float;
601 OPC->vector[0] = temp * OPA->vector[0];
602 OPC->vector[1] = temp * OPA->vector[1];
603 OPC->vector[2] = temp * OPA->vector[2];
606 HANDLE_OPCODE(OP_DIV_I):
607 OPC->_int = OPA->_int / OPB->_int;
609 HANDLE_OPCODE(OP_DIV_IF):
610 OPC->_int = OPA->_int / (prvm_int_t) OPB->_float;
612 HANDLE_OPCODE(OP_DIV_FI):
613 OPC->_float = OPA->_float / (prvm_vec_t) OPB->_int;
615 HANDLE_OPCODE(OP_CONV_IF):
616 OPC->_float = OPA->_int;
618 HANDLE_OPCODE(OP_CONV_FI):
619 OPC->_int = OPA->_float;
621 HANDLE_OPCODE(OP_BITAND_I):
622 OPC->_int = OPA->_int & OPB->_int;
624 HANDLE_OPCODE(OP_BITOR_I):
625 OPC->_int = OPA->_int | OPB->_int;
627 HANDLE_OPCODE(OP_BITAND_IF):
628 OPC->_int = OPA->_int & (prvm_int_t)OPB->_float;
630 HANDLE_OPCODE(OP_BITOR_IF):
631 OPC->_int = OPA->_int | (prvm_int_t)OPB->_float;
633 HANDLE_OPCODE(OP_BITAND_FI):
634 OPC->_float = (prvm_int_t)OPA->_float & OPB->_int;
636 HANDLE_OPCODE(OP_BITOR_FI):
637 OPC->_float = (prvm_int_t)OPA->_float | OPB->_int;
639 HANDLE_OPCODE(OP_GE_I):
640 OPC->_float = OPA->_int >= OPB->_int;
642 HANDLE_OPCODE(OP_LE_I):
643 OPC->_float = OPA->_int <= OPB->_int;
645 HANDLE_OPCODE(OP_GT_I):
646 OPC->_float = OPA->_int > OPB->_int;
648 HANDLE_OPCODE(OP_LT_I):
649 OPC->_float = OPA->_int < OPB->_int;
651 HANDLE_OPCODE(OP_AND_I):
652 OPC->_float = OPA->_int && OPB->_int;
654 HANDLE_OPCODE(OP_OR_I):
655 OPC->_float = OPA->_int || OPB->_int;
657 HANDLE_OPCODE(OP_GE_IF):
658 OPC->_float = (prvm_vec_t)OPA->_int >= OPB->_float;
660 HANDLE_OPCODE(OP_LE_IF):
661 OPC->_float = (prvm_vec_t)OPA->_int <= OPB->_float;
663 HANDLE_OPCODE(OP_GT_IF):
664 OPC->_float = (prvm_vec_t)OPA->_int > OPB->_float;
666 HANDLE_OPCODE(OP_LT_IF):
667 OPC->_float = (prvm_vec_t)OPA->_int < OPB->_float;
669 HANDLE_OPCODE(OP_AND_IF):
670 OPC->_float = (prvm_vec_t)OPA->_int && OPB->_float;
672 HANDLE_OPCODE(OP_OR_IF):
673 OPC->_float = (prvm_vec_t)OPA->_int || OPB->_float;
675 HANDLE_OPCODE(OP_GE_FI):
676 OPC->_float = OPA->_float >= (prvm_vec_t)OPB->_int;
678 HANDLE_OPCODE(OP_LE_FI):
679 OPC->_float = OPA->_float <= (prvm_vec_t)OPB->_int;
681 HANDLE_OPCODE(OP_GT_FI):
682 OPC->_float = OPA->_float > (prvm_vec_t)OPB->_int;
684 HANDLE_OPCODE(OP_LT_FI):
685 OPC->_float = OPA->_float < (prvm_vec_t)OPB->_int;
687 HANDLE_OPCODE(OP_AND_FI):
688 OPC->_float = OPA->_float && (prvm_vec_t)OPB->_int;
690 HANDLE_OPCODE(OP_OR_FI):
691 OPC->_float = OPA->_float || (prvm_vec_t)OPB->_int;
693 HANDLE_OPCODE(OP_NOT_I):
694 OPC->_float = !OPA->_int;
696 HANDLE_OPCODE(OP_EQ_I):
697 OPC->_float = OPA->_int == OPB->_int;
699 HANDLE_OPCODE(OP_EQ_IF):
700 OPC->_float = (prvm_vec_t)OPA->_int == OPB->_float;
702 HANDLE_OPCODE(OP_EQ_FI):
703 OPC->_float = OPA->_float == (prvm_vec_t)OPB->_int;
705 HANDLE_OPCODE(OP_NE_I):
706 OPC->_float = OPA->_int != OPB->_int;
708 HANDLE_OPCODE(OP_NE_IF):
709 OPC->_float = (prvm_vec_t)OPA->_int != OPB->_float;
711 HANDLE_OPCODE(OP_NE_FI):
712 OPC->_float = OPA->_float != (prvm_vec_t)OPB->_int;
714 HANDLE_OPCODE(OP_STORE_I):
715 OPB->_int = OPA->_int;
717 HANDLE_OPCODE(OP_STOREP_I):
719 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
722 prog->error_cmd("%s Progs attempted to write to an out of bounds edict", prog->name);
726 ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
727 ptr->_int = OPA->_int;
729 HANDLE_OPCODE(OP_LOAD_I):
731 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
734 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
737 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
740 prog->error_cmd("%s Progs attempted to read an invalid field in an edict", prog->name);
744 ed = PRVM_PROG_TO_EDICT(OPA->edict);
745 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
748 HANDLE_OPCODE(OP_GSTOREP_I):
749 HANDLE_OPCODE(OP_GSTOREP_F):
750 HANDLE_OPCODE(OP_GSTOREP_ENT):
751 HANDLE_OPCODE(OP_GSTOREP_FLD): // integers
752 HANDLE_OPCODE(OP_GSTOREP_S):
753 HANDLE_OPCODE(OP_GSTOREP_FNC): // pointers
755 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
758 prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name);
762 pr_iglobals[OPB->_int] = OPA->_int;
764 HANDLE_OPCODE(OP_GSTOREP_V):
766 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
769 prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name);
773 pr_iglobals[OPB->_int ] = OPA->ivector[0];
774 pr_iglobals[OPB->_int+1] = OPA->ivector[1];
775 pr_iglobals[OPB->_int+2] = OPA->ivector[2];
778 HANDLE_OPCODE(OP_GADDRESS):
779 i = OPA->_int + (prvm_int_t) OPB->_float;
781 if (i < 0 || i >= pr_globaldefs)
784 prog->error_cmd("%s Progs attempted to address an out of bounds global", prog->name);
788 OPC->_int = pr_iglobals[i];
791 HANDLE_OPCODE(OP_GLOAD_I):
792 HANDLE_OPCODE(OP_GLOAD_F):
793 HANDLE_OPCODE(OP_GLOAD_FLD):
794 HANDLE_OPCODE(OP_GLOAD_ENT):
795 HANDLE_OPCODE(OP_GLOAD_S):
796 HANDLE_OPCODE(OP_GLOAD_FNC):
798 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
801 prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name);
805 OPC->_int = pr_iglobals[OPA->_int];
808 HANDLE_OPCODE(OP_GLOAD_V):
810 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
813 prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name);
817 OPC->ivector[0] = pr_iglobals[OPA->_int ];
818 OPC->ivector[1] = pr_iglobals[OPA->_int+1];
819 OPC->ivector[2] = pr_iglobals[OPA->_int+2];
822 HANDLE_OPCODE(OP_BOUNDCHECK):
823 if (OPA->_int < 0 || OPA->_int >= st->b)
826 prog->error_cmd("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", prog->name, st->b, st->c);
833 #if !USE_COMPUTED_GOTOS
836 prog->error_cmd("Bad opcode %i in %s", st->op, prog->name);
839 #if PRVMSLOWINTERPRETER
841 if (prog->watch_global_type != ev_void)
843 prvm_eval_t *g = PRVM_GLOBALFIELDVALUE(prog->watch_global);
844 prog->xstatement = st - cached_statements;
845 PRVM_Watchpoint(prog, 0, "Global watchpoint hit", prog->watch_global_type, &prog->watch_global_value, g);
847 if (prog->watch_field_type != ev_void && prog->watch_edict < prog->max_edicts)
849 prvm_eval_t *g = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field);
850 prog->xstatement = st - cached_statements;
851 PRVM_Watchpoint(prog, 0, "Entityfield watchpoint hit", prog->watch_field_type, &prog->watch_edictfield_value, g);
856 #endif // !USE_COMPUTED_GOTOS
858 #undef DISPATCH_OPCODE
860 #undef USE_COMPUTED_GOTOS
862 #undef ADVANCE_PROFILE_BEFORE_JUMP