From 6ca85d770d471a9212cff42b8981d3222328c052 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 11 Mar 2020 22:48:55 +0900 Subject: [PATCH] [gamecode] Add memset instructions --- include/QF/pr_comp.h | 3 +++ libs/gamecode/pr_exec.c | 23 ++++++++++++++++++++++- libs/gamecode/pr_opcode.c | 10 ++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/include/QF/pr_comp.h b/include/QF/pr_comp.h index 6458d3913..80b9e963d 100644 --- a/include/QF/pr_comp.h +++ b/include/QF/pr_comp.h @@ -395,6 +395,9 @@ typedef enum { OP_MOD_I, OP_MOD_F, OP_MOD_D, + + OP_MEMSET, + OP_MEMSETI, } pr_opcode_e; #define OP_BREAK 0x8000 diff --git a/libs/gamecode/pr_exec.c b/libs/gamecode/pr_exec.c index d673b7d1c..718e2b09a 100644 --- a/libs/gamecode/pr_exec.c +++ b/libs/gamecode/pr_exec.c @@ -404,6 +404,14 @@ check_stack_pointer (progs_t *pr, pointer_t stack, int size) } } +static inline void +pr_memset (pr_type_t *dst, int val, int count) +{ + while (count-- > 0) { + (*dst++).integer_var = val; + } +} + /* PR_ExecuteProgram @@ -1608,7 +1616,20 @@ op_call: pr->pr_globals + OPA.integer_var, st->b * 4); break; - + case OP_MEMSET: + if (pr_boundscheck->int_val) { + PR_BoundsCheckSize (pr, OPC.pointer_var, OPB.uinteger_var); + } + pr_memset (pr->pr_globals + OPC.pointer_var, OPA.integer_var, + OPB.integer_var); + break; + case OP_MEMSETI: + if (pr_boundscheck->int_val) { + PR_BoundsCheckSize (pr, OPC.pointer_var, st->b); + } + pr_memset (pr->pr_globals + OPC.pointer_var, OPA.integer_var, + st->b); + break; case OP_GE_D: OPC.float_var = OPA_double_var >= OPB_double_var; break; diff --git a/libs/gamecode/pr_opcode.c b/libs/gamecode/pr_opcode.c index 853176925..dc3a59fb9 100644 --- a/libs/gamecode/pr_opcode.c +++ b/libs/gamecode/pr_opcode.c @@ -1183,6 +1183,16 @@ VISIBLE const opcode_t pr_opcodes[] = { PROG_VERSION, "%Ga, %Gb, %Gc", }, + {"", "memset", OP_MEMSET, true, + ev_integer, ev_integer, ev_pointer, + PROG_VERSION, + "%Ga, %Gb, %Gc", + }, + {"", "memseti", OP_MEMSETI, true, + ev_integer, ev_short, ev_pointer, + PROG_VERSION, + "%Ga, %Gb, %Gc", + }, {"", "push.s", OP_PUSH_S, false, ev_string, ev_invalid, ev_invalid,