Re: Question about AMD64 ABI

From: Paul Procacci <pprocacci_at_gmail.com>
Date: Mon, 14 Nov 2022 05:12:46 UTC
On Sun, Nov 13, 2022 at 11:55 PM Paul Procacci <pprocacci@gmail.com> wrote:

> >> And what if the function requires a 16-bit or an 8-bit parameter?
>
> When you pass a value, you pass the entirety of the 64-bit register to the
> function.
> If there's even the slightest chance that the function body acts upon the
> entirety of the register, then you _should_ ensure it's zero padded
> appropriately.
>
> Again, most compilers are smart enough to perhaps `and reg, 0x0FFFF` or
> simply ignore the high bits on its own, but ultimately you do feed it the
> entire register in which if the callee expects to operate on 16-bits or
> smaller it better do so.
>
> As the programmer of the callee, YOU can take shortcuts.  If YOU want to
> pass an 8-bit value to a function that you wrote that expects 8-bits then
> you can do as you please; don't worry about anything, don't clear the high
> bits, etc.
> However, note this will seldom be the case.  In the 64-bit amd
> environment, you'll be operating on 32-bit operands MOST of the time (again
> which automatically clears the high bits for you), if not 64 bits directly.
>
> To wrap this all up ... if you want to write a `memcpy' function, its
> parameter should expect a `char' that's been zero filled to an `int'.
> 0xFF -> 0x000000FF
> In the function `memcpy' this isn't so important, but when it comes to
> arithmetic related ops like `inc/dec/add/sub/etc' it matters as to avoid
> eflag stalls.
>
> Thanks,
> ~Paul
>
> --
> __________________
>
> :(){ :|:& };:
>


As an aside to the above, feel free to start writing something, and send me
some personal emails with snippets and examples of what you might have in
mind.
I'm happy to critique and provide comments as necessary.  I also have a
treasure trove of asm related things that I wrote that could potentially
help with your asm endeavors.
Fair warning though, this isn't for the faint of heart.  There's seldom a
case where I've been able to out-wit a compiler.  They are THAT good
nowadays.

~Paul

-- 
__________________

:(){ :|:& };: