Support CLZ intrinsic for VC.
authorMathis Rosenhauer <rosenhauer@dkrz.de>
Wed, 23 Jul 2014 09:19:59 +0000 (11:19 +0200)
committerMathis Rosenhauer <rosenhauer@dkrz.de>
Wed, 23 Jul 2014 09:19:59 +0000 (11:19 +0200)
CMakeLists.txt
config.h.in
src/aec.c
src/decode.c

index 8c6c3c7..1d62836 100644 (file)
@@ -2,6 +2,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8.6)
 INCLUDE(CheckIncludeFiles)
 INCLUDE(TestBigEndian)
 INCLUDE(CheckCSourceCompiles)
+INCLUDE(GenerateExportHeader)
 PROJECT(libaec)
 SET(libaec_VERSION_MAJOR 0)
 SET(libaec_VERSION_MINOR 2)
@@ -16,6 +17,14 @@ CHECK_C_SOURCE_COMPILES(
 {return __builtin_clzll(1LL);}"
   HAVE_DECL___BUILTIN_CLZLL
   )
+IF (NOT HAVE_DECL___BUILTIN_CLZLL)
+  CHECK_C_SOURCE_COMPILES(
+    "int main(int argc, char *argv[])
+{unsigned long foo; unsigned __int64 bar=1LL;
+return _BitScanReverse64(&foo, bar);}"
+    HAVE_BSR64
+  )
+ENDIF (NOT HAVE_DECL___BUILTIN_CLZLL)
 
 #Inspired from http://www.cmake.org/Wiki/CMakeTestInline
 SET(INLINE_TEST_SRC "/* Inspired by autoconf's c.m4 */
@@ -75,7 +84,13 @@ CONFIGURE_FILE(
   ${CMAKE_CURRENT_BINARY_DIR}/config.h
   )
 
-SET(BUILD_SHARED_LIBS TRUE)
+SET(BUILD_SHARED_LIBS FALSE)
 INCLUDE_DIRECTORIES("${PROJECT_BINARY_DIR}")
+INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/src")
+
 ADD_SUBDIRECTORY(src)
-ADD_SUBDIRECTORY(tests EXCLUDE_FROM_ALL)
+IF(WIN32)
+  ADD_SUBDIRECTORY(tests)
+ELSE(WIN32)
+  ADD_SUBDIRECTORY(tests EXCLUDE_FROM_ALL)
+ENDIF(WIN32)
index 160959d..9f5fffb 100644 (file)
@@ -2,3 +2,4 @@
 #cmakedefine HAVE_STDINT_H 1
 #cmakedefine WORDS_BIGENDIAN 1
 #cmakedefine HAVE_DECL___BUILTIN_CLZLL 1
+#cmakedefine HAVE_BSR64 1
index e053723..9acf4b1 100644 (file)
--- a/src/aec.c
+++ b/src/aec.c
@@ -64,7 +64,7 @@ int main(int argc, char *argv[])
     unsigned char *in;
     unsigned char *out;
     size_t total_out;
-    int chunk, status, c;
+    int chunk, status;
     int input_avail, output_avail;
     char *outfn, *infn, *ext;
     FILE *infp, *outfp;
index efd2273..d94f1bb 100644 (file)
 #include <config.h>
 
 #if HAVE_STDINT_H
-# include <stdint.h>
+#include <stdint.h>
 #endif
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
+#ifdef HAVE_BSR64
+#include <intrin.h>
+#endif
+
 #include "libaec.h"
 #include "decode.h"
 
@@ -266,7 +270,7 @@ static inline uint32_t direct_get_fs(struct aec_stream *strm)
      */
 
     uint32_t fs = 0;
-#if HAVE_DECL___BUILTIN_CLZLL
+#if HAVE_DECL___BUILTIN_CLZLL||HAVE_BSR64
     uint32_t lz;
 #endif
     struct internal_state *state = strm->state;
@@ -283,6 +287,10 @@ static inline uint32_t direct_get_fs(struct aec_stream *strm)
     lz = __builtin_clzll(state->acc);
     fs += lz + state->bitp - 64;
     state->bitp = 63 - lz;
+#elif HAVE_BSR64
+    _BitScanReverse64(&lz, state->acc);
+    fs += state->bitp - 1 - lz;
+    state->bitp = lz;
 #else
     state->bitp--;
     while ((state->acc & (1ULL << state->bitp)) == 0) {