diff --git a/enc/fast_log.h b/enc/fast_log.h index 88b3f69..19b66f3 100644 --- a/enc/fast_log.h +++ b/enc/fast_log.h @@ -164,7 +164,14 @@ static inline double FastLog2(int v) { if (v < (int)(sizeof(kLog2Table) / sizeof(kLog2Table[0]))) { return kLog2Table[v]; } +#if defined(_MSC_VER) && _MSC_VER <= 1600 + // Visual Studio 2010 does not have the log2() function defined, so we use + // log() and a multiplication instead. + static const double kLog2Inv = 1.4426950408889634f; + return log(static_cast(v)) * kLog2Inv; +#else return log2(static_cast(v)); +#endif } } // namespace brotli diff --git a/enc/literal_cost.cc b/enc/literal_cost.cc index 50d9754..1da2321 100644 --- a/enc/literal_cost.cc +++ b/enc/literal_cost.cc @@ -20,6 +20,8 @@ #include #include +#include "./fast_log.h" + namespace brotli { static int UTF8Position(int last, int c, int clamp) { @@ -111,8 +113,7 @@ void EstimateBitCostsForLiteralsUTF8(size_t pos, size_t len, size_t mask, if (histo == 0) { histo = 1; } - float lit_cost = log2(static_cast(in_window_utf8[utf8_pos]) - / histo); + float lit_cost = FastLog2(in_window_utf8[utf8_pos]) - FastLog2(histo); lit_cost += 0.02905; if (lit_cost < 1.0) { lit_cost *= 0.5;