From c1c5785e337226e42213b30ab963b2aeca05d5bf Mon Sep 17 00:00:00 2001 From: uis Date: Mon, 13 May 2024 14:32:39 +0300 Subject: [PATCH] Rewrite LT and GT instructions as modified LE and GE --- pr_comp.h | 3 +-- prvm_edict.c | 23 ++++++++++++++++++----- prvm_exec.c | 2 -- prvm_execprogram.h | 15 ++------------- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/pr_comp.h b/pr_comp.h index 60081bbb..7825f506 100644 --- a/pr_comp.h +++ b/pr_comp.h @@ -149,8 +149,7 @@ typedef enum instruction_e INS_LE, INS_GE, - INS_LT, - INS_GT, + //GAP: 4(rewritten) INS_LOAD_SCALAR, INS_LOAD_VECTOR, diff --git a/prvm_edict.c b/prvm_edict.c index ae9e4243..85a94fcb 100644 --- a/prvm_edict.c +++ b/prvm_edict.c @@ -2126,7 +2126,6 @@ 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); - //To be rewritten prog->statements[i].ins = INS_IF; prog->statements[i].operand[0] = remapglobal(a); prog->statements[i].operand[1] = op - OP_IF; @@ -2177,6 +2176,23 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, unsigned char * da prog->statements[i].operand[2] = remapglobal(c); prog->statements[i].jumpabsolute = -1; break; + case OP_GT: + case OP_LT: + case OP_GE: + case OP_LE: + //TODO: rewrite all float comparasions in one instruction + 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); + if(op == OP_LT) + d = 1; + else if (op == OP_GT) + d = 3; + prog->statements[i].ins = op - OP_LE + INS_LE - d; + 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 = !!d; + break; //regular case OP_BITAND: case OP_BITOR: @@ -2187,10 +2203,7 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, unsigned char * da 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: + d += 2;//Skip LT, GT case OP_NE_F: case OP_NE_V: case OP_NE_S: diff --git a/prvm_exec.c b/prvm_exec.c index 488cb1da..ad5e4c63 100644 --- a/prvm_exec.c +++ b/prvm_exec.c @@ -52,8 +52,6 @@ const char *prvm_opnames[] = "^2LE", "^2GE", -"^2LT", -"^2GT", "^6FIELD_SCALAR", "^6FIELD_VECTOR", diff --git a/prvm_execprogram.h b/prvm_execprogram.h index 95d6da91..f60f74cc 100644 --- a/prvm_execprogram.h +++ b/prvm_execprogram.h @@ -40,9 +40,6 @@ &&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, @@ -64,8 +61,6 @@ &&handle_INS_LE, &&handle_INS_GE, - &&handle_INS_LT, - &&handle_INS_GT, &&handle_INS_LOAD_SCALAR, &&handle_INS_LOAD_VECTOR, @@ -192,16 +187,10 @@ OPC->_float = (prvm_int_t)OPA->_float | (prvm_int_t)OPB->_float; DISPATCH_OPCODE(); HANDLE_OPCODE(INS_GE): - OPC->_float = OPA->_float >= OPB->_float; + OPC->_float = st->jumpabsolute ^ (OPA->_float >= OPB->_float); DISPATCH_OPCODE(); HANDLE_OPCODE(INS_LE): - OPC->_float = OPA->_float <= OPB->_float; - DISPATCH_OPCODE(); - HANDLE_OPCODE(INS_GT): - OPC->_float = OPA->_float > OPB->_float; - DISPATCH_OPCODE(); - HANDLE_OPCODE(INS_LT): - OPC->_float = OPA->_float < OPB->_float; + OPC->_float = st->jumpabsolute ^ (OPA->_float <= OPB->_float); DISPATCH_OPCODE(); 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 -- 2.39.2