Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[goal] Support loop unrolling with :unroll factor #3449

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Brent-Hickey
Copy link
Contributor

Not sure if this will actually be useful but thought it'd be cool to support

Supports optional loop unrolling with :unroll factor
Supports (_ x) syntax to unroll without binding and incrementing a variable when fully unrolled. Otherwise uses gensym var to iterate.

Could add to countdown as well

Examples:

 (dotimes (_ 4) :unroll 4
    (print "hi")
  )

(begin (print "hi") (print "hi") (print "hi") (print "hi"))

(unchanged)

(dotimes (i 4)
    (format #t "i: ~D~%" i)
  )

((lambda :immediate #t (i) (while (< i 4)
                             :label #f
                             (block continue (format #t "i: ~D~%" i) (1+! i))
                             )
         )
 0
 )
(dotimes (_ 4) :unroll 2
    (print "hi")
  )

((lambda :immediate
   #t
   (gensym20077)
   (while (< gensym20077 4)
     :label #f
     (block continue (print "hi") (1+! gensym20077) (print "hi") (1+! gensym20077))
     )
   )
 0
 )
(dotimes (i 4) :unroll 4
    (format #t "i: ~D~%" i)
  )

((lambda :immediate
   #t
   (i)
   (format #t "i: ~D~%" i)
   (1+! i)
   (format #t "i: ~D~%" i)
   (1+! i)
   (format #t "i: ~D~%" i)
   (1+! i)
   (format #t "i: ~D~%" i)
   (1+! i)
   )
 0
 )

@xTVaser xTVaser added this to the July 2024 milestone May 31, 2024
@xTVaser xTVaser modified the milestones: July 2024, August 2024 Jul 28, 2024
Comment on lines +391 to +398
(when (and (integer? limit)
(> unroll limit)
)
(error ":unroll factor must be <= the loop limit.")
)
(when (< unroll 1)
(error ":unroll factor must be >= 1.")
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For whatever reason, in the original code they left dotimes in that iterate 0 times. This highlights an edge-case with the assumption that every loop will execute atleast once.

See cloth.gc in jak3

@xTVaser xTVaser removed this from the August 2024 milestone Aug 18, 2024
@xTVaser xTVaser marked this pull request as draft September 4, 2024 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants