Contents    Page-10    Prev    Next    Page+10    Index   

Loop Unrolling

Substitution makes it easy to do loop unrolling:


(defun unroll (var n code)
  (let (res)
    (dotimes (i n)
      (push (subst (1+ i) var code) res))
    (cons 'progn (reverse res)) ))


>(unroll 'j 5 '(|:=| (aref x (+ -8 (* 8 j))) 0))

(PROGN
  (|:=| (AREF X (+ -8 (* 8 1))) 0)
  (|:=| (AREF X (+ -8 (* 8 2))) 0)
  (|:=| (AREF X (+ -8 (* 8 3))) 0)
  (|:=| (AREF X (+ -8 (* 8 4))) 0)
  (|:=| (AREF X (+ -8 (* 8 5))) 0))