Skip to content

Commit

Permalink
riscv: kernel: Shared NEXT saves about 256 bytes out of 1 KiB
Browse files Browse the repository at this point in the history
So it might be worth doing. The key parts of the runtime - doconst,
docolon etc - have their copies of NEXT for speed, but the rest of the
code words that make up the kernel share a single copy and simply jump
to it instead of including it inline. For every jump that replaces NEXT,
12 bytes are saved.

It's also very easy to turn this on and off.
  • Loading branch information
nimblemachines committed Apr 6, 2017
1 parent 1ba0aa3 commit e6588d8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions mu/target/RISC-V/kernel-itc.mu4
Expand Up @@ -69,7 +69,8 @@ forth
-- ------------------------------------------------------------------------
assembler

: next asm{ 0 ip w lw 4 ip ip addi -4 w x lw 0 x jr } ;
( Compile NEXT inline.)
: next, asm{ 0 ip w lw 4 ip ip addi -4 w x lw 0 x jr } ;

( XXX Macros or subroutines?)
( Data stack macros.)
Expand Down Expand Up @@ -118,15 +119,16 @@ meta: constant new , ;code label doconst

meta: create new ;code label dovar
label wpush
top push1 w top mv ( move pfa to top) next ;c
top push1 w top mv ( move pfa to top)
label shared-next next, ;c

label dodoes
top push1 w top mv ( move pfa to top)
x w mv ( x is parent ip) ( fall thru) ;c

meta: : new __target-colon
;code label docolon
ip rpush1 w ip mv ( pfa is new ip) next ;c
ip rpush1 w ip mv ( pfa is new ip) next, ;c

definer
meta: does> <;code> asm{ dodoes x jal } __target-colon ;
Expand All @@ -143,7 +145,7 @@ meta: variable cell buffer ; ( A variable is a cell-sized buffer!)
meta: 2variable cell 2* buffer ;


code* ^ ( unnest) ip rpop1 here ( begin) next ;c
code* ^ ( unnest) ip rpop1 here ( begin) next, ;c
codes nope

code* (lit) 0 ip w lw 4 ip ip addi ( fetch literal) wpush j ;c
Expand All @@ -153,6 +155,10 @@ code execute ( pfa) top w mv here ( begin)
code @execute ( 'pfa) 0 top w lw j ( again) ;c


( Compile a jump to a previous inline NEXT.)
meta: next asm{ shared-next j } ;


.ifdef notyet ( skip stuff that is still MSP430 code ;-)

code* (branch) 0 ip ip lw ( follow branch) next ;c
Expand Down

0 comments on commit e6588d8

Please sign in to comment.