From nobody Sun Nov 13 15:42:41 2022 X-Original-To: freebsd-questions@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4N9Gt63ZzBz4hPt2 for ; Sun, 13 Nov 2022 15:42:54 +0000 (UTC) (envelope-from pprocacci@gmail.com) Received: from mail-oa1-x2b.google.com (mail-oa1-x2b.google.com [IPv6:2001:4860:4864:20::2b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4N9Gt61BvQz3RFT for ; Sun, 13 Nov 2022 15:42:54 +0000 (UTC) (envelope-from pprocacci@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-12c8312131fso10212095fac.4 for ; Sun, 13 Nov 2022 07:42:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=t1bOGi9AiKC2aQ6NGn5KIxiy7k1De4P768HHgFUUxt0=; b=jZxIopV29HgwSx9fTvU34GfPnFFTVfYm1hrlOAw3l2ooFRODwovRjD2giLn9IrfVcY /bT/l4rkZXaX2ToFnLqQd0JiypqspSNRA5vuBl5WMtZk3frcmL9h7NgSaeltvyp4CTPa qacHL8WdRazfYBI782gWOhB09EwCxLStlExib4vmvZCv5pfpIFX1ecIOEgr/hpX4YXaA RsUgNJXp4ilURoLQEnK+GUrQqRTulz9iLsU8jXbV4LgRhTDZXlwEs3emhjLOmGp5a1L9 YOkf7Jcr+vrOWf3ykKUDUBlgqSOEAh2W+ARiGtcFPLZI9Szj9Ez/i85aVbVXMGe57T1b kdiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=t1bOGi9AiKC2aQ6NGn5KIxiy7k1De4P768HHgFUUxt0=; b=3s98+zIKL6WBqdT9l1aS1p9gRSKUNZvoQg8pvpS+tVK6DKlhoVsJt5O/4wYrn2OI5C 8KvEeJR8pWUkfZfq3+Ezmv1celXYKHisPkpu4yYMbdgJ1Wy1ap7Wezx3VjwIG+emR8nz lv/Dd6aiUwNui/UQlXEIwMQc67qLqxk1KbMa2Qz33aafoy6OQjDfIl1H2ZhseRbRlgGe JX7X5h35m2+q4qIVYGV/Ztewt2nZl5gy1CqOWioxkOtyLfTn4MM0sxl0izXtpdWm0tWd IcMIOl4kc2fAW76nBE4nFKY+aFaVpLemp020dEsPmsO+XNhrWSJYHBRbjEnQm3uhB70G hecA== X-Gm-Message-State: ANoB5pkSd78Sqo6JV73poGQ42Kh+wExc2+M5ZNUdFoy7VxfZly7cYXIF 8TOZKXQat06IJrn+ZxFUW13tgzyn5eyXvfebbRjXHjih2nUo X-Google-Smtp-Source: AA0mqf4uD5OuDh+SffePklveDMF+Ylw7sA5t7nNwbp55JtxAf8MOeq4w0X5JPOi2TYu+mzCl9PlvjldEwoMmwpoTbX0= X-Received: by 2002:a05:6871:4317:b0:12c:2494:b571 with SMTP id lu23-20020a056871431700b0012c2494b571mr4915835oab.225.1668354172675; Sun, 13 Nov 2022 07:42:52 -0800 (PST) List-Id: User questions List-Archive: https://lists.freebsd.org/archives/freebsd-questions List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org MIME-Version: 1.0 References: In-Reply-To: From: Paul Procacci Date: Sun, 13 Nov 2022 10:42:41 -0500 Message-ID: Subject: Re: Question about AMD64 ABI To: Daniel Cervus Cc: "freebsd-questions@freebsd.org" Content-Type: multipart/alternative; boundary="000000000000d26b8805ed5bf980" X-Rspamd-Queue-Id: 4N9Gt61BvQz3RFT X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:2001:4860:4864::/48, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N --000000000000d26b8805ed5bf980 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, Nov 13, 2022 at 7:41 AM Daniel Cervus 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


On Sun, Nov 13, 2022= at 7:41 AM Daniel Cervus <= DanieltheDeer@outlook.com> wrote:
=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?

>> 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 in u= pper bits? Or I have to expand=20 everything to 64 bits?

This depends on the function and w= ho wrote it.

What I mean specifically is, if you'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's a problem because whatever results you get are erroneous= .

If instead you're leaning on a compiler to build th= e function body, then the compiler will undoubtedly do the right thing.
=
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's safe to ignore= higher bits of passed 32-bit registers.

Thank= s,
Paul

--
__________________

:(){ :|:& };:
--000000000000d26b8805ed5bf980--