flat assembler
Message board for the users of flat assembler.

Index > Main > Registers vs. stack in calling convention

Author
Thread Post new topic Reply to topic
beppe85



Joined: 23 Oct 2004
Posts: 181
beppe85
Passing arguments on stack is too slow for small, lightweight routines, but for non-leaves routines they perform pretty well. So I made an attempt to put in numbers its (in)efficiency.

I provide two macroes, regcall and stdcall. The first pass arguments on eax, edx, ecx, ebx before pass control to callee. The last pushes arguments on stack.

With this I want to know the best way to pass arguments. The overhead of stdcall can be tolerated, as it's the easiest to use? Or should regcall be used for being lightning fast?

I would like to hear your experience.


Description: This is the benchmark. Macroes included.
Download
Filename: CallConv.ASM
Filesize: 2.87 KB
Downloaded: 213 Time(s)

Post 10 Jan 2005, 15:45
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
Imho, if the overhead of stack-call is a bottleneck in your program, you should re-think the design - inline very small routines (probably through the use of macros to avoid maintenance nightmare). Stack calling also has the advantage of being able to use, say, a "counter" or "length" argument directly from the stack, freeing up a x86 register - ie, "dec [esp + ARG_COUNT]" rather than putting it in a register. It should be fast enough since the stack is in L1 cache.

Register based calling convention forces you to write your code around this calling convention. And for some algorithms, it means you might have to do register preservation and parameter shuffling when calling the routines.

If you have a function that takes a lot of argument, you could consider putting those arguments in a structure, and only passing a pointer to this structure - that can help both speed- and size-wise.
Post 10 Jan 2005, 18:34
View user's profile Send private message Visit poster's website Reply with quote
beppe85



Joined: 23 Oct 2004
Posts: 181
beppe85
I missed the role of the cache, but even so, in leaf routines you need to perform more actions(code).

But no, I'm not considering routines with many parameters, having 6 as ideal maximum, the point I could think in build up structures or break subroutine in smaller functional parts.

I want to broaden the scope of the question a little. I usually set (eax,edx, ecx) as caller-save and the others as callee-save. What combination do you think is best, for both speed and ease?
Post 10 Jan 2005, 19:26
View user's profile Send private message Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc
I use a custom stack for passing data. (eax is the top of my stack, esi points to the rest of it. A few macros simplify using it). The hardware stack is mostly used for return addresses (I have a lot of small functions and sometimes being able to manipulate the hardware stack is helpful)

Register-based calling conventions are worse in my view as you have to save/restore the registers. Passing them directly on the hardware stack reduces the impact on the register useage even further.
Post 11 Jan 2005, 01:38
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:  


< 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.

Powered by rwasa.