[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: test-bitrotate.c missing test cases
From: |
Bruno Haible |
Subject: |
Re: test-bitrotate.c missing test cases |
Date: |
Sun, 29 Mar 2020 14:53:49 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-174-generic; KDE/5.18.0; x86_64; ; ) |
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