#16166 - animension - Tue Feb 10, 2004 1:34 am
I was wondering just how much of an impact a branch instruction would have in a loop. For instance, what if you had something like:
How much would the cmp and beq in the middle of the loop cost, aside from extra instructions? Would there be a big impact with the cache, etc? I'm trying to optimize the inner loop in a time critical task, and I'm thinking it might be better if I sort out certain criteria before hand and run different loops based on these criteria. The only problem is that the code will bloat if I have too many different versions of the loop not to mention the fact that it'll be a maintenance nightmare :/
Any suggestions?
_________________
"Beer is proof that God loves us and wants us to be happy."
-- Benjamin Franklin
Code: |
mov r0,#0 looptop: cmp r0,#128 @ loop 128 times beq endloop @ do stuff here ... cmp r1,#0 @ some other arbitrary number beq loopbottom @ skip if equal @ do other stuff here loopbottom: add r0,r0,#1 b looptop endloop: @ finished with loop here |
How much would the cmp and beq in the middle of the loop cost, aside from extra instructions? Would there be a big impact with the cache, etc? I'm trying to optimize the inner loop in a time critical task, and I'm thinking it might be better if I sort out certain criteria before hand and run different loops based on these criteria. The only problem is that the code will bloat if I have too many different versions of the loop not to mention the fact that it'll be a maintenance nightmare :/
Any suggestions?
_________________
"Beer is proof that God loves us and wants us to be happy."
-- Benjamin Franklin