Skip to content

Commit

Permalink
reduced native stack usage ~10%
Browse files Browse the repository at this point in the history
  • Loading branch information
soundandform committed Jan 31, 2020
1 parent f99d76c commit b86dd01
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 9 additions & 2 deletions source/m3_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ d_m3OpDef (Compile)

d_m3OpDef (Entry)
{
d_m3ClearRegisters

IM3Function function = immediate (IM3Function);

#if defined(d_m3SkipStackCheck)
Expand All @@ -196,10 +198,11 @@ d_m3OpDef (Entry)
{
function->hits++; m3log (exec, " enter %p > %s %s", _pc - 2, function->name ? function->name : ".unnamed", SPrintFunctionArgList (function, _sp));

m3stack_t stack = _sp + function->funcType->numArgs;
u32 numLocals = function->numLocals;

m3stack_t stack = _sp + GetFunctionNumArgs (function);
while (numLocals--) // it seems locals need to init to zero (at least for optimized Wasm code) TODO: see if this is still true.
// zero locals
while (numLocals--)
* (stack++) = 0;

if (function->constants) {
Expand Down Expand Up @@ -257,6 +260,10 @@ d_m3OpDef (SetGlobal_i64)

d_m3OpDef (Loop)
{
// regs are unused coming into a loop anyway
// this reduces code size & stack usage
d_m3ClearRegisters

m3ret_t r;

IM3Memory memory = GetMemoryInfo (_mem);
Expand Down
3 changes: 2 additions & 1 deletion source/m3_exec_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ extern "C" {
# define d_m3OpSig pc_t _pc, u64 * _sp, M3MemoryHeader * _mem, m3reg_t _r0, f64 _fp0
# define d_m3OpArgs _sp, _mem, _r0, _fp0
# define d_m3OpAllArgs _pc, _sp, _mem, _r0, _fp0
# define d_m3OpDefaultArgs 666, NAN
# define d_m3OpDefaultArgs 0, 0.
# define d_m3ClearRegisters _r0 = 0; _fp0 = 0.;

# define m3MemData(mem) (u8*)((M3MemoryHeader*)(mem)+1)

Expand Down

0 comments on commit b86dd01

Please sign in to comment.