mirror of
https://github.com/remko/waforth
synced 2024-12-27 09:59:29 +01:00
Shortcut if conditions
This commit is contained in:
parent
40f53ee6fe
commit
c79c2f647e
1 changed files with 59 additions and 58 deletions
117
src/waforth.wat
117
src/waforth.wat
|
@ -1304,13 +1304,11 @@
|
||||||
(local.tee $n1 (i64.load (local.tee $bbbtos (i32.sub (local.get $tos) (i32.const 12)))))
|
(local.tee $n1 (i64.load (local.tee $bbbtos (i32.sub (local.get $tos) (i32.const 12)))))
|
||||||
(local.tee $n2 (i64.extend_i32_s (local.tee $n2_32 (i32.load (local.tee $btos (i32.sub (local.get $tos) (i32.const 4))))))))))
|
(local.tee $n2 (i64.extend_i32_s (local.tee $n2_32 (i32.load (local.tee $btos (i32.sub (local.get $tos) (i32.const 4))))))))))
|
||||||
(local.set $q (i32.wrap_i64 (i64.div_s (local.get $n1) (local.get $n2))))
|
(local.set $q (i32.wrap_i64 (i64.div_s (local.get $n1) (local.get $n2))))
|
||||||
(if
|
(block
|
||||||
(i32.and
|
(br_if 0 (i32.eqz (local.get $mod)))
|
||||||
(i32.ne (local.get $mod (i32.const 0)))
|
(br_if 0 (i64.ge_s (i64.xor (local.get $n1) (local.get $n2)) (i64.const 0)))
|
||||||
(i64.lt_s (i64.xor (local.get $n1) (local.get $n2)) (i64.const 0)))
|
(local.set $q (i32.sub (local.get $q) (i32.const 1)))
|
||||||
(then
|
(local.set $mod (i32.add (local.get $mod) (local.get $n2_32))))
|
||||||
(local.set $q (i32.sub (local.get $q) (i32.const 1)))
|
|
||||||
(local.set $mod (i32.add (local.get $mod) (local.get $n2_32)))))
|
|
||||||
(i32.store (local.get $bbbtos) (local.get $mod))
|
(i32.store (local.get $bbbtos) (local.get $mod))
|
||||||
(i32.store (i32.sub (local.get $tos) (i32.const 8)) (local.get $q))
|
(i32.store (i32.sub (local.get $tos) (i32.const 8)) (local.get $q))
|
||||||
(local.get $btos))
|
(local.get $btos))
|
||||||
|
@ -2251,19 +2249,20 @@
|
||||||
(call $failUndefinedWord (local.get $wordAddr) (local.get $wordLen)))))
|
(call $failUndefinedWord (local.get $wordAddr) (local.get $wordLen)))))
|
||||||
(else
|
(else
|
||||||
;; Name found in the dictionary.
|
;; Name found in the dictionary.
|
||||||
;; Are we compiling and is the word non-immediate?
|
(block
|
||||||
(if (i32.and
|
;; Are we interpreting?
|
||||||
(i32.load (i32.const 0x2092c (; = body(STATE) ;)))
|
(br_if 0 (i32.eqz (i32.load (i32.const 0x2092c (; = body(STATE) ;)))))
|
||||||
(i32.ne (local.get $FINDResult) (i32.const 1)))
|
;; Is the word immediate?
|
||||||
(then
|
(br_if 0 (i32.eq (local.get $FINDResult) (i32.const 1)))
|
||||||
;; We're compiling a non-immediate.
|
|
||||||
;; Compile the execution of the word into the current compilation body.
|
;; We're compiling a non-immediate.
|
||||||
(local.set $tos (call $compileExecute (local.get $tos) (local.get $FINDToken))))
|
;; Compile the execution of the word into the current compilation body.
|
||||||
(else
|
(local.set $tos (call $compileExecute (local.get $tos) (local.get $FINDToken)))
|
||||||
;; We're not compiling, or this is an immediate word
|
(br $loop))
|
||||||
;; Execute the word.
|
;; We're interpreting, or this is an immediate word
|
||||||
(local.set $tos (call $execute (local.get $tos) (local.get $FINDToken)))))))
|
;; Execute the word.
|
||||||
(br $loop)))
|
(local.set $tos (call $execute (local.get $tos) (local.get $FINDToken)))))
|
||||||
|
(br $loop)))
|
||||||
(local.get $tos))
|
(local.get $tos))
|
||||||
|
|
||||||
;; Execute the given execution token
|
;; Execute the given execution token
|
||||||
|
@ -2396,8 +2395,9 @@
|
||||||
(call $leb128-4p (i32.add (global.get $nextTableIndex) (i32.const 1))))
|
(call $leb128-4p (i32.add (global.get $nextTableIndex) (i32.const 1))))
|
||||||
|
|
||||||
;; Write a name section (if we're ending the code for the current dictionary entry)
|
;; Write a name section (if we're ending the code for the current dictionary entry)
|
||||||
(if (i32.eq (i32.load (call $body (global.get $latest)))
|
(if (i32.eq
|
||||||
(global.get $nextTableIndex))
|
(i32.load (call $body (global.get $latest)))
|
||||||
|
(global.get $nextTableIndex))
|
||||||
(then
|
(then
|
||||||
(local.set $nameLength (i32.and (i32.load8_u (i32.add (global.get $latest) (i32.const 4)))
|
(local.set $nameLength (i32.and (i32.load8_u (i32.add (global.get $latest) (i32.const 4)))
|
||||||
(i32.const 0x1f (; = LENGTH_MASK ;))))
|
(i32.const 0x1f (; = LENGTH_MASK ;))))
|
||||||
|
@ -2608,12 +2608,11 @@
|
||||||
(local $btos i32)
|
(local $btos i32)
|
||||||
(block $endLoop
|
(block $endLoop
|
||||||
(loop $loop
|
(loop $loop
|
||||||
|
(br_if $endLoop (i32.le_u (local.get $tos) (i32.const 0x10000 (; = STACK_BASE ;))))
|
||||||
(br_if $endLoop
|
(br_if $endLoop
|
||||||
(i32.or
|
(i32.ne
|
||||||
(i32.le_u (local.get $tos) (i32.const 0x10000 (; = STACK_BASE ;)))
|
(i32.load (local.tee $btos (i32.sub (local.get $tos) (i32.const 4))))
|
||||||
(i32.ne
|
(i32.or (global.get $branchNesting) (i32.const 0x80000000 (; dest bit ;)))))
|
||||||
(i32.load (local.tee $btos (i32.sub (local.get $tos) (i32.const 4))))
|
|
||||||
(i32.or (global.get $branchNesting) (i32.const 0x80000000 (; dest bit ;))))))
|
|
||||||
(call $emitEnd)
|
(call $emitEnd)
|
||||||
(global.set $branchNesting (i32.sub (global.get $branchNesting) (i32.const 1)))
|
(global.set $branchNesting (i32.sub (global.get $branchNesting) (i32.const 1)))
|
||||||
(local.set $tos (local.get $btos))))
|
(local.set $tos (local.get $btos))))
|
||||||
|
@ -2662,15 +2661,16 @@
|
||||||
(call $emit1v (i32.const 0x21) (local.get $n))
|
(call $emit1v (i32.const 0x21) (local.get $n))
|
||||||
(global.set $lastEmitWasGetTOS (i32.eqz (local.get $n))))
|
(global.set $lastEmitWasGetTOS (i32.eqz (local.get $n))))
|
||||||
(func $emitGetLocal (param $n i32)
|
(func $emitGetLocal (param $n i32)
|
||||||
(if (i32.or (i32.ne (local.get $n) (i32.const 0)) (i32.eqz (global.get $lastEmitWasGetTOS)))
|
(block
|
||||||
(then
|
(br_if 0 (local.get $n))
|
||||||
(call $emit1v (i32.const 0x20) (local.get $n)))
|
(br_if 0 (i32.eqz (global.get $lastEmitWasGetTOS)))
|
||||||
(else
|
;; In case we have a TOS get after a TOS set, replace the previous one with tee.
|
||||||
;; In case we have a TOS get after a TOS set, replace the previous one with tee.
|
;; Doesn't seem to have much of a performance impact, but this makes the code a little bit shorter,
|
||||||
;; Doesn't seem to have much of a performance impact, but this makes the code a little bit shorter,
|
;; and easier to step through.
|
||||||
;; and easier to step through.
|
(i32.store8 (i32.sub (global.get $cp) (i32.const 2)) (i32.const 0x22))
|
||||||
(i32.store8 (i32.sub (global.get $cp) (i32.const 2)) (i32.const 0x22))))
|
(global.set $lastEmitWasGetTOS (i32.const 0))
|
||||||
(global.set $lastEmitWasGetTOS (i32.const 0)))
|
(return))
|
||||||
|
(call $emit1v (i32.const 0x20) (local.get $n)))
|
||||||
(func $emitTeeLocal (param $n i32) (call $emit1v (i32.const 0x22) (local.get $n)))
|
(func $emitTeeLocal (param $n i32) (call $emit1v (i32.const 0x22) (local.get $n)))
|
||||||
(func $emitAdd (call $emit0 (i32.const 0x6a)))
|
(func $emitAdd (call $emit0 (i32.const 0x6a)))
|
||||||
(func $emitSub (call $emit0 (i32.const 0x6b)))
|
(func $emitSub (call $emit0 (i32.const 0x6b)))
|
||||||
|
@ -2912,15 +2912,17 @@
|
||||||
(loop $loop
|
(loop $loop
|
||||||
(local.set $byte (i32.and (i32.const 0x7F) (local.get $value)))
|
(local.set $byte (i32.and (i32.const 0x7F) (local.get $value)))
|
||||||
(local.set $value (i32.shr_s (local.get $value) (i32.const 7)))
|
(local.set $value (i32.shr_s (local.get $value) (i32.const 7)))
|
||||||
(if (i32.or (i32.and (i32.eqz (local.get $value))
|
(block $next
|
||||||
(i32.eqz (i32.and (local.get $byte) (i32.const 0x40))))
|
(block
|
||||||
(i32.and (i32.eq (local.get $value) (i32.const -1))
|
(br_if 0 (i32.and
|
||||||
(i32.eq (i32.and (local.get $byte) (i32.const 0x40))
|
(i32.eqz (local.get $value))
|
||||||
(i32.const 0x40))))
|
(i32.eqz (i32.and (local.get $byte) (i32.const 0x40)))))
|
||||||
(then
|
(br_if 0 (i32.and
|
||||||
(local.set $more (i32.const 0)))
|
(i32.eq (local.get $value) (i32.const -1))
|
||||||
(else
|
(i32.eq (i32.and (local.get $byte) (i32.const 0x40)) (i32.const 0x40))))
|
||||||
(local.set $byte (i32.or (local.get $byte) (i32.const 0x80)))))
|
(local.set $byte (i32.or (local.get $byte) (i32.const 0x80)))
|
||||||
|
(br $next))
|
||||||
|
(local.set $more (i32.const 0)))
|
||||||
(i32.store8 (local.get $p) (local.get $byte))
|
(i32.store8 (local.get $p) (local.get $byte))
|
||||||
(local.set $p (i32.add (local.get $p) (i32.const 1)))
|
(local.set $p (i32.add (local.get $p) (i32.const 1)))
|
||||||
(br_if $loop (local.get $more)))
|
(br_if $loop (local.get $more)))
|
||||||
|
@ -3066,22 +3068,21 @@
|
||||||
(local $entryLF i32)
|
(local $entryLF i32)
|
||||||
(local.set $entryP (global.get $latest))
|
(local.set $entryP (global.get $latest))
|
||||||
(loop $loop
|
(loop $loop
|
||||||
(if
|
(block
|
||||||
|
(br_if 0
|
||||||
(i32.and
|
(i32.and
|
||||||
(i32.eqz
|
(local.tee $entryLF (i32.load (i32.add (local.get $entryP) (i32.const 4))))
|
||||||
(i32.and
|
(i32.const 0x20 (; = F_HIDDEN ;))))
|
||||||
(local.tee $entryLF (i32.load (i32.add (local.get $entryP) (i32.const 4))))
|
(br_if 0
|
||||||
(i32.const 0x20 (; = F_HIDDEN ;))))
|
(i32.eqz
|
||||||
(call $stringEqual
|
(call $stringEqual
|
||||||
(local.get $addr) (local.get $len)
|
(local.get $addr) (local.get $len)
|
||||||
(i32.add (local.get $entryP) (i32.const 5)) (i32.and (local.get $entryLF) (i32.const 0x1f (; = LENGTH_MASK ;)))))
|
(i32.add (local.get $entryP) (i32.const 5)) (i32.and (local.get $entryLF) (i32.const 0x1f (; = LENGTH_MASK ;))))))
|
||||||
(then
|
(local.get $entryP)
|
||||||
(return
|
(if (result i32) (i32.eqz (i32.and (local.get $entryLF) (i32.const 0x80 (; = F_IMMEDIATE ;))))
|
||||||
(local.get $entryP)
|
(then (i32.const -1))
|
||||||
(select
|
(else (i32.const 1)))
|
||||||
(i32.const -1)
|
(return))
|
||||||
(i32.const 1)
|
|
||||||
(i32.eqz (i32.and (local.get $entryLF) (i32.const 0x80 (; = F_IMMEDIATE ;))))))))
|
|
||||||
(local.set $entryP (i32.load (local.get $entryP)))
|
(local.set $entryP (i32.load (local.get $entryP)))
|
||||||
(br_if $loop (local.get $entryP)))
|
(br_if $loop (local.get $entryP)))
|
||||||
(i32.const 0) (i32.const 0))
|
(i32.const 0) (i32.const 0))
|
||||||
|
|
Loading…
Reference in a new issue