X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fbitrotate.h;h=c3a5e1a5d2b92917a3d8f7113e29e0097176e630;hb=112b21e3861a4887731b61888d1388127957ba93;hp=d4911d0b2d83c2c0b6ee1c914673d04474a27598;hpb=e6f0227e493c3104cead93665d37104a9c7f473c;p=gnulib.git diff --git a/lib/bitrotate.h b/lib/bitrotate.h index d4911d0b2..c3a5e1a5d 100644 --- a/lib/bitrotate.h +++ b/lib/bitrotate.h @@ -1,5 +1,5 @@ /* bitrotate.h - Rotate bits in integers - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008-2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,7 +19,9 @@ #ifndef _GL_BITROTATE_H #define _GL_BITROTATE_H +#include #include +#include #ifdef UINT64_MAX /* Given an unsigned 64-bit argument X, return the value corresponding @@ -59,6 +61,24 @@ rotr32 (uint32_t x, int n) return ((x >> n) | (x << (32 - n))) & UINT32_MAX; } +/* Given a size_t argument X, return the value corresponding + to rotating the bits N steps to the left. N must be between 1 and + (CHAR_BIT * sizeof (size_t) - 1) inclusive. */ +static inline size_t +rotl_sz (size_t x, int n) +{ + return ((x << n) | (x >> ((CHAR_BIT * sizeof x) - n))) & SIZE_MAX; +} + +/* Given a size_t argument X, return the value corresponding + to rotating the bits N steps to the right. N must be between 1 to + (CHAR_BIT * sizeof (size_t) - 1) inclusive. */ +static inline size_t +rotr_sz (size_t x, int n) +{ + return ((x >> n) | (x << ((CHAR_BIT * sizeof x) - n))) & SIZE_MAX; +} + /* 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, but on most relevant targets N can also be 0 and 16