[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bitrotate
From: |
Ben Pfaff |
Subject: |
Re: bitrotate |
Date: |
Fri, 29 Aug 2008 10:14:24 -0700 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) |
Simon Josefsson <address@hidden> writes:
> I have pushed the patch below, but i still appreciate further review of
> the code.
Since you're using the inline keyword, you should add a
dependency on the inline module.
> +/* Given an unsigned 32-bit argument X, return the value corresponding
> + to rotating the bits N steps to the left. N must be between 1 and
> + 31 inclusive. */
> +static inline uint32_t
> +rotl32 (uint32_t x, int n)
> +{
> + return ((x << n) | (x >> (32 - n))) & 0xFFFFFFFF;
> +}
There is no benefit to the bitwise "and" operation: a uint32_t is
guaranteed to have exactly 32 bits, so the conversion implied by
the return statement will trim off any high bits. Similarly for
the other functions.
--
Ben Pfaff
http://benpfaff.org