PocketMatrix forums

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

asm function to C

I have this easy ASM function to multiply two 1:15:16 fixed numbers and return a 1:15:16 fixed too:

Code:

mult1_15_16x1_15_16_return_1_15_16
smull r2,r3,r0,r1
mov r0,r2,lsr #16
add r0,r0,r3,lsl #16
mov pc,lr


I use it very often in my program, but as it's in a external asm file it's impossible to make it inline (at least I've tried everything in my hands). BTW, thanks microsoft for not including __asm in your compiler.

microsoft states clearly that if you want a function inlined, define it in a .h so that every file including it can see the function. That would be great, if __asm were supported :)

after being frustrated a lot with this issue (as most of you, probably) I thought about hacking a little bit their compiler so that I could create a custom intrinsic function, but that requires a lot of time, work and knowledge I don't have.

Unfortunately I think there's only one way to go, and it's trying to do a C function which has the same code as my ASM code, but I haven't been able to do so. I've tried the "logical"

Code:

_int64 c;
c=a*b;
c=c>>16;
return (int)c;


but it's generating a mul instead of an smull. casting the result or the operands is not working.

any ideas? :)
TIA
Kak

p.s. of course I suppose there's no way to fool the compiler and generate raw opcodes, something like dcd in the middle of the code,isn't it? :)
Sergey Chaban · 14 Dec 2003, 13:54 UTC
Upgrade you compiler - newer versions support this optimization and will generate code exactly like your asm function.

It's also possible to insert raw opcodes with __emit (not documented in older docs).
Sergey Chaban wrote:
Upgrade you compiler - newer versions support this optimization and will generate code exactly like your asm function.


Do you mean using the PPC 2002 SDK? Or trying to use the compiler from eVC 4.0?

Dan East
Sergey Chaban · 14 Dec 2003, 16:02 UTC
Yes, using new EVC4 compiler (the most recent update) with old IDE.
I think required compiler version to support this optimization is at least 12.20.9615.
Sergey Chaban wrote:
Yes, using new EVC4 compiler (the most recent update) with old IDE.
I think required compiler version to support this optimization is at least 12.20.9615.


I haven't been able to use the __emit construct, it seems it is inside of __asm {} which unfortunately I can't use :(

I'll have a look at the new compilers, lots of thanks :)
Kak
Sergey Chaban · 14 Dec 2003, 18:50 UTC
It's possible that you're using the wrong syntax.
__emit is actually a built-in function so correct one would be:
__emit(0xe1a00000); // mov r0, r0

Works with new compiler.
But it's not very useful anyway (e.g. no easy way to access local variables and the like).
Sergey Chaban wrote:
Upgrade you compiler - newer versions support this optimization and will generate code exactly like your asm function.


it worked perfectly, thanks :)
Sergey Chaban wrote:
Yes, using new EVC4 compiler (the most recent update) with old IDE.
I think required compiler version to support this optimization is at least 12.20.9615.


How do you go about extracting the new compiler and putting it into EVC3?

Is it just a case of copying across clarm.exe ?
I think that is discussed here:
http://www.pocketmatrix.com/forums/viewtopic.php?t=12005

Be sure to look at that other thread mentioned by Sergey as well, since it appears that you don't have to do all the copying.
Dave H":bbmlynzi]


I just got EVC4 sp2 cd and copied the wce420 in a hd directory. then tools->options->directories, binary directory and choose the wce420. it worked for me :)