| 1 | /* RotateDefs.h -- Rotate functions |
| 2 | 2023-06-18 : Igor Pavlov : Public domain */ |
| 3 | |
| 4 | #ifndef ZIP7_INC_ROTATE_DEFS_H |
| 5 | #define ZIP7_INC_ROTATE_DEFS_H |
| 6 | |
| 7 | #ifdef _MSC_VER |
| 8 | |
| 9 | #include <stdlib.h> |
| 10 | |
| 11 | /* don't use _rotl with old MINGW. It can insert slow call to function. */ |
| 12 | |
| 13 | /* #if (_MSC_VER >= 1200) */ |
| 14 | #pragma intrinsic(_rotl) |
| 15 | #pragma intrinsic(_rotr) |
| 16 | /* #endif */ |
| 17 | |
| 18 | #define rotlFixed(x, n) _rotl((x), (n)) |
| 19 | #define rotrFixed(x, n) _rotr((x), (n)) |
| 20 | |
| 21 | #if (_MSC_VER >= 1300) |
| 22 | #define Z7_ROTL64(x, n) _rotl64((x), (n)) |
| 23 | #define Z7_ROTR64(x, n) _rotr64((x), (n)) |
| 24 | #else |
| 25 | #define Z7_ROTL64(x, n) (((x) << (n)) | ((x) >> (64 - (n)))) |
| 26 | #define Z7_ROTR64(x, n) (((x) >> (n)) | ((x) << (64 - (n)))) |
| 27 | #endif |
| 28 | |
| 29 | #else |
| 30 | |
| 31 | /* new compilers can translate these macros to fast commands. */ |
| 32 | |
| 33 | #if defined(__clang__) && (__clang_major__ >= 4) \ |
| 34 | || defined(__GNUC__) && (__GNUC__ >= 5) |
| 35 | /* GCC 4.9.0 and clang 3.5 can recognize more correct version: */ |
| 36 | #define rotlFixed(x, n) (((x) << (n)) | ((x) >> (-(n) & 31))) |
| 37 | #define rotrFixed(x, n) (((x) >> (n)) | ((x) << (-(n) & 31))) |
| 38 | #define Z7_ROTL64(x, n) (((x) << (n)) | ((x) >> (-(n) & 63))) |
| 39 | #define Z7_ROTR64(x, n) (((x) >> (n)) | ((x) << (-(n) & 63))) |
| 40 | #else |
| 41 | /* for old GCC / clang: */ |
| 42 | #define rotlFixed(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) |
| 43 | #define rotrFixed(x, n) (((x) >> (n)) | ((x) << (32 - (n)))) |
| 44 | #define Z7_ROTL64(x, n) (((x) << (n)) | ((x) >> (64 - (n)))) |
| 45 | #define Z7_ROTR64(x, n) (((x) >> (n)) | ((x) << (64 - (n)))) |
| 46 | #endif |
| 47 | |
| 48 | #endif |
| 49 | |
| 50 | #endif |