PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

ARM asm optimizations

Hey,
I'm looking for some help optimizing my inner loop for affine tmapper.

It looks and works pretty nicely, but I have got 2 points where it could be possibly improved.

1.Is there an instruction to improve loops like:

loop start
....
decrease parameter by 1
jump if parameter is !=0

in asm:

loop
...
subs r0,r0,#1
bge loop

In tmapper I have to repear my inner loop x times, can it be handled nicer, without the additional "decrease register by 1" instruction?
any ideas how I could possibly replace it to have one instruction less?

2.I have got something like

add r1,r1,r3 lsl #1
ldrh r6,[r1]

I would like to put it as

ldrh r6,[r1,r3,lsl #1]

but EVC++3.0 doesn't allow me to compile it...

ldr r6,[r1,r3,lsl #1] is fine...?

what's wrong with it? Can I somehow use it (again to have one less instruction in inner loop:)


Thanks for your time :)

  1. Not really. If you're looping you need to decrement the counter, or make some other comparison to see if you still need to loop. If you unroll it, be careful because unrolling it too far trashes the instruction cache and you lose performance.

  2. ldrh cannot take a shifted register as an offset. Basically the original ARM instruction set didn't include a load half-word instruction, so when the half-word (and other) extensions were added, they had to use opcode encodings with a restricted set of operands.


If you want me to offer advice on the whole routine, private message me.
Thanks a lot refractor :)

atm there's not much to give advice, just some lines of code, I have arm-optimized only the most inner loop.
I will contact you when I fight with persp-corrcet tmapping as this will be much bigger/harder etc ;-)