From 89e120ba3436f3916822dc09d32001fd53beff14 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 17 Jan 2022 16:54:27 +0900 Subject: [PATCH] [gamecode] Make return support 32 words This took interpreting the lower 5 bits of operand c as size - 1, and 0xffff as void (0 words). --- libs/gamecode/pr_exec.c | 6 +++--- libs/gamecode/test/test-callret.c | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libs/gamecode/pr_exec.c b/libs/gamecode/pr_exec.c index 46d474a7b..90296c153 100644 --- a/libs/gamecode/pr_exec.c +++ b/libs/gamecode/pr_exec.c @@ -3131,9 +3131,9 @@ pr_exec_ruamoko (progs_t *pr, int exitdepth) break; OP_cmp_T (LT, U, long, lvec2, lvec4, <, ulong, ulvec2, ulvec4); case OP_RETURN: - int ret_size = st->c & 0x1f; // up to 32 words - if (ret_size) { - mm = pr_return_mode (pr, st, (st->c >> 5) & 7); + int ret_size = (st->c & 0x1f) + 1; // up to 32 words + if (st->c != 0xffff) { + mm = pr_return_mode (pr, st, st->c >> 5); memcpy (&R_INT (pr), mm, ret_size * sizeof (*op_a)); } pr->pr_xfunction->profile += profile - startprofile; diff --git a/libs/gamecode/test/test-callret.c b/libs/gamecode/test/test-callret.c index 64a597ce7..9bf96fa54 100644 --- a/libs/gamecode/test/test-callret.c +++ b/libs/gamecode/test/test-callret.c @@ -85,7 +85,7 @@ static dstatement_t callret_statements[] = { { OP(2, 2, 2, OP_ADD_F_4), fa, fi, fa }, // f += inc { OP(2, 0, 2, OP_LEA_C), c, -1, c }, // dec count { OP(0, 0, 2, OP_IFA), -7, 0, c }, // count > 0 - { OP(2, 0, 0, OP_RETURN), ac, 0, 4 }, + { OP(2, 0, 0, OP_RETURN), ac, 0, 3 }, // size is (c&31)+1 #undef x #undef xn #undef x2 @@ -132,7 +132,7 @@ static dstatement_t call32_statements[] = { { OP(2, 0, 2, OP_LEA_C), 32, -1, 32 }, { OP(2, 2, 2, OP_STORE_D_1), 33, 32, 32 }, // array[index] = index { OP(0, 0, 0, OP_JUMP_A), -3, 0, 0 }, - { OP(2, 0, 0, OP_RETURN), 0, 0, 32 }, + { OP(2, 0, 0, OP_RETURN), 0, 0, 0x1f }, // only bits 0-5 are size }; static pr_ivec4_t callchain_init[32] = { @@ -152,12 +152,12 @@ static dstatement_t callchain_statements[] = { { OP_LEA_C, STK, -4, STK }, // reserve 4 words on the stack { OP_WITH, 2, 0, 2 }, // put locals into reg 2 { OP(0, 0, 2, OP_CALL_B), 2, 0, 0 }, - { OP(2, 0, 0, OP_RETURN), 0, 0, 1 }, + { OP(2, 0, 0, OP_RETURN), 0, 0, 0 }, [64]= { OP_LEA_C, STK, -4, STK }, // reserve 4 words on the stack { OP_WITH, 2, 0, 2 }, // put locals into reg 2 { OP(0, 0, 2, OP_LEA_A), 42, 0, 0 }, // init value - { OP(2, 0, 0, OP_RETURN), 0, 0, 1 }, // return value + { OP(2, 0, 0, OP_RETURN), 0, 0, 0 }, // return value }; static bfunction_t callret_functions[] = {