Skip to content

Commit

Permalink
Add opcodes for uint and bit shifting.
Browse files Browse the repository at this point in the history
- OP_RSHIFT_I
- OP_LSHIFT_I
- OP_LE_U
- OP_LT_U
- OP_DIV_U
- OP_RSHIFT_U

For all other ops FTEQCC emits the _I operations; this is technically
broken but meh. Compile DP with `-fwrapv` if you care.
  • Loading branch information
divVerent committed Jan 3, 2025
1 parent 1059745 commit 765a1ae
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 5 deletions.
6 changes: 6 additions & 0 deletions prvm_edict.c
Original file line number Diff line number Diff line change
Expand Up @@ -2443,6 +2443,12 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char *filename, unsigned char *data
case OP_STOREP_FNC:
case OP_STOREP_V:
case OP_STOREP_I:
case OP_RSHIFT_I:
case OP_LSHIFT_I:
case OP_LE_U:
case OP_LT_U:
case OP_DIV_U:
case OP_RSHIFT_U:
if (a >= prog->progs_numglobals || b >= prog->progs_numglobals || c >= prog->progs_numglobals)
prog->error_cmd("%s: out of bounds global index (statement %d)", __func__, i);
prog->statements[i].op = op;
Expand Down
22 changes: 20 additions & 2 deletions prvm_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ NULL,
"DIV_VF",

NULL,
NULL,
NULL,
"RSHIFT_I",
"LSHIFT_I",

"GLOBALADDRESS",
"ADD_PIW",
Expand Down Expand Up @@ -294,6 +294,24 @@ NULL,
NULL,

"GLOAD_V",

NULL,
NULL,

NULL,
NULL,
NULL,
NULL,


NULL,
NULL,


"^2LE_U",
"^2LT_U",
"DIV_U",
"RSHIFT_U",
};


Expand Down
53 changes: 50 additions & 3 deletions prvm_execprogram.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ prvm_eval_t *src;
&&handle_OP_DIV_VF,

NULL,
NULL,
NULL,
&&handle_OP_RSHIFT_I,
&&handle_OP_LSHIFT_I,

&&handle_OP_GLOBALADDRESS,
&&handle_OP_ADD_PIW,
Expand Down Expand Up @@ -287,11 +287,31 @@ prvm_eval_t *src;
&&handle_OP_GLOAD_S,
&&handle_OP_GLOAD_FNC,
&&handle_OP_BOUNDCHECK,

NULL,
NULL,
NULL,
NULL,

&&handle_OP_GLOAD_V,

NULL,
NULL,

NULL,
NULL,
NULL,
NULL,


NULL,
NULL,
&&handle_OP_GLOAD_V


&&handle_OP_LE_U,
&&handle_OP_LT_U,
&&handle_OP_DIV_U,
&&handle_OP_RSHIFT_U,
};
#define DISPATCH_OPCODE() \
goto *dispatchtable[(++st)->op]
Expand Down Expand Up @@ -1207,6 +1227,33 @@ prvm_eval_t *src;
OPC->ivector[1] = ptr->ivector[1];
OPC->ivector[2] = ptr->ivector[2];
DISPATCH_OPCODE();
HANDLE_OPCODE(OP_RSHIFT_I):
OPC->_int = OPA->_int >> OPB->_int;
DISPATCH_OPCODE();
HANDLE_OPCODE(OP_LSHIFT_I):
OPC->_int = OPA->_int << OPB->_int;
DISPATCH_OPCODE();
HANDLE_OPCODE(OP_LE_U):
OPC->_int = (OPA->_uint <= OPB->_uint);
DISPATCH_OPCODE();
HANDLE_OPCODE(OP_LT_U):
OPC->_int = (OPA->_uint < OPB->_uint);
DISPATCH_OPCODE();
HANDLE_OPCODE(OP_DIV_U):
if( OPB->_uint != 0 )
{
OPC->_uint = OPA->_uint / OPB->_uint;
}
else
{
PRE_ERROR();
VM_Warning(prog, "Attempted division of %u by zero\n", OPA->_uint);
OPC->_uint = 0;
}
DISPATCH_OPCODE();
HANDLE_OPCODE(OP_RSHIFT_U):
OPC->_uint = OPA->_uint >> OPB->_uint;
DISPATCH_OPCODE();

#if !USE_COMPUTED_GOTOS
default:
Expand Down

0 comments on commit 765a1ae

Please sign in to comment.