From: Dan White Date: Thu, 2 May 2013 16:53:49 +0000 (-0500) Subject: msp4th: speedup pop/pushMathStack X-Git-Tag: bootrom-initial-submission~18 X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=6c9254ceb2118afc96ef711dae96769fcbdb8dd4;p=430.git msp4th: speedup pop/pushMathStack --- diff --git a/msp4th/msp4th.c b/msp4th/msp4th.c index b05ac3b..16131f7 100644 --- a/msp4th/msp4th.c +++ b/msp4th/msp4th.c @@ -1,3 +1,11 @@ +/* + * + * TODO: + * - use enum for VM opcodes + * - speed up pop/pushMathStack (need bounds check??) + * + */ + #if defined(MSP430) /* use devboard uart */ @@ -95,6 +103,7 @@ const int16_t cmdList2N[] = {0,10000,10032,10135}; // need an extra zero at the int16_t ALIGN_2 mathStack[MATH_STACK_SIZE]; +int16_t mathStackDepth; int16_t ALIGN_2 addrStack[ADDR_STACK_SIZE]; uint16_t addrStackPtr; @@ -472,10 +481,14 @@ int16_t popMathStack(void) j = mathStack[0]; - for (i=1;i 0) { + mathStackDepth--; + } + return(j); } @@ -483,9 +496,12 @@ void pushMathStack(int16_t n) { int16_t i; - for (i=MATH_STACK_SIZE - 2; i > 0; i--) { + mathStackDepth++; + + for (i=mathStackDepth; i > 0; i--) { mathStack[i] = mathStack[i-1]; } + mathStack[0] = n; } @@ -1064,6 +1080,7 @@ void init_msp4th(void) xit = 0; + mathStackDepth = 0; addrStackPtr = ADDR_STACK_SIZE; // this is one past the end !!!! as it should be progCounter = 10000; progPtr = 1; // this will be the first opcode