This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: C/C++ Calling assembler
- From: Bob Plantz <plantz at cds1 dot net>
- To: John Fine <johnsfine at verizon dot net>
- Cc: gcc-help at gcc dot gnu dot org, Michael <michael dot yacc at blueyonder dot co dot uk>
- Date: Fri, 01 May 2009 08:46:41 -0700
- Subject: Re: C/C++ Calling assembler
- References: <!&!AAAAAAAAAAAYAAAAAAAAANA8SANFHgdHhIs3uy+XLe3CgAAAEAAAAOEDoz/FQkdEmgQI70kHLY8BAAAAAA==@blueyonder.co.uk> <49FAF90B.5070202@verizon.net>
On Fri, 2009-05-01 at 09:28 -0400, John Fine wrote:
> > An examination of the assembler produced always shows it passes the buffer
> > pointer in %edi and not on the stack.
> >
> ?? %edi not %rdi ??
>
> That would mean you are compiling 32 bit code. I assume that is not
> what you intended.
>
> But possibly with a statically allocated buffer, the compiler can deduce
> that the buffer will be in the first 4GB at run time and it can put the
> correct address into rdi more efficiently by moving it to edi (with
> implicit zeroing of the high 32 bits) than by moving it to rdi.
Yes, apparently the compiler does this. It will, for example, put
constants like text messages in a "small memory" area and pass the
address in the 32-bit portion of the register. Because changing the
32-bit portion of the register always zeros the high-order 32 bits, this
results in a correct 64-bit address. The main saving here is that the
instruction to access edi does not require a REX prefix byte, but rdi
does.
Aside: changing 8 or 16 bits in a register does NOT affect the other
portions of the register.
Bob