1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-30 03:48:17 +00:00

Adding compiler intrinsics implementation for bit operations

This commit is contained in:
jsteube 2016-10-01 12:29:05 +02:00
parent a02f6f5ad6
commit 4fe0c9ac94

View File

@ -9,34 +9,61 @@
u32 rotl32 (const u32 a, const u32 n) u32 rotl32 (const u32 a, const u32 n)
{ {
#if defined (_MSC_VER)
return _rotl (a, n);
#else
return ((a << n) | (a >> (32 - n))); return ((a << n) | (a >> (32 - n)));
#endif
} }
u32 rotr32 (const u32 a, const u32 n) u32 rotr32 (const u32 a, const u32 n)
{ {
#if defined (_MSC_VER)
return _rotr (a, n);
#else
return ((a >> n) | (a << (32 - n))); return ((a >> n) | (a << (32 - n)));
#endif
} }
u64 rotl64 (const u64 a, const u64 n) u64 rotl64 (const u64 a, const u64 n)
{ {
#if defined (_MSC_VER)
return _rotl64 (a, n);
#else
return ((a << n) | (a >> (64 - n))); return ((a << n) | (a >> (64 - n)));
#endif
} }
u64 rotr64 (const u64 a, const u64 n) u64 rotr64 (const u64 a, const u64 n)
{ {
#if defined (_MSC_VER)
return _rotr64 (a, n);
#else
return ((a >> n) | (a << (64 - n))); return ((a >> n) | (a << (64 - n)));
#endif
} }
u32 byte_swap_32 (const u32 n) u32 byte_swap_32 (const u32 n)
{ {
#if defined (_MSC_VER)
return _byteswap_ulong (n);
#elif defined (__clang__) || defined (__GNUC__)
return __builtin_bswap32 (n);
#else
return (n & 0xff000000) >> 24 return (n & 0xff000000) >> 24
| (n & 0x00ff0000) >> 8 | (n & 0x00ff0000) >> 8
| (n & 0x0000ff00) << 8 | (n & 0x0000ff00) << 8
| (n & 0x000000ff) << 24; | (n & 0x000000ff) << 24;
#endif
} }
u64 byte_swap_64 (const u64 n) u64 byte_swap_64 (const u64 n)
{ {
#if defined (_MSC_VER)
return _byteswap_uint64 (n);
#elif defined (__clang__) || defined (__GNUC__)
return __builtin_bswap64 (n);
#else
return (n & 0xff00000000000000ULL) >> 56 return (n & 0xff00000000000000ULL) >> 56
| (n & 0x00ff000000000000ULL) >> 40 | (n & 0x00ff000000000000ULL) >> 40
| (n & 0x0000ff0000000000ULL) >> 24 | (n & 0x0000ff0000000000ULL) >> 24
@ -45,4 +72,5 @@ u64 byte_swap_64 (const u64 n)
| (n & 0x0000000000ff0000ULL) << 24 | (n & 0x0000000000ff0000ULL) << 24
| (n & 0x000000000000ff00ULL) << 40 | (n & 0x000000000000ff00ULL) << 40
| (n & 0x00000000000000ffULL) << 56; | (n & 0x00000000000000ffULL) << 56;
#endif
} }