1 extern cvar_t prvm_garbagecollection_enable;
3 // NEED to reset startst after calling this! startst may or may not be clobbered!
4 #define ADVANCE_PROFILE_BEFORE_JUMP() \
5 prog->xfunction->profile += (st - startst); \
6 if (prvm_statementprofiling.integer || (prvm_coverage.integer & 4)) { \
7 /* All statements from startst+1 to st have been hit. */ \
8 while (++startst <= st) { \
9 if (prog->statement_profile[startst - cached_statements]++ == 0 && (prvm_coverage.integer & 4)) \
10 PRVM_StatementCoverageEvent(prog, prog->xfunction, startst - cached_statements); \
12 /* Observe: startst now is clobbered (now at st+1)! */ \
15 #ifdef PRVMTIMEPROFILING
17 ADVANCE_PROFILE_BEFORE_JUMP(); \
18 prog->xstatement = st - cached_statements; \
19 tm = Sys_DirtyTime(); \
20 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0; \
25 ADVANCE_PROFILE_BEFORE_JUMP(); \
26 prog->xstatement = st - cached_statements; \
30 // This code isn't #ifdef/#define protectable, don't try.
32 #if HAVE_COMPUTED_GOTOS && !(PRVMSLOWINTERPRETER || PRVMTIMEPROFILING)
33 // NOTE: Due to otherwise duplicate labels, only ONE interpreter path may
35 # define USE_COMPUTED_GOTOS 1
38 #if USE_COMPUTED_GOTOS
39 // Must exactly match opcode_e enum in pr_comp.h
40 const static void *dispatchtable[] = {
81 &&handle_OP_STORE_ENT,
82 &&handle_OP_STORE_FLD,
83 &&handle_OP_STORE_FNC,
88 &&handle_OP_STOREP_ENT,
89 &&handle_OP_STOREP_FLD,
90 &&handle_OP_STOREP_FNC,
184 &&handle_OP_STOREP_I,
189 &&handle_OP_BITAND_I,
259 &&handle_OP_BITAND_IF,
260 &&handle_OP_BITOR_IF,
261 &&handle_OP_BITAND_FI,
262 &&handle_OP_BITOR_FI,
272 &&handle_OP_GSTOREP_I,
273 &&handle_OP_GSTOREP_F,
274 &&handle_OP_GSTOREP_ENT,
275 &&handle_OP_GSTOREP_FLD,
276 &&handle_OP_GSTOREP_S,
277 &&handle_OP_GSTOREP_FNC,
278 &&handle_OP_GSTOREP_V,
279 &&handle_OP_GADDRESS,
282 &&handle_OP_GLOAD_FLD,
283 &&handle_OP_GLOAD_ENT,
285 &&handle_OP_GLOAD_FNC,
286 &&handle_OP_BOUNDCHECK,
293 #define DISPATCH_OPCODE() \
294 goto *dispatchtable[(++st)->op]
295 #define HANDLE_OPCODE(opcode) handle_##opcode
297 DISPATCH_OPCODE(); // jump to first opcode
298 #else // USE_COMPUTED_GOTOS
299 #define DISPATCH_OPCODE() break
300 #define HANDLE_OPCODE(opcode) case opcode
302 #if PRVMSLOWINTERPRETER
304 if (prog->watch_global_type != ev_void)
306 prvm_eval_t *g = PRVM_GLOBALFIELDVALUE(prog->watch_global);
307 prog->xstatement = st + 1 - cached_statements;
308 PRVM_Watchpoint(prog, 1, "Global watchpoint hit by engine", prog->watch_global_type, &prog->watch_global_value, g);
310 if (prog->watch_field_type != ev_void && prog->watch_edict < prog->max_edicts)
312 prvm_eval_t *g = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field);
313 prog->xstatement = st + 1 - cached_statements;
314 PRVM_Watchpoint(prog, 1, "Entityfield watchpoint hit by engine", prog->watch_field_type, &prog->watch_edictfield_value, g);
322 #endif // USE_COMPUTED_GOTOS
324 #if !USE_COMPUTED_GOTOS
326 #if PRVMSLOWINTERPRETER
328 PRVM_PrintStatement(prog, st);
329 if (prog->break_statement >= 0)
330 if ((st - cached_statements) == prog->break_statement)
332 prog->xstatement = st - cached_statements;
333 PRVM_Breakpoint(prog, prog->break_stack_index, "Breakpoint hit");
339 HANDLE_OPCODE(OP_ADD_F):
340 OPC->_float = OPA->_float + OPB->_float;
342 HANDLE_OPCODE(OP_ADD_V):
343 OPC->vector[0] = OPA->vector[0] + OPB->vector[0];
344 OPC->vector[1] = OPA->vector[1] + OPB->vector[1];
345 OPC->vector[2] = OPA->vector[2] + OPB->vector[2];
347 HANDLE_OPCODE(OP_SUB_F):
348 OPC->_float = OPA->_float - OPB->_float;
350 HANDLE_OPCODE(OP_SUB_V):
351 OPC->vector[0] = OPA->vector[0] - OPB->vector[0];
352 OPC->vector[1] = OPA->vector[1] - OPB->vector[1];
353 OPC->vector[2] = OPA->vector[2] - OPB->vector[2];
355 HANDLE_OPCODE(OP_MUL_F):
356 OPC->_float = OPA->_float * OPB->_float;
358 HANDLE_OPCODE(OP_MUL_V):
359 OPC->_float = OPA->vector[0]*OPB->vector[0] + OPA->vector[1]*OPB->vector[1] + OPA->vector[2]*OPB->vector[2];
361 HANDLE_OPCODE(OP_MUL_FV):
362 tempfloat = OPA->_float;
363 OPC->vector[0] = tempfloat * OPB->vector[0];
364 OPC->vector[1] = tempfloat * OPB->vector[1];
365 OPC->vector[2] = tempfloat * OPB->vector[2];
367 HANDLE_OPCODE(OP_MUL_VF):
368 tempfloat = OPB->_float;
369 OPC->vector[0] = tempfloat * OPA->vector[0];
370 OPC->vector[1] = tempfloat * OPA->vector[1];
371 OPC->vector[2] = tempfloat * OPA->vector[2];
373 HANDLE_OPCODE(OP_DIV_F):
374 if( OPB->_float != 0.0f )
376 OPC->_float = OPA->_float / OPB->_float;
380 if (developer.integer)
383 VM_Warning(prog, "Attempted division by zero in %s\n", prog->name );
388 HANDLE_OPCODE(OP_BITAND):
389 OPC->_float = (prvm_int_t)OPA->_float & (prvm_int_t)OPB->_float;
391 HANDLE_OPCODE(OP_BITOR):
392 OPC->_float = (prvm_int_t)OPA->_float | (prvm_int_t)OPB->_float;
394 HANDLE_OPCODE(OP_GE):
395 OPC->_float = OPA->_float >= OPB->_float;
397 HANDLE_OPCODE(OP_LE):
398 OPC->_float = OPA->_float <= OPB->_float;
400 HANDLE_OPCODE(OP_GT):
401 OPC->_float = OPA->_float > OPB->_float;
403 HANDLE_OPCODE(OP_LT):
404 OPC->_float = OPA->_float < OPB->_float;
406 HANDLE_OPCODE(OP_AND):
407 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
409 HANDLE_OPCODE(OP_OR):
410 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
412 HANDLE_OPCODE(OP_NOT_F):
413 OPC->_float = !FLOAT_IS_TRUE_FOR_INT(OPA->_int);
415 HANDLE_OPCODE(OP_NOT_V):
416 OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2];
418 HANDLE_OPCODE(OP_NOT_S):
419 OPC->_float = !OPA->string || !*PRVM_GetString(prog, OPA->string);
421 HANDLE_OPCODE(OP_NOT_FNC):
422 OPC->_float = !OPA->function;
424 HANDLE_OPCODE(OP_NOT_ENT):
425 OPC->_float = (OPA->edict == 0);
427 HANDLE_OPCODE(OP_EQ_F):
428 OPC->_float = OPA->_float == OPB->_float;
430 HANDLE_OPCODE(OP_EQ_V):
431 OPC->_float = (OPA->vector[0] == OPB->vector[0]) && (OPA->vector[1] == OPB->vector[1]) && (OPA->vector[2] == OPB->vector[2]);
433 HANDLE_OPCODE(OP_EQ_S):
434 OPC->_float = !strcmp(PRVM_GetString(prog, OPA->string),PRVM_GetString(prog, OPB->string));
436 HANDLE_OPCODE(OP_EQ_E):
437 OPC->_float = OPA->_int == OPB->_int;
439 HANDLE_OPCODE(OP_EQ_FNC):
440 OPC->_float = OPA->function == OPB->function;
442 HANDLE_OPCODE(OP_NE_F):
443 OPC->_float = OPA->_float != OPB->_float;
445 HANDLE_OPCODE(OP_NE_V):
446 OPC->_float = (OPA->vector[0] != OPB->vector[0]) || (OPA->vector[1] != OPB->vector[1]) || (OPA->vector[2] != OPB->vector[2]);
448 HANDLE_OPCODE(OP_NE_S):
449 OPC->_float = strcmp(PRVM_GetString(prog, OPA->string),PRVM_GetString(prog, OPB->string));
451 HANDLE_OPCODE(OP_NE_E):
452 OPC->_float = OPA->_int != OPB->_int;
454 HANDLE_OPCODE(OP_NE_FNC):
455 OPC->_float = OPA->function != OPB->function;
459 HANDLE_OPCODE(OP_STORE_F):
460 HANDLE_OPCODE(OP_STORE_ENT):
461 HANDLE_OPCODE(OP_STORE_FLD): // integers
462 HANDLE_OPCODE(OP_STORE_FNC): // pointers
463 OPB->_int = OPA->_int;
465 HANDLE_OPCODE(OP_STORE_S):
466 // refresh the garbage collection on the string - this guards
467 // against a certain sort of repeated migration to earlier
468 // points in the scan that could otherwise result in the string
469 // being freed for being unused
470 if(prvm_garbagecollection_enable.integer)
471 PRVM_GetString(prog, OPA->_int);
472 OPB->_int = OPA->_int;
474 HANDLE_OPCODE(OP_STORE_V):
475 OPB->ivector[0] = OPA->ivector[0];
476 OPB->ivector[1] = OPA->ivector[1];
477 OPB->ivector[2] = OPA->ivector[2];
480 HANDLE_OPCODE(OP_STOREP_F):
481 HANDLE_OPCODE(OP_STOREP_ENT):
482 HANDLE_OPCODE(OP_STOREP_FLD): // integers
483 HANDLE_OPCODE(OP_STOREP_FNC): // pointers
484 if ((prvm_uint_t)OPB->_int - cached_entityfields >= cached_entityfieldsarea_entityfields)
486 if ((prvm_uint_t)OPB->_int >= cached_entityfieldsarea)
489 prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
492 if ((prvm_uint_t)OPB->_int < cached_entityfields && !cached_allowworldwrites)
495 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);
498 ptr = (prvm_eval_t *)(cached_edictsfields + OPB->_int);
499 ptr->_int = OPA->_int;
501 HANDLE_OPCODE(OP_STOREP_S):
502 if ((prvm_uint_t)OPB->_int - cached_entityfields >= cached_entityfieldsarea_entityfields)
504 if ((prvm_uint_t)OPB->_int >= cached_entityfieldsarea)
507 prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
510 if ((prvm_uint_t)OPB->_int < cached_entityfields && !cached_allowworldwrites)
513 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);
516 // refresh the garbage collection on the string - this guards
517 // against a certain sort of repeated migration to earlier
518 // points in the scan that could otherwise result in the string
519 // being freed for being unused
520 if(prvm_garbagecollection_enable.integer)
521 PRVM_GetString(prog, OPA->_int);
522 ptr = (prvm_eval_t *)(cached_edictsfields + OPB->_int);
523 ptr->_int = OPA->_int;
525 HANDLE_OPCODE(OP_STOREP_V):
526 if ((prvm_uint_t)OPB->_int - cached_entityfields > (prvm_uint_t)cached_entityfieldsarea_entityfields_3)
528 if ((prvm_uint_t)OPB->_int > cached_entityfieldsarea_3)
531 prog->error_cmd("%s attempted to write to an out of bounds edict (%i)", prog->name, (int)OPB->_int);
534 if ((prvm_uint_t)OPB->_int < cached_entityfields && !cached_allowworldwrites)
537 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);
540 ptr = (prvm_eval_t *)(cached_edictsfields + OPB->_int);
541 ptr->ivector[0] = OPA->ivector[0];
542 ptr->ivector[1] = OPA->ivector[1];
543 ptr->ivector[2] = OPA->ivector[2];
546 HANDLE_OPCODE(OP_ADDRESS):
547 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
550 prog->error_cmd("%s Progs attempted to address an out of bounds edict number", prog->name);
553 if ((prvm_uint_t)OPB->_int >= cached_entityfields)
556 prog->error_cmd("%s attempted to address an invalid field (%i) in an edict", prog->name, (int)OPB->_int);
560 if (OPA->edict == 0 && !cached_allowworldwrites)
563 prog->error_cmd("forbidden assignment to null/world entity in %s", prog->name);
567 OPC->_int = OPA->edict * cached_entityfields + OPB->_int;
570 HANDLE_OPCODE(OP_LOAD_F):
571 HANDLE_OPCODE(OP_LOAD_FLD):
572 HANDLE_OPCODE(OP_LOAD_ENT):
573 HANDLE_OPCODE(OP_LOAD_FNC):
574 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
577 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
580 if ((prvm_uint_t)OPB->_int >= cached_entityfields)
583 prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
586 ed = PRVM_PROG_TO_EDICT(OPA->edict);
587 OPC->_int = ((prvm_eval_t *)(ed->fields.ip + OPB->_int))->_int;
589 HANDLE_OPCODE(OP_LOAD_S):
590 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
593 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
596 if ((prvm_uint_t)OPB->_int >= cached_entityfields)
599 prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
602 ed = PRVM_PROG_TO_EDICT(OPA->edict);
603 OPC->_int = ((prvm_eval_t *)(ed->fields.ip + OPB->_int))->_int;
604 // refresh the garbage collection on the string - this guards
605 // against a certain sort of repeated migration to earlier
606 // points in the scan that could otherwise result in the string
607 // being freed for being unused
608 if(prvm_garbagecollection_enable.integer)
609 PRVM_GetString(prog, OPC->_int);
612 HANDLE_OPCODE(OP_LOAD_V):
613 if ((prvm_uint_t)OPA->edict >= cached_max_edicts)
616 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
619 if ((prvm_uint_t)OPB->_int > cached_entityfields_3)
622 prog->error_cmd("%s attempted to read an invalid field in an edict (%i)", prog->name, (int)OPB->_int);
625 ed = PRVM_PROG_TO_EDICT(OPA->edict);
626 ptr = (prvm_eval_t *)(ed->fields.ip + OPB->_int);
627 OPC->ivector[0] = ptr->ivector[0];
628 OPC->ivector[1] = ptr->ivector[1];
629 OPC->ivector[2] = ptr->ivector[2];
634 HANDLE_OPCODE(OP_IFNOT):
635 if(!FLOAT_IS_TRUE_FOR_INT(OPA->_int))
636 // TODO add an "int-if", and change this one to OPA->_float
637 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
638 // and entity, string, field values can never have that value
640 ADVANCE_PROFILE_BEFORE_JUMP();
641 st = cached_statements + st->jumpabsolute - 1; // offset the st++
643 // no bounds check needed, it is done when loading progs
644 if (++jumpcount == 10000000 && prvm_runawaycheck)
646 prog->xstatement = st - cached_statements;
647 PRVM_Profile(prog, 1<<30, 1000000, 0);
648 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
653 HANDLE_OPCODE(OP_IF):
654 if(FLOAT_IS_TRUE_FOR_INT(OPA->_int))
655 // TODO add an "int-if", and change this one, as well as the FLOAT_IS_TRUE_FOR_INT usages, to OPA->_float
656 // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero)
657 // and entity, string, field values can never have that value
659 ADVANCE_PROFILE_BEFORE_JUMP();
660 st = cached_statements + st->jumpabsolute - 1; // offset the st++
662 // no bounds check needed, it is done when loading progs
663 if (++jumpcount == 10000000 && prvm_runawaycheck)
665 prog->xstatement = st - cached_statements;
666 PRVM_Profile(prog, 1<<30, 0.01, 0);
667 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
672 HANDLE_OPCODE(OP_GOTO):
673 ADVANCE_PROFILE_BEFORE_JUMP();
674 st = cached_statements + st->jumpabsolute - 1; // offset the st++
676 // no bounds check needed, it is done when loading progs
677 if (++jumpcount == 10000000 && prvm_runawaycheck)
679 prog->xstatement = st - cached_statements;
680 PRVM_Profile(prog, 1<<30, 0.01, 0);
681 prog->error_cmd("%s runaway loop counter hit limit of %d jumps\ntip: read above for list of most-executed functions", prog->name, jumpcount);
685 HANDLE_OPCODE(OP_CALL0):
686 HANDLE_OPCODE(OP_CALL1):
687 HANDLE_OPCODE(OP_CALL2):
688 HANDLE_OPCODE(OP_CALL3):
689 HANDLE_OPCODE(OP_CALL4):
690 HANDLE_OPCODE(OP_CALL5):
691 HANDLE_OPCODE(OP_CALL6):
692 HANDLE_OPCODE(OP_CALL7):
693 HANDLE_OPCODE(OP_CALL8):
694 #ifdef PRVMTIMEPROFILING
695 tm = Sys_DirtyTime();
696 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
699 ADVANCE_PROFILE_BEFORE_JUMP();
701 prog->xstatement = st - cached_statements;
702 prog->argc = st->op - OP_CALL0;
705 prog->error_cmd("NULL function in %s", prog->name);
708 if(!OPA->function || OPA->function < 0 || OPA->function >= prog->numfunctions)
711 prog->error_cmd("%s CALL outside the program", prog->name);
715 enterfunc = &prog->functions[OPA->function];
716 if (enterfunc->callcount++ == 0 && (prvm_coverage.integer & 1))
717 PRVM_FunctionCoverageEvent(prog, enterfunc);
719 if (enterfunc->first_statement < 0)
721 // negative first_statement values are built in functions
722 int builtinnumber = -enterfunc->first_statement;
723 prog->xfunction->builtinsprofile++;
724 if (builtinnumber < prog->numbuiltins && prog->builtins[builtinnumber])
726 prog->builtins[builtinnumber](prog);
727 #ifdef PRVMTIMEPROFILING
728 tm = Sys_DirtyTime();
729 enterfunc->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
730 prog->xfunction->tbprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
733 // builtins may cause ED_Alloc() to be called, update cached variables
734 cached_edictsfields = prog->edictsfields.fp;
735 cached_entityfields = prog->entityfields;
736 cached_entityfields_3 = prog->entityfields - 3;
737 cached_entityfieldsarea = prog->entityfieldsarea;
738 cached_entityfieldsarea_entityfields = prog->entityfieldsarea - prog->entityfields;
739 cached_entityfieldsarea_3 = prog->entityfieldsarea - 3;
740 cached_entityfieldsarea_entityfields_3 = prog->entityfieldsarea - prog->entityfields - 3;
741 cached_max_edicts = prog->max_edicts;
742 // these do not change
743 //cached_statements = prog->statements;
744 //cached_allowworldwrites = prog->allowworldwrites;
745 //cached_flag = prog->flag;
746 // if prog->trace changed we need to change interpreter path
747 if (prog->trace != cachedpr_trace)
748 goto chooseexecprogram;
751 prog->error_cmd("No such builtin #%i in %s; most likely cause: outdated engine build. Try updating!", builtinnumber, prog->name);
754 st = cached_statements + PRVM_EnterFunction(prog, enterfunc);
758 HANDLE_OPCODE(OP_DONE):
759 HANDLE_OPCODE(OP_RETURN):
760 #ifdef PRVMTIMEPROFILING
761 tm = Sys_DirtyTime();
762 prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0;
765 ADVANCE_PROFILE_BEFORE_JUMP();
766 prog->xstatement = st - cached_statements;
768 prog->globals.ip[OFS_RETURN ] = prog->globals.ip[st->operand[0] ];
769 prog->globals.ip[OFS_RETURN+1] = prog->globals.ip[st->operand[0]+1];
770 prog->globals.ip[OFS_RETURN+2] = prog->globals.ip[st->operand[0]+2];
772 st = cached_statements + PRVM_LeaveFunction(prog);
774 if (prog->depth <= exitdepth)
775 goto cleanup; // all done
778 HANDLE_OPCODE(OP_STATE):
779 if(cached_flag & PRVM_OP_STATE)
781 ed = PRVM_PROG_TO_EDICT(PRVM_gameglobaledict(self));
782 PRVM_gameedictfloat(ed,nextthink) = PRVM_gameglobalfloat(time) + 0.1;
783 PRVM_gameedictfloat(ed,frame) = OPA->_float;
784 PRVM_gameedictfunction(ed,think) = OPB->function;
789 prog->xstatement = st - cached_statements;
790 prog->error_cmd("OP_STATE not supported by %s", prog->name);
794 HANDLE_OPCODE(OP_ADD_I):
795 OPC->_int = OPA->_int + OPB->_int;
797 HANDLE_OPCODE(OP_ADD_IF):
798 OPC->_float = OPA->_int + (prvm_int_t) OPB->_float;
800 HANDLE_OPCODE(OP_ADD_FI):
801 OPC->_float = OPA->_float + (prvm_vec_t) OPB->_int;
803 HANDLE_OPCODE(OP_SUB_I):
804 OPC->_int = OPA->_int - OPB->_int;
806 HANDLE_OPCODE(OP_SUB_IF):
807 OPC->_float = OPA->_int - (prvm_int_t) OPB->_float;
809 HANDLE_OPCODE(OP_SUB_FI):
810 OPC->_float = OPA->_float - (prvm_vec_t) OPB->_int;
812 HANDLE_OPCODE(OP_MUL_I):
813 OPC->_int = OPA->_int * OPB->_int;
815 HANDLE_OPCODE(OP_MUL_IF):
816 OPC->_float = OPA->_int * (prvm_int_t) OPB->_float;
818 HANDLE_OPCODE(OP_MUL_FI):
819 OPC->_float = OPA->_float * (prvm_vec_t) OPB->_int;
821 HANDLE_OPCODE(OP_MUL_VI):
822 OPC->vector[0] = (prvm_vec_t) OPB->_int * OPA->vector[0];
823 OPC->vector[1] = (prvm_vec_t) OPB->_int * OPA->vector[1];
824 OPC->vector[2] = (prvm_vec_t) OPB->_int * OPA->vector[2];
826 HANDLE_OPCODE(OP_DIV_VF):
828 float temp = 1.0f / OPB->_float;
829 OPC->vector[0] = temp * OPA->vector[0];
830 OPC->vector[1] = temp * OPA->vector[1];
831 OPC->vector[2] = temp * OPA->vector[2];
834 HANDLE_OPCODE(OP_DIV_I):
835 OPC->_int = OPA->_int / OPB->_int;
837 HANDLE_OPCODE(OP_DIV_IF):
838 OPC->_float = OPA->_int / (prvm_int_t) OPB->_float;
840 HANDLE_OPCODE(OP_DIV_FI):
841 OPC->_float = OPA->_float / (prvm_vec_t) OPB->_int;
843 HANDLE_OPCODE(OP_CONV_IF):
844 OPC->_float = OPA->_int;
846 HANDLE_OPCODE(OP_CONV_FI):
847 OPC->_int = OPA->_float;
849 HANDLE_OPCODE(OP_BITAND_I):
850 OPC->_int = OPA->_int & OPB->_int;
852 HANDLE_OPCODE(OP_BITOR_I):
853 OPC->_int = OPA->_int | OPB->_int;
855 HANDLE_OPCODE(OP_BITAND_IF):
856 OPC->_int = OPA->_int & (prvm_int_t)OPB->_float;
858 HANDLE_OPCODE(OP_BITOR_IF):
859 OPC->_int = OPA->_int | (prvm_int_t)OPB->_float;
861 HANDLE_OPCODE(OP_BITAND_FI):
862 OPC->_int = (prvm_int_t)OPA->_float & OPB->_int;
864 HANDLE_OPCODE(OP_BITOR_FI):
865 OPC->_int = (prvm_int_t)OPA->_float | OPB->_int;
867 HANDLE_OPCODE(OP_GE_I):
868 OPC->_int = OPA->_int >= OPB->_int;
870 HANDLE_OPCODE(OP_LE_I):
871 OPC->_int = OPA->_int <= OPB->_int;
873 HANDLE_OPCODE(OP_GT_I):
874 OPC->_int = OPA->_int > OPB->_int;
876 HANDLE_OPCODE(OP_LT_I):
877 OPC->_int = OPA->_int < OPB->_int;
879 HANDLE_OPCODE(OP_AND_I):
880 OPC->_int = OPA->_int && OPB->_int;
882 HANDLE_OPCODE(OP_OR_I):
883 OPC->_int = OPA->_int || OPB->_int;
885 HANDLE_OPCODE(OP_GE_IF):
886 OPC->_int = (prvm_vec_t)OPA->_int >= OPB->_float;
888 HANDLE_OPCODE(OP_LE_IF):
889 OPC->_int = (prvm_vec_t)OPA->_int <= OPB->_float;
891 HANDLE_OPCODE(OP_GT_IF):
892 OPC->_int = (prvm_vec_t)OPA->_int > OPB->_float;
894 HANDLE_OPCODE(OP_LT_IF):
895 OPC->_int = (prvm_vec_t)OPA->_int < OPB->_float;
897 HANDLE_OPCODE(OP_AND_IF):
898 OPC->_int = (prvm_vec_t)OPA->_int && OPB->_float;
900 HANDLE_OPCODE(OP_OR_IF):
901 OPC->_int = (prvm_vec_t)OPA->_int || OPB->_float;
903 HANDLE_OPCODE(OP_GE_FI):
904 OPC->_int = OPA->_float >= (prvm_vec_t)OPB->_int;
906 HANDLE_OPCODE(OP_LE_FI):
907 OPC->_int = OPA->_float <= (prvm_vec_t)OPB->_int;
909 HANDLE_OPCODE(OP_GT_FI):
910 OPC->_int = OPA->_float > (prvm_vec_t)OPB->_int;
912 HANDLE_OPCODE(OP_LT_FI):
913 OPC->_int = OPA->_float < (prvm_vec_t)OPB->_int;
915 HANDLE_OPCODE(OP_AND_FI):
916 OPC->_int = OPA->_float && (prvm_vec_t)OPB->_int;
918 HANDLE_OPCODE(OP_OR_FI):
919 OPC->_int = OPA->_float || (prvm_vec_t)OPB->_int;
921 HANDLE_OPCODE(OP_NOT_I):
922 OPC->_int = !OPA->_int;
924 HANDLE_OPCODE(OP_EQ_I):
925 OPC->_int = OPA->_int == OPB->_int;
927 HANDLE_OPCODE(OP_EQ_IF):
928 OPC->_int = (prvm_vec_t)OPA->_int == OPB->_float;
930 HANDLE_OPCODE(OP_EQ_FI):
931 OPC->_int = OPA->_float == (prvm_vec_t)OPB->_int;
933 HANDLE_OPCODE(OP_NE_I):
934 OPC->_int = OPA->_int != OPB->_int;
936 HANDLE_OPCODE(OP_NE_IF):
937 OPC->_int = (prvm_vec_t)OPA->_int != OPB->_float;
939 HANDLE_OPCODE(OP_NE_FI):
940 OPC->_int = OPA->_float != (prvm_vec_t)OPB->_int;
942 HANDLE_OPCODE(OP_STORE_I):
943 HANDLE_OPCODE(OP_STORE_P):
944 OPB->_int = OPA->_int;
946 HANDLE_OPCODE(OP_STOREP_I):
948 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
951 prog->error_cmd("%s Progs attempted to write to an out of bounds edict", prog->name);
955 ptr = (prvm_eval_t *)(prog->edictsfields.ip + OPB->_int);
956 ptr->_int = OPA->_int;
958 HANDLE_OPCODE(OP_LOAD_I):
960 if (OPA->edict < 0 || OPA->edict >= prog->max_edicts)
963 prog->error_cmd("%s Progs attempted to read an out of bounds edict number", prog->name);
966 if (OPB->_int < 0 || OPB->_int >= progs->entityfields.ip)
969 prog->error_cmd("%s Progs attempted to read an invalid field in an edict", prog->name);
973 ed = PRVM_PROG_TO_EDICT(OPA->edict);
974 OPC->_int = ((prvm_eval_t *)((int *)ed->fields.ip + OPB->_int))->_int;
977 HANDLE_OPCODE(OP_GSTOREP_I):
978 HANDLE_OPCODE(OP_GSTOREP_F):
979 HANDLE_OPCODE(OP_GSTOREP_ENT):
980 HANDLE_OPCODE(OP_GSTOREP_FLD): // integers
981 HANDLE_OPCODE(OP_GSTOREP_S):
982 HANDLE_OPCODE(OP_GSTOREP_FNC): // pointers
983 if (OPB->_int < 0 || OPB->_int >= prog->numglobals)
986 prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name);
989 prog->globals.ip[OPB->_int] = OPA->_int;
991 HANDLE_OPCODE(OP_GSTOREP_V):
992 if (OPB->_int < 0 || OPB->_int + 2 >= prog->numglobaldefs)
995 prog->error_cmd("%s Progs attempted to write to an invalid indexed global", prog->name);
998 prog->globals.ip[OPB->_int ] = OPA->ivector[0];
999 prog->globals.ip[OPB->_int+1] = OPA->ivector[1];
1000 prog->globals.ip[OPB->_int+2] = OPA->ivector[2];
1003 HANDLE_OPCODE(OP_GADDRESS):
1004 i = OPA->_int + (prvm_int_t) OPB->_float;
1005 if (i < 0 || i >= prog->numglobaldefs)
1008 prog->error_cmd("%s Progs attempted to address an out of bounds global", prog->name);
1011 OPC->_int = prog->globals.ip[i];
1014 HANDLE_OPCODE(OP_GLOAD_I):
1015 HANDLE_OPCODE(OP_GLOAD_F):
1016 HANDLE_OPCODE(OP_GLOAD_FLD):
1017 HANDLE_OPCODE(OP_GLOAD_ENT):
1018 HANDLE_OPCODE(OP_GLOAD_S):
1019 HANDLE_OPCODE(OP_GLOAD_FNC):
1020 // FIXME?: Is this correct? vvvvvvvvvvvvv
1021 if (OPA->_int < 0 || OPA->_int >= prog->numglobaldefs)
1024 prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name);
1027 OPC->_int = prog->globals.ip[OPA->_int];
1030 HANDLE_OPCODE(OP_GLOAD_V):
1031 // FIXME?: Is this correct? vvvvvvvvvvvvv
1032 if (OPA->_int < 0 || OPA->_int + 2 >= prog->numglobaldefs)
1035 prog->error_cmd("%s Progs attempted to read an invalid indexed global", prog->name);
1038 OPC->ivector[0] = prog->globals.ip[OPA->_int ];
1039 OPC->ivector[1] = prog->globals.ip[OPA->_int+1];
1040 OPC->ivector[2] = prog->globals.ip[OPA->_int+2];
1043 HANDLE_OPCODE(OP_BOUNDCHECK):
1044 if (OPA->_int < 0 || OPA->_int >= OPB->_int)
1047 prog->error_cmd("%s Progs boundcheck failed at line number %d, value is < 0 or >= %d", prog->name, OPB->_int, OPC->_int);
1052 #if !USE_COMPUTED_GOTOS
1055 prog->error_cmd("Bad opcode %i in %s", st->op, prog->name);
1058 #if PRVMSLOWINTERPRETER
1060 if (prog->watch_global_type != ev_void)
1062 prvm_eval_t *g = PRVM_GLOBALFIELDVALUE(prog->watch_global);
1063 prog->xstatement = st - cached_statements;
1064 PRVM_Watchpoint(prog, 0, "Global watchpoint hit", prog->watch_global_type, &prog->watch_global_value, g);
1066 if (prog->watch_field_type != ev_void && prog->watch_edict < prog->max_edicts)
1068 prvm_eval_t *g = PRVM_EDICTFIELDVALUE(prog->edicts + prog->watch_edict, prog->watch_field);
1069 prog->xstatement = st - cached_statements;
1070 PRVM_Watchpoint(prog, 0, "Entityfield watchpoint hit", prog->watch_field_type, &prog->watch_edictfield_value, g);
1075 #endif // !USE_COMPUTED_GOTOS
1077 #undef DISPATCH_OPCODE
1078 #undef HANDLE_OPCODE
1079 #undef USE_COMPUTED_GOTOS
1081 #undef ADVANCE_PROFILE_BEFORE_JUMP