From: Bruno Haible <bruno@clisp.org>
To: bug-gnulib@gnu.org, noloader@gmail.com
Subject: Re: test-bitrotate.c missing test cases
Date: Sun, 29 Mar 2020 14:53:49 +0200 [thread overview]
Message-ID: <36880643.fgSLelLy8r@omega> (raw)
In-Reply-To: <CAH8yC8=Ag8v8pxVboUtoD9pZUg67wuLr2+ZQUU_QkPO07fmj7w@mail.gmail.com>
Hi Jeffrey,
> It looks like test-bitrotate.c is missing test cases. It is missing
> the 32-bit rotl and rotr of 0-bits.
>
> The 0-bit rotate should tickle undefined behavior.
>
> If you want to clear the undefined behavior, then use this code. ...
The functions are specified in bitrotate.h, e.g. like this:
/* Given an unsigned 64-bit argument X, return the value corresponding
to rotating the bits N steps to the left. N must be between 1 and
63 inclusive. */
BITROTATE_INLINE uint64_t
rotl64 (uint64_t x, int n)
I think it is on purpose that N = 0 and N = 64 are not allowed. Namely,
when N = 0 or N = 64, you would have a different, more efficient code
branch anyway.
> It will be compiled down to a single instruction on platforms like IA-32.
Yes, this is the intent. And we should help the compiler produce good
code, for example by adding statements like
assume (n > 0 && n < 64);
Allowing N = 0 or N = 64 goes backwards, because on some platforms it
will prevent the compiler from choosing the best possible instruction.
Bruno
next prev parent reply other threads:[~2020-03-29 12:54 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-29 9:00 test-bitrotate.c missing test cases Jeffrey Walton
2020-03-29 10:27 ` Jeffrey Walton
2020-03-29 12:53 ` Bruno Haible [this message]
2020-03-29 13:10 ` Jeffrey Walton
2020-03-29 15:40 ` Bruno Haible
2020-03-31 6:31 ` Jeffrey Walton
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
List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=36880643.fgSLelLy8r@omega \
--to=bruno@clisp.org \
--cc=bug-gnulib@gnu.org \
--cc=noloader@gmail.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).