• Welcome to Valhalla Legends Archive.
 

Is there a better way to do this?

Started by Paul, November 16, 2003, 02:03 AM

Previous topic - Next topic

Skywing

Quote from: Etheran on November 26, 2003, 06:24 PM
Quote from: Kp on November 26, 2003, 04:23 PM
Quote from: Skywing on November 26, 2003, 11:34 AM
You could improve those by making them naked and fastcall.

Even better, make them attribute ((regparm (1))), in which case the argument will be in eax/ax when the function starts, saving you from even having to move it from ecx. ;)  Also, it might be worth doing some testing on whether it's faster to xchg or do the exchange manually.  Same with bswap -- just because it's one instruction, it might not be fast.  Finally, I'm certain CupHead's dword swapper is bloated.  I've inlined something that has that effect several times and it's never been that long. :)
How would you do that in msvc++ ?  I can't find regparm or __attribute__ on msdn.

__attribute__((regparm(1))) ... ?
Those are GCC extensions and are incompatible with VC.

Etheran

#16
that's what I thought, but is there any way to do this in vc? I'm thinking no and the only way to do it would be to put the value in eax before you make the function call.

int __declspec(naked) myFunction(void);
int ret;

__asm { mov eax, theVal }

ret = myFunction();

or perhaps this generates a compiler error..

myFunction();
__asm { mov ret, eax }



Skywing


Kp

Quote from: Skywing on November 26, 2003, 06:52 PM
Quote from: Etheran on November 26, 2003, 06:48 PM
that's what I thought, but is there any way to do this in vc?
No.

Which is truly unfortunate, because there's really no reason that I can see why you shouldn't use all three call-clobbered registers for parameter passing (if you're going to pass values in registers at all -- there exist some circumstances (typically when the parameters are ignored for a while) when it's better not to pass them as registers).

As an interesting quirk, GCC supports MSVC's _fastcall correctly by creating a two-register pass using ecx,edx; too bad VC can't do the reverse and support GCC's ability to do three-register using eax,edx,ecx. :)
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!