1 #ifdef PRVMTIMEPROFILING
3 prog->xstatement = st - cached_statements; \
4 tm = Sys_DirtyTime(); \
5 prog->xfunction->profile += (st - startst); \
6 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
9 prog->xstatement = st - cached_statements; \
10 prog->xfunction->profile += (st - startst);
13 // This code isn't #ifdef/#define protectable, don't try.
15 #if HAVE_COMPUTED_GOTOS && !(PRVMSLOWINTERPRETER || PRVMTIMEPROFILING)
16 // NOTE: Due to otherwise duplicate labels, only ONE interpreter path may
18 # define USE_COMPUTED_GOTOS 1
21 #if USE_COMPUTED_GOTOS
22 // Must exactly match opcode_e enum in pr_comp.h
23 const static void *dispatchtable[] = {
64 &&handle_OP_STORE_ENT,
65 &&handle_OP_STORE_FLD,
66 &&handle_OP_STORE_FNC,
71 &&handle_OP_STOREP_ENT,
72 &&handle_OP_STOREP_FLD,
73 &&handle_OP_STOREP_FNC,
100 #define DISPATCH_OPCODE() \
101 goto *dispatchtable[(++st)->op]
102 #define HANDLE_OPCODE(opcode) handle_##opcode
104 DISPATCH_OPCODE(); // jump to first opcode
105 #else // USE_COMPUTED_GOTOS
106 #define DISPATCH_OPCODE() break
107 #define HANDLE_OPCODE(opcode) case opcode
109 #if PRVMSLOWINTERPRETER
111 if (prog->watch_global_type != ev_void)
113 prvm_eval_t *f = PRVM_GLOBALFIELDVALUE(prog->watch_global);
114 prog->xstatement = st + 1 - cached_statements;
115 PRVM_Watchpoint(prog, 1, "Global watchpoint hit by engine", prog->watch_global_type, &prog->watch_global_value, f);
117 if (prog->watch_field_type != ev_void && prog->watch_edict < prog->max_edicts)
119 prvm_eval_t *f = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field);
120 prog->xstatement = st + 1 - cached_statements;
121 PRVM_Watchpoint(prog, 1, "Entityfield watchpoint hit by engine", prog->watch_field_type, &prog->watch_edictfield_value, f);
129 #endif // USE_COMPUTED_GOTOS
131 #if !USE_COMPUTED_GOTOS
133 #if PRVMSLOWINTERPRETER
135 PRVM_PrintStatement(prog, st);
136 if (prog->statement_profile[st - cached_statements]++ == 0 && (prvm_coverage.integer & 4))
137 PRVM_StatementCoverageEvent(prog, prog->xfunction, st - cached_statements);
138 if (prog->break_statement >= 0)
139 if ((st - cached_statements) == prog->break_statement)
141 prog->xstatement = st - cached_statements;
142 PRVM_Breakpoint(prog, prog->break_stack_index, "Breakpoint hit");
148 HANDLE_OPCODE(OP_ADD_F):
149 OPC->_float = OPA->_float + OPB->_float;
151 HANDLE_OPCODE(OP_ADD_V):
152 OPC->vector[0] = OPA->vector[0] + OPB->vector[0];
153 OPC->vector[1] = OPA->vector[1] + OPB->vector[1];
154 OPC->vector[2] = OPA->vector[2] + OPB->vector[2];
156 HANDLE_OPCODE(OP_SUB_F):
157 OPC->_float = OPA->_float - OPB->_float;
159 HANDLE_OPCODE(OP_SUB_V):
160 OPC->vector[0] = OPA->vector[0] - OPB->vector[0];
161 OPC->vector[1] = OPA->vector[1] - OPB->vector[1];
162 OPC->vector[2] = OPA->vector[2] - OPB->vector[2];
164 HANDLE_OPCODE(OP_MUL_F):
165 OPC->_float = OPA->_float * OPB->_float;
167 HANDLE_OPCODE(OP_MUL_V):
168 OPC->_float = OPA->vector[0]*OPB->vector[0] + OPA->vector[1]*OPB->vector[1] + OPA->vector[2]*OPB->vector[2];
170 HANDLE_OPCODE(OP_MUL_FV):
171 tempfloat = OPA->_float;
172 OPC->vector[0] = tempfloat * OPB->vector[0];
173 OPC->vector[1] = tempfloat * OPB->vector[1];
174 OPC->vector[2] = tempfloat * OPB->vector[2];
176 HANDLE_OPCODE(OP_MUL_VF):
177 tempfloat = OPB->_float;
178 OPC->vector[0] = tempfloat * OPA->vector[0];
179 OPC->vector[1] = tempfloat * OPA->vector[1];
180 OPC->vector[2] = tempfloat * OPA->vector[2];
182 HANDLE_OPCODE(OP_DIV_F):
183 if( OPB->_float != 0.0f )
185 OPC->_float = OPA->_float / OPB->_float;
189 if (developer.integer)
191 prog->xfunction->profile += (st - startst);
193 prog->xstatement = st - cached_statements;
194 VM_Warning(prog, "Attempted division by zero in %s\n", prog->name );
199 HANDLE_OPCODE(OP_BITAND):
200 OPC->_float = (prvm_int_t)OPA->_float & (prvm_int_t)OPB->_float;
202 HANDLE_OPCODE(OP_BITOR):
203 OPC->_float = (prvm_int_t)OPA->_float | (prvm_int_t)OPB->_float;
205 HANDLE_OPCODE(OP_GE):
206 OPC->_float = OPA->_float >= OPB->_float;
208 HANDLE_OPCODE(OP_LE):
209 OPC->_float = OPA->_float <= OPB->_float;
211 HANDLE_OPCODE(OP_GT):
212 OPC->_float = OPA->_float > OPB->_float;
214 HANDLE_OPCODE(OP_LT):
215 OPC->_float = OPA->_float < OPB->_float;
217 HANDLE_OPCODE(OP_AND):
218 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
220 HANDLE_OPCODE(OP_OR):
221 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
223 HANDLE_OPCODE(OP_NOT_F):
224 OPC->_float = !FLOAT_IS_TRUE_FOR_INT(OPA->_int);
226 HANDLE_OPCODE(OP_NOT_V):
227 OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2];
229 HANDLE_OPCODE(OP_NOT_S):
230 OPC->_float = !OPA->string || !*PRVM_GetString(prog, OPA->string);
232 HANDLE_OPCODE(OP_NOT_FNC):
233 OPC->_float = !OPA->function;
235 HANDLE_OPCODE(OP_NOT_ENT):
236 OPC->_float = (OPA->edict == 0);
238 HANDLE_OPCODE(OP_EQ_F):
239 OPC->_float = OPA->_float == OPB->_float;
241 HANDLE_OPCODE(OP_EQ_V):
242 OPC->_float = (OPA->vector[0] == OPB->vector[0]) && (OPA->vector[1] == OPB->vector[1]) && (OPA->vector[2] == OPB->vector[2]);
244 HANDLE_OPCODE(OP_EQ_S):
245 OPC->_float = !strcmp(PRVM_GetString(prog, OPA->string),PRVM_GetString(prog, OPB->string));
247 HANDLE_OPCODE(OP_EQ_E):
248 OPC->_float = OPA->_int == OPB->_int;
250 HANDLE_OPCODE(OP_EQ_FNC):
251 OPC->_float = OPA->function == OPB->function;
253 HANDLE_OPCODE(OP_NE_F):
254 OPC->_float = OPA->_float != OPB->_float;
256 HANDLE_OPCODE(OP_NE_V):
257 OPC->_float = (OPA->vector[0] != OPB->vector[0]) || (OPA->vector[1] != OPB->vector[1]) || (OPA->vector[2] != OPB->vector[2]);
259 HANDLE_OPCODE(OP_NE_S):
260 OPC->_float = strcmp(PRVM_GetString(prog, OPA->string),PRVM_GetString(prog, OPB->string));
262 HANDLE_OPCODE(OP_NE_E):
263 OPC->_float = OPA->_int != OPB->_int;
265 HANDLE_OPCODE(OP_NE_FNC):
266 OPC->_float = OPA->function != OPB->function;
270 HANDLE_OPCODE(OP_STORE_F):
271 HANDLE_OPCODE(OP_STORE_ENT):
272 HANDLE_OPCODE(OP_STORE_FLD): // integers
273 HANDLE_OPCODE(OP_STORE_S):
274 HANDLE_OPCODE(OP_STORE_FNC): // pointers
275 OPB->_int = OPA->_int;
277 HANDLE_OPCODE(OP_STORE_V):
278 OPB->ivector[0] = OPA->ivector[0];
279 OPB->ivector[1] = OPA->ivector[1];
280 OPB->ivector[2] = OPA->ivector[2];
283 HANDLE_OPCODE(OP_STOREP_F):
284 HANDLE_OPCODE(OP_STOREP_ENT):
285 HANDLE_OPCODE(OP_STOREP_FLD): // integers
286 HANDLE_OPCODE(OP_STOREP_S):
287 HANDLE_OPCODE(OP_STOREP_FNC): // pointers
288 if ((prvm_uint_t)OPB->_int - cached_entityfields >= cached_entityfieldsarea_entityfields)
290 if ((prvm_uint_t)OPB->_int >= cached_entityfieldsarea)
293 prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
296 if ((prvm_uint_t)OPB->_int < cached_entityfields && !cached_allowworldwrites)
298 prog->xstatement = st - cached_statements;
299 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);
302 ptr = (prvm_eval_t *)(cached_edictsfields + OPB->_int);
303 ptr->_int = OPA->_int;
305 HANDLE_OPCODE(OP_STOREP_V):
306 if ((prvm_uint_t)OPB->_int - cached_entityfields > (prvm_uint_t)cached_entityfieldsarea_entityfields_3)
308 if ((prvm_uint_t)OPB->_int > cached_entityfieldsarea_3)
311 prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
314 if ((prvm_uint_t)OPB->_int < cached_entityfields && !cached_allowworldwrites)
316 prog->xstatement = st - cached_statements;
317 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);
320 ptr = (prvm_eval_t *)(cached_edictsfields + OPB->_int);
321 ptr->ivector[0] = OPA->ivector[0];
322 ptr->ivector[1] = OPA->ivector[1];
323 ptr->ivector[2] = OPA->ivector[2];
326 HANDLE_OPCODE(OP_ADDRESS):
327 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
330 prog->error_cmd("%s Progs attempted to address an out of bounds edict number", prog->name);
333 if ((prvm_uint_t)OPB->_int >= cached_entityfields)
336 prog->error_cmd("%s attempted to address an invalid field (%i) in an edict", prog->name, (int)OPB->_int);
340 if (OPA->edict == 0 && !cached_allowworldwrites)
343 prog->error_cmd("forbidden assignment to null/world entity in %s", prog->name);
347 OPC->_int = OPA->edict * cached_entityfields + OPB->_int;
350 HANDLE_OPCODE(OP_LOAD_F):
351 HANDLE_OPCODE(OP_LOAD_FLD):
352 HANDLE_OPCODE(OP_LOAD_ENT):
353 HANDLE_OPCODE(OP_LOAD_S):
354 HANDLE_OPCODE(OP_LOAD_FNC):
355 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
358 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
361 if ((prvm_uint_t)OPB->_int >= cached_entityfields)
364 prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
367 ed = PRVM_PROG_TO_EDICT(OPA->edict);
368 OPC->_int = ((prvm_eval_t *)(ed->fields.ip + OPB->_int))->_int;
371 HANDLE_OPCODE(OP_LOAD_V):
372 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
375 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
378 if ((prvm_uint_t)OPB->_int > cached_entityfields_3)
381 prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
384 ed = PRVM_PROG_TO_EDICT(OPA->edict);
385 ptr = (prvm_eval_t *)(ed->fields.ip + OPB->_int);
386 OPC->ivector[0] = ptr->ivector[0];
387 OPC->ivector[1] = ptr->ivector[1];
388 OPC->ivector[2] = ptr->ivector[2];
393 HANDLE_OPCODE(OP_IFNOT):
394 if(!FLOAT_IS_TRUE_FOR_INT(OPA->_int))
395 // TODO add an "int-if", and change this one to OPA->_float
396 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
397 // and entity, string, field values can never have that value
399 prog->xfunction->profile += (st - startst);
400 st = cached_statements + st->jumpabsolute - 1; // offset the st++
402 // no bounds check needed, it is done when loading progs
403 if (++jumpcount == 10000000 && prvm_runawaycheck)
405 prog->xstatement = st - cached_statements;
406 PRVM_Profile(prog, 1<<30, 1000000, 0);
407 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
412 HANDLE_OPCODE(OP_IF):
413 if(FLOAT_IS_TRUE_FOR_INT(OPA->_int))
414 // TODO add an "int-if", and change this one, as well as the FLOAT_IS_TRUE_FOR_INT usages, to OPA->_float
415 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
416 // and entity, string, field values can never have that value
418 prog->xfunction->profile += (st - startst);
419 st = cached_statements + st->jumpabsolute - 1; // offset the st++
421 // no bounds check needed, it is done when loading progs
422 if (++jumpcount == 10000000 && prvm_runawaycheck)
424 prog->xstatement = st - cached_statements;
425 PRVM_Profile(prog, 1<<30, 0.01, 0);
426 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
431 HANDLE_OPCODE(OP_GOTO):
432 prog->xfunction->profile += (st - startst);
433 st = cached_statements + st->jumpabsolute - 1; // offset the st++
435 // no bounds check needed, it is done when loading progs
436 if (++jumpcount == 10000000 && prvm_runawaycheck)
438 prog->xstatement = st - cached_statements;
439 PRVM_Profile(prog, 1<<30, 0.01, 0);
440 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
444 HANDLE_OPCODE(OP_CALL0):
445 HANDLE_OPCODE(OP_CALL1):
446 HANDLE_OPCODE(OP_CALL2):
447 HANDLE_OPCODE(OP_CALL3):
448 HANDLE_OPCODE(OP_CALL4):
449 HANDLE_OPCODE(OP_CALL5):
450 HANDLE_OPCODE(OP_CALL6):
451 HANDLE_OPCODE(OP_CALL7):
452 HANDLE_OPCODE(OP_CALL8):
453 #ifdef PRVMTIMEPROFILING
454 tm = Sys_DirtyTime();
455 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
458 prog->xfunction->profile += (st - startst);
460 prog->xstatement = st - cached_statements;
461 prog->argc = st->op - OP_CALL0;
463 prog->error_cmd("NULL function in %s", prog->name);
465 if(!OPA->function || OPA->function < 0 || OPA->function >= prog->numfunctions)
468 prog->error_cmd("%s CALL outside the program", prog->name);
472 newf = &prog->functions[OPA->function];
473 if (newf->callcount++ == 0 && (prvm_coverage.integer & 1))
474 PRVM_FunctionCoverageEvent(prog, newf);
476 if (newf->first_statement < 0)
478 // negative first_statement values are built in functions
479 int builtinnumber = -newf->first_statement;
480 prog->xfunction->builtinsprofile++;
481 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
483 prog->builtins[builtinnumber](prog);
484 #ifdef PRVMTIMEPROFILING
485 tm = Sys_DirtyTime();
486 newf->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
487 prog->xfunction->tbprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
490 // builtins may cause ED_Alloc() to be called, update cached variables
491 cached_edictsfields = prog->edictsfields;
492 cached_entityfields = prog->entityfields;
493 cached_entityfields_3 = prog->entityfields - 3;
494 cached_entityfieldsarea = prog->entityfieldsarea;
495 cached_entityfieldsarea_entityfields = prog->entityfieldsarea - prog->entityfields;
496 cached_entityfieldsarea_3 = prog->entityfieldsarea - 3;
497 cached_entityfieldsarea_entityfields_3 = prog->entityfieldsarea - prog->entityfields - 3;
498 cached_max_edicts = prog->max_edicts;
499 // these do not change
500 //cached_statements = prog->statements;
501 //cached_allowworldwrites = prog->allowworldwrites;
502 //cached_flag = prog->flag;
503 // if prog->trace changed we need to change interpreter path
504 if (prog->trace != cachedpr_trace)
505 goto chooseexecprogram;
508 prog->error_cmd("No such builtin #%i in %s; most likely cause: outdated engine build. Try updating!", builtinnumber, prog->name);
511 st = cached_statements + PRVM_EnterFunction(prog, newf);
515 HANDLE_OPCODE(OP_DONE):
516 HANDLE_OPCODE(OP_RETURN):
517 #ifdef PRVMTIMEPROFILING
518 tm = Sys_DirtyTime();
519 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
522 prog->xfunction->profile += (st - startst);
523 prog->xstatement = st - cached_statements;
525 prog->globals.ip[OFS_RETURN ] = prog->globals.ip[st->operand[0] ];
526 prog->globals.ip[OFS_RETURN+1] = prog->globals.ip[st->operand[0]+1];
527 prog->globals.ip[OFS_RETURN+2] = prog->globals.ip[st->operand[0]+2];
529 st = cached_statements + PRVM_LeaveFunction(prog);
531 if (prog->depth <= exitdepth)
532 goto cleanup; // all done
535 HANDLE_OPCODE(OP_STATE):
536 if(cached_flag & PRVM_OP_STATE)
538 ed = PRVM_PROG_TO_EDICT(PRVM_gameglobaledict(self));
539 PRVM_gameedictfloat(ed,nextthink) = PRVM_gameglobalfloat(time) + 0.1;
540 PRVM_gameedictfloat(ed,frame) = OPA->_float;
541 PRVM_gameedictfunction(ed,think) = OPB->function;
546 prog->xstatement = st - cached_statements;
547 prog->error_cmd("OP_STATE not supported by %s", prog->name);
551 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
553 HANDLE_OPCODE(OP_ADD_I):
554 OPC->_int = OPA->_int + OPB->_int;
556 HANDLE_OPCODE(OP_ADD_IF):
557 OPC->_int = OPA->_int + (prvm_int_t) OPB->_float;
559 HANDLE_OPCODE(OP_ADD_FI):
560 OPC->_float = OPA->_float + (prvm_vec_t) OPB->_int;
562 HANDLE_OPCODE(OP_SUB_I):
563 OPC->_int = OPA->_int - OPB->_int;
565 HANDLE_OPCODE(OP_SUB_IF):
566 OPC->_int = OPA->_int - (prvm_int_t) OPB->_float;
568 HANDLE_OPCODE(OP_SUB_FI):
569 OPC->_float = OPA->_float - (prvm_vec_t) OPB->_int;
571 HANDLE_OPCODE(OP_MUL_I):
572 OPC->_int = OPA->_int * OPB->_int;
574 HANDLE_OPCODE(OP_MUL_IF):
575 OPC->_int = OPA->_int * (prvm_int_t) OPB->_float;
577 HANDLE_OPCODE(OP_MUL_FI):
578 OPC->_float = OPA->_float * (prvm_vec_t) OPB->_int;
580 HANDLE_OPCODE(OP_MUL_VI):
581 OPC->vector[0] = (prvm_vec_t) OPB->_int * OPA->vector[0];
582 OPC->vector[1] = (prvm_vec_t) OPB->_int * OPA->vector[1];
583 OPC->vector[2] = (prvm_vec_t) OPB->_int * OPA->vector[2];
585 HANDLE_OPCODE(OP_DIV_VF):
587 float temp = 1.0f / OPB->_float;
588 OPC->vector[0] = temp * OPA->vector[0];
589 OPC->vector[1] = temp * OPA->vector[1];
590 OPC->vector[2] = temp * OPA->vector[2];
593 HANDLE_OPCODE(OP_DIV_I):
594 OPC->_int = OPA->_int / OPB->_int;
596 HANDLE_OPCODE(OP_DIV_IF):
597 OPC->_int = OPA->_int / (prvm_int_t) OPB->_float;
599 HANDLE_OPCODE(OP_DIV_FI):
600 OPC->_float = OPA->_float / (prvm_vec_t) OPB->_int;
602 HANDLE_OPCODE(OP_CONV_IF):
603 OPC->_float = OPA->_int;
605 HANDLE_OPCODE(OP_CONV_FI):
606 OPC->_int = OPA->_float;
608 HANDLE_OPCODE(OP_BITAND_I):
609 OPC->_int = OPA->_int & OPB->_int;
611 HANDLE_OPCODE(OP_BITOR_I):
612 OPC->_int = OPA->_int | OPB->_int;
614 HANDLE_OPCODE(OP_BITAND_IF):
615 OPC->_int = OPA->_int & (prvm_int_t)OPB->_float;
617 HANDLE_OPCODE(OP_BITOR_IF):
618 OPC->_int = OPA->_int | (prvm_int_t)OPB->_float;
620 HANDLE_OPCODE(OP_BITAND_FI):
621 OPC->_float = (prvm_int_t)OPA->_float & OPB->_int;
623 HANDLE_OPCODE(OP_BITOR_FI):
624 OPC->_float = (prvm_int_t)OPA->_float | OPB->_int;
626 HANDLE_OPCODE(OP_GE_I):
627 OPC->_float = OPA->_int >= OPB->_int;
629 HANDLE_OPCODE(OP_LE_I):
630 OPC->_float = OPA->_int <= OPB->_int;
632 HANDLE_OPCODE(OP_GT_I):
633 OPC->_float = OPA->_int > OPB->_int;
635 HANDLE_OPCODE(OP_LT_I):
636 OPC->_float = OPA->_int < OPB->_int;
638 HANDLE_OPCODE(OP_AND_I):
639 OPC->_float = OPA->_int && OPB->_int;
641 HANDLE_OPCODE(OP_OR_I):
642 OPC->_float = OPA->_int || OPB->_int;
644 HANDLE_OPCODE(OP_GE_IF):
645 OPC->_float = (prvm_vec_t)OPA->_int >= OPB->_float;
647 HANDLE_OPCODE(OP_LE_IF):
648 OPC->_float = (prvm_vec_t)OPA->_int <= OPB->_float;
650 HANDLE_OPCODE(OP_GT_IF):
651 OPC->_float = (prvm_vec_t)OPA->_int > OPB->_float;
653 HANDLE_OPCODE(OP_LT_IF):
654 OPC->_float = (prvm_vec_t)OPA->_int < OPB->_float;
656 HANDLE_OPCODE(OP_AND_IF):
657 OPC->_float = (prvm_vec_t)OPA->_int && OPB->_float;
659 HANDLE_OPCODE(OP_OR_IF):
660 OPC->_float = (prvm_vec_t)OPA->_int || OPB->_float;
662 HANDLE_OPCODE(OP_GE_FI):
663 OPC->_float = OPA->_float >= (prvm_vec_t)OPB->_int;
665 HANDLE_OPCODE(OP_LE_FI):
666 OPC->_float = OPA->_float <= (prvm_vec_t)OPB->_int;
668 HANDLE_OPCODE(OP_GT_FI):
669 OPC->_float = OPA->_float > (prvm_vec_t)OPB->_int;
671 HANDLE_OPCODE(OP_LT_FI):
672 OPC->_float = OPA->_float < (prvm_vec_t)OPB->_int;
674 HANDLE_OPCODE(OP_AND_FI):
675 OPC->_float = OPA->_float && (prvm_vec_t)OPB->_int;
677 HANDLE_OPCODE(OP_OR_FI):
678 OPC->_float = OPA->_float || (prvm_vec_t)OPB->_int;
680 HANDLE_OPCODE(OP_NOT_I):
681 OPC->_float = !OPA->_int;
683 HANDLE_OPCODE(OP_EQ_I):
684 OPC->_float = OPA->_int == OPB->_int;
686 HANDLE_OPCODE(OP_EQ_IF):
687 OPC->_float = (prvm_vec_t)OPA->_int == OPB->_float;
689 HANDLE_OPCODE(OP_EQ_FI):
690 OPC->_float = OPA->_float == (prvm_vec_t)OPB->_int;
692 HANDLE_OPCODE(OP_NE_I):
693 OPC->_float = OPA->_int != OPB->_int;
695 HANDLE_OPCODE(OP_NE_IF):
696 OPC->_float = (prvm_vec_t)OPA->_int != OPB->_float;
698 HANDLE_OPCODE(OP_NE_FI):
699 OPC->_float = OPA->_float != (prvm_vec_t)OPB->_int;
701 HANDLE_OPCODE(OP_STORE_I):
702 OPB->_int = OPA->_int;
704 HANDLE_OPCODE(OP_STOREP_I):
706 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
709 prog->error_cmd("%s Progs attempted to write to an out of bounds edict", prog->name);
713 ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
714 ptr->_int = OPA->_int;
716 HANDLE_OPCODE(OP_LOAD_I):
718 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
721 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
724 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
727 prog->error_cmd("%s Progs attempted to read an invalid field in an edict", prog->name);
731 ed = PRVM_PROG_TO_EDICT(OPA->edict);
732 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
735 HANDLE_OPCODE(OP_GSTOREP_I):
736 HANDLE_OPCODE(OP_GSTOREP_F):
737 HANDLE_OPCODE(OP_GSTOREP_ENT):
738 HANDLE_OPCODE(OP_GSTOREP_FLD): // integers
739 HANDLE_OPCODE(OP_GSTOREP_S):
740 HANDLE_OPCODE(OP_GSTOREP_FNC): // pointers
742 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
745 prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name);
749 pr_iglobals[OPB->_int] = OPA->_int;
751 HANDLE_OPCODE(OP_GSTOREP_V):
753 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
756 prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name);
760 pr_iglobals[OPB->_int ] = OPA->ivector[0];
761 pr_iglobals[OPB->_int+1] = OPA->ivector[1];
762 pr_iglobals[OPB->_int+2] = OPA->ivector[2];
765 HANDLE_OPCODE(OP_GADDRESS):
766 i = OPA->_int + (prvm_int_t) OPB->_float;
768 if (i < 0 || i >= pr_globaldefs)
771 prog->error_cmd("%s Progs attempted to address an out of bounds global", prog->name);
775 OPC->_int = pr_iglobals[i];
778 HANDLE_OPCODE(OP_GLOAD_I):
779 HANDLE_OPCODE(OP_GLOAD_F):
780 HANDLE_OPCODE(OP_GLOAD_FLD):
781 HANDLE_OPCODE(OP_GLOAD_ENT):
782 HANDLE_OPCODE(OP_GLOAD_S):
783 HANDLE_OPCODE(OP_GLOAD_FNC):
785 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
788 prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name);
792 OPC->_int = pr_iglobals[OPA->_int];
795 HANDLE_OPCODE(OP_GLOAD_V):
797 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
800 prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name);
804 OPC->ivector[0] = pr_iglobals[OPA->_int ];
805 OPC->ivector[1] = pr_iglobals[OPA->_int+1];
806 OPC->ivector[2] = pr_iglobals[OPA->_int+2];
809 HANDLE_OPCODE(OP_BOUNDCHECK):
810 if (OPA->_int < 0 || OPA->_int >= st->b)
813 prog->error_cmd("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", prog->name, st->b, st->c);
820 #if !USE_COMPUTED_GOTOS
823 prog->error_cmd("Bad opcode %i in %s", st->op, prog->name);
826 #if PRVMSLOWINTERPRETER
828 if (prog->watch_global_type != ev_void)
830 prvm_eval_t *f = PRVM_GLOBALFIELDVALUE(prog->watch_global);
831 prog->xstatement = st - cached_statements;
832 PRVM_Watchpoint(prog, 0, "Global watchpoint hit", prog->watch_global_type, &prog->watch_global_value, f);
834 if (prog->watch_field_type != ev_void && prog->watch_edict < prog->max_edicts)
836 prvm_eval_t *f = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field);
837 prog->xstatement = st - cached_statements;
838 PRVM_Watchpoint(prog, 0, "Entityfield watchpoint hit", prog->watch_field_type, &prog->watch_edictfield_value, f);
843 #endif // !USE_COMPUTED_GOTOS
845 #undef DISPATCH_OPCODE
847 #undef USE_COMPUTED_GOTOS