Re: bitrotate

2008-09-08 Thread Simon Josefsson
Paul Eggert <[EMAIL PROTECTED]> writes: > 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

Re: bitrotate

2008-09-04 Thread Ben Pfaff
Paul Eggert <[EMAIL PROTECTED]> writes: > 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. For wha

Re: bitrotate

2008-09-04 Thread Paul Eggert
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 f

Re: bitrotate

2008-09-02 Thread Simon Josefsson
Eric Blake <[EMAIL PROTECTED]> writes: > Simon Josefsson josefsson.org> writes: > >> >> Thanks for ideas. I have pushed this. >> >> >> +#if defined UINT64_MAX && defined UINT64_C > > Bruno's point was that UINT64_C is not usable in C++ programs. Checking > UINT64_MAX is sufficient, so lose

Re: bitrotate

2008-09-02 Thread Eric Blake
Simon Josefsson josefsson.org> writes: > > Thanks for ideas. I have pushed this. > > > +#if defined UINT64_MAX && defined UINT64_C Bruno's point was that UINT64_C is not usable in C++ programs. Checking UINT64_MAX is sufficient, so lose the &&. > +/* Given an unsigned 64-bit argument X, r

Re: bitrotate

2008-09-02 Thread Simon Josefsson
Thanks for ideas. I have pushed this. /Simon >From 4316d00d707d97f660fd0432035780fc0d3f23eb Mon Sep 17 00:00:00 2001 From: Simon Josefsson <[EMAIL PROTECTED]> Date: Tue, 2 Sep 2008 15:53:09 +0200 Subject: [PATCH] bitrotate: Add 64-bit rotates. Suggested by Bruce Korb <[EMAIL PROTECTED]> with id

Re: bitrotate

2008-09-01 Thread Bruno Haible
Ben Pfaff wrote: > > There was a suggestion to support 64-bit rotates as well. That would > > use uint64_t. Does stdint.m4 define some symbol that may be useful > > here? > > I believe that UINT64_C (for writing an unsigned 64-bit integer > literal) is defined if and only if uint64_t is availabl

Re: bitrotate

2008-09-01 Thread Ben Pfaff
Simon Josefsson <[EMAIL PROTECTED]> writes: > There was a suggestion to support 64-bit rotates as well. That would > use uint64_t. Does stdint.m4 define some symbol that may be useful > here? I believe that UINT64_C (for writing an unsigned 64-bit integer literal) is defined if and only if uint

Re: bitrotate

2008-09-01 Thread Simon Josefsson
Paolo Bonzini <[EMAIL PROTECTED]> writes: >> I suspect the rotation part is the sarl+sall and or. Either we could >> experiment with changing the code, or we could try to make gcc detect >> that this code actually is a rotate... Possibly gcc already does that >> right thing, with today's CPU arc

Re: bitrotate

2008-09-01 Thread Simon Josefsson
There was a suggestion to support 64-bit rotates as well. That would use uint64_t. Does stdint.m4 define some symbol that may be useful here? The code is rather complex so I'm trying to save time asking here first. I guess stdint.h cannot always define a uint64_t type, for example if the platfo

Re: bitrotate

2008-09-01 Thread Simon Josefsson
Bruno Haible <[EMAIL PROTECTED]> writes: > Simon Josefsson wrote: >> --- a/modules/bitrotate >> +++ b/modules/bitrotate >> @@ -1,5 +1,5 @@ >> Description: >> -Rotate bits in 16 and 32 bit integers. >> +Rotate bits in 16 and 32 bit integers using stdint.h. >> >> Files: >> lib/bitrotate.h > > W

Re: bitrotate

2008-09-01 Thread Bruno Haible
Simon Josefsson wrote: > --- a/modules/bitrotate > +++ b/modules/bitrotate > @@ -1,5 +1,5 @@ > Description: > -Rotate bits in 16 and 32 bit integers. > +Rotate bits in 16 and 32 bit integers using stdint.h. > > Files: > lib/bitrotate.h Well, that's not what I meant. I meant to add a format de

Re: bitrotate

2008-09-01 Thread Paolo Bonzini
> I suspect the rotation part is the sarl+sall and or. Either we could > experiment with changing the code, or we could try to make gcc detect > that this code actually is a rotate... Possibly gcc already does that > right thing, with today's CPU architectures it can be difficult to know > which

Re: bitrotate

2008-09-01 Thread Simon Josefsson
Paolo Bonzini <[EMAIL PROTECTED]> writes: >> +/* 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) >> +{ >> + return ((x <<

Re: bitrotate

2008-08-29 Thread Bruno Haible
Simon Josefsson wrote: > + > +#include > + The module description needs to list the dependency to the 'stdint' module. Bruno

Re: bitrotate

2008-08-29 Thread Bruno Haible
Ben Pfaff wrote: > Since you're using the inline keyword, you should add a > dependency on the inline module. He's only using 'static inline'; therefore an AC_REQUIRE([AC_C_INLINE]) is all that he needs. > > +/* Given an unsigned 32-bit argument X, return the value corresponding > > + to rotati

Re: bitrotate

2008-08-29 Thread Ben Pfaff
Simon Josefsson <[EMAIL PROTECTED]> 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 > +

Re: bitrotate

2008-08-29 Thread Paolo Bonzini
> +/* 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) > +{ > + return ((x << n) | (x >> (16 - n))) & 0x; > +} & 0xFFF

Re: bitrotate

2008-08-29 Thread Simon Josefsson
Paul Eggert <[EMAIL PROTECTED]> writes: > Simon Josefsson <[EMAIL PROTECTED]> writes: > >> +#define rotl32(x,n) \ >> + x) << ((uint16_t)(n))) | ((x) >> (32 - (uint16_t)(n & 0x) > > I suggest using inline functions rather than macros, to avoid hassles > with double-evaluating argum

Re: bitrotate

2008-08-28 Thread Paul Eggert
Simon Josefsson <[EMAIL PROTECTED]> writes: > +#define rotl32(x,n) \ > + x) << ((uint16_t)(n))) | ((x) >> (32 - (uint16_t)(n & 0x) I suggest using inline functions rather than macros, to avoid hassles with double-evaluating arguments. That way, you won't need any casts. The cast

Re: bitrotate

2008-08-28 Thread Paolo Bonzini
> +#define rotl32(x,n) \ > + x) << ((uint16_t)(n))) | ((x) >> (32 - (uint16_t)(n & 0x) > +#define rotr32(x,n) \ > + x) >> ((uint16_t)(n))) | ((x) << (32 - (uint16_t)(n & 0x) > +#define rotl16(x,n) \ > + x) << ((uint16_t)(n))) | ((x) >> (16 - (uint16_t)(n &