1 // NEED to reset startst after calling this!
2 #define ADVANCE_PROFILE_BEFORE_JUMP() \
3 prog->xfunction->profile += (st - startst)
5 #ifdef PRVMTIMEPROFILING
7 ADVANCE_PROFILE_BEFORE_JUMP(); \
8 prog->xstatement = st - cached_statements; \
9 tm = Sys_DirtyTime(); \
10 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0; \
15 ADVANCE_PROFILE_BEFORE_JUMP(); \
16 prog->xstatement = st - cached_statements; \
20 // This code isn't #ifdef/#define protectable, don't try.
22 #if HAVE_COMPUTED_GOTOS && !(PRVMSLOWINTERPRETER || PRVMTIMEPROFILING)
23 // NOTE: Due to otherwise duplicate labels, only ONE interpreter path may
25 # define USE_COMPUTED_GOTOS 1
28 #if USE_COMPUTED_GOTOS
29 // Must exactly match opcode_e enum in pr_comp.h
30 const static void *dispatchtable[] = {
71 &&handle_OP_STORE_ENT,
72 &&handle_OP_STORE_FLD,
73 &&handle_OP_STORE_FNC,
78 &&handle_OP_STOREP_ENT,
79 &&handle_OP_STOREP_FLD,
80 &&handle_OP_STOREP_FNC,
107 #define DISPATCH_OPCODE() \
108 goto *dispatchtable[(++st)->op]
109 #define HANDLE_OPCODE(opcode) handle_##opcode
111 DISPATCH_OPCODE(); // jump to first opcode
112 #else // USE_COMPUTED_GOTOS
113 #define DISPATCH_OPCODE() break
114 #define HANDLE_OPCODE(opcode) case opcode
116 #if PRVMSLOWINTERPRETER
118 if (prog->watch_global_type != ev_void)
120 prvm_eval_t *f = PRVM_GLOBALFIELDVALUE(prog->watch_global);
121 prog->xstatement = st + 1 - cached_statements;
122 PRVM_Watchpoint(prog, 1, "Global watchpoint hit by engine", prog->watch_global_type, &prog->watch_global_value, f);
124 if (prog->watch_field_type != ev_void && prog->watch_edict < prog->max_edicts)
126 prvm_eval_t *f = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field);
127 prog->xstatement = st + 1 - cached_statements;
128 PRVM_Watchpoint(prog, 1, "Entityfield watchpoint hit by engine", prog->watch_field_type, &prog->watch_edictfield_value, f);
136 #endif // USE_COMPUTED_GOTOS
138 #if !USE_COMPUTED_GOTOS
140 #if PRVMSLOWINTERPRETER
142 PRVM_PrintStatement(prog, st);
143 if (prog->statement_profile[st - cached_statements]++ == 0 && (prvm_coverage.integer & 4))
144 PRVM_StatementCoverageEvent(prog, prog->xfunction, st - cached_statements);
145 if (prog->break_statement >= 0)
146 if ((st - cached_statements) == prog->break_statement)
148 prog->xstatement = st - cached_statements;
149 PRVM_Breakpoint(prog, prog->break_stack_index, "Breakpoint hit");
155 HANDLE_OPCODE(OP_ADD_F):
156 OPC->_float = OPA->_float + OPB->_float;
158 HANDLE_OPCODE(OP_ADD_V):
159 OPC->vector[0] = OPA->vector[0] + OPB->vector[0];
160 OPC->vector[1] = OPA->vector[1] + OPB->vector[1];
161 OPC->vector[2] = OPA->vector[2] + OPB->vector[2];
163 HANDLE_OPCODE(OP_SUB_F):
164 OPC->_float = OPA->_float - OPB->_float;
166 HANDLE_OPCODE(OP_SUB_V):
167 OPC->vector[0] = OPA->vector[0] - OPB->vector[0];
168 OPC->vector[1] = OPA->vector[1] - OPB->vector[1];
169 OPC->vector[2] = OPA->vector[2] - OPB->vector[2];
171 HANDLE_OPCODE(OP_MUL_F):
172 OPC->_float = OPA->_float * OPB->_float;
174 HANDLE_OPCODE(OP_MUL_V):
175 OPC->_float = OPA->vector[0]*OPB->vector[0] + OPA->vector[1]*OPB->vector[1] + OPA->vector[2]*OPB->vector[2];
177 HANDLE_OPCODE(OP_MUL_FV):
178 tempfloat = OPA->_float;
179 OPC->vector[0] = tempfloat * OPB->vector[0];
180 OPC->vector[1] = tempfloat * OPB->vector[1];
181 OPC->vector[2] = tempfloat * OPB->vector[2];
183 HANDLE_OPCODE(OP_MUL_VF):
184 tempfloat = OPB->_float;
185 OPC->vector[0] = tempfloat * OPA->vector[0];
186 OPC->vector[1] = tempfloat * OPA->vector[1];
187 OPC->vector[2] = tempfloat * OPA->vector[2];
189 HANDLE_OPCODE(OP_DIV_F):
190 if( OPB->_float != 0.0f )
192 OPC->_float = OPA->_float / OPB->_float;
196 if (developer.integer)
199 VM_Warning(prog, "Attempted division by zero in %s\n", prog->name );
204 HANDLE_OPCODE(OP_BITAND):
205 OPC->_float = (prvm_int_t)OPA->_float & (prvm_int_t)OPB->_float;
207 HANDLE_OPCODE(OP_BITOR):
208 OPC->_float = (prvm_int_t)OPA->_float | (prvm_int_t)OPB->_float;
210 HANDLE_OPCODE(OP_GE):
211 OPC->_float = OPA->_float >= OPB->_float;
213 HANDLE_OPCODE(OP_LE):
214 OPC->_float = OPA->_float <= OPB->_float;
216 HANDLE_OPCODE(OP_GT):
217 OPC->_float = OPA->_float > OPB->_float;
219 HANDLE_OPCODE(OP_LT):
220 OPC->_float = OPA->_float < OPB->_float;
222 HANDLE_OPCODE(OP_AND):
223 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
225 HANDLE_OPCODE(OP_OR):
226 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
228 HANDLE_OPCODE(OP_NOT_F):
229 OPC->_float = !FLOAT_IS_TRUE_FOR_INT(OPA->_int);
231 HANDLE_OPCODE(OP_NOT_V):
232 OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2];
234 HANDLE_OPCODE(OP_NOT_S):
235 OPC->_float = !OPA->string || !*PRVM_GetString(prog, OPA->string);
237 HANDLE_OPCODE(OP_NOT_FNC):
238 OPC->_float = !OPA->function;
240 HANDLE_OPCODE(OP_NOT_ENT):
241 OPC->_float = (OPA->edict == 0);
243 HANDLE_OPCODE(OP_EQ_F):
244 OPC->_float = OPA->_float == OPB->_float;
246 HANDLE_OPCODE(OP_EQ_V):
247 OPC->_float = (OPA->vector[0] == OPB->vector[0]) && (OPA->vector[1] == OPB->vector[1]) && (OPA->vector[2] == OPB->vector[2]);
249 HANDLE_OPCODE(OP_EQ_S):
250 OPC->_float = !strcmp(PRVM_GetString(prog, OPA->string),PRVM_GetString(prog, OPB->string));
252 HANDLE_OPCODE(OP_EQ_E):
253 OPC->_float = OPA->_int == OPB->_int;
255 HANDLE_OPCODE(OP_EQ_FNC):
256 OPC->_float = OPA->function == OPB->function;
258 HANDLE_OPCODE(OP_NE_F):
259 OPC->_float = OPA->_float != OPB->_float;
261 HANDLE_OPCODE(OP_NE_V):
262 OPC->_float = (OPA->vector[0] != OPB->vector[0]) || (OPA->vector[1] != OPB->vector[1]) || (OPA->vector[2] != OPB->vector[2]);
264 HANDLE_OPCODE(OP_NE_S):
265 OPC->_float = strcmp(PRVM_GetString(prog, OPA->string),PRVM_GetString(prog, OPB->string));
267 HANDLE_OPCODE(OP_NE_E):
268 OPC->_float = OPA->_int != OPB->_int;
270 HANDLE_OPCODE(OP_NE_FNC):
271 OPC->_float = OPA->function != OPB->function;
275 HANDLE_OPCODE(OP_STORE_F):
276 HANDLE_OPCODE(OP_STORE_ENT):
277 HANDLE_OPCODE(OP_STORE_FLD): // integers
278 HANDLE_OPCODE(OP_STORE_S):
279 HANDLE_OPCODE(OP_STORE_FNC): // pointers
280 OPB->_int = OPA->_int;
282 HANDLE_OPCODE(OP_STORE_V):
283 OPB->ivector[0] = OPA->ivector[0];
284 OPB->ivector[1] = OPA->ivector[1];
285 OPB->ivector[2] = OPA->ivector[2];
288 HANDLE_OPCODE(OP_STOREP_F):
289 HANDLE_OPCODE(OP_STOREP_ENT):
290 HANDLE_OPCODE(OP_STOREP_FLD): // integers
291 HANDLE_OPCODE(OP_STOREP_S):
292 HANDLE_OPCODE(OP_STOREP_FNC): // pointers
293 if ((prvm_uint_t)OPB->_int - cached_entityfields >= cached_entityfieldsarea_entityfields)
295 if ((prvm_uint_t)OPB->_int >= cached_entityfieldsarea)
298 prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
301 if ((prvm_uint_t)OPB->_int < cached_entityfields && !cached_allowworldwrites)
304 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);
307 ptr = (prvm_eval_t *)(cached_edictsfields + OPB->_int);
308 ptr->_int = OPA->_int;
310 HANDLE_OPCODE(OP_STOREP_V):
311 if ((prvm_uint_t)OPB->_int - cached_entityfields > (prvm_uint_t)cached_entityfieldsarea_entityfields_3)
313 if ((prvm_uint_t)OPB->_int > cached_entityfieldsarea_3)
316 prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
319 if ((prvm_uint_t)OPB->_int < cached_entityfields && !cached_allowworldwrites)
322 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);
325 ptr = (prvm_eval_t *)(cached_edictsfields + OPB->_int);
326 ptr->ivector[0] = OPA->ivector[0];
327 ptr->ivector[1] = OPA->ivector[1];
328 ptr->ivector[2] = OPA->ivector[2];
331 HANDLE_OPCODE(OP_ADDRESS):
332 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
335 prog->error_cmd("%s Progs attempted to address an out of bounds edict number", prog->name);
338 if ((prvm_uint_t)OPB->_int >= cached_entityfields)
341 prog->error_cmd("%s attempted to address an invalid field (%i) in an edict", prog->name, (int)OPB->_int);
345 if (OPA->edict == 0 && !cached_allowworldwrites)
348 prog->error_cmd("forbidden assignment to null/world entity in %s", prog->name);
352 OPC->_int = OPA->edict * cached_entityfields + OPB->_int;
355 HANDLE_OPCODE(OP_LOAD_F):
356 HANDLE_OPCODE(OP_LOAD_FLD):
357 HANDLE_OPCODE(OP_LOAD_ENT):
358 HANDLE_OPCODE(OP_LOAD_S):
359 HANDLE_OPCODE(OP_LOAD_FNC):
360 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
363 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
366 if ((prvm_uint_t)OPB->_int >= cached_entityfields)
369 prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
372 ed = PRVM_PROG_TO_EDICT(OPA->edict);
373 OPC->_int = ((prvm_eval_t *)(ed->fields.ip + OPB->_int))->_int;
376 HANDLE_OPCODE(OP_LOAD_V):
377 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
380 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
383 if ((prvm_uint_t)OPB->_int > cached_entityfields_3)
386 prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
389 ed = PRVM_PROG_TO_EDICT(OPA->edict);
390 ptr = (prvm_eval_t *)(ed->fields.ip + OPB->_int);
391 OPC->ivector[0] = ptr->ivector[0];
392 OPC->ivector[1] = ptr->ivector[1];
393 OPC->ivector[2] = ptr->ivector[2];
398 HANDLE_OPCODE(OP_IFNOT):
399 if(!FLOAT_IS_TRUE_FOR_INT(OPA->_int))
400 // TODO add an "int-if", and change this one to OPA->_float
401 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
402 // and entity, string, field values can never have that value
404 ADVANCE_PROFILE_BEFORE_JUMP();
405 st = cached_statements + st->jumpabsolute - 1; // offset the st++
407 // no bounds check needed, it is done when loading progs
408 if (++jumpcount == 10000000 && prvm_runawaycheck)
410 prog->xstatement = st - cached_statements;
411 PRVM_Profile(prog, 1<<30, 1000000, 0);
412 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
417 HANDLE_OPCODE(OP_IF):
418 if(FLOAT_IS_TRUE_FOR_INT(OPA->_int))
419 // TODO add an "int-if", and change this one, as well as the FLOAT_IS_TRUE_FOR_INT usages, to OPA->_float
420 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
421 // and entity, string, field values can never have that value
423 ADVANCE_PROFILE_BEFORE_JUMP();
424 st = cached_statements + st->jumpabsolute - 1; // offset the st++
426 // no bounds check needed, it is done when loading progs
427 if (++jumpcount == 10000000 && prvm_runawaycheck)
429 prog->xstatement = st - cached_statements;
430 PRVM_Profile(prog, 1<<30, 0.01, 0);
431 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
436 HANDLE_OPCODE(OP_GOTO):
437 ADVANCE_PROFILE_BEFORE_JUMP();
438 st = cached_statements + st->jumpabsolute - 1; // offset the st++
440 // no bounds check needed, it is done when loading progs
441 if (++jumpcount == 10000000 && prvm_runawaycheck)
443 prog->xstatement = st - cached_statements;
444 PRVM_Profile(prog, 1<<30, 0.01, 0);
445 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
449 HANDLE_OPCODE(OP_CALL0):
450 HANDLE_OPCODE(OP_CALL1):
451 HANDLE_OPCODE(OP_CALL2):
452 HANDLE_OPCODE(OP_CALL3):
453 HANDLE_OPCODE(OP_CALL4):
454 HANDLE_OPCODE(OP_CALL5):
455 HANDLE_OPCODE(OP_CALL6):
456 HANDLE_OPCODE(OP_CALL7):
457 HANDLE_OPCODE(OP_CALL8):
458 #ifdef PRVMTIMEPROFILING
459 tm = Sys_DirtyTime();
460 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
463 ADVANCE_PROFILE_BEFORE_JUMP();
465 prog->xstatement = st - cached_statements;
466 prog->argc = st->op - OP_CALL0;
469 prog->error_cmd("NULL function in %s", prog->name);
472 if(!OPA->function || OPA->function < 0 || OPA->function >= prog->numfunctions)
475 prog->error_cmd("%s CALL outside the program", prog->name);
479 newf = &prog->functions[OPA->function];
480 if (newf->callcount++ == 0 && (prvm_coverage.integer & 1))
481 PRVM_FunctionCoverageEvent(prog, newf);
483 if (newf->first_statement < 0)
485 // negative first_statement values are built in functions
486 int builtinnumber = -newf->first_statement;
487 prog->xfunction->builtinsprofile++;
488 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
490 prog->builtins[builtinnumber](prog);
491 #ifdef PRVMTIMEPROFILING
492 tm = Sys_DirtyTime();
493 newf->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
494 prog->xfunction->tbprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
497 // builtins may cause ED_Alloc() to be called, update cached variables
498 cached_edictsfields = prog->edictsfields;
499 cached_entityfields = prog->entityfields;
500 cached_entityfields_3 = prog->entityfields - 3;
501 cached_entityfieldsarea = prog->entityfieldsarea;
502 cached_entityfieldsarea_entityfields = prog->entityfieldsarea - prog->entityfields;
503 cached_entityfieldsarea_3 = prog->entityfieldsarea - 3;
504 cached_entityfieldsarea_entityfields_3 = prog->entityfieldsarea - prog->entityfields - 3;
505 cached_max_edicts = prog->max_edicts;
506 // these do not change
507 //cached_statements = prog->statements;
508 //cached_allowworldwrites = prog->allowworldwrites;
509 //cached_flag = prog->flag;
510 // if prog->trace changed we need to change interpreter path
511 if (prog->trace != cachedpr_trace)
512 goto chooseexecprogram;
515 prog->error_cmd("No such builtin #%i in %s; most likely cause: outdated engine build. Try updating!", builtinnumber, prog->name);
518 st = cached_statements + PRVM_EnterFunction(prog, newf);
522 HANDLE_OPCODE(OP_DONE):
523 HANDLE_OPCODE(OP_RETURN):
524 #ifdef PRVMTIMEPROFILING
525 tm = Sys_DirtyTime();
526 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
529 ADVANCE_PROFILE_BEFORE_JUMP();
530 prog->xstatement = st - cached_statements;
532 prog->globals.ip[OFS_RETURN ] = prog->globals.ip[st->operand[0] ];
533 prog->globals.ip[OFS_RETURN+1] = prog->globals.ip[st->operand[0]+1];
534 prog->globals.ip[OFS_RETURN+2] = prog->globals.ip[st->operand[0]+2];
536 st = cached_statements + PRVM_LeaveFunction(prog);
538 if (prog->depth <= exitdepth)
539 goto cleanup; // all done
542 HANDLE_OPCODE(OP_STATE):
543 if(cached_flag & PRVM_OP_STATE)
545 ed = PRVM_PROG_TO_EDICT(PRVM_gameglobaledict(self));
546 PRVM_gameedictfloat(ed,nextthink) = PRVM_gameglobalfloat(time) + 0.1;
547 PRVM_gameedictfloat(ed,frame) = OPA->_float;
548 PRVM_gameedictfunction(ed,think) = OPB->function;
553 prog->xstatement = st - cached_statements;
554 prog->error_cmd("OP_STATE not supported by %s", prog->name);
558 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
560 HANDLE_OPCODE(OP_ADD_I):
561 OPC->_int = OPA->_int + OPB->_int;
563 HANDLE_OPCODE(OP_ADD_IF):
564 OPC->_int = OPA->_int + (prvm_int_t) OPB->_float;
566 HANDLE_OPCODE(OP_ADD_FI):
567 OPC->_float = OPA->_float + (prvm_vec_t) OPB->_int;
569 HANDLE_OPCODE(OP_SUB_I):
570 OPC->_int = OPA->_int - OPB->_int;
572 HANDLE_OPCODE(OP_SUB_IF):
573 OPC->_int = OPA->_int - (prvm_int_t) OPB->_float;
575 HANDLE_OPCODE(OP_SUB_FI):
576 OPC->_float = OPA->_float - (prvm_vec_t) OPB->_int;
578 HANDLE_OPCODE(OP_MUL_I):
579 OPC->_int = OPA->_int * OPB->_int;
581 HANDLE_OPCODE(OP_MUL_IF):
582 OPC->_int = OPA->_int * (prvm_int_t) OPB->_float;
584 HANDLE_OPCODE(OP_MUL_FI):
585 OPC->_float = OPA->_float * (prvm_vec_t) OPB->_int;
587 HANDLE_OPCODE(OP_MUL_VI):
588 OPC->vector[0] = (prvm_vec_t) OPB->_int * OPA->vector[0];
589 OPC->vector[1] = (prvm_vec_t) OPB->_int * OPA->vector[1];
590 OPC->vector[2] = (prvm_vec_t) OPB->_int * OPA->vector[2];
592 HANDLE_OPCODE(OP_DIV_VF):
594 float temp = 1.0f / OPB->_float;
595 OPC->vector[0] = temp * OPA->vector[0];
596 OPC->vector[1] = temp * OPA->vector[1];
597 OPC->vector[2] = temp * OPA->vector[2];
600 HANDLE_OPCODE(OP_DIV_I):
601 OPC->_int = OPA->_int / OPB->_int;
603 HANDLE_OPCODE(OP_DIV_IF):
604 OPC->_int = OPA->_int / (prvm_int_t) OPB->_float;
606 HANDLE_OPCODE(OP_DIV_FI):
607 OPC->_float = OPA->_float / (prvm_vec_t) OPB->_int;
609 HANDLE_OPCODE(OP_CONV_IF):
610 OPC->_float = OPA->_int;
612 HANDLE_OPCODE(OP_CONV_FI):
613 OPC->_int = OPA->_float;
615 HANDLE_OPCODE(OP_BITAND_I):
616 OPC->_int = OPA->_int & OPB->_int;
618 HANDLE_OPCODE(OP_BITOR_I):
619 OPC->_int = OPA->_int | OPB->_int;
621 HANDLE_OPCODE(OP_BITAND_IF):
622 OPC->_int = OPA->_int & (prvm_int_t)OPB->_float;
624 HANDLE_OPCODE(OP_BITOR_IF):
625 OPC->_int = OPA->_int | (prvm_int_t)OPB->_float;
627 HANDLE_OPCODE(OP_BITAND_FI):
628 OPC->_float = (prvm_int_t)OPA->_float & OPB->_int;
630 HANDLE_OPCODE(OP_BITOR_FI):
631 OPC->_float = (prvm_int_t)OPA->_float | OPB->_int;
633 HANDLE_OPCODE(OP_GE_I):
634 OPC->_float = OPA->_int >= OPB->_int;
636 HANDLE_OPCODE(OP_LE_I):
637 OPC->_float = OPA->_int <= OPB->_int;
639 HANDLE_OPCODE(OP_GT_I):
640 OPC->_float = OPA->_int > OPB->_int;
642 HANDLE_OPCODE(OP_LT_I):
643 OPC->_float = OPA->_int < OPB->_int;
645 HANDLE_OPCODE(OP_AND_I):
646 OPC->_float = OPA->_int && OPB->_int;
648 HANDLE_OPCODE(OP_OR_I):
649 OPC->_float = OPA->_int || OPB->_int;
651 HANDLE_OPCODE(OP_GE_IF):
652 OPC->_float = (prvm_vec_t)OPA->_int >= OPB->_float;
654 HANDLE_OPCODE(OP_LE_IF):
655 OPC->_float = (prvm_vec_t)OPA->_int <= OPB->_float;
657 HANDLE_OPCODE(OP_GT_IF):
658 OPC->_float = (prvm_vec_t)OPA->_int > OPB->_float;
660 HANDLE_OPCODE(OP_LT_IF):
661 OPC->_float = (prvm_vec_t)OPA->_int < OPB->_float;
663 HANDLE_OPCODE(OP_AND_IF):
664 OPC->_float = (prvm_vec_t)OPA->_int && OPB->_float;
666 HANDLE_OPCODE(OP_OR_IF):
667 OPC->_float = (prvm_vec_t)OPA->_int || OPB->_float;
669 HANDLE_OPCODE(OP_GE_FI):
670 OPC->_float = OPA->_float >= (prvm_vec_t)OPB->_int;
672 HANDLE_OPCODE(OP_LE_FI):
673 OPC->_float = OPA->_float <= (prvm_vec_t)OPB->_int;
675 HANDLE_OPCODE(OP_GT_FI):
676 OPC->_float = OPA->_float > (prvm_vec_t)OPB->_int;
678 HANDLE_OPCODE(OP_LT_FI):
679 OPC->_float = OPA->_float < (prvm_vec_t)OPB->_int;
681 HANDLE_OPCODE(OP_AND_FI):
682 OPC->_float = OPA->_float && (prvm_vec_t)OPB->_int;
684 HANDLE_OPCODE(OP_OR_FI):
685 OPC->_float = OPA->_float || (prvm_vec_t)OPB->_int;
687 HANDLE_OPCODE(OP_NOT_I):
688 OPC->_float = !OPA->_int;
690 HANDLE_OPCODE(OP_EQ_I):
691 OPC->_float = OPA->_int == OPB->_int;
693 HANDLE_OPCODE(OP_EQ_IF):
694 OPC->_float = (prvm_vec_t)OPA->_int == OPB->_float;
696 HANDLE_OPCODE(OP_EQ_FI):
697 OPC->_float = OPA->_float == (prvm_vec_t)OPB->_int;
699 HANDLE_OPCODE(OP_NE_I):
700 OPC->_float = OPA->_int != OPB->_int;
702 HANDLE_OPCODE(OP_NE_IF):
703 OPC->_float = (prvm_vec_t)OPA->_int != OPB->_float;
705 HANDLE_OPCODE(OP_NE_FI):
706 OPC->_float = OPA->_float != (prvm_vec_t)OPB->_int;
708 HANDLE_OPCODE(OP_STORE_I):
709 OPB->_int = OPA->_int;
711 HANDLE_OPCODE(OP_STOREP_I):
713 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
716 prog->error_cmd("%s Progs attempted to write to an out of bounds edict", prog->name);
720 ptr = (prvm_eval_t *)(prog->edictsfields + OPB->_int);
721 ptr->_int = OPA->_int;
723 HANDLE_OPCODE(OP_LOAD_I):
725 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
728 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
731 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
734 prog->error_cmd("%s Progs attempted to read an invalid field in an edict", prog->name);
738 ed = PRVM_PROG_TO_EDICT(OPA->edict);
739 OPC->_int = ((prvm_eval_t *)((int *)ed->v + OPB->_int))->_int;
742 HANDLE_OPCODE(OP_GSTOREP_I):
743 HANDLE_OPCODE(OP_GSTOREP_F):
744 HANDLE_OPCODE(OP_GSTOREP_ENT):
745 HANDLE_OPCODE(OP_GSTOREP_FLD): // integers
746 HANDLE_OPCODE(OP_GSTOREP_S):
747 HANDLE_OPCODE(OP_GSTOREP_FNC): // pointers
749 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
752 prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name);
756 pr_iglobals[OPB->_int] = OPA->_int;
758 HANDLE_OPCODE(OP_GSTOREP_V):
760 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
763 prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name);
767 pr_iglobals[OPB->_int ] = OPA->ivector[0];
768 pr_iglobals[OPB->_int+1] = OPA->ivector[1];
769 pr_iglobals[OPB->_int+2] = OPA->ivector[2];
772 HANDLE_OPCODE(OP_GADDRESS):
773 i = OPA->_int + (prvm_int_t) OPB->_float;
775 if (i < 0 || i >= pr_globaldefs)
778 prog->error_cmd("%s Progs attempted to address an out of bounds global", prog->name);
782 OPC->_int = pr_iglobals[i];
785 HANDLE_OPCODE(OP_GLOAD_I):
786 HANDLE_OPCODE(OP_GLOAD_F):
787 HANDLE_OPCODE(OP_GLOAD_FLD):
788 HANDLE_OPCODE(OP_GLOAD_ENT):
789 HANDLE_OPCODE(OP_GLOAD_S):
790 HANDLE_OPCODE(OP_GLOAD_FNC):
792 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
795 prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name);
799 OPC->_int = pr_iglobals[OPA->_int];
802 HANDLE_OPCODE(OP_GLOAD_V):
804 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
807 prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name);
811 OPC->ivector[0] = pr_iglobals[OPA->_int ];
812 OPC->ivector[1] = pr_iglobals[OPA->_int+1];
813 OPC->ivector[2] = pr_iglobals[OPA->_int+2];
816 HANDLE_OPCODE(OP_BOUNDCHECK):
817 if (OPA->_int < 0 || OPA->_int >= st->b)
820 prog->error_cmd("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", prog->name, st->b, st->c);
827 #if !USE_COMPUTED_GOTOS
830 prog->error_cmd("Bad opcode %i in %s", st->op, prog->name);
833 #if PRVMSLOWINTERPRETER
835 if (prog->watch_global_type != ev_void)
837 prvm_eval_t *f = PRVM_GLOBALFIELDVALUE(prog->watch_global);
838 prog->xstatement = st - cached_statements;
839 PRVM_Watchpoint(prog, 0, "Global watchpoint hit", prog->watch_global_type, &prog->watch_global_value, f);
841 if (prog->watch_field_type != ev_void && prog->watch_edict < prog->max_edicts)
843 prvm_eval_t *f = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field);
844 prog->xstatement = st - cached_statements;
845 PRVM_Watchpoint(prog, 0, "Entityfield watchpoint hit", prog->watch_field_type, &prog->watch_edictfield_value, f);
850 #endif // !USE_COMPUTED_GOTOS
852 #undef DISPATCH_OPCODE
854 #undef USE_COMPUTED_GOTOS
856 #undef ADVANCE_PROFILE_BEFORE_JUMP