Coverage Report

Created: 2026-01-09 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ots/subprojects/woff2-1.0.2/src/port.h
Line
Count
Source
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
/* Helper function for bit twiddling and macros for branch prediction. */
8
9
#ifndef WOFF2_PORT_H_
10
#define WOFF2_PORT_H_
11
12
#include <assert.h>
13
14
namespace woff2 {
15
16
typedef unsigned int       uint32;
17
18
0
inline int Log2Floor(uint32 n) {
19
0
#if defined(__GNUC__)
20
0
  return n == 0 ? -1 : 31 ^ __builtin_clz(n);
21
0
#else
22
0
  if (n == 0)
23
0
    return -1;
24
0
  int log = 0;
25
0
  uint32 value = n;
26
0
  for (int i = 4; i >= 0; --i) {
27
0
    int shift = (1 << i);
28
0
    uint32 x = value >> shift;
29
0
    if (x != 0) {
30
0
      value = x;
31
0
      log += shift;
32
0
    }
33
0
  }
34
0
  assert(value == 1);
35
0
  return log;
36
0
#endif
37
0
}
38
39
} // namespace woff2
40
41
/* Compatibility with non-clang compilers. */
42
#ifndef __has_builtin
43
#define __has_builtin(x) 0
44
#endif
45
46
#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ > 95) || \
47
    (defined(__llvm__) && __has_builtin(__builtin_expect))
48
3.94M
#define PREDICT_FALSE(x) (__builtin_expect(x, 0))
49
#define PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
50
#else
51
#define PREDICT_FALSE(x) (x)
52
#define PREDICT_TRUE(x) (x)
53
#endif
54
55
#if (defined(__ARM_ARCH) && (__ARM_ARCH == 7)) || \
56
    (defined(M_ARM) && (M_ARM == 7)) || \
57
    defined(__aarch64__) || defined(__ARM64_ARCH_8__) || defined(__i386) || \
58
    defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64)
59
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
60
#define WOFF_LITTLE_ENDIAN
61
#elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
62
#define WOFF_BIG_ENDIAN
63
#endif  /* endianness */
64
#endif  /* CPU whitelist */
65
66
#endif  // WOFF2_PORT_H_