Commit 891dd2e3 authored by Anton Ertl's avatar Anton Ertl

optimize +loop with postitive constant parameter

parent 068490d8
......@@ -79,3 +79,21 @@ dup folds d+ d-
folds 2drop 2nip
4 ' 4lits> ' >4lits ' peephole-compile, folder
folds 2swap
\ optimize +loop (not quite folding)
: replace-(+loop)
case
['] (+loop) of ['] (/loop)# endof
['] (+loop)-lp+!# of ['] (/loop)#-lp+!# endof
-21 throw
endcase ;
: (+loop)-optimizer ( xt -- )
lits# 1 u>= if
lits> dup 0> if
swap replace-(+loop) peephole-compile, , exit then
>lits then
peephole-compile, ;
vt, ' (+loop) dup (make-latest) ' (+loop)-optimizer set-optimizer
vt, ' (+loop)-lp+!# dup (make-latest) ' (+loop)-optimizer set-optimizer
......@@ -300,7 +300,7 @@ SET_IP((Xt *)a_target);
\ condbranch(forthname,stackeffect,restline,code1,code2,forthcode)
\ this is non-syntactical: code must open a brace that is closed by the macro
define(condbranch,
$1 ( `#'a_target $2 ) $3
$1 ( $7 `#'a_target $2 ) $3
$4 $5 SET_IP((Xt *)a_target);
ifelse(condbranch_opt,`1',`INST_TAIL; NEXT_P2;',`/* condbranch_opt=0 */')
}
......@@ -309,7 +309,7 @@ $6
\+glocals
$1-lp+!`#' ( `#'a_target `#'nlocals $2 ) $3_lp_plus_store_number
$1-lp+!`#' ( $7 `#'a_target `#'nlocals $2 ) $3_lp_plus_store_number
$4 $5 lp += nlocals;
SET_IP((Xt *)a_target);
ifelse(condbranch_opt,`1',`INST_TAIL; NEXT_P2;',`/* condbranch_opt=0 */')
......@@ -392,6 +392,11 @@ n2=n1-u;
,if (olddiff>u) {
,)
condbranch((/loop)`#',R:nlimit R:n1 -- R:nlimit R:n2,gforth-internal paren_slash_loop,
n2=n1+u;
,if (n2-nlimit>=u) {
,,`#'u)
condbranch((s+loop),n R:nlimit R:n1 -- R:nlimit R:n2,gforth paren_symmetric_plus_loop,
""The run-time procedure compiled by S+LOOP. It loops until the index
crosses the boundary between limit and limit-sign(n). I.e. a symmetric
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment