flat assembler
Message board for the users of flat assembler.

Index > Windows > Win32 calls. Register usage?

Goto page Previous  1, 2, 3, ... 9, 10, 11  Next
Author
Thread Post new topic Reply to topic
bitRAKE



Joined: 21 Jul 2003
Posts: 3037
Location: vpcmipstrm
bitRAKE
cdecl has fewer dependencies - can be faster than stdcall. There are often code patterns calling the same function with slightly different parameters. Personally, I use what works best for the code (i.e. hybrids) - maximizing cohesion and minimizing reuse, lol.

Windows 64 combines fastcall and cdecl conventions.

The alignment requirement has me using a two level convention throughout - not counting leaf functions. The first level is dictated by Windows, the second level can access parameters from the first level with the call instruction aligning the stack - in contrast the windows unaligning the stack with the call instruction return address. Additionally, the second level doesn't have a shadow/home area.

Another trick is to POP the return address into the fifth parameter space, and reuse the shadow stack space locally. I know - unconventional.
Post 17 May 2009, 22:15
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
bitRake wrote:
Personally, I use what works best for the code (i.e. hybrids) - maximizing cohesion and minimizing reuse, lol.
I agree hybrids are good, but I still don't see why would anyone use cdecl.
Post 20 May 2009, 00:58
View user's profile Send private message Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu
revolution wrote:
For variable argument counts. Else how?
Obviously it knows how many arguments there are, since it uses all of them.
The first arg passed tells it how many more there are to expect.
There is no reason for it not to use this to clean up the stack. Just another example of bad Windows code.
Post 03 Jun 2009, 23:28
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17659
Location: In your JS exploiting you and your system
revolution
Sure, but remember that the API is written in an HLL (probably C) so variable stack adjustments are not possible since the compiler doesn't support it. And inserting asm code just for that one function is not a sensible solution for HLL programmers targeting multiple systems. Besides, it is not a very critical function, and it is only that one function in the the entire API.
Post 03 Jun 2009, 23:35
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu
revolution wrote:
Sure, but remember that the API is written in an HLL (probably C) so variable stack adjustments are not possible since the compiler doesn't support it. And inserting asm code just for that one function is not a sensible solution for HLL programmers targeting multiple systems.
It trashes the stack though. So obviously it IS taking all the parameters off the stack.. but then at the end doing something like 'add esp,varcount'.. what is the point of this?


revolution wrote:
Besides, it is not a very critical function, and it is only that one function in the the entire API.
It's just one function that is like this, and it's used very often.. isn't that a reason to make it good?




And if the performance DOESN'T matter.. why even make a new calling standard for this function, when the normal way works fine?
The first arg would be the same as it is now.. and there would be a second arg that points to the string of "arguments". Voila, no more need for vararg.
This way might actually be faster in some situations, like when you want to re-use it without changing everything.
Post 03 Jun 2009, 23:39
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17659
Location: In your JS exploiting you and your system
revolution
Azu wrote:
It trashes the stack though. So obviously it IS taking all the parameters off the stack.. but then at the end doing something like 'add esp,varcount'.. what is the point of this?
Have a look at the code with your disassembler. I think you will find it does not do what you suggest.
Azu wrote:
And if the performance DOESN'T matter.. why even make a new calling standard for this function, when the normal way works fine?
But the normal way doesn't "work fine", it is a problem for HLL code.
Azu wrote:
The first arg would be the same as it is now.. and there would be a second arg that points to the string of "arguments". Voila, no more need for vararg.
This way might actually be faster in some situations, like when you want to re-use it without changing everything.
There is already an alternate function that does this, wvsprintf. You are not forced to use the vararg version, but it is more convenient in many circumstances. Up to you what you want to use.
Post 03 Jun 2009, 23:50
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu
revolution wrote:
Have a look at the code with your disassembler. I think you will find it does not do what you suggest.
Oh. Turns out it is just a wrapper function for wvsprintf.


revolution wrote:
But the normal way doesn't "work fine", it is a problem for HLL code.
There is already an alternate function that does this, wvsprintf

So wvsprintf wasn't written in an HLL? They created it in MASM or something??
Post 03 Jun 2009, 23:55
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17659
Location: In your JS exploiting you and your system
revolution
Azu wrote:
So wvsprintf wasn't written in an HLL? They created it in MASM or something??
I doubt it needs to be written in asm. It is within the normal C (and other HLL) compiler capabilities. There are no tricky stack adjustments required in the non-vararg version.
Post 04 Jun 2009, 00:01
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu
revolution wrote:
Azu wrote:
So wvsprintf wasn't written in an HLL? They created it in MASM or something??
I doubt it needs to be written in asm. It is within the normal C (and other HLL) compiler capabilities. There are no tricky stack adjustments required in the non-vararg version.
Oh. I thought you said it wouldn't work in an HLL. Confused
Post 04 Jun 2009, 00:19
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17659
Location: In your JS exploiting you and your system
revolution
I said the vararg version is not possible in HLL with auto stack adjustment (stdcall), that is why it is ccall.

The non-vararg version is not a problem.

The vararg wraps the non-vararg, like you saw in the disassembler. The non-vararg can adjust the stack (stdcall) but the vararg cannot, it is still a ccall version, it can't adjust the stack.
Post 04 Jun 2009, 00:31
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
revolution wrote:
I said the vararg version is not possible in HLL with auto stack adjustment (stdcall), that is why it is ccall.
Are you joking? Of course it is. Just make the compiler push the last argument as the 'number of args' transparently if it detects varargs. (and also, the function, offset every parameter by 1 variable more because there's an invisible one at the beginning).

_________________
Previously known as The_Grey_Beast
Post 05 Jun 2009, 01:09
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17659
Location: In your JS exploiting you and your system
revolution
Borsuc: How many HLLs do you know that can directly manipulate the stack register? In asm we can do all those fancy tricks, but not in an HLL.
Post 05 Jun 2009, 01:24
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3037
Location: vpcmipstrm
bitRAKE
That wouldn't be STDCALL convention then, Borsuc - it's a good idea none the less to adjust the stack automatically in the case of variable arguments. Simply having the callee manage the array of arguments (passing a pointer) is the usual solution - it is seen throughout the Win APIs.
Post 05 Jun 2009, 01:28
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
I'm talking about a different calling convention.
You can do in a HLL the same way cdecl does it: by making another convention. Or rather, get rid of cdecl and/or replace it with that method I described.

Like maybe call it smartcdecl Razz

_________________
Previously known as The_Grey_Beast
Post 05 Jun 2009, 02:58
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17659
Location: In your JS exploiting you and your system
revolution
To what end? It is only one function anyway. No need to invent a whole new calling convention for it.
Post 05 Jun 2009, 03:07
View user's profile Send private message Visit poster's website Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
revolution wrote:
To what end? It is only one function anyway. No need to invent a whole new calling convention for it.
BUT THERE IS! WE ARE LOSING OMG PRECIOUS CLOCK CYCLES BIGTIME BECAUSE OF THIS LEIM CALLING CONVENTION OMG!</sarcasm>

_________________
Image - carpe noctem
Post 05 Jun 2009, 05:20
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17659
Location: In your JS exploiting you and your system
revolution
Haha, yeah, if your whole code is so reliant upon wsprintf and you complain that you are losing precious time because of an extra add esp,x after each call, then you have written your app very wrongly.
Post 05 Jun 2009, 05:45
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
You can't fix something fully by ignoring even one small fix. Razz
Post 06 Jun 2009, 22:42
View user's profile Send private message Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu
revolution wrote:
To what end? It is only one function anyway. No need to invent a whole new calling convention for it.
They felt the need to make "a whole new calling convention" for this "one little function", so they may as well do it right..


BTW why does this forum keep forgetting to notify me when a reply is posted? I have to keep re-checking the box over and over.. =/
Post 07 Jun 2009, 07:56
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
Azu wrote:
revolution wrote:
To what end? It is only one function anyway. No need to invent a whole new calling convention for it.
They felt the need to make "a whole new calling convention" for this "one little function", so they may as well do it right..
No, they went with standard cdecl.

_________________
Image - carpe noctem
Post 07 Jun 2009, 08:28
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3, ... 9, 10, 11  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.