/src/ghostpdl/brotli/c/enc/fast_log.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright 2013 Google Inc. All Rights Reserved. |
2 | | |
3 | | Distributed under MIT license. |
4 | | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT |
5 | | */ |
6 | | |
7 | | /* Utilities for fast computation of logarithms. */ |
8 | | |
9 | | #ifndef BROTLI_ENC_FAST_LOG_H_ |
10 | | #define BROTLI_ENC_FAST_LOG_H_ |
11 | | |
12 | | #include <math.h> |
13 | | |
14 | | #include <brotli/types.h> |
15 | | |
16 | | #include "../common/platform.h" |
17 | | |
18 | | #if defined(__cplusplus) || defined(c_plusplus) |
19 | | extern "C" { |
20 | | #endif |
21 | | |
22 | 0 | static BROTLI_INLINE uint32_t Log2FloorNonZero(size_t n) { |
23 | 0 | #if defined(BROTLI_BSR32) |
24 | 0 | return BROTLI_BSR32((uint32_t)n); |
25 | | #else |
26 | | uint32_t result = 0; |
27 | | while (n >>= 1) result++; |
28 | | return result; |
29 | | #endif |
30 | 0 | } Unexecuted instantiation: encode.c:Log2FloorNonZero Unexecuted instantiation: encoder_dict.c:Log2FloorNonZero Unexecuted instantiation: fast_log.c:Log2FloorNonZero Unexecuted instantiation: metablock.c:Log2FloorNonZero Unexecuted instantiation: backward_references.c:Log2FloorNonZero Unexecuted instantiation: backward_references_hq.c:Log2FloorNonZero Unexecuted instantiation: bit_cost.c:Log2FloorNonZero Unexecuted instantiation: block_splitter.c:Log2FloorNonZero Unexecuted instantiation: brotli_bit_stream.c:Log2FloorNonZero Unexecuted instantiation: cluster.c:Log2FloorNonZero Unexecuted instantiation: command.c:Log2FloorNonZero Unexecuted instantiation: compress_fragment.c:Log2FloorNonZero Unexecuted instantiation: compress_fragment_two_pass.c:Log2FloorNonZero Unexecuted instantiation: histogram.c:Log2FloorNonZero Unexecuted instantiation: literal_cost.c:Log2FloorNonZero |
31 | | |
32 | 0 | #define BROTLI_LOG2_TABLE_SIZE 256 |
33 | | |
34 | | /* A lookup table for small values of log2(int) to be used in entropy |
35 | | computation. */ |
36 | | BROTLI_INTERNAL extern const double kBrotliLog2Table[BROTLI_LOG2_TABLE_SIZE]; |
37 | | |
38 | | /* Visual Studio 2012 and Android API levels < 18 do not have the log2() |
39 | | * function defined, so we use log() and a multiplication instead. */ |
40 | | #if !defined(BROTLI_HAVE_LOG2) |
41 | | #if ((defined(_MSC_VER) && _MSC_VER <= 1700) || \ |
42 | | (defined(__ANDROID_API__) && __ANDROID_API__ < 18)) |
43 | | #define BROTLI_HAVE_LOG2 0 |
44 | | #else |
45 | | #define BROTLI_HAVE_LOG2 1 |
46 | | #endif |
47 | | #endif |
48 | | |
49 | | #define LOG_2_INV 1.4426950408889634 |
50 | | |
51 | | /* Faster logarithm for small integers, with the property of log2(0) == 0. */ |
52 | 0 | static BROTLI_INLINE double FastLog2(size_t v) { |
53 | 0 | if (v < BROTLI_LOG2_TABLE_SIZE) { |
54 | 0 | return kBrotliLog2Table[v]; |
55 | 0 | } |
56 | | #if !(BROTLI_HAVE_LOG2) |
57 | | return log((double)v) * LOG_2_INV; |
58 | | #else |
59 | 0 | return log2((double)v); |
60 | 0 | #endif |
61 | 0 | } Unexecuted instantiation: encode.c:FastLog2 Unexecuted instantiation: encoder_dict.c:FastLog2 Unexecuted instantiation: fast_log.c:FastLog2 Unexecuted instantiation: metablock.c:FastLog2 Unexecuted instantiation: backward_references.c:FastLog2 Unexecuted instantiation: backward_references_hq.c:FastLog2 Unexecuted instantiation: bit_cost.c:FastLog2 Unexecuted instantiation: block_splitter.c:FastLog2 Unexecuted instantiation: brotli_bit_stream.c:FastLog2 Unexecuted instantiation: cluster.c:FastLog2 Unexecuted instantiation: command.c:FastLog2 Unexecuted instantiation: compress_fragment.c:FastLog2 Unexecuted instantiation: compress_fragment_two_pass.c:FastLog2 Unexecuted instantiation: histogram.c:FastLog2 Unexecuted instantiation: literal_cost.c:FastLog2 |
62 | | |
63 | | #if defined(__cplusplus) || defined(c_plusplus) |
64 | | } /* extern "C" */ |
65 | | #endif |
66 | | |
67 | | #endif /* BROTLI_ENC_FAST_LOG_H_ */ |