/src/vlc/contrib/contrib-build/bpg/libavutil/intmath.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2010 Mans Rullgard <mans@mansr.com> |
3 | | * |
4 | | * This file is part of FFmpeg. |
5 | | * |
6 | | * FFmpeg is free software; you can redistribute it and/or |
7 | | * modify it under the terms of the GNU Lesser General Public |
8 | | * License as published by the Free Software Foundation; either |
9 | | * version 2.1 of the License, or (at your option) any later version. |
10 | | * |
11 | | * FFmpeg is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | | * Lesser General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU Lesser General Public |
17 | | * License along with FFmpeg; if not, write to the Free Software |
18 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
19 | | */ |
20 | | |
21 | | #ifndef AVUTIL_INTMATH_H |
22 | | #define AVUTIL_INTMATH_H |
23 | | |
24 | | #include <stdint.h> |
25 | | |
26 | | #include "config.h" |
27 | | #include "attributes.h" |
28 | | |
29 | | #if ARCH_ARM |
30 | | # include "arm/intmath.h" |
31 | | #endif |
32 | | |
33 | | /** |
34 | | * @addtogroup lavu_internal |
35 | | * @{ |
36 | | */ |
37 | | |
38 | | #if HAVE_FAST_CLZ |
39 | | #if AV_GCC_VERSION_AT_LEAST(3,4) |
40 | | #ifndef ff_log2 |
41 | | # define ff_log2(x) (31 - __builtin_clz((x)|1)) |
42 | | # ifndef ff_log2_16bit |
43 | | # define ff_log2_16bit av_log2 |
44 | | # endif |
45 | | #endif /* ff_log2 */ |
46 | | #elif defined( __INTEL_COMPILER ) |
47 | | #ifndef ff_log2 |
48 | | # define ff_log2(x) (_bit_scan_reverse(x|1)) |
49 | | # ifndef ff_log2_16bit |
50 | | # define ff_log2_16bit av_log2 |
51 | | # endif |
52 | | #endif /* ff_log2 */ |
53 | | #endif |
54 | | #endif /* AV_GCC_VERSION_AT_LEAST(3,4) */ |
55 | | |
56 | | extern const uint8_t ff_log2_tab[256]; |
57 | | |
58 | | #ifndef ff_log2 |
59 | 0 | #define ff_log2 ff_log2_c |
60 | | #if !defined( _MSC_VER ) |
61 | | static av_always_inline av_const int ff_log2_c(unsigned int v) |
62 | 0 | { |
63 | 0 | int n = 0; |
64 | 0 | if (v & 0xffff0000) { |
65 | 0 | v >>= 16; |
66 | 0 | n += 16; |
67 | 0 | } |
68 | 0 | if (v & 0xff00) { |
69 | 0 | v >>= 8; |
70 | 0 | n += 8; |
71 | 0 | } |
72 | 0 | n += ff_log2_tab[v]; |
73 | |
|
74 | 0 | return n; |
75 | 0 | } Unexecuted instantiation: hevc_cabac.c:ff_log2_c Unexecuted instantiation: hevc_filter.c:ff_log2_c Unexecuted instantiation: hevc.c:ff_log2_c Unexecuted instantiation: hevcpred.c:ff_log2_c Unexecuted instantiation: hevc_refs.c:ff_log2_c Unexecuted instantiation: hevcdsp.c:ff_log2_c Unexecuted instantiation: hevc_mvs.c:ff_log2_c Unexecuted instantiation: hevc_ps.c:ff_log2_c Unexecuted instantiation: hevc_sei.c:ff_log2_c Unexecuted instantiation: utils.c:ff_log2_c Unexecuted instantiation: cabac.c:ff_log2_c Unexecuted instantiation: golomb.c:ff_log2_c Unexecuted instantiation: videodsp.c:ff_log2_c Unexecuted instantiation: mem.c:ff_log2_c Unexecuted instantiation: buffer.c:ff_log2_c Unexecuted instantiation: frame.c:ff_log2_c Unexecuted instantiation: pixdesc.c:ff_log2_c Unexecuted instantiation: md5.c:ff_log2_c Unexecuted instantiation: libbpg.c:ff_log2_c |
76 | | #else |
77 | | static av_always_inline av_const int ff_log2_c(unsigned int v) |
78 | | { |
79 | | unsigned long n; |
80 | | _BitScanReverse(&n, v|1); |
81 | | return n; |
82 | | } |
83 | | #define ff_log2_16bit av_log2 |
84 | | #endif |
85 | | #endif |
86 | | |
87 | | #ifndef ff_log2_16bit |
88 | | #define ff_log2_16bit ff_log2_16bit_c |
89 | | static av_always_inline av_const int ff_log2_16bit_c(unsigned int v) |
90 | 0 | { |
91 | 0 | int n = 0; |
92 | 0 | if (v & 0xff00) { |
93 | 0 | v >>= 8; |
94 | 0 | n += 8; |
95 | 0 | } |
96 | 0 | n += ff_log2_tab[v]; |
97 | 0 |
|
98 | 0 | return n; |
99 | 0 | } Unexecuted instantiation: hevc_cabac.c:ff_log2_16bit_c Unexecuted instantiation: hevc_filter.c:ff_log2_16bit_c Unexecuted instantiation: hevc.c:ff_log2_16bit_c Unexecuted instantiation: hevcpred.c:ff_log2_16bit_c Unexecuted instantiation: hevc_refs.c:ff_log2_16bit_c Unexecuted instantiation: hevcdsp.c:ff_log2_16bit_c Unexecuted instantiation: hevc_mvs.c:ff_log2_16bit_c Unexecuted instantiation: hevc_ps.c:ff_log2_16bit_c Unexecuted instantiation: hevc_sei.c:ff_log2_16bit_c Unexecuted instantiation: utils.c:ff_log2_16bit_c Unexecuted instantiation: cabac.c:ff_log2_16bit_c Unexecuted instantiation: golomb.c:ff_log2_16bit_c Unexecuted instantiation: videodsp.c:ff_log2_16bit_c Unexecuted instantiation: mem.c:ff_log2_16bit_c Unexecuted instantiation: buffer.c:ff_log2_16bit_c Unexecuted instantiation: frame.c:ff_log2_16bit_c Unexecuted instantiation: pixdesc.c:ff_log2_16bit_c Unexecuted instantiation: md5.c:ff_log2_16bit_c Unexecuted instantiation: libbpg.c:ff_log2_16bit_c |
100 | | #endif |
101 | | |
102 | 0 | #define av_log2 ff_log2 |
103 | | #define av_log2_16bit ff_log2_16bit |
104 | | |
105 | | /** |
106 | | * @} |
107 | | */ |
108 | | |
109 | | /** |
110 | | * @addtogroup lavu_math |
111 | | * @{ |
112 | | */ |
113 | | |
114 | | #if HAVE_FAST_CLZ |
115 | | #if AV_GCC_VERSION_AT_LEAST(3,4) |
116 | | #ifndef ff_ctz |
117 | | #define ff_ctz(v) __builtin_ctz(v) |
118 | | #endif |
119 | | #elif defined( __INTEL_COMPILER ) |
120 | | #ifndef ff_ctz |
121 | | #define ff_ctz(v) _bit_scan_forward(v) |
122 | | #endif |
123 | | #endif |
124 | | #endif |
125 | | |
126 | | #ifndef ff_ctz |
127 | | #define ff_ctz ff_ctz_c |
128 | | #if !defined( _MSC_VER ) |
129 | | static av_always_inline av_const int ff_ctz_c(int v) |
130 | 0 | { |
131 | 0 | int c; |
132 | 0 |
|
133 | 0 | if (v & 0x1) |
134 | 0 | return 0; |
135 | 0 |
|
136 | 0 | c = 1; |
137 | 0 | if (!(v & 0xffff)) { |
138 | 0 | v >>= 16; |
139 | 0 | c += 16; |
140 | 0 | } |
141 | 0 | if (!(v & 0xff)) { |
142 | 0 | v >>= 8; |
143 | 0 | c += 8; |
144 | 0 | } |
145 | 0 | if (!(v & 0xf)) { |
146 | 0 | v >>= 4; |
147 | 0 | c += 4; |
148 | 0 | } |
149 | 0 | if (!(v & 0x3)) { |
150 | 0 | v >>= 2; |
151 | 0 | c += 2; |
152 | 0 | } |
153 | 0 | c -= v & 0x1; |
154 | 0 |
|
155 | 0 | return c; |
156 | 0 | } Unexecuted instantiation: hevc_cabac.c:ff_ctz_c Unexecuted instantiation: hevc_filter.c:ff_ctz_c Unexecuted instantiation: hevc.c:ff_ctz_c Unexecuted instantiation: hevcpred.c:ff_ctz_c Unexecuted instantiation: hevc_refs.c:ff_ctz_c Unexecuted instantiation: hevcdsp.c:ff_ctz_c Unexecuted instantiation: hevc_mvs.c:ff_ctz_c Unexecuted instantiation: hevc_ps.c:ff_ctz_c Unexecuted instantiation: hevc_sei.c:ff_ctz_c Unexecuted instantiation: utils.c:ff_ctz_c Unexecuted instantiation: cabac.c:ff_ctz_c Unexecuted instantiation: golomb.c:ff_ctz_c Unexecuted instantiation: videodsp.c:ff_ctz_c Unexecuted instantiation: mem.c:ff_ctz_c Unexecuted instantiation: buffer.c:ff_ctz_c Unexecuted instantiation: frame.c:ff_ctz_c Unexecuted instantiation: pixdesc.c:ff_ctz_c Unexecuted instantiation: md5.c:ff_ctz_c Unexecuted instantiation: libbpg.c:ff_ctz_c |
157 | | #else |
158 | | static av_always_inline av_const int ff_ctz_c( int v ) |
159 | | { |
160 | | unsigned long c; |
161 | | _BitScanForward(&c, v); |
162 | | return c; |
163 | | } |
164 | | #endif |
165 | | #endif |
166 | | |
167 | | /** |
168 | | * Trailing zero bit count. |
169 | | * |
170 | | * @param v input value. If v is 0, the result is undefined. |
171 | | * @return the number of trailing 0-bits |
172 | | */ |
173 | | int av_ctz(int v); |
174 | | |
175 | | /** |
176 | | * @} |
177 | | */ |
178 | | #endif /* AVUTIL_INTMATH_H */ |