PocketMatrix forums

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

Arm Assembly help for IPAQ HELP PLEASE!!

I am in serious need of some ARM Assembly help for the IPAQ.
I am trying to pass two floating point values from C to asm and add them, but I am obviously missing something.

If I write it in C and look at the generated asm code it loads the values in r0 and r1 then calls a section of the processor returning the result...

ldr r0, [sp, #8]
ldr r1, [sp, #0xC]
ldr r3, [pc, #0x10] ;where is this?
ldr r2, [r3]
mov lr, pc
mov pc, r2 ;call elsewhere. but where?
str r0, [sp, #8]

I really need this to be in assembly since it is an important part of a larger routine that needs speed.

If someone could help I would be very gratefull.
Examples with explanations would be perfect.

thanks
:?
Let me suggest something. Writing the routine in ASM will not help anything, because floating point math is emulated by a software library. To perform floating point math you call into that library. A hundred or more cycles are consumed by performing a floating point mult alone. So if performance is that critical then you must avoid floating point math in the first place.

Dan East
I agree 100% with Dan. Calling floating point from assembler will gain you practically nothing. There's nothing optimisable about the code you posted... And as you'll read, the floating point (emulation) system is really kind of "tricky" to use.

However, to try to answer the questions anyway:

ldr r3, [pc, #0x10] ;where is this?


It's the value 4 + 2 instructions away from the "ldr r3, [pc, #0x10]" itself.

The 4 (16 bytes) comes from the #0x10, and the extra 2 comes from the fact that the PC (program counter) is actually 2 instructions (8 bytes) ahead of the "executing" instruction on the StrongARM/Xscale because of its pipeline system.

So, r3 is the content of that address.
r2 then loads that
the link register sets the return to where the program counter currently is (taking the extra 2 into account again it's the "str r0, [sp, #8]")
and control branches off the the value it loads from the address in r2.

Basically, it looks like it's using a vector-tabled FP system.

Slight proviso:
I can't remember if the StrongARM/XScale's PC is 2 or 3 instructions ahead, but the theory is there :P
mcrah · 19 Sep 2003, 14:51 UTC — Thanks
Thanks guys for the responses.

Actually last night I figured it out.
The compiler stores an unreachable asm instruction near the routine itself, which evaluates to a pointer to what must be the FP table or in-processor fp-emulator.

ldr r3, [pc, #0x10] ;where is this?
ldr r2, [r3]
mov lr, pc
mov pc, r2 ;call elsewhere. but where?

this I understood as a setup for a call, but was unclear where the call was being made to.

now I know it is made to what the unreachable instruction evaluates to.

I can now mimic this in my own asm code, and get correct floating point results.

As for the optimization, the routine is highly optimized in asm and now runs approximately 20 times faster than its C++ counterpart.

The floating point calculation is just a very small(but integral) piece that is performed on pre-calculated values.

Since it is called many thousand times, it had to go to asm.

Thanks again for the comments, I appreciate the help.

McRah :D
simonjacobs · 19 Sep 2003, 16:30 UTC
I have to say that the evc arm compiler is actually very good. If your asm really runs 20 times faster than the c++ it is very likely that your c++ could be massively optimised. In my experience the difference between very well optimised c++ and hand written assembler is far far less than a doubling in speed in every case I've tried.
simonjacobs wrote:
I have to say that the evc arm compiler is actually very good. If your asm really runs 20 times faster than the c++ it is very likely that your c++ could be massively optimised. In my experience the difference between very well optimised c++ and hand written assembler is far far less than a doubling in speed in every case I've tried.


I've got the same experience.
Thierry":yrfl5ho0]


Not me. 8)

evc compiler is quite good but I've never seen it using ldmia/stmia when it's possible.

The compiler generally produce too much code for a given routine.

I always write C code and check the generated asm until I don't find a way to improve it, then I rework the asm code and get generally 1.5~2x more speed and 2x less code.
StephC wrote:
...I rework the asm code and get generally 1.5~2x more speed and 2x less code.


That's exactly what SimonJacob said, impovement less then 2x... And this is also my experience, 1.5-2x... Not worth the effort most of the time.