Is there an easy way of make unrolled loops with macros?

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
psycopathicteen
Posts: 3140
Joined: Wed May 19, 2010 6:12 pm

Is there an easy way of make unrolled loops with macros?

Post by psycopathicteen »

The guy who programmed Toy Story used unrolled loops for 3D maze. Is that possible to do bass.exe or other assemblers?
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Is there an easy way of make unrolled loops with macros?

Post by rainwarrior »

ca65 has the .repeat directive.
psycopathicteen
Posts: 3140
Joined: Wed May 19, 2010 6:12 pm

Re: Is there an easy way of make unrolled loops with macros?

Post by psycopathicteen »

I looked through the documentation of bass.exe, and I figured out how to have a repeating macros.

Code: Select all

define n(0)
while {n} < 16 {
jsr spawn_single_explosion
evaluate n({n}+1)
}
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Is there an easy way of make unrolled loops with macros?

Post by tokumaru »

I always use macros to make unrolled loops. Doing it manually is too error-prone and difficult to maintain.
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Is there an easy way of make unrolled loops with macros?

Post by rainwarrior »

In a situation where you have a way to define a macro (but no repeat), I've found this kind of thing to be a relatively straightforward / low risk of error way to unroll loops:

Code: Select all

.macro THING index
	; loop iteration here
.endmacro

THING 0
THING 1
THING 2
THING 3
THING 4
THING 5
; ...
Mostly this has come up for me in C or C++ cases where I knew an unroll was warranted but the compiler's optimizer wasn't going to do it on its own. (In a lot of cases just writing a for loop with a simple static range is enough to get the optimizer to unroll anyway, though. This is not something I've had to use frequently at all.)
calima
Posts: 1745
Joined: Tue Oct 06, 2015 10:16 am

Re: Is there an easy way of make unrolled loops with macros?

Post by calima »

^This, and automated with the command to print it in comments.

// for i in `seq 0 15`; do echo THING $i; done
Post Reply