public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Richard Biener <rguenther@suse.de>,
	"Joseph S. Myers" <joseph@codesourcery.com>,
	Jason Merrill <jason@redhat.com>,
	gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] Add type-generic clz/ctz/clrsb/ffs/parity/popcount builtins [PR111309]
Date: Sat, 11 Nov 2023 09:18:25 +0100	[thread overview]
Message-ID: <ZU840RRwhul7CwKB@tucnak> (raw)
In-Reply-To: <ZU37bBPOZTk2aIv/@tucnak>

On Fri, Nov 10, 2023 at 10:44:12AM +0100, Jakub Jelinek wrote:
> Because the builtins are just something matching in behavior to existing
> builtins which can be used for those macros, not exact implementation of
> those.

BTW, the new builtins also allow implementation of generic signed_type_for
and unsigned_type_for macros in C (together with __builtin_classify_type),
I think _Generic over known standard and extended types plus for _BitInt
(__builtin_classify_type (__typeof (x)) == 18) something like in the
following source:

void bar (_BitInt(193) *, unsigned _BitInt(193) *);

void
foo (void)
{
  unsigned _BitInt(193) a = 0uwb;
  _BitInt(__builtin_popcountg ((__typeof (a)) -1)) b = 0wb;
  bar (&b, &a);
}

void
baz (void)
{
  _BitInt(193) a = 0wb;
  unsigned _BitInt(__builtin_clrsbg ((__typeof (a)) - 1) + 1) b = 0uwb;
  bar (&a, &b);
}

One needs to use __builtin_popcountg on all ones for unsigned types and
1 + __builtin_clrsbg on all ones for signed types, but otherwise it seems to
work fine.  Of course, for signed_type_for one would need to decide what
to do with unsigned _BitInt(1) type which doesn't have signed counterpart,
but that can be dealt in _Generic.

	Jakub


  reply	other threads:[~2023-11-11  8:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-09 15:02 Jakub Jelinek
2023-11-09 21:43 ` Joseph Myers
2023-11-10  8:09 ` Richard Biener
2023-11-10  9:10   ` Jakub Jelinek
2023-11-10  9:19     ` Richard Biener
2023-11-10  9:44       ` Jakub Jelinek
2023-11-11  8:18         ` Jakub Jelinek [this message]
2023-11-13 23:45     ` Joseph Myers
2023-12-16  5:51 ` Andrew Pinski
2023-12-16  8:36   ` Jakub Jelinek

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=ZU840RRwhul7CwKB@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=joseph@codesourcery.com \
    --cc=rguenther@suse.de \
    /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).