bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* test-bitrotate.c missing test cases
@ 2020-03-29  9:00 Jeffrey Walton
  2020-03-29 10:27 ` Jeffrey Walton
  2020-03-29 12:53 ` Bruno Haible
  0 siblings, 2 replies; 6+ messages in thread
From: Jeffrey Walton @ 2020-03-29  9:00 UTC (permalink / raw)
  To: bug-gnulib

Hi Everyone,

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. It is
recognized by Clang, GCC, ICC. It will be compiled down to a single
instruction on platforms like IA-32. I can find the mailing list
messages for a citation, if needed.

BITROTATE_INLINE uint32_t
rotl32 (uint32_t x, int n)
{
  return ((x << n) | ( x>>(-n&31));
}

BITROTATE_INLINE uint32_t
rotr32 (uint32_t x, int n)
{
  return ((x >> n) | ( x<<(-n&31));
}

Ditto for the other rotates, like rotl64 and rotr64. The 64-bit
rotates should use a mask of 63 instead of 31.

Jeff


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-03-31  6:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2020-03-29 13:10   ` Jeffrey Walton
2020-03-29 15:40     ` Bruno Haible
2020-03-31  6:31       ` Jeffrey Walton

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).