Skip to content

Commit 13a8629

Browse files
author
theBF
committed
Experiments with literal stack
1 parent e80ec57 commit 13a8629

File tree

9 files changed

+774
-48
lines changed

9 files changed

+774
-48
lines changed

COMPILER/Optimizers/POPPUSH-OPT.FTH

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
\ poppush optimizer
2+
\ This idea failed because the logic is not correct for all
3+
\ cases. More work needed.
4+
5+
C136 CONSTANT 'DROP' \ 9900 machine code for DROP (*SP+ R4 MOV,)
6+
VARIABLE DROPS \ count when DROP, is executed
7+
VARIABLE #OPTS \ # of optimizations made
8+
VARIABLE #DUPS \ # of DUPS made
9+
10+
: DUP, ( n -- n n) TOS DPUSH, #DUPS 1+! ; \ normal dup
11+
: DROP, TOS DPOP, DROPS 1+! ; \ count each drop
12+
13+
: LOOKBACK ( -- u) THERE 2- @ ; \ fetch previous instruction code
14+
15+
: OPT-DUP, ( n -- n ?n)
16+
#DUPS @ 2 < ( this is PFM )
17+
IF \ not enough DUPS were done so we must do one
18+
DUP,
19+
ELSE
20+
LOOKBACK 'DROP' = \ look back for DROP
21+
IF
22+
-2 TALLOT \ move target dictionary ie: erase DROP
23+
#OPTS 1+!
24+
ELSE
25+
DUP,
26+
THEN
27+
THEN
28+
;
29+
30+
DEFER SMARTDUP, ' DUP, IS SMARTDUP, \ default is unoptimized
File renamed without changes.

0 commit comments

Comments
 (0)