diff --git a/src/headers/tomcrypt_cfg.h b/src/headers/tomcrypt_cfg.h index f7ad3cc..cc3b6df 100644 --- a/src/headers/tomcrypt_cfg.h +++ b/src/headers/tomcrypt_cfg.h @@ -128,6 +128,22 @@ LTC_EXPORT int LTC_CALL XSTRCMP(const char *s1, const char *s2); #define ENDIAN_NEUTRAL #endif +/* gcc 4.3 and up has a bswap builtin; detect it by gcc version. + * clang also supports the bswap builtin, and although clang pretends + * to be gcc (macro-wise, anyway), clang pretends to be a version + * prior to gcc 4.3, so we can't detect bswap that way. Instead, + * clang has a __has_builtin mechanism that can be used to check + * for builtins: + * http://clang.llvm.org/docs/LanguageExtensions.html#feature_check */ +#ifndef __has_builtin + #define __has_builtin(x) 0 +#endif +#if !defined(LTC_NO_BSWAP) && defined(__GNUC__) && \ + ((__GNUC__ * 100 + __GNUC_MINOR__ >= 403) || \ + (__has_builtin(__builtin_bswap32) && __has_builtin(__builtin_bswap64))) + #define LTC_HAVE_BSWAP_BUILTIN +#endif + #endif diff --git a/src/headers/tomcrypt_macros.h b/src/headers/tomcrypt_macros.h index 732ec3c..86156cc 100644 --- a/src/headers/tomcrypt_macros.h +++ b/src/headers/tomcrypt_macros.h @@ -67,7 +67,17 @@ #ifdef ENDIAN_LITTLE -#if !defined(LTC_NO_BSWAP) && (defined(INTEL_CC) || (defined(__GNUC__) && (defined(__DJGPP__) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__i386__) || defined(__x86_64__)))) +#ifdef LTC_HAVE_BSWAP_BUILTIN + +#define STORE32H(x, y) \ + { ulong32 __t = __builtin_bswap32 ((x)); \ + XMEMCPY ((y), &__t, 4); } + +#define LOAD32H(x, y) \ + { XMEMCPY (&(x), (y), 4); \ + (x) = __builtin_bswap32 ((x)); } + +#elif !defined(LTC_NO_BSWAP) && (defined(INTEL_CC) || (defined(__GNUC__) && (defined(__DJGPP__) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__i386__) || defined(__x86_64__)))) #define STORE32H(x, y) \ asm __volatile__ ( \ @@ -96,9 +106,7 @@ asm __volatile__ ( \ #endif -/* gcc 4.3 and up has a bswap builtin */ -#if !defined(LTC_NO_BSWAP) && \ - (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)) +#ifdef LTC_HAVE_BSWAP_BUILTIN #define STORE64H(x, y) \ { ulong64 __t = __builtin_bswap64 ((x)); \ diff --git a/src/misc/crypt/crypt.c b/src/misc/crypt/crypt.c index 1298397..e1b1ce0 100644 --- a/src/misc/crypt/crypt.c +++ b/src/misc/crypt/crypt.c @@ -286,7 +286,9 @@ const char *crypt_build_settings = #if defined(_MSC_VER) " MSVC compiler detected.\n" #endif -#if defined(__GNUC__) +#if defined(__clang_version__) + " Clang compiler " __clang_version__ ".\n" +#elif defined(__GNUC__) /* clang also defines __GNUC__ */ " GCC compiler detected.\n" #endif #if defined(INTEL_CC)