2022-05-12 07:48:39 +00:00
|
|
|
/* RotateDefs.h -- Rotate functions
|
2024-05-10 23:10:28 +00:00
|
|
|
2023-06-18 : Igor Pavlov : Public domain */
|
2022-05-12 07:48:39 +00:00
|
|
|
|
2024-05-10 23:10:28 +00:00
|
|
|
#ifndef ZIP7_INC_ROTATE_DEFS_H
|
|
|
|
#define ZIP7_INC_ROTATE_DEFS_H
|
2022-05-12 07:48:39 +00:00
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2024-05-10 23:10:28 +00:00
|
|
|
/* don't use _rotl with old MINGW. It can insert slow call to function. */
|
2022-05-12 07:48:39 +00:00
|
|
|
|
|
|
|
/* #if (_MSC_VER >= 1200) */
|
|
|
|
#pragma intrinsic(_rotl)
|
|
|
|
#pragma intrinsic(_rotr)
|
|
|
|
/* #endif */
|
|
|
|
|
|
|
|
#define rotlFixed(x, n) _rotl((x), (n))
|
|
|
|
#define rotrFixed(x, n) _rotr((x), (n))
|
|
|
|
|
2024-05-10 23:10:28 +00:00
|
|
|
#if (_MSC_VER >= 1300)
|
|
|
|
#define Z7_ROTL64(x, n) _rotl64((x), (n))
|
|
|
|
#define Z7_ROTR64(x, n) _rotr64((x), (n))
|
|
|
|
#else
|
|
|
|
#define Z7_ROTL64(x, n) (((x) << (n)) | ((x) >> (64 - (n))))
|
|
|
|
#define Z7_ROTR64(x, n) (((x) >> (n)) | ((x) << (64 - (n))))
|
|
|
|
#endif
|
|
|
|
|
2022-05-12 07:48:39 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
/* new compilers can translate these macros to fast commands. */
|
|
|
|
|
2024-05-10 23:10:28 +00:00
|
|
|
#if defined(__clang__) && (__clang_major__ >= 4) \
|
|
|
|
|| defined(__GNUC__) && (__GNUC__ >= 5)
|
|
|
|
/* GCC 4.9.0 and clang 3.5 can recognize more correct version: */
|
|
|
|
#define rotlFixed(x, n) (((x) << (n)) | ((x) >> (-(n) & 31)))
|
|
|
|
#define rotrFixed(x, n) (((x) >> (n)) | ((x) << (-(n) & 31)))
|
|
|
|
#define Z7_ROTL64(x, n) (((x) << (n)) | ((x) >> (-(n) & 63)))
|
|
|
|
#define Z7_ROTR64(x, n) (((x) >> (n)) | ((x) << (-(n) & 63)))
|
|
|
|
#else
|
|
|
|
/* for old GCC / clang: */
|
2022-05-12 07:48:39 +00:00
|
|
|
#define rotlFixed(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
|
|
|
|
#define rotrFixed(x, n) (((x) >> (n)) | ((x) << (32 - (n))))
|
2024-05-10 23:10:28 +00:00
|
|
|
#define Z7_ROTL64(x, n) (((x) << (n)) | ((x) >> (64 - (n))))
|
|
|
|
#define Z7_ROTR64(x, n) (((x) >> (n)) | ((x) << (64 - (n))))
|
|
|
|
#endif
|
2022-05-12 07:48:39 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|