D
David Brown
Le 17/02/2014 11:27, David Brown a écrit :
Adding 32 bytes of stack space is not really anything complex!
That space is required to save the values of the 4 registers that hold
the arguments in case it is needed to save them. Nothing really
extraordinary!
Adding stack space is not particularly complex - it is a standard
operation used in many functions. But it is obviously vastly more
complex than not adding stack space at all. A lot of functions can get
away without doing any stack allocation, especially on x86-64 which has
quite a few registers (and on other cpu architectures with more
registers). Omitting stack allocation, frame pointers, and stack
deallocation saves code. Forcing functions to allocate 32 bytes,
whether they are needed or not, means extra code and wasted time. If
the callee function needs to save the parameter registers on the stack,
then there is a high chance that it needs to put more on the stack - so
the pre-allocation of 32 bytes is wasted. With the Linux ABI, there
only needs to be /one/ stack allocation, of exactly the size actually
needed (and sometimes that can be omitted too, if the function is a leaf
function).
So no, allocating 32 bytes on the stack is not difficult or complex.
But it will almost always be a waste of effort - it is inefficient.
Excuse me but Intel did not say anything about calling conventions that
is a myth.
You are probably right on that one, as Intel played catch-up to AMD
here. So let me change that and say the calling convention was designed
by AMD to be the most efficient for their instruction set. Technically,
I believe the ABI made by AMD here was targeting *nix systems - but at
the time it was defined, *nix was the only system that was ready for
64-bit x86.
And there were NO compatibility reasons either because 64 bit
code is completely different than 32 bit code because there are 8 new
registers, and (at last) the possibility of using the registers to pass
arguments.
I can't think of any particular compatibility reasons here either - but
I can't think of any other reason why MS would pick a different ABI and
calling convention when they started Windows for x86-64. /Maybe/ the
compatibility was for their previous 64-bit Windows versions (such as
for the DEC Alpha betas, or for the Itanium) - I don't know any details
here, so I am guessing. I presume they had /some/ reason for picking
something more complicated and less efficient than the existing standard.
One ABI change that MS /did/ make for compatibility reasons is the size
of "long" - on most x86-64 systems, "long" is 64 bits, but on Win64 it
is 32 bits as an ease to existing Windows programmers who made
assumptions about the size of "long".
There is no basis for that but keep your opinion if you wish. I agree
that we disagree.
My basis is the facts of the calling conventions, which are well
documented on the web. Opinions about what effect this would have on
the real-world speed of the code are merely opinions, as I haven't
tested them (and as noted I don't think the differences will be very
significant for most code).