Coverage Report

Created: 2024-09-06 07:53

/src/libvpx/vpx_ports/bitops.h
Line
Count
Source
1
/*
2
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3
 *
4
 *  Use of this source code is governed by a BSD-style license
5
 *  that can be found in the LICENSE file in the root of the source
6
 *  tree. An additional intellectual property rights grant can be found
7
 *  in the file PATENTS.  All contributing project authors may
8
 *  be found in the AUTHORS file in the root of the source tree.
9
 */
10
11
#ifndef VPX_VPX_PORTS_BITOPS_H_
12
#define VPX_VPX_PORTS_BITOPS_H_
13
14
#include <assert.h>
15
16
#ifdef _MSC_VER
17
#if defined(_M_X64) || defined(_M_IX86)
18
#include <intrin.h>
19
#define USE_MSC_INTRINSICS
20
#endif
21
#endif
22
23
#ifdef __cplusplus
24
extern "C" {
25
#endif
26
27
// These versions of get_lsb() and get_msb() are only valid when n != 0
28
// because all of the optimized versions are undefined when n == 0:
29
// https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
30
31
// use GNU builtins where available.
32
#if defined(__GNUC__) && \
33
    ((__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || __GNUC__ >= 4)
34
489M
static INLINE int get_lsb(unsigned int n) {
35
489M
  assert(n != 0);
36
489M
  return __builtin_ctz(n);
37
489M
}
Unexecuted instantiation: vp8_quantize.c:get_lsb
Unexecuted instantiation: vp9_cx_iface.c:get_lsb
Unexecuted instantiation: vp9_firstpass.c:get_lsb
Unexecuted instantiation: vp9_mcomp.c:get_lsb
Unexecuted instantiation: vp9_encoder.c:get_lsb
Unexecuted instantiation: vp9_picklpf.c:get_lsb
Unexecuted instantiation: vp9_quantize.c:get_lsb
Unexecuted instantiation: vp9_ratectrl.c:get_lsb
Unexecuted instantiation: vp9_rd.c:get_lsb
Unexecuted instantiation: vp9_segmentation.c:get_lsb
Unexecuted instantiation: vp9_speed_features.c:get_lsb
Unexecuted instantiation: vp9_svc_layercontext.c:get_lsb
Unexecuted instantiation: vp9_resize.c:get_lsb
Unexecuted instantiation: vp9_tokenize.c:get_lsb
Unexecuted instantiation: vp9_aq_variance.c:get_lsb
Unexecuted instantiation: vp9_aq_360.c:get_lsb
Unexecuted instantiation: vp9_aq_cyclicrefresh.c:get_lsb
Unexecuted instantiation: vp9_aq_complexity.c:get_lsb
Unexecuted instantiation: vp9_alt_ref_aq.c:get_lsb
Unexecuted instantiation: vp9_skin_detection.c:get_lsb
Unexecuted instantiation: vp9_noise_estimate.c:get_lsb
Unexecuted instantiation: vp9_ext_ratectrl.c:get_lsb
Unexecuted instantiation: vp9_temporal_filter.c:get_lsb
Unexecuted instantiation: vp9_tpl_model.c:get_lsb
Unexecuted instantiation: vp9_mbgraph.c:get_lsb
Unexecuted instantiation: yv12config.c:get_lsb
Unexecuted instantiation: yv12extend.c:get_lsb
Unexecuted instantiation: vp8_quantize_ssse3.c:get_lsb
quantize_sse4.c:get_lsb
Line
Count
Source
34
489M
static INLINE int get_lsb(unsigned int n) {
35
489M
  assert(n != 0);
36
489M
  return __builtin_ctz(n);
37
489M
}
Unexecuted instantiation: vp9_alloccommon.c:get_lsb
Unexecuted instantiation: vp9_blockd.c:get_lsb
Unexecuted instantiation: vp9_entropy.c:get_lsb
Unexecuted instantiation: vp9_entropymode.c:get_lsb
Unexecuted instantiation: vp9_entropymv.c:get_lsb
Unexecuted instantiation: vp9_idct.c:get_lsb
Unexecuted instantiation: vp9_rtcd.c:get_lsb
Unexecuted instantiation: vp9_scale.c:get_lsb
Unexecuted instantiation: vp9_seg_common.c:get_lsb
Unexecuted instantiation: vp9_tile_common.c:get_lsb
Unexecuted instantiation: vp9_loopfilter.c:get_lsb
Unexecuted instantiation: vp9_thread_common.c:get_lsb
Unexecuted instantiation: vp9_quant_common.c:get_lsb
Unexecuted instantiation: vp9_reconinter.c:get_lsb
Unexecuted instantiation: vp9_reconintra.c:get_lsb
Unexecuted instantiation: vp9_scan.c:get_lsb
Unexecuted instantiation: vp9_idct_intrin_sse2.c:get_lsb
Unexecuted instantiation: vp9_highbd_iht4x4_add_sse4.c:get_lsb
Unexecuted instantiation: vp9_highbd_iht8x8_add_sse4.c:get_lsb
Unexecuted instantiation: vp9_highbd_iht16x16_add_sse4.c:get_lsb
Unexecuted instantiation: vp9_bitstream.c:get_lsb
Unexecuted instantiation: vp9_context_tree.c:get_lsb
Unexecuted instantiation: vp9_dct.c:get_lsb
Unexecuted instantiation: vp9_encodeframe.c:get_lsb
Unexecuted instantiation: vp9_encodemb.c:get_lsb
Unexecuted instantiation: vp9_encodemv.c:get_lsb
Unexecuted instantiation: vp9_ethread.c:get_lsb
Unexecuted instantiation: vp9_frame_scale.c:get_lsb
Unexecuted instantiation: vp9_lookahead.c:get_lsb
Unexecuted instantiation: vp9_multi_thread.c:get_lsb
Unexecuted instantiation: vp9_rdopt.c:get_lsb
Unexecuted instantiation: vp9_pickmode.c:get_lsb
Unexecuted instantiation: vp9_subexp.c:get_lsb
Unexecuted instantiation: temporal_filter_sse4.c:get_lsb
Unexecuted instantiation: vp9_quantize_sse2.c:get_lsb
Unexecuted instantiation: vp9_quantize_ssse3.c:get_lsb
Unexecuted instantiation: vp9_quantize_avx2.c:get_lsb
Unexecuted instantiation: vp9_highbd_block_error_intrin_sse2.c:get_lsb
Unexecuted instantiation: highbd_temporal_filter_sse4.c:get_lsb
Unexecuted instantiation: vp9_dct_intrin_sse2.c:get_lsb
Unexecuted instantiation: vp9_frame_scale_ssse3.c:get_lsb
Unexecuted instantiation: vp9_error_avx2.c:get_lsb
Unexecuted instantiation: quantize.c:get_lsb
Unexecuted instantiation: quantize_sse2.c:get_lsb
Unexecuted instantiation: quantize_ssse3.c:get_lsb
Unexecuted instantiation: quantize_avx.c:get_lsb
Unexecuted instantiation: quantize_avx2.c:get_lsb
Unexecuted instantiation: highbd_quantize_intrin_sse2.c:get_lsb
Unexecuted instantiation: highbd_quantize_intrin_avx2.c:get_lsb
Unexecuted instantiation: vp9_pred_common.c:get_lsb
Unexecuted instantiation: vp9_mvref_common.c:get_lsb
Unexecuted instantiation: vp9_extend.c:get_lsb
38
39
385M
static INLINE int get_msb(unsigned int n) {
40
385M
  assert(n != 0);
41
385M
  return 31 ^ __builtin_clz(n);
42
385M
}
vp8_quantize.c:get_msb
Line
Count
Source
39
7.54M
static INLINE int get_msb(unsigned int n) {
40
7.54M
  assert(n != 0);
41
7.54M
  return 31 ^ __builtin_clz(n);
42
7.54M
}
Unexecuted instantiation: vp9_cx_iface.c:get_msb
Unexecuted instantiation: vp9_firstpass.c:get_msb
Unexecuted instantiation: vp9_mcomp.c:get_msb
Unexecuted instantiation: vp9_encoder.c:get_msb
Unexecuted instantiation: vp9_picklpf.c:get_msb
vp9_quantize.c:get_msb
Line
Count
Source
39
29.3M
static INLINE int get_msb(unsigned int n) {
40
29.3M
  assert(n != 0);
41
29.3M
  return 31 ^ __builtin_clz(n);
42
29.3M
}
Unexecuted instantiation: vp9_ratectrl.c:get_msb
vp9_rd.c:get_msb
Line
Count
Source
39
83.4M
static INLINE int get_msb(unsigned int n) {
40
83.4M
  assert(n != 0);
41
83.4M
  return 31 ^ __builtin_clz(n);
42
83.4M
}
Unexecuted instantiation: vp9_segmentation.c:get_msb
Unexecuted instantiation: vp9_speed_features.c:get_msb
Unexecuted instantiation: vp9_svc_layercontext.c:get_msb
Unexecuted instantiation: vp9_resize.c:get_msb
Unexecuted instantiation: vp9_tokenize.c:get_msb
Unexecuted instantiation: vp9_aq_variance.c:get_msb
Unexecuted instantiation: vp9_aq_360.c:get_msb
Unexecuted instantiation: vp9_aq_cyclicrefresh.c:get_msb
Unexecuted instantiation: vp9_aq_complexity.c:get_msb
Unexecuted instantiation: vp9_alt_ref_aq.c:get_msb
Unexecuted instantiation: vp9_skin_detection.c:get_msb
Unexecuted instantiation: vp9_noise_estimate.c:get_msb
Unexecuted instantiation: vp9_ext_ratectrl.c:get_msb
Unexecuted instantiation: vp9_temporal_filter.c:get_msb
Unexecuted instantiation: vp9_tpl_model.c:get_msb
Unexecuted instantiation: vp9_mbgraph.c:get_msb
Unexecuted instantiation: yv12config.c:get_msb
Unexecuted instantiation: yv12extend.c:get_msb
vp8_quantize_ssse3.c:get_msb
Line
Count
Source
39
261M
static INLINE int get_msb(unsigned int n) {
40
261M
  assert(n != 0);
41
261M
  return 31 ^ __builtin_clz(n);
42
261M
}
Unexecuted instantiation: quantize_sse4.c:get_msb
Unexecuted instantiation: vp9_alloccommon.c:get_msb
Unexecuted instantiation: vp9_blockd.c:get_msb
Unexecuted instantiation: vp9_entropy.c:get_msb
Unexecuted instantiation: vp9_entropymode.c:get_msb
Unexecuted instantiation: vp9_entropymv.c:get_msb
Unexecuted instantiation: vp9_idct.c:get_msb
Unexecuted instantiation: vp9_rtcd.c:get_msb
Unexecuted instantiation: vp9_scale.c:get_msb
Unexecuted instantiation: vp9_seg_common.c:get_msb
Unexecuted instantiation: vp9_tile_common.c:get_msb
Unexecuted instantiation: vp9_loopfilter.c:get_msb
Unexecuted instantiation: vp9_thread_common.c:get_msb
Unexecuted instantiation: vp9_quant_common.c:get_msb
Unexecuted instantiation: vp9_reconinter.c:get_msb
Unexecuted instantiation: vp9_reconintra.c:get_msb
Unexecuted instantiation: vp9_scan.c:get_msb
Unexecuted instantiation: vp9_idct_intrin_sse2.c:get_msb
Unexecuted instantiation: vp9_highbd_iht4x4_add_sse4.c:get_msb
Unexecuted instantiation: vp9_highbd_iht8x8_add_sse4.c:get_msb
Unexecuted instantiation: vp9_highbd_iht16x16_add_sse4.c:get_msb
Unexecuted instantiation: vp9_bitstream.c:get_msb
Unexecuted instantiation: vp9_context_tree.c:get_msb
Unexecuted instantiation: vp9_dct.c:get_msb
Unexecuted instantiation: vp9_encodeframe.c:get_msb
Unexecuted instantiation: vp9_encodemb.c:get_msb
Unexecuted instantiation: vp9_encodemv.c:get_msb
Unexecuted instantiation: vp9_ethread.c:get_msb
Unexecuted instantiation: vp9_frame_scale.c:get_msb
Unexecuted instantiation: vp9_lookahead.c:get_msb
Unexecuted instantiation: vp9_multi_thread.c:get_msb
vp9_rdopt.c:get_msb
Line
Count
Source
39
3.89M
static INLINE int get_msb(unsigned int n) {
40
3.89M
  assert(n != 0);
41
3.89M
  return 31 ^ __builtin_clz(n);
42
3.89M
}
Unexecuted instantiation: vp9_pickmode.c:get_msb
Unexecuted instantiation: vp9_subexp.c:get_msb
Unexecuted instantiation: temporal_filter_sse4.c:get_msb
Unexecuted instantiation: vp9_quantize_sse2.c:get_msb
Unexecuted instantiation: vp9_quantize_ssse3.c:get_msb
Unexecuted instantiation: vp9_quantize_avx2.c:get_msb
Unexecuted instantiation: vp9_highbd_block_error_intrin_sse2.c:get_msb
Unexecuted instantiation: highbd_temporal_filter_sse4.c:get_msb
Unexecuted instantiation: vp9_dct_intrin_sse2.c:get_msb
Unexecuted instantiation: vp9_frame_scale_ssse3.c:get_msb
Unexecuted instantiation: vp9_error_avx2.c:get_msb
Unexecuted instantiation: quantize.c:get_msb
Unexecuted instantiation: quantize_sse2.c:get_msb
Unexecuted instantiation: quantize_ssse3.c:get_msb
Unexecuted instantiation: quantize_avx.c:get_msb
Unexecuted instantiation: quantize_avx2.c:get_msb
Unexecuted instantiation: highbd_quantize_intrin_sse2.c:get_msb
Unexecuted instantiation: highbd_quantize_intrin_avx2.c:get_msb
Unexecuted instantiation: vp9_pred_common.c:get_msb
Unexecuted instantiation: vp9_mvref_common.c:get_msb
Unexecuted instantiation: vp9_extend.c:get_msb
43
#elif defined(USE_MSC_INTRINSICS)
44
#pragma intrinsic(_BitScanForward)
45
#pragma intrinsic(_BitScanReverse)
46
47
static INLINE int get_lsb(unsigned int n) {
48
  unsigned long first_set_bit;  // NOLINT(runtime/int)
49
  _BitScanForward(&first_set_bit, n);
50
  return first_set_bit;
51
}
52
53
static INLINE int get_msb(unsigned int n) {
54
  unsigned long first_set_bit;
55
  assert(n != 0);
56
  _BitScanReverse(&first_set_bit, n);
57
  return first_set_bit;
58
}
59
#undef USE_MSC_INTRINSICS
60
#else
61
static INLINE int get_lsb(unsigned int n) {
62
  int i;
63
  assert(n != 0);
64
  for (i = 0; i < 32 && !(n & 1); ++i) n >>= 1;
65
  return i;
66
}
67
68
// Returns (int)floor(log2(n)). n must be > 0.
69
static INLINE int get_msb(unsigned int n) {
70
  int log = 0;
71
  unsigned int value = n;
72
  int i;
73
74
  assert(n != 0);
75
76
  for (i = 4; i >= 0; --i) {
77
    const int shift = (1 << i);
78
    const unsigned int x = value >> shift;
79
    if (x != 0) {
80
      value = x;
81
      log += shift;
82
    }
83
  }
84
  return log;
85
}
86
#endif
87
88
#ifdef __cplusplus
89
}  // extern "C"
90
#endif
91
92
#endif  // VPX_VPX_PORTS_BITOPS_H_