Permalink
Browse files

Handle early gcc compilers that are missing __builtin_bswap64 or __bu…

…iltin_ctz

(closes #84)
  • Loading branch information...
1 parent d867a71 commit 3b2604b81c3538b4198746280b2d039a39d65e67 @quentinmit quentinmit committed with keithw Mar 24, 2012
Showing with 16 additions and 6 deletions.
  1. +2 −0 configure.ac
  2. +14 −6 src/crypto/ocb.cc
View
@@ -117,6 +117,8 @@ AC_SEARCH_LIBS([clock_gettime], [rt], [AC_DEFINE([HAVE_CLOCK_GETTIME], [1], [Def
AC_CHECK_LIB([ncurses], [setupterm])
+AC_CHECK_DECLS([__builtin_bswap64, __builtin_ctz])
+
AC_CHECK_DECL([mach_absolute_time],
[AC_DEFINE([HAVE_MACH_ABSOLUTE_TIME], [1],
[Define if mach_absolute_time is available.])],
View
@@ -92,14 +92,16 @@
#define __SSSE3__ (_M_IX86 || _M_AMD64 || _M_X64) /* Assume SSSE3 */
#include <intrin.h>
#pragma intrinsic(_byteswap_uint64, _BitScanForward, memcpy)
- #define bswap64(x) _byteswap_uint64(x)
- static inline unsigned ntz(unsigned x) {_BitScanForward(&x,x);return x;}
#elif __GNUC__
#define inline __inline__ /* No "inline" in GCC ansi C mode */
#define restrict __restrict__ /* No "restrict" in GCC ansi C mode */
- #define bswap64(x) __builtin_bswap64(x) /* Assuming GCC 4.3+ */
- #define ntz(x) __builtin_ctz((unsigned)(x)) /* Assuming GCC 3.4+ */
-#else /* Assume some C99 features: stdint.h, inline, restrict */
+#endif
+
+#if _MSC_VER
+ #define bswap64(x) _byteswap_uint64(x)
+#elif HAVE_DECL___BUILTIN_BSWAP64
+ #define bswap64(x) __builtin_bswap64(x) /* GCC 4.3+ */
+#else
#define bswap32(x) \
((((x) & 0xff000000u) >> 24) | (((x) & 0x00ff0000u) >> 8) | \
(((x) & 0x0000ff00u) << 8) | (((x) & 0x000000ffu) << 24))
@@ -111,7 +113,13 @@
out.u32[1] = bswap32(in.u32[0]);
return out.u64;
}
-
+#endif
+
+#if _MSC_VER
+ static inline unsigned ntz(unsigned x) {_BitScanForward(&x,x);return x;}
+#elif HAVE_DECL___BUILTIN_CTZ
+ #define ntz(x) __builtin_ctz((unsigned)(x)) /* GCC 3.4+ */
+#else
#if (L_TABLE_SZ <= 9) && (L_TABLE_SZ_IS_ENOUGH) /* < 2^13 byte texts */
static inline unsigned ntz(unsigned x) {
static const unsigned char tz_table[] = {0,

0 comments on commit 3b2604b

Please sign in to comment.