public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: LIU Hao <lh_mouse@126.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>,
	Andrew Cooper via Gcc <gcc@gcc.gnu.org>
Subject: Re: Builtin for consulting value analysis (better ffs() code gen)
Date: Thu, 21 Mar 2024 16:15:04 +0800	[thread overview]
Message-ID: <7bcb6398-cc7a-41ab-b8e2-ce4f0e9e5b7c@126.com> (raw)
In-Reply-To: <9704774f-00f9-48d4-ad27-6cd07a816359@citrix.com>


[-- Attachment #1.1: Type: text/plain, Size: 931 bytes --]

在 2024-03-14 23:33, Andrew Cooper via Gcc 写道:
> And for x86's arch_ffs(),
> 
> unsigned int arch_ffs(unsigned int x)
> {
>      unsigned int res;
> 
>      if ( __builtin_constant_p(x > 0) && x > 0 )
>      {
>          // Well defined when x is known non-zero
>          asm("bsf %1, %0" : "=r"(res) : "rm"(x));

Even if you may assume that the destination operand is always destroyed, the hardware has no 
knowledge about that, so this statement has a dependency on `res`, and shouldn't be declared `=r`.

I think it's better to remove this `if`. The other branch below clearly eliminates the dependency.


>      }
>      else
>      {
>          // The architects say this is safe even for 0.
>          res = -1;
>          asm("bsf %1, %0" : "+r"(res) : "rm"(x));
>      }
> 
>      return res + 1;
> }

-- 
Best regards,
LIU Hao


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

  reply	other threads:[~2024-03-21  8:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-14  0:03 Andrew Cooper
2024-03-14  6:04 ` Alexander Monakov
2024-03-14 11:30   ` Andrew Cooper
2024-03-14 12:03     ` Andreas Schwab
2024-03-14 15:33       ` Andrew Cooper
2024-03-21  8:15         ` LIU Hao [this message]
2024-03-14 11:02 ` Florian Weimer
2024-03-14 11:52   ` Andrew Cooper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7bcb6398-cc7a-41ab-b8e2-ce4f0e9e5b7c@126.com \
    --to=lh_mouse@126.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).