From 676c2623bec11d94ed6cf0204e87f37c0e020385 Mon Sep 17 00:00:00 2001 From: uis Date: Sat, 11 May 2024 19:59:16 +0300 Subject: [PATCH] Implement bytecode rewriting To make cache happier --- pr_comp.h | 69 +++++++++++- prvm_edict.c | 122 +++++++++++++++------ prvm_exec.c | 50 +++------ prvm_execprogram.h | 261 +++++++++++++++++++-------------------------- 4 files changed, 283 insertions(+), 219 deletions(-) diff --git a/pr_comp.h b/pr_comp.h index d1643b62..98920a1b 100644 --- a/pr_comp.h +++ b/pr_comp.h @@ -122,6 +122,73 @@ typedef enum opcode_e } opcode_t; +typedef enum instruction_e +{ + INS_DONE = 0, + INS_MUL_F, + INS_MUL_V, + //GAP: 1(rewritten) + INS_MUL_VF, + INS_DIV_F, + INS_ADD_F, + INS_ADD_V, + INS_SUB_F, + INS_SUB_V, + + INS_EQ_F, + INS_EQ_V, + INS_EQ_S, + INS_EQ_E, + INS_EQ_FNC, + + INS_NE_F, + INS_NE_V, + INS_NE_S, + INS_NE_E, + INS_NE_FNC, + + INS_LE, + INS_GE, + INS_LT, + INS_GT, + + INS_LOAD_SCALAR, + INS_LOAD_VECTOR, + //GAP: 4(remapped) + + INS_ADDRESS, + + INS_STORE_SCALAR, + INS_STORE_VECTOR, + //GAP: 4(remapped) + + INS_STOREP_SCALAR, + INS_STOREP_VECTOR, + //GAP: 4(remapped) + + //GAP: 1(remapped) + INS_NOT_F, + INS_NOT_V, + INS_NOT_S, + INS_NOT_ENT, + INS_NOT_FNC, + INS_IF, + INS_IFNOT, + INS_CALL,//argc in OPB + //GAP: 8(rewritten) + INS_STATE, + INS_GOTO, + INS_AND, + INS_OR, + + INS_BITAND, + INS_BITOR, + + //SIGILL the VM + INS_ILL, + INSNS +} +instruction_t; typedef struct statement_s { @@ -186,7 +253,7 @@ mfunction_t; typedef struct mstatement_s { - opcode_t op; + instruction_t ins; int operand[3]; // always a global or -1 for unused int jumpabsolute; // only used by IF, IFNOT, GOTO } diff --git a/prvm_edict.c b/prvm_edict.c index 79c937a4..b64567d7 100644 --- a/prvm_edict.c +++ b/prvm_edict.c @@ -2118,6 +2118,7 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, unsigned char * da a = (unsigned short)LittleShort(instatements[i].a); b = (unsigned short)LittleShort(instatements[i].b); c = (unsigned short)LittleShort(instatements[i].c); + d = 0; switch (op) { case OP_IF: @@ -2125,8 +2126,10 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, unsigned char * da b = (short)b; if (a >= prog->progs_numglobals || b + i < 0 || b + i >= prog->progs_numstatements) prog->error_cmd("PRVM_LoadProgs: out of bounds IF/IFNOT (statement %d) in %s", i, prog->name); - prog->statements[i].op = op; + //To be rewritten + prog->statements[i].ins = op - OP_IF + INS_IF; prog->statements[i].operand[0] = remapglobal(a); + //prog->statements[i].operand[1] = OP_IF - op; prog->statements[i].operand[1] = -1; prog->statements[i].operand[2] = -1; prog->statements[i].jumpabsolute = i + b; @@ -2135,7 +2138,7 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, unsigned char * da a = (short)a; if (a + i < 0 || a + i >= prog->progs_numstatements) prog->error_cmd("PRVM_LoadProgs: out of bounds GOTO (statement %d) in %s", i, prog->name); - prog->statements[i].op = op; + prog->statements[i].ins = INS_GOTO; prog->statements[i].operand[0] = -1; prog->statements[i].operand[1] = -1; prog->statements[i].operand[2] = -1; @@ -2143,45 +2146,74 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, unsigned char * da break; default: Con_DPrintf("PRVM_LoadProgs: unknown opcode %d at statement %d in %s\n", (int)op, i, prog->name); + #if 1 + prog->statements[i].ins = INS_ILL; + prog->statements[i].operand[0] = -1; + prog->statements[i].operand[1] = -1; + prog->statements[i].operand[2] = -1; + prog->statements[i].jumpabsolute = -1; break; + #endif // global global global - case OP_ADD_F: - case OP_ADD_V: - case OP_SUB_F: - case OP_SUB_V: - case OP_MUL_F: - case OP_MUL_V: + //rewritten case OP_MUL_FV: - case OP_MUL_VF: - case OP_DIV_F: + if (a >= prog->progs_numglobals || b >= prog->progs_numglobals || c >= prog->progs_numglobals) + prog->error_cmd("PRVM_LoadProgs: out of bounds global index (statement %d)", i); + prog->statements[i].ins = INS_MUL_VF; + prog->statements[i].operand[0] = remapglobal(b); + prog->statements[i].operand[1] = remapglobal(a); + prog->statements[i].operand[2] = remapglobal(c); + prog->statements[i].jumpabsolute = -1; + break; + //remapped + case OP_LOAD_FLD: + case OP_LOAD_ENT: + case OP_LOAD_S: + case OP_LOAD_FNC: + if (a >= prog->progs_numglobals || b >= prog->progs_numglobals || c >= prog->progs_numglobals) + prog->error_cmd("PRVM_LoadProgs: out of bounds global index (statement %d)", i); + prog->statements[i].ins = INS_LOAD_SCALAR; + prog->statements[i].operand[0] = remapglobal(a); + prog->statements[i].operand[1] = remapglobal(b); + prog->statements[i].operand[2] = remapglobal(c); + prog->statements[i].jumpabsolute = -1; + break; + //regular case OP_BITAND: case OP_BITOR: + case OP_AND: + case OP_OR: + d = (OP_AND - INS_AND) - (OP_ADDRESS - INS_ADDRESS); + case OP_ADDRESS: + d += 4;//Skip loads + case OP_LOAD_V://LOAD_VECTOR + case OP_LOAD_F://LOAD_SCALAR case OP_GE: case OP_LE: case OP_GT: case OP_LT: - case OP_AND: - case OP_OR: - case OP_EQ_F: - case OP_EQ_V: - case OP_EQ_S: - case OP_EQ_E: - case OP_EQ_FNC: case OP_NE_F: case OP_NE_V: case OP_NE_S: case OP_NE_E: case OP_NE_FNC: - case OP_ADDRESS: - case OP_LOAD_F: - case OP_LOAD_FLD: - case OP_LOAD_ENT: - case OP_LOAD_S: - case OP_LOAD_FNC: - case OP_LOAD_V: + case OP_EQ_F: + case OP_EQ_V: + case OP_EQ_S: + case OP_EQ_E: + case OP_EQ_FNC: + case OP_ADD_F: + case OP_ADD_V: + case OP_SUB_F: + case OP_SUB_V: + case OP_DIV_F: + case OP_MUL_VF: + d++; + case OP_MUL_V: + case OP_MUL_F: if (a >= prog->progs_numglobals || b >= prog->progs_numglobals || c >= prog->progs_numglobals) prog->error_cmd("PRVM_LoadProgs: out of bounds global index (statement %d)", i); - prog->statements[i].op = op; + prog->statements[i].ins = op - d; prog->statements[i].operand[0] = remapglobal(a); prog->statements[i].operand[1] = remapglobal(b); prog->statements[i].operand[2] = remapglobal(c); @@ -2195,29 +2227,42 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, unsigned char * da case OP_NOT_ENT: if (a >= prog->progs_numglobals || c >= prog->progs_numglobals) prog->error_cmd("PRVM_LoadProgs: out of bounds global index (statement %d) in %s", i, prog->name); - prog->statements[i].op = op; + prog->statements[i].ins = op - OP_NOT_F + INS_NOT_F; prog->statements[i].operand[0] = remapglobal(a); prog->statements[i].operand[1] = -1; prog->statements[i].operand[2] = remapglobal(c); prog->statements[i].jumpabsolute = -1; break; // 2 globals + case OP_STATE: + //d = INS_STATE - INS_STOREP_VECTOR; + //DELETEME + if (a >= prog->progs_numglobals || b >= prog->progs_numglobals) + prog->error_cmd("PRVM_LoadProgs: out of bounds global index (statement %d) in %s", i, prog->name); + prog->statements[i].ins = INS_STATE; + prog->statements[i].operand[0] = remapglobal(a); + prog->statements[i].operand[1] = remapglobal(b); + prog->statements[i].operand[2] = -1; + prog->statements[i].jumpabsolute = -1; + break; + case OP_STOREP_V: + d++; case OP_STOREP_F: case OP_STOREP_ENT: case OP_STOREP_FLD: case OP_STOREP_S: case OP_STOREP_FNC: + d += INS_STOREP_SCALAR - INS_STORE_VECTOR; + case OP_STORE_V: + d++; case OP_STORE_F: case OP_STORE_ENT: case OP_STORE_FLD: case OP_STORE_S: case OP_STORE_FNC: - case OP_STATE: - case OP_STOREP_V: - case OP_STORE_V: if (a >= prog->progs_numglobals || b >= prog->progs_numglobals) prog->error_cmd("PRVM_LoadProgs: out of bounds global index (statement %d) in %s", i, prog->name); - prog->statements[i].op = op; + prog->statements[i].ins = INS_STORE_SCALAR + d; prog->statements[i].operand[0] = remapglobal(a); prog->statements[i].operand[1] = remapglobal(b); prog->statements[i].operand[2] = -1; @@ -2238,11 +2283,19 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, unsigned char * da case OP_CALL6: case OP_CALL7: case OP_CALL8: + if ( a >= prog->progs_numglobals) + prog->error_cmd("PRVM_LoadProgs: out of bounds global index (statement %d) in %s", i, prog->name); + prog->statements[i].ins = INS_CALL; + prog->statements[i].operand[0] = remapglobal(a); + prog->statements[i].operand[1] = op - OP_CALL0;//argc + prog->statements[i].operand[2] = -1; + prog->statements[i].jumpabsolute = -1; + break; case OP_DONE: case OP_RETURN: if ( a >= prog->progs_numglobals) prog->error_cmd("PRVM_LoadProgs: out of bounds global index (statement %d) in %s", i, prog->name); - prog->statements[i].op = op; + prog->statements[i].ins = INS_DONE; prog->statements[i].operand[0] = remapglobal(a); prog->statements[i].operand[1] = -1; prog->statements[i].operand[2] = -1; @@ -2254,11 +2307,10 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, unsigned char * da { prog->error_cmd("PRVM_LoadProgs: empty program in %s", prog->name); } - else switch(prog->statements[prog->numstatements - 1].op) + else switch(prog->statements[prog->numstatements - 1].ins) { - case OP_RETURN: - case OP_GOTO: - case OP_DONE: + case INS_GOTO: + case INS_DONE: break; default: prog->error_cmd("PRVM_LoadProgs: program may fall off the edge (does not end with RETURN, GOTO or DONE) in %s", prog->name); diff --git a/prvm_exec.c b/prvm_exec.c index 37daaaa2..ebef1d4d 100644 --- a/prvm_exec.c +++ b/prvm_exec.c @@ -27,7 +27,7 @@ const char *prvm_opnames[] = "MUL_F", "MUL_V", -"MUL_FV", +//1 "MUL_VF", "DIV", @@ -55,30 +55,21 @@ const char *prvm_opnames[] = "^2LT", "^2GT", -"^6FIELD_F", -"^6FIELD_V", -"^6FIELD_S", -"^6FIELD_ENT", -"^6FIELD_FLD", -"^6FIELD_FNC", +"^6FIELD_SCALAR", +"^6FIELD_VECTOR", +//4 "^1ADDRESS", -"STORE_F", -"STORE_V", -"STORE_S", -"STORE_ENT", -"STORE_FLD", -"STORE_FNC", +"STORE_SCALAR", +"STORE_VECTOR", +//4 -"^1STOREP_F", -"^1STOREP_V", -"^1STOREP_S", -"^1STOREP_ENT", -"^1STOREP_FLD", -"^1STOREP_FNC", +"^1STOREP_SCALAR", +"^1STOREP_VECTOR", +//4 -"^5RETURN", +//1 "^2NOT_F", "^2NOT_V", @@ -89,15 +80,8 @@ const char *prvm_opnames[] = "^5IF", "^5IFNOT", -"^3CALL0", -"^3CALL1", -"^3CALL2", -"^3CALL3", -"^3CALL4", -"^3CALL5", -"^3CALL6", -"^3CALL7", -"^3CALL8", +"^3CALL", +//8 "^1STATE", @@ -140,12 +124,12 @@ static void PRVM_PrintStatement(prvm_prog_t *prog, mstatement_t *s) if (prvm_statementprofiling.integer) Con_Printf("%7.0f ", prog->statement_profile[s - prog->statements]); - if ( (unsigned)s->op < sizeof(prvm_opnames)/sizeof(prvm_opnames[0])) + if ( (unsigned)s->ins < sizeof(prvm_opnames)/sizeof(prvm_opnames[0])) { - Con_Printf("%s ", prvm_opnames[s->op]); - i = strlen(prvm_opnames[s->op]); + Con_Printf("%s ", prvm_opnames[s->ins]); + i = strlen(prvm_opnames[s->ins]); // don't count a preceding color tag when padding the name - if (prvm_opnames[s->op][0] == STRING_COLOR_TAG) + if (prvm_opnames[s->ins][0] == STRING_COLOR_TAG) i -= 2; for ( ; i<10 ; i++) Con_Print(" "); diff --git a/prvm_execprogram.h b/prvm_execprogram.h index 6578d789..55e7952e 100644 --- a/prvm_execprogram.h +++ b/prvm_execprogram.h @@ -33,87 +33,72 @@ # define USE_COMPUTED_GOTOS 1 #endif + #if USE_COMPUTED_GOTOS // Must exactly match opcode_e enum in pr_comp.h const static void *dispatchtable[] = { - &&handle_OP_DONE, - &&handle_OP_MUL_F, - &&handle_OP_MUL_V, - &&handle_OP_MUL_FV, - &&handle_OP_MUL_VF, - &&handle_OP_DIV_F, - &&handle_OP_ADD_F, - &&handle_OP_ADD_V, - &&handle_OP_SUB_F, - &&handle_OP_SUB_V, - - &&handle_OP_EQ_F, - &&handle_OP_EQ_V, - &&handle_OP_EQ_S, - &&handle_OP_EQ_E, - &&handle_OP_EQ_FNC, - - &&handle_OP_NE_F, - &&handle_OP_NE_V, - &&handle_OP_NE_S, - &&handle_OP_NE_E, - &&handle_OP_NE_FNC, - - &&handle_OP_LE, - &&handle_OP_GE, - &&handle_OP_LT, - &&handle_OP_GT, - - &&handle_OP_LOAD_F, - &&handle_OP_LOAD_V, - &&handle_OP_LOAD_S, - &&handle_OP_LOAD_ENT, - &&handle_OP_LOAD_FLD, - &&handle_OP_LOAD_FNC, - - &&handle_OP_ADDRESS, - - &&handle_OP_STORE_F, - &&handle_OP_STORE_V, - &&handle_OP_STORE_S, - &&handle_OP_STORE_ENT, - &&handle_OP_STORE_FLD, - &&handle_OP_STORE_FNC, - - &&handle_OP_STOREP_F, - &&handle_OP_STOREP_V, - &&handle_OP_STOREP_S, - &&handle_OP_STOREP_ENT, - &&handle_OP_STOREP_FLD, - &&handle_OP_STOREP_FNC, - - &&handle_OP_RETURN, - &&handle_OP_NOT_F, - &&handle_OP_NOT_V, - &&handle_OP_NOT_S, - &&handle_OP_NOT_ENT, - &&handle_OP_NOT_FNC, - &&handle_OP_IF, - &&handle_OP_IFNOT, - &&handle_OP_CALL0, - &&handle_OP_CALL1, - &&handle_OP_CALL2, - &&handle_OP_CALL3, - &&handle_OP_CALL4, - &&handle_OP_CALL5, - &&handle_OP_CALL6, - &&handle_OP_CALL7, - &&handle_OP_CALL8, - &&handle_OP_STATE, - &&handle_OP_GOTO, - &&handle_OP_AND, - &&handle_OP_OR, - - &&handle_OP_BITAND, - &&handle_OP_BITOR + &&handle_INS_DONE, + &&handle_INS_MUL_F, + &&handle_INS_MUL_V, + #if 0 + NULL, + #endif + &&handle_INS_MUL_VF, + &&handle_INS_DIV_F, + &&handle_INS_ADD_F, + &&handle_INS_ADD_V, + &&handle_INS_SUB_F, + &&handle_INS_SUB_V, + + &&handle_INS_EQ_F, + &&handle_INS_EQ_V, + &&handle_INS_EQ_S, + &&handle_INS_EQ_E, + &&handle_INS_EQ_FNC, + + &&handle_INS_NE_F, + &&handle_INS_NE_V, + &&handle_INS_NE_S, + &&handle_INS_NE_E, + &&handle_INS_NE_FNC, + + &&handle_INS_LE, + &&handle_INS_GE, + &&handle_INS_LT, + &&handle_INS_GT, + + &&handle_INS_LOAD_SCALAR, + &&handle_INS_LOAD_VECTOR, + + &&handle_INS_ADDRESS, + + &&handle_INS_STORE_SCALAR, + &&handle_INS_STORE_VECTOR, + + &&handle_INS_STOREP_SCALAR, + &&handle_INS_STOREP_VECTOR, + + &&handle_INS_NOT_F, + &&handle_INS_NOT_V, + &&handle_INS_NOT_S, + &&handle_INS_NOT_ENT, + &&handle_INS_NOT_FNC, + &&handle_INS_IF, + &&handle_INS_IFNOT, + &&handle_INS_CALL, + + &&handle_INS_STATE, + &&handle_INS_GOTO, + &&handle_INS_AND, + &&handle_INS_OR, + + &&handle_INS_BITAND, + &&handle_INS_BITOR, + + &&handle_INS_ILL }; #define DISPATCH_OPCODE() \ - goto *dispatchtable[(++st)->op] + goto *dispatchtable[(++st)->ins] #define HANDLE_OPCODE(opcode) handle_##opcode DISPATCH_OPCODE(); // jump to first opcode @@ -155,44 +140,38 @@ PRVM_Breakpoint(prog, prog->break_stack_index, "Breakpoint hit"); } #endif - switch (st->op) + switch (st->ins) { #endif - HANDLE_OPCODE(OP_ADD_F): + HANDLE_OPCODE(INS_ADD_F): OPC->_float = OPA->_float + OPB->_float; DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_ADD_V): + HANDLE_OPCODE(INS_ADD_V): OPC->vector[0] = OPA->vector[0] + OPB->vector[0]; OPC->vector[1] = OPA->vector[1] + OPB->vector[1]; OPC->vector[2] = OPA->vector[2] + OPB->vector[2]; DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_SUB_F): + HANDLE_OPCODE(INS_SUB_F): OPC->_float = OPA->_float - OPB->_float; DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_SUB_V): + HANDLE_OPCODE(INS_SUB_V): OPC->vector[0] = OPA->vector[0] - OPB->vector[0]; OPC->vector[1] = OPA->vector[1] - OPB->vector[1]; OPC->vector[2] = OPA->vector[2] - OPB->vector[2]; DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_MUL_F): + HANDLE_OPCODE(INS_MUL_F): OPC->_float = OPA->_float * OPB->_float; DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_MUL_V): + HANDLE_OPCODE(INS_MUL_V): OPC->_float = OPA->vector[0]*OPB->vector[0] + OPA->vector[1]*OPB->vector[1] + OPA->vector[2]*OPB->vector[2]; DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_MUL_FV): - tempfloat = OPA->_float; - OPC->vector[0] = tempfloat * OPB->vector[0]; - OPC->vector[1] = tempfloat * OPB->vector[1]; - OPC->vector[2] = tempfloat * OPB->vector[2]; - DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_MUL_VF): + HANDLE_OPCODE(INS_MUL_VF): tempfloat = OPB->_float; OPC->vector[0] = tempfloat * OPA->vector[0]; OPC->vector[1] = tempfloat * OPA->vector[1]; OPC->vector[2] = tempfloat * OPA->vector[2]; DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_DIV_F): + HANDLE_OPCODE(INS_DIV_F): if( OPB->_float != 0.0f ) { OPC->_float = OPA->_float / OPB->_float; @@ -207,95 +186,87 @@ OPC->_float = 0.0f; } DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_BITAND): + HANDLE_OPCODE(INS_BITAND): OPC->_float = (prvm_int_t)OPA->_float & (prvm_int_t)OPB->_float; DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_BITOR): + HANDLE_OPCODE(INS_BITOR): OPC->_float = (prvm_int_t)OPA->_float | (prvm_int_t)OPB->_float; DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_GE): + HANDLE_OPCODE(INS_GE): OPC->_float = OPA->_float >= OPB->_float; DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_LE): + HANDLE_OPCODE(INS_LE): OPC->_float = OPA->_float <= OPB->_float; DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_GT): + HANDLE_OPCODE(INS_GT): OPC->_float = OPA->_float > OPB->_float; DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_LT): + HANDLE_OPCODE(INS_LT): OPC->_float = OPA->_float < OPB->_float; DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_AND): + HANDLE_OPCODE(INS_AND): 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 DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_OR): + HANDLE_OPCODE(INS_OR): 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 DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_NOT_F): + HANDLE_OPCODE(INS_NOT_F): OPC->_float = !FLOAT_IS_TRUE_FOR_INT(OPA->_int); DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_NOT_V): + HANDLE_OPCODE(INS_NOT_V): OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2]; DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_NOT_S): + HANDLE_OPCODE(INS_NOT_S): OPC->_float = !OPA->string || !*PRVM_GetString(prog, OPA->string); DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_NOT_FNC): + HANDLE_OPCODE(INS_NOT_FNC): OPC->_float = !OPA->function; DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_NOT_ENT): + HANDLE_OPCODE(INS_NOT_ENT): OPC->_float = (OPA->edict == 0); DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_EQ_F): + HANDLE_OPCODE(INS_EQ_F): OPC->_float = OPA->_float == OPB->_float; DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_EQ_V): + HANDLE_OPCODE(INS_EQ_V): OPC->_float = (OPA->vector[0] == OPB->vector[0]) && (OPA->vector[1] == OPB->vector[1]) && (OPA->vector[2] == OPB->vector[2]); DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_EQ_S): + HANDLE_OPCODE(INS_EQ_S): OPC->_float = !strcmp(PRVM_GetString(prog, OPA->string),PRVM_GetString(prog, OPB->string)); DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_EQ_E): + HANDLE_OPCODE(INS_EQ_E): OPC->_float = OPA->_int == OPB->_int; DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_EQ_FNC): + HANDLE_OPCODE(INS_EQ_FNC): OPC->_float = OPA->function == OPB->function; DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_NE_F): + HANDLE_OPCODE(INS_NE_F): OPC->_float = OPA->_float != OPB->_float; DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_NE_V): + HANDLE_OPCODE(INS_NE_V): OPC->_float = (OPA->vector[0] != OPB->vector[0]) || (OPA->vector[1] != OPB->vector[1]) || (OPA->vector[2] != OPB->vector[2]); DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_NE_S): + HANDLE_OPCODE(INS_NE_S): OPC->_float = strcmp(PRVM_GetString(prog, OPA->string),PRVM_GetString(prog, OPB->string)); DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_NE_E): + HANDLE_OPCODE(INS_NE_E): OPC->_float = OPA->_int != OPB->_int; DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_NE_FNC): + HANDLE_OPCODE(INS_NE_FNC): OPC->_float = OPA->function != OPB->function; DISPATCH_OPCODE(); //================== - HANDLE_OPCODE(OP_STORE_F): - HANDLE_OPCODE(OP_STORE_ENT): - HANDLE_OPCODE(OP_STORE_FLD): // integers - HANDLE_OPCODE(OP_STORE_S): - HANDLE_OPCODE(OP_STORE_FNC): // pointers + HANDLE_OPCODE(INS_STORE_SCALAR): OPB->_int = OPA->_int; DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_STORE_V): + HANDLE_OPCODE(INS_STORE_VECTOR): OPB->ivector[0] = OPA->ivector[0]; OPB->ivector[1] = OPA->ivector[1]; OPB->ivector[2] = OPA->ivector[2]; DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_STOREP_F): - HANDLE_OPCODE(OP_STOREP_ENT): - HANDLE_OPCODE(OP_STOREP_FLD): // integers - HANDLE_OPCODE(OP_STOREP_S): - HANDLE_OPCODE(OP_STOREP_FNC): // pointers + HANDLE_OPCODE(INS_STOREP_SCALAR): if ((prvm_uint_t)OPB->_int - cached_entityfields >= cached_entityfieldsarea_entityfields) { if ((prvm_uint_t)OPB->_int >= cached_entityfieldsarea) @@ -313,7 +284,7 @@ ptr = (prvm_eval_t *)(cached_edictsfields + OPB->_int); ptr->_int = OPA->_int; DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_STOREP_V): + HANDLE_OPCODE(INS_STOREP_VECTOR): if ((prvm_uint_t)OPB->_int - cached_entityfields > (prvm_uint_t)cached_entityfieldsarea_entityfields_3) { if ((prvm_uint_t)OPB->_int > cached_entityfieldsarea_3) @@ -334,7 +305,7 @@ ptr->ivector[2] = OPA->ivector[2]; DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_ADDRESS): + HANDLE_OPCODE(INS_ADDRESS): if ((prvm_uint_t)OPA->edict >= cached_max_edicts) { PRE_ERROR(); @@ -358,11 +329,7 @@ OPC->_int = OPA->edict * cached_entityfields + OPB->_int; DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_LOAD_F): - HANDLE_OPCODE(OP_LOAD_FLD): - HANDLE_OPCODE(OP_LOAD_ENT): - HANDLE_OPCODE(OP_LOAD_S): - HANDLE_OPCODE(OP_LOAD_FNC): + HANDLE_OPCODE(INS_LOAD_SCALAR): if ((prvm_uint_t)OPA->edict >= cached_max_edicts) { PRE_ERROR(); @@ -379,7 +346,7 @@ OPC->_int = ((prvm_eval_t *)(ed->fields.ip + OPB->_int))->_int; DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_LOAD_V): + HANDLE_OPCODE(INS_LOAD_VECTOR): if ((prvm_uint_t)OPA->edict >= cached_max_edicts) { PRE_ERROR(); @@ -401,7 +368,7 @@ //================== - HANDLE_OPCODE(OP_IFNOT): + HANDLE_OPCODE(INS_IFNOT): if(!FLOAT_IS_TRUE_FOR_INT(OPA->_int)) // TODO add an "int-if", and change this one to OPA->_float // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero) @@ -420,7 +387,7 @@ } DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_IF): + HANDLE_OPCODE(INS_IF): if(FLOAT_IS_TRUE_FOR_INT(OPA->_int)) // TODO add an "int-if", and change this one, as well as the FLOAT_IS_TRUE_FOR_INT usages, to OPA->_float // although mostly unneeded, thanks to the only float being false being 0x0 and 0x80000000 (negative zero) @@ -439,7 +406,7 @@ } DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_GOTO): + HANDLE_OPCODE(INS_GOTO): ADVANCE_PROFILE_BEFORE_JUMP(); st = cached_statements + st->jumpabsolute - 1; // offset the st++ startst = st; @@ -452,15 +419,7 @@ } DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_CALL0): - HANDLE_OPCODE(OP_CALL1): - HANDLE_OPCODE(OP_CALL2): - HANDLE_OPCODE(OP_CALL3): - HANDLE_OPCODE(OP_CALL4): - HANDLE_OPCODE(OP_CALL5): - HANDLE_OPCODE(OP_CALL6): - HANDLE_OPCODE(OP_CALL7): - HANDLE_OPCODE(OP_CALL8): + HANDLE_OPCODE(INS_CALL): #ifdef PRVMTIMEPROFILING tm = Sys_DirtyTime(); prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0; @@ -469,7 +428,7 @@ ADVANCE_PROFILE_BEFORE_JUMP(); startst = st; prog->xstatement = st - cached_statements; - prog->argc = st->op - OP_CALL0; + prog->argc = st->operand[1]; if (!OPA->function) { prog->error_cmd("NULL function in %s", prog->name); @@ -525,8 +484,7 @@ startst = st; DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_DONE): - HANDLE_OPCODE(OP_RETURN): + HANDLE_OPCODE(INS_DONE): #ifdef PRVMTIMEPROFILING tm = Sys_DirtyTime(); prog->xfunction->tprofile += (tm - starttm >= 0 && tm - starttm < 1800) ? (tm - starttm) : 0; @@ -545,7 +503,7 @@ goto cleanup; // all done DISPATCH_OPCODE(); - HANDLE_OPCODE(OP_STATE): + HANDLE_OPCODE(INS_STATE): if(cached_flag & PRVM_OP_STATE) { ed = PRVM_PROG_TO_EDICT(PRVM_gameglobaledict(self)); @@ -830,11 +788,14 @@ */ + HANDLE_OPCODE(INS_ILL): #if !USE_COMPUTED_GOTOS default: +#endif PRE_ERROR(); - prog->error_cmd("Bad opcode %i in %s", st->op, prog->name); + prog->error_cmd("Bad opcode %i in %s", st->ins, prog->name); goto cleanup; +#if !USE_COMPUTED_GOTOS } #if PRVMSLOWINTERPRETER { -- 2.39.2