theandrew168 / derzforth

Bare-metal Forth implementation for RISC-V
MIT License
42 stars 5 forks source link

Remove unnecessary instruction by adjusting data stack ptr decrement #8

Closed aw closed 3 years ago

aw commented 3 years ago

This is not a big change, but it essentially removes one addi instruction in the !, +, and nand words by moving the stack pointer down by 8 instead of 4.

aw commented 3 years ago

@theandrew168 wait a bit before blindly merging. I think there might be a bug in !. I'm running tests and will confirm later.

aw commented 3 years ago

Hah, I accidentally swapped the stack pointer offsets in my initial commit. This is fixed in 272f61f (although technically the order doesn't matter for + and nand).

To test, I uploaded lexicons/prelude.forth and used swap to verify if the ! store to memory works as expected:

1 2 swap 32 + emit
! ok
2 1 swap 32 + emit
" ok

Previously the results were reversed, which means obviously swap wasn't working. Sorry!

theandrew168 commented 3 years ago

Nice catch! I always appreciate these small optimizations to the Forth core. Every byte helps!