Re: Question about AMD64 ABI

From: Paul Procacci <pprocacci_at_gmail.com>
Date: Mon, 14 Nov 2022 04:55:54 UTC
>> 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

-- 
__________________

:(){ :|:& };: