commit 5d81cd85db9d5d18ad546ff953643918aeb35893
parent fccfed40211b47e8f3b25d8bc2739a98b99c4714
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Tue, 26 Jul 2022 14:44:06 -0400
cc: fix bad code generation on naked "if (x)" tests
With registers, the "test reg, reg" pattern makes sense and is compact, but
with "if (x)", our op is on the stackframe and this generated "test [esp], esp".
Replace this with "test [esp], -1".
The compiled CRC code worked by pure chance, which is why it broke on such
random little change.
Diffstat:
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/dusk.asm b/dusk.asm
@@ -60,7 +60,6 @@ jmp [eax]
SECTION .bss
areg: resd 1 ; A register
toptr: resd 1 ; Current "to" word pointer. 0 means none
-resb 1 ; TODO: tests/lib/crc.fs fails if we remove this! why?
bootptr: resd 1
current: resd 1
here: resd 1
diff --git a/fs/cc/vm.fs b/fs/cc/vm.fs
@@ -331,10 +331,13 @@ operands value 'curop
: _ here 4 - ;
: vmjmp, ( a -- ) abs>rel jmp, ;
: vmjmp[, ( -- a ) 0 vmjmp, _ ;
-: vmjz, ( -- addr )
- selop1 opAsm opAsm test, opdeinit
- 0 jz, here 4 - ;
-: vmjz, ( a -- ) selop1 opAsm opAsm test, opdeinit jz, ;
+\ we take current op and test whether it's zero, setting Z. If the op is a
+\ simple register, the "test eax, eax" form is more compact. Otherwise, use
+\ test ..., -1.
+: vmtest,
+ opAsm optype $f and VM_REGISTER = if opAsm else -1 i) then test, ( sets Z )
+ opdeinit ;
+: vmjz, ( a -- ) selop1 vmtest, jz, ;
: vmjz[, ( -- a ) 0 vmjz, _ ;
-: vmjnz, ( a -- ) selop1 opAsm opAsm test, opdeinit jnz, ;
+: vmjnz, ( a -- ) selop1 vmtest, jnz, ;
: vmjnz[, ( -- a ) 0 vmjnz, _ ;