diff options
author | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2013-09-21 13:54:38 +0300 |
---|---|---|
committer | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2013-09-21 15:34:35 +0300 |
commit | cfea5c28a3822e1e7e401e5107ebe07ba7fdcf37 (patch) | |
tree | 7aeac78031fc84f0fb239547983fbc9cbe7f2eb9 /cipher/bithelp.h | |
parent | 9337e03824a5bdd3bbbcb8382cabefe6d6c32e1e (diff) | |
download | libgcrypt-cfea5c28a3822e1e7e401e5107ebe07ba7fdcf37.tar.gz |
Remove i386 inline assembly version of rotation functions
* cipher/bithelp.h (rol, ror): Remove i386 version, change
macros to inline functions.
* src/hmac256.c (ror): Ditto.
--
(Current) compilers can optimize '(x << c) | (x >> (32-c))' to rotation
instruction. So remove i386 specific assembly for manually doing this.
Furthermore, compiler can generate faster code in case where 'c' is
constant and can use rotate with immediate value rather than rotate
with %cl register.
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
Diffstat (limited to 'cipher/bithelp.h')
-rw-r--r-- | cipher/bithelp.h | 26 |
1 files changed, 4 insertions, 22 deletions
diff --git a/cipher/bithelp.h b/cipher/bithelp.h index 734dcbb5..601ecac6 100644 --- a/cipher/bithelp.h +++ b/cipher/bithelp.h @@ -26,33 +26,15 @@ /**************** * Rotate the 32 bit unsigned integer X by N bits left/right */ -#if defined(__GNUC__) && defined(__i386__) -static inline u32 -rol( u32 x, int n) +static inline u32 rol( u32 x, int n) { - __asm__("roll %%cl,%0" - :"=r" (x) - :"0" (x),"c" (n) - :"cc"); - return x; + return ( (x << n) | (x >> (32-n)) ); } -#else -#define rol(x,n) ( ((x) << (n)) | ((x) >> (32-(n))) ) -#endif -#if defined(__GNUC__) && defined(__i386__) -static inline u32 -ror(u32 x, int n) +static inline u32 ror(u32 x, int n) { - __asm__("rorl %%cl,%0" - :"=r" (x) - :"0" (x),"c" (n) - :"cc"); - return x; + return ( (x >> n) | (x << (32-n)) ); } -#else -#define ror(x,n) ( ((x) >> (n)) | ((x) << (32-(n))) ) -#endif /* Byte swap for 32-bit and 64-bit integers. If available, use compiler provided helpers. */ |