home .. forth .. misc mail list archive ..

Re: MISC instruction set


Decrementing loops with -1s is the less efficient way to count iterations,
because it implies maximum (longest) carry propagation.
For shorter carry propagation, left-justify your counter and, instead of
decrementing a positive counter until it reaches zero, increment it until the
carry (T's MSBit) is set.  Finally, use the conditionnal add instruction (+*)
with the increment (a power of 2) under the counter (left justified with its
LSBit set to force the addition): the increment is not popped.

For a loop of N iterations, with n such that 1<<(n-1) <= N < 1<<n, use a
counter initialized with 1<<20 - N<<(20-n) + 1, and increment it by 1<<(20-n):

\ example for N=9
hex
  1,0000 #  7,0001 #	\ -- incr count ; will loop 9 times
  BEGIN		\ loop body here ... ends with same stack: -- incr count
  +* -UNTIL	\ -- incr 10,0001 ; -UNTIL jumps to BEGIN unless carry set

And of course, short loops are most efficient when unrolled.

CL
--
email: Christophe.Lavarenne@inria.fr		tel: +33.1.39.63.55.80
INRIA, Domaine de Voluceau Rocquencourt		Institut National de Recherche
B.P.105 - 78153 LE CHESNAY CEDEX FRANCE		en Informatique et Automatique

SynDEx, CAD tool for the distributed implementation of real-time applications.
Take a look at our Web Server: http://www-rocq.inria.fr/syndex