Quote:
Originally Posted by weevil
I'd love some tips for optimizing cycle counts. I find optimizing space/line count easier so I tend to focus on that, I get a bit lost trying to lower my cycles. Anyone want to spoiler a discussion on how they came to a good optimization with a particular mission?
Since these are general tips I won't spoil them, but a couple things I've figured out in general:
- Identify the portion of problems that occupies the most time and focus on optimizing that. Best example of this is Equity First Bank - you can shave a few cycles at the start by getting your EXAs where they need to be a little quicker, maybe, but when the problem takes a
minimum of thousands of cycles to complete and most of that is spent in loops, you obviously can't make a serious dent in your cycles without focusing on making that loop wayyyy faster.
- Identify parts of calculations or general processes that have to be done together, versus parts that can be done separately. If work can be done separately, then maybe you can parallelize it! REPL and the M register are your friend.
- I think cycle count is based on the
longest of your 100 test runs, so if a problem has tradeoffs (i.e. you can do part A faster or part B faster but you have to pick one), think about which optimization would help more in the longest-running case.
- Unrolling loops can be desirable for loops of a known length or an unknown but probably long length. Example 1:
Code:
@REP 6
COPY F M
@END
is much faster than
Code:
COPY 6 T
MARK LOOP
SUBI T 1 T
COPY F M
TJMP LOOP
^ also note the fact here that you can write directy to T before using TJMP/FJMP - the conditional JMP commands are just testing "does T equal or not equal 0", and all TEST does is set the T register according to the condition you're checking.
Example 2:
Code:
MARK FASTLOOP
TEST X > 10
FJMP NORMALLOOP
@REP 10
COPY F M
@END
JUMP FASTLOOP
MARK NORMALLOOP
*insert normal iter-by-1 loop here for the last <10 items*
^ for a loop that you expect to run dozens of times, this will be much faster than doing the whole thing 1 at a time.