Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 13 Nov 2022 03:52:20 -0500
From:      Paul Procacci <pprocacci@gmail.com>
To:        Daniel Cervus <DanieltheDeer@outlook.com>
Cc:        "freebsd-questions@freebsd.org" <freebsd-questions@freebsd.org>
Subject:   Re: Question about AMD64 ABI
Message-ID:  <CAFbbPujfaSZ%2BxGsKPL4J-arydLCr7=YGyrBTt18Cg8q16z3Tdg@mail.gmail.com>
In-Reply-To: <TYWP286MB26674EB7EA4AF70734843399B8029@TYWP286MB2667.JPNP286.PROD.OUTLOOK.COM>
References:  <TYWP286MB26674EB7EA4AF70734843399B8029@TYWP286MB2667.JPNP286.PROD.OUTLOOK.COM>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]
On Sat, Nov 12, 2022 at 10:31 PM Daniel Cervus <DanieltheDeer@outlook.com>
wrote:

> Hi everyone,
>
> I’m trying to do assembly programming on FB in 64-bit mode. I have a
> question, 64-bit mode requires parameters to be passed on 64-bit registers.
> But when a parameter is 32-bit or smaller, do I need to sign-extend (or
> zero-extend) them to 64-bit? The System V ABI specifications only says "The
> size of each argument gets rounded up to eightbytes." It’s somewhat
> ambiguous. How to round up 'float', when they are passed on stack?
>
> Thanks,
> Daniel


(Didn't Reply all)

Hi Daniel,

There are a handful of operations that operate on 32bit registers that
automatically clear the high bits for you.

32-bit operands generate a 32-bit result, zero-extended to a 64-bit result
in the destination general-purpose register.
16 and 8 bit operands don't have this "built-in" so you would indeed need
to ensure the higher bits are cleared.

mov dword edi, 1  is effectively setting rdi to the value of
0x0000000000000001

As for sign extending the values, the answer is `no'.....under most
circumstances.  If you are sticking to widths of 32 and 64 bits then you
are fine.
The moment you mess with 16bits or smaller, then yes, you need to ensure no
garbage lives in your higher bits because the cpu doesn't clear this for
you.

"The size of each argument gets rounded up to eight bytes."

The size of ALL arguments passed to the callee via general purpose
registers is 8 bytes "regardless of what a function def says".  It's HOW
the callee operates upon the register arguments that matters.

As for passing arguments on the stack ...  you shouldn't have to.  Not only
are there the GPR's rdi, rsi, rdx, rcx, r8, r9, r10 at your disposal for
int/scalar types there are also xmm0-xmm7 for your floats.

Thanks,
~Paul

-- 
__________________

:(){ :|:& };:

[-- Attachment #2 --]
<div dir="ltr"><div><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Nov 12, 2022 at 10:31 PM Daniel Cervus &lt;<a href="mailto:DanieltheDeer@outlook.com">DanieltheDeer@outlook.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi everyone,<br>
<br>
I’m trying to do assembly programming on FB in 64-bit mode. I have a question, 64-bit mode requires parameters to be passed on 64-bit registers. But when a parameter is 32-bit or smaller, do I need to sign-extend (or zero-extend) them to 64-bit? The System V ABI specifications only says &quot;The size of each argument gets rounded up to eightbytes.&quot; It’s somewhat ambiguous. How to round up &#39;float&#39;, when they are passed on stack?<br>
<br>
Thanks,<br>
Daniel</blockquote></div><br></div>(Didn&#39;t Reply all)<br><br clear="all"><div><div><div><div>Hi Daniel,</div><div><br></div><div>There are a handful of operations that operate on 32bit registers that automatically clear the high bits for you.<br><br>32-bit operands generate a 32-bit result, zero-extended to a 64-bit result in the destination general-purpose register.<br></div><div>16 and 8 bit operands don&#39;t have this &quot;built-in&quot; so you would indeed need to ensure the higher bits are cleared.<br><br></div><div>mov dword edi, 1  is effectively setting rdi to the value of 0x0000000000000001</div><br></div>As
 for sign extending the values, the answer is `no&#39;.....under most 
circumstances.  If you are sticking to widths of 32 and 64 bits then you
 are fine.</div><div>The moment you mess with 16bits or smaller, then 
yes, you need to ensure no garbage lives in your higher bits because the
 cpu doesn&#39;t clear this for you.<span class="gmail-im"><br><br>&quot;The size of each argument gets rounded up to eight bytes.&quot;<br></span></div><div><br>The
 size of ALL arguments passed to the callee via general purpose 
registers is 8 bytes &quot;regardless of what a function def says&quot;.  It&#39;s HOW
 the callee operates upon the register arguments that matters.<br><br></div><div>As
 for passing arguments on the stack ...  you shouldn&#39;t have to.  Not 
only are there the GPR&#39;s rdi, rsi, rdx, rcx, r8, r9, r10 at your 
disposal for int/scalar types there are also xmm0-xmm7 for your floats.<br></div><div><br></div><div><div><div>Thanks,</div><div>~Paul</div></div></div><br>-- <br><div dir="ltr" class="gmail_signature">__________________<br><br>:(){ :|:&amp; };:</div></div></div>
help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAFbbPujfaSZ%2BxGsKPL4J-arydLCr7=YGyrBTt18Cg8q16z3Tdg>