bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bitrotate


From: Paul Eggert
Subject: Re: bitrotate
Date: Thu, 04 Sep 2008 16:36:13 -0700
User-agent: Gnus/5.101 (Gnus v5.10.10) Emacs/22.2 (gnu/linux)

That change looks good.  Some minor points:

> +/* Given an unsigned 16-bit argument X, return the value corresponding
> +   to rotating the bits N steps to the left.  N must be between 1 to
> +   15 inclusive. */
> +static inline uint16_t
> +rotl16 (uint16_t x, int n)

On all targets of interest for GNU software (including all POSIX-2001
or later targets), N can also be 0 or 16.  That is because 'int' must
be at least 32 bits on these platforms, and the arguments must widen
to at least 32 bits before being shifted.  Perhaps this should be
noted in the comment?  Similarly for rotr16.

> return ((x << n) | (x >> (64 - n))) & 0xFFFFFFFFFFFFFFFFULL;

I found myself wondering "is that the right number of Fs?".  How about
the following rewording instead?  Similarly for the other functions.

  return ((x << n) | (x >> (64 - n))) & UINT64_MAX;

One other thing: if memory serves, the C standard does not require the
existence of uint32_t and uint16_t (this is for portability to 36-bit
hosts, I expect); this can easily be worked around by using #ifdef
UINT32_MAX and #ifdef UINT16_MAX.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]