Oh, I forgot...

by (Login Mikrondel)
R

a common optimisation technique is to actually write loops out the "long way". This is called "unrolling loops". E.g.

MOV [0], word 5
MOV [2], word 6
MOV [4], word 7
MOV [6], word 8
MOV [8], word 9
MOV [10], word 10

Note that this essentially removes two adds and a conditional jump per MOV. Removing 3 out of every 4 instructions is sure to give you a speed benefit.

This obviously makes the code take up more space, but if you only apply this at the heavily-repeated parts of your code, you can get a big speed boost without eating up too much memory.

Note that you can also partially unroll loops, i.e. rather than looping 100 times, or writing out 100 instructions, you can do a bit of both:

j:
ADD [BX], word 10
ADD [BX+2], word 10
ADD [BX+4], word 10
ADD [BX+6], word 10
ADD BX, 8
CMP BX, 200
JL j

This gives a good compromise between code size and speed.

Posted on Jul 18, 2009, 6:13 PM

Respond to this message   

Return to Index