Commit 91054846 authored by Anton Ertl's avatar Anton Ertl

optimize /MODF U/MOD; test division optimization

parent a31033d8
......@@ -202,3 +202,20 @@ optimizes fpick
' opt-modf optimizes umod
\ does not optimize MIN-N UMOD; add another optimizer if you want that.
: opt-/modf ( xt -- )
lits# 1 = if
lits> dup 0> over pow2? and if
dup 1- ]] dup literal and [[ ctz ]] swap literal arshift [[
drop exit then
>lits then
fold2-2 ;
' opt-/modf optimizes /modf
: opt-u/mod ( xt -- )
lits# 1 = if
lits> dup pow2? if
dup 1- ]] dup literal and [[ ctz ]] swap literal rshift [[
drop exit then
>lits then
fold2-2 ;
' opt-u/mod optimizes u/mod
......@@ -60,6 +60,9 @@ super33 = noop flit
super34 = lit+ @
super35 = f@ f*
super36 = f@ f+
super37 = lit and
super38 = lit arshift
super39 = dup lit and swap
\ compare-and-branch; comment them out if we take up work on gforth-native again
cb1 = 0< ?branch
......
......@@ -409,3 +409,12 @@ t{ 2 5 -7 */mod -> -4 -2 }t
t{ -2 5 -7 */mod -> -3 1 }t
t{ -2 15 -1 u*/mod -> -16 14 }t
\ optimization of division words
t{ :noname -21 4 /f ; execute -> -6 }t
t{ :noname -21 4 modf ; execute -> 3 }t
t{ :noname -21 4 /modf ; execute -> 3 -6 }t
t{ :noname 25 4 u/ ; execute -> 6 }t
t{ :noname 25 4 umod ; execute -> 1 }t
t{ :noname 25 4 u/mod ; execute -> 1 6 }t
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