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)
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)
......@@ -2,3 +2,4 @@
#cmakedefine HAVE_STDINT_H 1
#cmakedefine WORDS_BIGENDIAN 1
#cmakedefine HAVE_DECL___BUILTIN_CLZLL 1
#cmakedefine HAVE_BSR64 1
......@@ -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;
......
......@@ -54,13 +54,17 @@
#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) {
......
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