cdecl keyword
greg yachuk
greggy at infmx.UUCP
Wed Apr 6 05:16:11 AEST 1988
In article <213 at ateng.UUCP>, chip at ateng.UUCP (Chip Salzenberg) writes:
> In article <185 at premise.ZONE1.COM> chang at premise.ZONE1.COM (John Chang) writes:
> >However, the right to left parameter passing takes more code space
> >(one extra instruction to fix the stack after a function call) and
> >hence takes longer to execute than 'pascal' calling convention
?????????????????????????????
> >(left-to-right parameter passing).
>
> The Pascal calling sequence is faster than C, but for a different reason.
> The Pascal calling sequence is not faster because of its backwards (:-])
> order, but because it does not allow variadic functions. Since the called
> function is always called with the same number of arguments, it can clean
??????????????????????????????????????
> up the stack when it returns instead of making the caller do it.
I realize that this is somewhat of a digression from the original posting,
and that I might be stating the obvious, but I figured that I should get my
2000 lira in sometime.
My first thought was that both of the above posters were wrong, but when put
in the context of the IBM PC (see newsgroup line), it seems that they are both
sort-of correct. The reason that one is faster than the other is not because
of anything inherent in the order of pushing parameters, or in who can clean
up the stack, but rather in the 80x8x instruction set.
The 80x8x return instruction can take an argument which specifies how many
bytes are to be added to the stack pointer after popping the return address.
This is (probably) faster than returning and then increasing the stack pointer
as two separate instructions (as is usually generated by C compilers).
Since this argument is a constant word that follows the RET instruction (in
the OBJ or EXE), it must be fixed. Hence, Pascal can take advantage of it,
but C cannot (because of varargs)(except for very clever compilers :-).
If it wasn't for this instruction (or on machines that do not provide it),
the Pascal model would have to pop the return address, pop the args off
the stack, and then return (either through an indirect jump, or by again
pushing the return address, and then returning). This would probably take
more execution time than using the C model, and possibly even more code.
So while both of the above posters are correct about who can clean up the
stack and when, it is only because of the RET instruction that the Pascal
model can result in smaller code AND faster execution.
As an aside, I attended a Microsoft Windows course last summer, and the
instructor mentioned that for Windows Release 1.0x, they compiled the system
with C and Pascal calling conventions, and the latter was 17% smaller. This
makes sense if some functions are called more than once. However, smaller
is not necessarily the same as faster (it is in this case, I hope :-), and
if it were not for this Intel RET instruction, it could actually be slower.
Greg Yachuk Informix Software Inc., Menlo Park, CA (415) 322-4100
pyramid!infmx!greggy !yes, I chose that login myself, wutzit tooya?
So, like, uh, where do you guys get all these way cool .sig's, anyways?
More information about the Comp.lang.c
mailing list