From: Jakub Jelinek <jakub@redhat.com>
To: Joseph Myers <joseph@codesourcery.com>
Cc: gcc-patches@gcc.gnu.org, Florian Weimer <fweimer@redhat.com>
Subject: Re: [PATCH] c: Add __builtin_stdc_bit_{width,floor,ceil} builtins
Date: Mon, 20 Nov 2023 16:12:35 +0100 [thread overview]
Message-ID: <ZVt3YQaO+V0mxwn1@tucnak> (raw)
In-Reply-To: <c664e0cd-ce8-1d99-353-a6e12e91d95@codesourcery.com>
On Mon, Nov 20, 2023 at 02:55:33PM +0000, Joseph Myers wrote:
> On Sat, 18 Nov 2023, Jakub Jelinek wrote:
>
> > +@defbuiltin{@var{type} __builtin_stdc_bit_ceil (@var{type} @var{arg})}
> > +The @code{__builtin_stdc_bit_ceil} function is available only
> > +in C. It is type-generic, the argument can be any unsigned integer
> > +(standard, extended or bit-precise). No integral argument promotions are
> > +performed on the argument. It is equivalent to
> > +@code{@var{arg} <= 1 ? (@var{type}) 1
> > +: (@var{type}) 1 << (@var{prec} - __builtin_clzg ((@var{type}) (@var{arg} - 1)))}
> > +where @var{prec} is bit width of @var{type}, except that side-effects
> > +in @var{arg} are evaluated just once.
> > +@enddefbuiltin
>
> Note that stdc_bit_ceil now has defined behavior (return 0) on overflow:
> CD2 comment FR-135 was accepted for the DIS at the June WG14 meeting.
> This affects both the documentation and the implementation, as they need
> to avoid an undefined shift by the width of the type. That's why my
> stdbit.h implementations have two shifts (not claiming that's necessarily
> the optimal way of ensuring the correct result in the overflow case).
>
> return __x <= 1 ? 1 : ((uint64_t) 1) << (__bw64_inline (__x - 1) - 1) << 1;
So
return __x <= 1 ? 1 : ((uint64_t) 2) << (__bw64_inline (__x - 1) - 1);
then?
Jakub
next prev parent reply other threads:[~2023-11-21 8:22 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-18 19:42 Jakub Jelinek
2023-11-20 14:55 ` Joseph Myers
2023-11-20 15:03 ` Jakub Jelinek
2023-11-20 15:29 ` Jakub Jelinek
2023-11-21 8:24 ` Jakub Jelinek
2023-11-23 0:09 ` Joseph Myers
2023-11-23 10:05 ` Jakub Jelinek
2023-11-20 15:12 ` Jakub Jelinek [this message]
2023-11-21 23:35 ` Joseph Myers
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=ZVt3YQaO+V0mxwn1@tucnak \
--to=jakub@redhat.com \
--cc=fweimer@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=joseph@codesourcery.com \
/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).