mirror of
https://github.com/google/brotli.git
synced 2024-11-21 19:20:09 +00:00
Add HAVE_LOG2 build macro (#783)
* Add HAVE_LOG2 build macro Fixes #781 * Rename macro to BROTLI_HAVE_LOG2 and move comment for visibility
This commit is contained in:
parent
36ac0feaf9
commit
f503cb709c
@ -110,13 +110,16 @@ if(NOT LOG2_RES)
|
||||
CHECK_FUNCTION_EXISTS(log2 LOG2_LIBM_RES)
|
||||
if(LOG2_LIBM_RES)
|
||||
set(LIBM_LIBRARY "m")
|
||||
add_definitions(-DBROTLI_HAVE_LOG2=1)
|
||||
else()
|
||||
message(FATAL_ERROR "log2() not found")
|
||||
add_definitions(-DBROTLI_HAVE_LOG2=0)
|
||||
endif()
|
||||
|
||||
set(CMAKE_REQUIRED_LIBRARIES "${orig_req_libs}")
|
||||
unset(LOG2_LIBM_RES)
|
||||
unset(orig_req_libs)
|
||||
else()
|
||||
add_definitions(-DBROTLI_HAVE_LOG2=1)
|
||||
endif()
|
||||
unset(LOG2_RES)
|
||||
|
||||
|
@ -123,6 +123,16 @@ static const float kLog2Table[] = {
|
||||
7.9943534368588578f
|
||||
};
|
||||
|
||||
/* Visual Studio 2012 and Android API levels < 18 do not have the log2()
|
||||
* function defined, so we use log() and a multiplication instead. */
|
||||
#ifndef BROTLI_HAVE_LOG2
|
||||
#if ((defined(_MSC_VER) && _MSC_VER <= 1700) || (defined(__ANDROID_API__) && __ANDROID_API__ < 18))
|
||||
#define BROTLI_HAVE_LOG2 0
|
||||
#else
|
||||
#define BROTLI_HAVE_LOG2 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define LOG_2_INV 1.4426950408889634
|
||||
|
||||
/* Faster logarithm for small integers, with the property of log2(0) == 0. */
|
||||
@ -130,10 +140,7 @@ static BROTLI_INLINE double FastLog2(size_t v) {
|
||||
if (v < sizeof(kLog2Table) / sizeof(kLog2Table[0])) {
|
||||
return kLog2Table[v];
|
||||
}
|
||||
#if (defined(_MSC_VER) && _MSC_VER <= 1700) || \
|
||||
(defined(__ANDROID_API__) && __ANDROID_API__ < 18)
|
||||
/* Visual Studio 2012 and Android API levels < 18 do not have the log2()
|
||||
* function defined, so we use log() and a multiplication instead. */
|
||||
#if !(BROTLI_HAVE_LOG2)
|
||||
return log((double)v) * LOG_2_INV;
|
||||
#else
|
||||
return log2((double)v);
|
||||
|
Loading…
Reference in New Issue
Block a user