Coverage Report

Created: 2026-02-14 06:19

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/guetzli/guetzli/fast_log.h
Line
Count
Source
1
/*
2
 * Copyright 2016 Google Inc.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 * http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef GUETZLI_FAST_LOG_H_
18
#define GUETZLI_FAST_LOG_H_
19
20
#include <math.h>
21
22
namespace guetzli {
23
24
187M
inline int Log2FloorNonZero(uint32_t n) {
25
187M
#ifdef __GNUC__
26
187M
  return 31 ^ __builtin_clz(n);
27
#else
28
  unsigned int result = 0;
29
  while (n >>= 1) result++;
30
  return result;
31
#endif
32
187M
}
33
34
17.9M
inline int Log2Floor(uint32_t n) {
35
17.9M
  return n == 0 ? -1 : Log2FloorNonZero(n);
36
17.9M
}
37
38
}  // namespace guetzli
39
40
#endif  // GUETZLI_FAST_LOG_H_