]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Rewrite LT and GT instructions as modified LE and GE
authoruis <uis9936@gmail.com>
Mon, 13 May 2024 11:32:39 +0000 (14:32 +0300)
committeruis <uis9936@gmail.com>
Mon, 13 May 2024 14:53:23 +0000 (17:53 +0300)
pr_comp.h
prvm_edict.c
prvm_exec.c
prvm_execprogram.h

index 60081bbb8319efd03008379273a7508c9f075fe7..7825f506e11d44975c885b72040d6081203beade 100644 (file)
--- 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,
index ae9e42435ef2a5242967c0e7323f41aa539d8b31..85a94fcb40746f1d5bd517553b775d28bb788ff1 100644 (file)
@@ -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:
index 488cb1da9c6af98f6c7e357ac7b36e781d3069b7..ad5e4c63efef509f5f0317964db6037f56b214fa 100644 (file)
@@ -52,8 +52,6 @@ const char *prvm_opnames[] =
 
 "^2LE",
 "^2GE",
-"^2LT",
-"^2GT",
 
 "^6FIELD_SCALAR",
 "^6FIELD_VECTOR",
index 95d6da91837c36b0d304e0184a22fad622e779c8..f60f74ccee9c405beb6b5f037c807c14bf47fc9c 100644 (file)
@@ -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,
                                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