Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 13 Nov 2022 10:42:41 -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:  <CAFbbPuge7D4Cky5ucrBg1%2Bp8QLj7t2RMAY-440d935%2BYvyddFw@mail.gmail.com>
In-Reply-To: <TYWP286MB2667168BD04FDA3B30DF0435B8029@TYWP286MB2667.JPNP286.PROD.OUTLOOK.COM>
References:  <CAFbbPujfaSZ%2BxGsKPL4J-arydLCr7=YGyrBTt18Cg8q16z3Tdg@mail.gmail.com> <TYWP286MB2667FDC5425C52AD3A492052B8029@TYWP286MB2667.JPNP286.PROD.OUTLOOK.COM> <CAFbbPuiQHDa6GdmD3BZDfgXJ9_pmQ1g2FYsQ=gvxK12veq%2BSfw@mail.gmail.com> <TYWP286MB2667168BD04FDA3B30DF0435B8029@TYWP286MB2667.JPNP286.PROD.OUTLOOK.COM>

next in thread | previous in thread | raw e-mail | index | archive | help
--000000000000d26b8805ed5bf980
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Sun, Nov 13, 2022 at 7:41 AM Daniel Cervus <DanieltheDeer@outlook.com>
wrote:

>   Sorry if I didn=E2=80=99t make myself clear. in other words, I mean if =
a
> function prototype requires a parameter less than 64 bits (such as int,
> short...), since the ABI requires it to be passed by a 64-bit register,
> will the function completely ignore the unused bits? Can I safely leave t=
he
> garbage in upper bits? Or I have to expand everything to 64 bits?
>

>> 64 bits (such as int, short...), since the ABI requires it to be passed
by a 64-bit register, will the function completely ignore the unused bits?
Can I safely leave the garbage in upper bits? Or I have to expand
everything to 64 bits?

This depends on the function and who wrote it.

What I mean specifically is, if you're a fledgling asm programmer and you
wrote a function with the intention of addressing a 32-bit register, but
instead you address it as a 64-bit register, then that's a problem because
whatever results you get are erroneous.

If instead you're leaning on a compiler to build the function body, then
the compiler will undoubtedly do the right thing.

The above is a long winded way for me to say:  For most purposes and in my
experience has always been that it's safe to ignore higher bits of passed
32-bit registers.

Thanks,
Paul

--=20
__________________

:(){ :|:& };:

--000000000000d26b8805ed5bf980
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div class=
=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Sun, Nov 13, 2022=
 at 7:41 AM Daniel Cervus &lt;<a href=3D"mailto:DanieltheDeer@outlook.com">=
DanieltheDeer@outlook.com</a>&gt; wrote:<br></div><blockquote class=3D"gmai=
l_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,20=
4,204);padding-left:1ex">=C2=A0 Sorry if I didn=E2=80=99t make myself clear=
. in other words, I mean if a function prototype requires a parameter less =
than 64 bits (such as int, short...), since the ABI requires it to be passe=
d by a 64-bit register, will the function completely ignore the unused bits=
? Can I safely leave the garbage in upper bits? Or I have to expand everyth=
ing to 64 bits?<br>
</blockquote></div><br clear=3D"all">&gt;&gt; 64 bits (such as int, short..=
.), since the ABI requires it to be passed=20
by a 64-bit register, will the function completely ignore the unused=20
bits? Can I safely leave the garbage <span class=3D"gmail-Lm gmail-ng">in u=
pper</span> bits? Or I have to expand=20
everything to 64 bits?<br><br></div><div>This depends on the function and w=
ho wrote it. <br><br></div><div>What I mean specifically is, if you&#39;re =
a fledgling asm programmer and you wrote a function with the intention of a=
ddressing a 32-bit register, but instead you address it as a 64-bit registe=
r, then that&#39;s a problem because whatever results you get are erroneous=
.<br><br></div><div>If instead you&#39;re leaning on a compiler to build th=
e function body, then the compiler will undoubtedly do the right thing.<br>=
<br></div><div>The above is a long winded way for me to say:=C2=A0 For most=
 purposes and in my experience has always been that it&#39;s safe to ignore=
 higher bits of passed 32-bit registers.<br></div><div><br></div><div>Thank=
s,</div><div>Paul<br><br></div><div dir=3D"ltr">-- <br><div dir=3D"ltr" cla=
ss=3D"gmail_signature">__________________<br><br>:(){ :|:&amp; };:</div></d=
iv></div>

--000000000000d26b8805ed5bf980--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAFbbPuge7D4Cky5ucrBg1%2Bp8QLj7t2RMAY-440d935%2BYvyddFw>