Commit 6f8b3ae7 authored by Mathis Rosenhauer's avatar Mathis Rosenhauer

Support CLZ intrinsic for VC.

parent 60937215
...@@ -2,6 +2,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8.6) ...@@ -2,6 +2,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8.6)
INCLUDE(CheckIncludeFiles) INCLUDE(CheckIncludeFiles)
INCLUDE(TestBigEndian) INCLUDE(TestBigEndian)
INCLUDE(CheckCSourceCompiles) INCLUDE(CheckCSourceCompiles)
INCLUDE(GenerateExportHeader)
PROJECT(libaec) PROJECT(libaec)
SET(libaec_VERSION_MAJOR 0) SET(libaec_VERSION_MAJOR 0)
SET(libaec_VERSION_MINOR 2) SET(libaec_VERSION_MINOR 2)
...@@ -16,6 +17,14 @@ CHECK_C_SOURCE_COMPILES( ...@@ -16,6 +17,14 @@ CHECK_C_SOURCE_COMPILES(
{return __builtin_clzll(1LL);}" {return __builtin_clzll(1LL);}"
HAVE_DECL___BUILTIN_CLZLL 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 #Inspired from http://www.cmake.org/Wiki/CMakeTestInline
SET(INLINE_TEST_SRC "/* Inspired by autoconf's c.m4 */ SET(INLINE_TEST_SRC "/* Inspired by autoconf's c.m4 */
...@@ -75,7 +84,13 @@ CONFIGURE_FILE( ...@@ -75,7 +84,13 @@ CONFIGURE_FILE(
${CMAKE_CURRENT_BINARY_DIR}/config.h ${CMAKE_CURRENT_BINARY_DIR}/config.h
) )
SET(BUILD_SHARED_LIBS TRUE) SET(BUILD_SHARED_LIBS FALSE)
INCLUDE_DIRECTORIES("${PROJECT_BINARY_DIR}") INCLUDE_DIRECTORIES("${PROJECT_BINARY_DIR}")
INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/src")
ADD_SUBDIRECTORY(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)
...@@ -2,3 +2,4 @@ ...@@ -2,3 +2,4 @@
#cmakedefine HAVE_STDINT_H 1 #cmakedefine HAVE_STDINT_H 1
#cmakedefine WORDS_BIGENDIAN 1 #cmakedefine WORDS_BIGENDIAN 1
#cmakedefine HAVE_DECL___BUILTIN_CLZLL 1 #cmakedefine HAVE_DECL___BUILTIN_CLZLL 1
#cmakedefine HAVE_BSR64 1
...@@ -64,7 +64,7 @@ int main(int argc, char *argv[]) ...@@ -64,7 +64,7 @@ int main(int argc, char *argv[])
unsigned char *in; unsigned char *in;
unsigned char *out; unsigned char *out;
size_t total_out; size_t total_out;
int chunk, status, c; int chunk, status;
int input_avail, output_avail; int input_avail, output_avail;
char *outfn, *infn, *ext; char *outfn, *infn, *ext;
FILE *infp, *outfp; FILE *infp, *outfp;
......
...@@ -54,13 +54,17 @@ ...@@ -54,13 +54,17 @@
#include <config.h> #include <config.h>
#if HAVE_STDINT_H #if HAVE_STDINT_H
# include <stdint.h> #include <stdint.h>
#endif #endif
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef HAVE_BSR64
#include <intrin.h>
#endif
#include "libaec.h" #include "libaec.h"
#include "decode.h" #include "decode.h"
...@@ -266,7 +270,7 @@ static inline uint32_t direct_get_fs(struct aec_stream *strm) ...@@ -266,7 +270,7 @@ static inline uint32_t direct_get_fs(struct aec_stream *strm)
*/ */
uint32_t fs = 0; uint32_t fs = 0;
#if HAVE_DECL___BUILTIN_CLZLL #if HAVE_DECL___BUILTIN_CLZLL||HAVE_BSR64
uint32_t lz; uint32_t lz;
#endif #endif
struct internal_state *state = strm->state; struct internal_state *state = strm->state;
...@@ -283,6 +287,10 @@ static inline uint32_t direct_get_fs(struct aec_stream *strm) ...@@ -283,6 +287,10 @@ static inline uint32_t direct_get_fs(struct aec_stream *strm)
lz = __builtin_clzll(state->acc); lz = __builtin_clzll(state->acc);
fs += lz + state->bitp - 64; fs += lz + state->bitp - 64;
state->bitp = 63 - lz; state->bitp = 63 - lz;
#elif HAVE_BSR64
_BitScanReverse64(&lz, state->acc);
fs += state->bitp - 1 - lz;
state->bitp = lz;
#else #else
state->bitp--; state->bitp--;
while ((state->acc & (1ULL << state->bitp)) == 0) { while ((state->acc & (1ULL << state->bitp)) == 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment