tiny performance tweaks: removing some variables, making some static

This commit is contained in:
JeffBezanson 2009-06-09 18:46:02 +00:00
parent 27a3e413d3
commit 943c0d71d1
2 changed files with 26 additions and 25 deletions

View File

@ -819,12 +819,12 @@ static value_t apply_cl(uint32_t nargs)
uint8_t *code; uint8_t *code;
// temporary variables (not necessary to preserve across calls) // temporary variables (not necessary to preserve across calls)
uint32_t op, envsz; uint32_t op;
int64_t accum;
symbol_t *sym; symbol_t *sym;
cons_t *c; static cons_t *c;
value_t func, v, x, e; static value_t *pv;
value_t *lenv, *pv; static int64_t accum;
static value_t func, v, e;
apply_cl_top: apply_cl_top:
captured = 0; captured = 0;
@ -883,7 +883,7 @@ static value_t apply_cl(uint32_t nargs)
case OP_LVARGC: case OP_LVARGC:
// move extra arguments from list to stack // move extra arguments from list to stack
i = GET_UINT32(code, ip); ip+=4; i = GET_UINT32(code, ip); ip+=4;
x = POP(); // cloenv e = POP(); // cloenv
if (nargs > MAX_ARGS) { if (nargs > MAX_ARGS) {
v = POP(); // list of rest args v = POP(); // list of rest args
nargs--; nargs--;
@ -904,7 +904,7 @@ static value_t apply_cl(uint32_t nargs)
if (iscons(v)) if (iscons(v))
lerror(ArgError, "apply: too many arguments"); lerror(ArgError, "apply: too many arguments");
} }
PUSH(x); PUSH(e);
goto next_op; goto next_op;
case OP_LET: case OP_LET:
// last arg is closure environment to use // last arg is closure environment to use
@ -1396,10 +1396,10 @@ static value_t apply_cl(uint32_t nargs)
assert(nargs > 0); assert(nargs > 0);
i = code[ip++]; i = code[ip++];
if (captured) { if (captured) {
x = Stack[bp]; e = Stack[bp];
assert(isvector(x)); assert(isvector(e));
assert(i < vector_size(x)); assert(i < vector_size(e));
v = vector_elt(x, i); v = vector_elt(e, i);
} }
else { else {
assert(bp+i < SP); assert(bp+i < SP);
@ -1435,10 +1435,10 @@ static value_t apply_cl(uint32_t nargs)
v = Stack[SP-1]; v = Stack[SP-1];
i = code[ip++]; i = code[ip++];
if (captured) { if (captured) {
x = Stack[bp]; e = Stack[bp];
assert(isvector(x)); assert(isvector(e));
assert(i < vector_size(x)); assert(i < vector_size(e));
vector_elt(x, i) = v; vector_elt(e, i) = v;
} }
else { else {
assert(bp+i < SP); assert(bp+i < SP);
@ -1492,14 +1492,15 @@ static value_t apply_cl(uint32_t nargs)
// build a closure (lambda args body . env) // build a closure (lambda args body . env)
if (nargs > 0 && !captured) { if (nargs > 0 && !captured) {
// save temporary environment to the heap // save temporary environment to the heap
lenv = &Stack[bp]; //lenv = &Stack[bp];
envsz = nargs+1; n = nargs;
pv = alloc_words(envsz + 1); pv = alloc_words(n + 2);
PUSH(tagptr(pv, TAG_VECTOR)); PUSH(tagptr(pv, TAG_VECTOR));
pv[0] = fixnum(envsz); pv[0] = fixnum(n+1);
pv++; pv++;
while (envsz--) do {
*pv++ = *lenv++; pv[n] = Stack[bp+n];
} while (n--);
// environment representation changed; install // environment representation changed; install
// the new representation so everybody can see it // the new representation so everybody can see it
captured = 1; captured = 1;
@ -1510,10 +1511,10 @@ static value_t apply_cl(uint32_t nargs)
} }
if (op == OP_CLOSURE) { if (op == OP_CLOSURE) {
pv = alloc_words(4); pv = alloc_words(4);
x = Stack[SP-2]; // closure to copy e = Stack[SP-2]; // closure to copy
assert(isfunction(x)); assert(isfunction(x));
pv[0] = ((value_t*)ptr(x))[0]; pv[0] = ((value_t*)ptr(e))[0];
pv[1] = ((value_t*)ptr(x))[1]; pv[1] = ((value_t*)ptr(e))[1];
pv[2] = Stack[SP-1]; // env pv[2] = Stack[SP-1]; // env
POPN(1); POPN(1);
Stack[SP-1] = tagptr(pv, TAG_FUNCTION); Stack[SP-1] = tagptr(pv, TAG_FUNCTION);

View File

@ -14,7 +14,7 @@ FLAGS = -Wall -Wextra -Wno-strict-aliasing $(CFLAGS)
LIBS = LIBS =
DEBUGFLAGS = -g -DDEBUG $(FLAGS) DEBUGFLAGS = -g -DDEBUG $(FLAGS)
SHIPFLAGS = -O2 -DNDEBUG $(FLAGS) SHIPFLAGS = -O3 -DNDEBUG $(FLAGS)
default: release default: release