From: Joseph Myers <joseph@codesourcery.com>
To: Jakub Jelinek <jakub@redhat.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: Thu, 23 Nov 2023 00:09:05 +0000 [thread overview]
Message-ID: <27683a52-8754-c85b-df8d-abd0a5676f0@codesourcery.com> (raw)
In-Reply-To: <ZVt7aYPx5pNMYi8h@tucnak>
On Mon, 20 Nov 2023, Jakub Jelinek wrote:
> On Mon, Nov 20, 2023 at 04:03:07PM +0100, Jakub Jelinek wrote:
> > > 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;
> >
> > Given the feedback from Richi I've in the meantime reworked the patch to
> > add all 14 builtins (but because the enum rid is very close to 256 values
> > and with 14 new ones was already 7 too many, used one RID value for all 14
> > builtins (different spellings)).
> >
> > Will need to rework it for CD2 FR-135 then...
>
> Here it is updated to use that
> x <= 1 ? 1 : ((type) 2) << (prec - 1 - __builtin_clzg ((type) (x - 1)))
> I've mentioned.
>
> 2023-11-20 Jakub Jelinek <jakub@redhat.com>
>
> gcc/
> * doc/extend.texi (__builtin_stdc_bit_ceil, __builtin_stdc_bit_floor,
> __builtin_stdc_bit_width, __builtin_stdc_count_ones,
> __builtin_stdc_count_zeros, __builtin_stdc_first_leading_one,
> __builtin_stdc_first_leading_zero, __builtin_stdc_first_trailing_one,
> __builtin_stdc_first_trailing_zero, __builtin_stdc_has_single_bit,
> __builtin_stdc_leading_ones, __builtin_stdc_leading_zeros,
> __builtin_stdc_trailing_ones, __builtin_stdc_trailing_zeros): Document.
> gcc/c-family/
> * c-common.h (enum rid): Add RID_BUILTIN_STDC: New.
> * c-common.cc (c_common_reswords): Add __builtin_stdc_bit_ceil,
> __builtin_stdc_bit_floor, __builtin_stdc_bit_width,
> __builtin_stdc_count_ones, __builtin_stdc_count_zeros,
> __builtin_stdc_first_leading_one, __builtin_stdc_first_leading_zero,
> __builtin_stdc_first_trailing_one, __builtin_stdc_first_trailing_zero,
> __builtin_stdc_has_single_bit, __builtin_stdc_leading_ones,
> __builtin_stdc_leading_zeros, __builtin_stdc_trailing_ones and
> __builtin_stdc_trailing_zeros. Move __builtin_assoc_barrier
> alphabetically earlier.
> gcc/c/
> * c-parser.cc (c_parser_postfix_expression): Handle RID_BUILTIN_STDC.
> * c-decl.cc (names_builtin_p): Likewise.
> gcc/testsuite/
> * gcc.dg/builtin-stdc-bit-1.c: New test.
> * gcc.dg/builtin-stdc-bit-2.c: New test.
OK with tests added for unsigned _BitInt(1). Specifically, unsigned
_BitInt(1) is a bit of a degenerate case for stdc_bit_ceil (always
returning 1 after evaluating the argument's side effects); I think the
code that builds of constant 2 of that type (a constant only used in dead
code) should still work (and produce a constant 0), and that the
documentation is also still correct in the case where converting 2 to the
type produces 0, but given those degeneracies I think it's worth testing
unsigned _BitInt(1) with these functions to make sure they do behave as
expected.
--
Joseph S. Myers
joseph@codesourcery.com
next prev parent reply other threads:[~2023-11-23 0:09 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 [this message]
2023-11-23 10:05 ` Jakub Jelinek
2023-11-20 15:12 ` Jakub Jelinek
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=27683a52-8754-c85b-df8d-abd0a5676f0@codesourcery.com \
--to=joseph@codesourcery.com \
--cc=fweimer@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.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).