FFmpeg
common.h
Go to the documentation of this file.
1 /*
2  * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
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 /**
22  * @file
23  * common internal and external API header
24  */
25 
26 #ifndef AVUTIL_COMMON_H
27 #define AVUTIL_COMMON_H
28 
29 #if defined(__cplusplus) && !defined(__STDC_CONSTANT_MACROS) && !defined(UINT64_C)
30 #error missing -D__STDC_CONSTANT_MACROS / #define __STDC_CONSTANT_MACROS
31 #endif
32 
33 #include <errno.h>
34 #include <inttypes.h>
35 #include <limits.h>
36 #include <math.h>
37 #include <stdint.h>
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <string.h>
41 
42 #include "attributes.h"
43 #include "error.h"
44 #include "macros.h"
45 
46 #ifdef HAVE_AV_CONFIG_H
47 # include "config.h"
48 # include "intmath.h"
49 # include "internal.h"
50 #else
51 # include "mem.h"
52 #endif /* HAVE_AV_CONFIG_H */
53 
54 //rounded division & shift
55 #define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b))
56 /* assume b>0 */
57 #define ROUNDED_DIV(a,b) (((a)>=0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
58 /* Fast a/(1<<b) rounded toward +inf. Assume a>=0 and b>=0 */
59 #define AV_CEIL_RSHIFT(a,b) (!av_builtin_constant_p(b) ? -((-(a)) >> (b)) \
60  : ((a) + (1<<(b)) - 1) >> (b))
61 /* Backwards compat. */
62 #define FF_CEIL_RSHIFT AV_CEIL_RSHIFT
63 
64 #define FFUDIV(a,b) (((a)>0 ?(a):(a)-(b)+1) / (b))
65 #define FFUMOD(a,b) ((a)-(b)*FFUDIV(a,b))
66 
67 /**
68  * Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they
69  * are not representable as absolute values of their type. This is the same
70  * as with *abs()
71  * @see FFNABS()
72  */
73 #define FFABS(a) ((a) >= 0 ? (a) : (-(a)))
74 #define FFSIGN(a) ((a) > 0 ? 1 : -1)
75 
76 /**
77  * Negative Absolute value.
78  * this works for all integers of all types.
79  * As with many macros, this evaluates its argument twice, it thus must not have
80  * a sideeffect, that is FFNABS(x++) has undefined behavior.
81  */
82 #define FFNABS(a) ((a) <= 0 ? (a) : (-(a)))
83 
84 /**
85  * Unsigned Absolute value.
86  * This takes the absolute value of a signed int and returns it as a unsigned.
87  * This also works with INT_MIN which would otherwise not be representable
88  * As with many macros, this evaluates its argument twice.
89  */
90 #define FFABSU(a) ((a) <= 0 ? -(unsigned)(a) : (unsigned)(a))
91 #define FFABS64U(a) ((a) <= 0 ? -(uint64_t)(a) : (uint64_t)(a))
92 
93 /* misc math functions */
94 
95 #ifndef av_ceil_log2
96 # define av_ceil_log2 av_ceil_log2_c
97 #endif
98 #ifndef av_clip
99 # define av_clip av_clip_c
100 #endif
101 #ifndef av_clip64
102 # define av_clip64 av_clip64_c
103 #endif
104 #ifndef av_clip_uint8
105 # define av_clip_uint8 av_clip_uint8_c
106 #endif
107 #ifndef av_clip_int8
108 # define av_clip_int8 av_clip_int8_c
109 #endif
110 #ifndef av_clip_uint16
111 # define av_clip_uint16 av_clip_uint16_c
112 #endif
113 #ifndef av_clip_int16
114 # define av_clip_int16 av_clip_int16_c
115 #endif
116 #ifndef av_clipl_int32
117 # define av_clipl_int32 av_clipl_int32_c
118 #endif
119 #ifndef av_clip_intp2
120 # define av_clip_intp2 av_clip_intp2_c
121 #endif
122 #ifndef av_clip_uintp2
123 # define av_clip_uintp2 av_clip_uintp2_c
124 #endif
125 #ifndef av_mod_uintp2
126 # define av_mod_uintp2 av_mod_uintp2_c
127 #endif
128 #ifndef av_sat_add32
129 # define av_sat_add32 av_sat_add32_c
130 #endif
131 #ifndef av_sat_dadd32
132 # define av_sat_dadd32 av_sat_dadd32_c
133 #endif
134 #ifndef av_sat_sub32
135 # define av_sat_sub32 av_sat_sub32_c
136 #endif
137 #ifndef av_sat_dsub32
138 # define av_sat_dsub32 av_sat_dsub32_c
139 #endif
140 #ifndef av_sat_add64
141 # define av_sat_add64 av_sat_add64_c
142 #endif
143 #ifndef av_sat_sub64
144 # define av_sat_sub64 av_sat_sub64_c
145 #endif
146 #ifndef av_clipf
147 # define av_clipf av_clipf_c
148 #endif
149 #ifndef av_clipd
150 # define av_clipd av_clipd_c
151 #endif
152 #ifndef av_popcount
153 # define av_popcount av_popcount_c
154 #endif
155 #ifndef av_popcount64
156 # define av_popcount64 av_popcount64_c
157 #endif
158 #ifndef av_parity
159 # define av_parity av_parity_c
160 #endif
161 
162 #ifndef av_log2
163 av_const int av_log2(unsigned v);
164 #endif
165 
166 #ifndef av_log2_16bit
167 av_const int av_log2_16bit(unsigned v);
168 #endif
169 
170 /**
171  * Clip a signed integer value into the amin-amax range.
172  * @param a value to clip
173  * @param amin minimum value of the clip range
174  * @param amax maximum value of the clip range
175  * @return clipped value
176  */
177 static av_always_inline av_const int av_clip_c(int a, int amin, int amax)
178 {
179 #if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2
180  if (amin > amax) abort();
181 #endif
182  if (a < amin) return amin;
183  else if (a > amax) return amax;
184  else return a;
185 }
186 
187 /**
188  * Clip a signed 64bit integer value into the amin-amax range.
189  * @param a value to clip
190  * @param amin minimum value of the clip range
191  * @param amax maximum value of the clip range
192  * @return clipped value
193  */
194 static av_always_inline av_const int64_t av_clip64_c(int64_t a, int64_t amin, int64_t amax)
195 {
196 #if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2
197  if (amin > amax) abort();
198 #endif
199  if (a < amin) return amin;
200  else if (a > amax) return amax;
201  else return a;
202 }
203 
204 /**
205  * Clip a signed integer value into the 0-255 range.
206  * @param a value to clip
207  * @return clipped value
208  */
210 {
211  if (a&(~0xFF)) return (~a)>>31;
212  else return a;
213 }
214 
215 /**
216  * Clip a signed integer value into the -128,127 range.
217  * @param a value to clip
218  * @return clipped value
219  */
221 {
222  if ((a+0x80U) & ~0xFF) return (a>>31) ^ 0x7F;
223  else return a;
224 }
225 
226 /**
227  * Clip a signed integer value into the 0-65535 range.
228  * @param a value to clip
229  * @return clipped value
230  */
232 {
233  if (a&(~0xFFFF)) return (~a)>>31;
234  else return a;
235 }
236 
237 /**
238  * Clip a signed integer value into the -32768,32767 range.
239  * @param a value to clip
240  * @return clipped value
241  */
243 {
244  if ((a+0x8000U) & ~0xFFFF) return (a>>31) ^ 0x7FFF;
245  else return a;
246 }
247 
248 /**
249  * Clip a signed 64-bit integer value into the -2147483648,2147483647 range.
250  * @param a value to clip
251  * @return clipped value
252  */
254 {
255  if ((a+0x80000000u) & ~UINT64_C(0xFFFFFFFF)) return (int32_t)((a>>63) ^ 0x7FFFFFFF);
256  else return (int32_t)a;
257 }
258 
259 /**
260  * Clip a signed integer into the -(2^p),(2^p-1) range.
261  * @param a value to clip
262  * @param p bit position to clip at
263  * @return clipped value
264  */
266 {
267  if (((unsigned)a + (1 << p)) & ~((2 << p) - 1))
268  return (a >> 31) ^ ((1 << p) - 1);
269  else
270  return a;
271 }
272 
273 /**
274  * Clip a signed integer to an unsigned power of two range.
275  * @param a value to clip
276  * @param p bit position to clip at
277  * @return clipped value
278  */
279 static av_always_inline av_const unsigned av_clip_uintp2_c(int a, int p)
280 {
281  if (a & ~((1<<p) - 1)) return (~a) >> 31 & ((1<<p) - 1);
282  else return a;
283 }
284 
285 /**
286  * Clear high bits from an unsigned integer starting with specific bit position
287  * @param a value to clip
288  * @param p bit position to clip at
289  * @return clipped value
290  */
291 static av_always_inline av_const unsigned av_mod_uintp2_c(unsigned a, unsigned p)
292 {
293  return a & ((1U << p) - 1);
294 }
295 
296 /**
297  * Add two signed 32-bit values with saturation.
298  *
299  * @param a one value
300  * @param b another value
301  * @return sum with signed saturation
302  */
303 static av_always_inline int av_sat_add32_c(int a, int b)
304 {
305  return av_clipl_int32((int64_t)a + b);
306 }
307 
308 /**
309  * Add a doubled value to another value with saturation at both stages.
310  *
311  * @param a first value
312  * @param b value doubled and added to a
313  * @return sum sat(a + sat(2*b)) with signed saturation
314  */
315 static av_always_inline int av_sat_dadd32_c(int a, int b)
316 {
317  return av_sat_add32(a, av_sat_add32(b, b));
318 }
319 
320 /**
321  * Subtract two signed 32-bit values with saturation.
322  *
323  * @param a one value
324  * @param b another value
325  * @return difference with signed saturation
326  */
327 static av_always_inline int av_sat_sub32_c(int a, int b)
328 {
329  return av_clipl_int32((int64_t)a - b);
330 }
331 
332 /**
333  * Subtract a doubled value from another value with saturation at both stages.
334  *
335  * @param a first value
336  * @param b value doubled and subtracted from a
337  * @return difference sat(a - sat(2*b)) with signed saturation
338  */
339 static av_always_inline int av_sat_dsub32_c(int a, int b)
340 {
341  return av_sat_sub32(a, av_sat_add32(b, b));
342 }
343 
344 /**
345  * Add two signed 64-bit values with saturation.
346  *
347  * @param a one value
348  * @param b another value
349  * @return sum with signed saturation
350  */
351 static av_always_inline int64_t av_sat_add64_c(int64_t a, int64_t b) {
352 #if (!defined(__INTEL_COMPILER) && AV_GCC_VERSION_AT_LEAST(5,1)) || AV_HAS_BUILTIN(__builtin_add_overflow)
353  int64_t tmp;
354  return !__builtin_add_overflow(a, b, &tmp) ? tmp : (tmp < 0 ? INT64_MAX : INT64_MIN);
355 #else
356  int64_t s = a+(uint64_t)b;
357  if ((int64_t)(a^b | ~s^b) >= 0)
358  return INT64_MAX ^ (b >> 63);
359  return s;
360 #endif
361 }
362 
363 /**
364  * Subtract two signed 64-bit values with saturation.
365  *
366  * @param a one value
367  * @param b another value
368  * @return difference with signed saturation
369  */
370 static av_always_inline int64_t av_sat_sub64_c(int64_t a, int64_t b) {
371 #if (!defined(__INTEL_COMPILER) && AV_GCC_VERSION_AT_LEAST(5,1)) || AV_HAS_BUILTIN(__builtin_sub_overflow)
372  int64_t tmp;
373  return !__builtin_sub_overflow(a, b, &tmp) ? tmp : (tmp < 0 ? INT64_MAX : INT64_MIN);
374 #else
375  if (b <= 0 && a >= INT64_MAX + b)
376  return INT64_MAX;
377  if (b >= 0 && a <= INT64_MIN + b)
378  return INT64_MIN;
379  return a - b;
380 #endif
381 }
382 
383 /**
384  * Clip a float value into the amin-amax range.
385  * If a is nan or -inf amin will be returned.
386  * If a is +inf amax will be returned.
387  * @param a value to clip
388  * @param amin minimum value of the clip range
389  * @param amax maximum value of the clip range
390  * @return clipped value
391  */
392 static av_always_inline av_const float av_clipf_c(float a, float amin, float amax)
393 {
394 #if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2
395  if (amin > amax) abort();
396 #endif
397  return FFMIN(FFMAX(a, amin), amax);
398 }
399 
400 /**
401  * Clip a double value into the amin-amax range.
402  * If a is nan or -inf amin will be returned.
403  * If a is +inf amax will be returned.
404  * @param a value to clip
405  * @param amin minimum value of the clip range
406  * @param amax maximum value of the clip range
407  * @return clipped value
408  */
409 static av_always_inline av_const double av_clipd_c(double a, double amin, double amax)
410 {
411 #if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2
412  if (amin > amax) abort();
413 #endif
414  return FFMIN(FFMAX(a, amin), amax);
415 }
416 
417 /** Compute ceil(log2(x)).
418  * @param x value used to compute ceil(log2(x))
419  * @return computed ceiling of log2(x)
420  */
422 {
423  return av_log2((x - 1U) << 1);
424 }
425 
426 /**
427  * Count number of bits set to one in x
428  * @param x value to count bits of
429  * @return the number of bits set to one in x
430  */
432 {
433  x -= (x >> 1) & 0x55555555;
434  x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
435  x = (x + (x >> 4)) & 0x0F0F0F0F;
436  x += x >> 8;
437  return (x + (x >> 16)) & 0x3F;
438 }
439 
440 /**
441  * Count number of bits set to one in x
442  * @param x value to count bits of
443  * @return the number of bits set to one in x
444  */
446 {
447  return av_popcount((uint32_t)x) + av_popcount((uint32_t)(x >> 32));
448 }
449 
450 static av_always_inline av_const int av_parity_c(uint32_t v)
451 {
452  return av_popcount(v) & 1;
453 }
454 
455 /**
456  * Convert a UTF-8 character (up to 4 bytes) to its 32-bit UCS-4 encoded form.
457  *
458  * @param val Output value, must be an lvalue of type uint32_t.
459  * @param GET_BYTE Expression reading one byte from the input.
460  * Evaluated up to 7 times (4 for the currently
461  * assigned Unicode range). With a memory buffer
462  * input, this could be *ptr++, or if you want to make sure
463  * that *ptr stops at the end of a NULL terminated string then
464  * *ptr ? *ptr++ : 0
465  * @param ERROR Expression to be evaluated on invalid input,
466  * typically a goto statement.
467  *
468  * @warning ERROR should not contain a loop control statement which
469  * could interact with the internal while loop, and should force an
470  * exit from the macro code (e.g. through a goto or a return) in order
471  * to prevent undefined results.
472  */
473 #define GET_UTF8(val, GET_BYTE, ERROR)\
474  val= (GET_BYTE);\
475  {\
476  uint32_t top = (val & 128) >> 1;\
477  if ((val & 0xc0) == 0x80 || val >= 0xFE)\
478  {ERROR}\
479  while (val & top) {\
480  unsigned int tmp = (GET_BYTE) - 128;\
481  if(tmp>>6)\
482  {ERROR}\
483  val= (val<<6) + tmp;\
484  top <<= 5;\
485  }\
486  val &= (top << 1) - 1;\
487  }
488 
489 /**
490  * Convert a UTF-16 character (2 or 4 bytes) to its 32-bit UCS-4 encoded form.
491  *
492  * @param val Output value, must be an lvalue of type uint32_t.
493  * @param GET_16BIT Expression returning two bytes of UTF-16 data converted
494  * to native byte order. Evaluated one or two times.
495  * @param ERROR Expression to be evaluated on invalid input,
496  * typically a goto statement.
497  */
498 #define GET_UTF16(val, GET_16BIT, ERROR)\
499  val = (GET_16BIT);\
500  {\
501  unsigned int hi = val - 0xD800;\
502  if (hi < 0x800) {\
503  val = (GET_16BIT) - 0xDC00;\
504  if (val > 0x3FFU || hi > 0x3FFU)\
505  {ERROR}\
506  val += (hi<<10) + 0x10000;\
507  }\
508  }\
509 
510 /**
511  * @def PUT_UTF8(val, tmp, PUT_BYTE)
512  * Convert a 32-bit Unicode character to its UTF-8 encoded form (up to 4 bytes long).
513  * @param val is an input-only argument and should be of type uint32_t. It holds
514  * a UCS-4 encoded Unicode character that is to be converted to UTF-8. If
515  * val is given as a function it is executed only once.
516  * @param tmp is a temporary variable and should be of type uint8_t. It
517  * represents an intermediate value during conversion that is to be
518  * output by PUT_BYTE.
519  * @param PUT_BYTE writes the converted UTF-8 bytes to any proper destination.
520  * It could be a function or a statement, and uses tmp as the input byte.
521  * For example, PUT_BYTE could be "*output++ = tmp;" PUT_BYTE will be
522  * executed up to 4 times for values in the valid UTF-8 range and up to
523  * 7 times in the general case, depending on the length of the converted
524  * Unicode character.
525  */
526 #define PUT_UTF8(val, tmp, PUT_BYTE)\
527  {\
528  int bytes, shift;\
529  uint32_t in = val;\
530  if (in < 0x80) {\
531  tmp = in;\
532  PUT_BYTE\
533  } else {\
534  bytes = (av_log2(in) + 4) / 5;\
535  shift = (bytes - 1) * 6;\
536  tmp = (256 - (256 >> bytes)) | (in >> shift);\
537  PUT_BYTE\
538  while (shift >= 6) {\
539  shift -= 6;\
540  tmp = 0x80 | ((in >> shift) & 0x3f);\
541  PUT_BYTE\
542  }\
543  }\
544  }
545 
546 /**
547  * @def PUT_UTF16(val, tmp, PUT_16BIT)
548  * Convert a 32-bit Unicode character to its UTF-16 encoded form (2 or 4 bytes).
549  * @param val is an input-only argument and should be of type uint32_t. It holds
550  * a UCS-4 encoded Unicode character that is to be converted to UTF-16. If
551  * val is given as a function it is executed only once.
552  * @param tmp is a temporary variable and should be of type uint16_t. It
553  * represents an intermediate value during conversion that is to be
554  * output by PUT_16BIT.
555  * @param PUT_16BIT writes the converted UTF-16 data to any proper destination
556  * in desired endianness. It could be a function or a statement, and uses tmp
557  * as the input byte. For example, PUT_BYTE could be "*output++ = tmp;"
558  * PUT_BYTE will be executed 1 or 2 times depending on input character.
559  */
560 #define PUT_UTF16(val, tmp, PUT_16BIT)\
561  {\
562  uint32_t in = val;\
563  if (in < 0x10000) {\
564  tmp = in;\
565  PUT_16BIT\
566  } else {\
567  tmp = 0xD800 | ((in - 0x10000) >> 10);\
568  PUT_16BIT\
569  tmp = 0xDC00 | ((in - 0x10000) & 0x3FF);\
570  PUT_16BIT\
571  }\
572  }\
573 
574 #endif /* AVUTIL_COMMON_H */
av_mod_uintp2_c
static av_always_inline av_const unsigned av_mod_uintp2_c(unsigned a, unsigned p)
Clear high bits from an unsigned integer starting with specific bit position.
Definition: common.h:291
av_log2_16bit
int av_log2_16bit(unsigned v)
Definition: intmath.c:31
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
av_clip_uintp2_c
static av_always_inline av_const unsigned av_clip_uintp2_c(int a, int p)
Clip a signed integer to an unsigned power of two range.
Definition: common.h:279
av_sat_sub32_c
static av_always_inline int av_sat_sub32_c(int a, int b)
Subtract two signed 32-bit values with saturation.
Definition: common.h:327
av_const
#define av_const
Definition: attributes.h:84
b
#define b
Definition: input.c:41
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
av_popcount
#define av_popcount
Definition: common.h:153
av_clip_uint16_c
static av_always_inline av_const uint16_t av_clip_uint16_c(int a)
Clip a signed integer value into the 0-65535 range.
Definition: common.h:231
av_clip_uint8_c
static av_always_inline av_const uint8_t av_clip_uint8_c(int a)
Clip a signed integer value into the 0-255 range.
Definition: common.h:209
av_sat_dadd32_c
static av_always_inline int av_sat_dadd32_c(int a, int b)
Add a doubled value to another value with saturation at both stages.
Definition: common.h:315
av_clip64_c
static av_always_inline av_const int64_t av_clip64_c(int64_t a, int64_t amin, int64_t amax)
Clip a signed 64bit integer value into the amin-amax range.
Definition: common.h:194
macros.h
s
#define s(width, name)
Definition: cbs_vp9.c:198
limits.h
av_sat_sub32
#define av_sat_sub32
Definition: common.h:135
av_clipf_c
static av_always_inline av_const float av_clipf_c(float a, float amin, float amax)
Clip a float value into the amin-amax range.
Definition: common.h:392
av_clipd_c
static av_always_inline av_const double av_clipd_c(double a, double amin, double amax)
Clip a double value into the amin-amax range.
Definition: common.h:409
av_clip_intp2_c
static av_always_inline av_const int av_clip_intp2_c(int a, int p)
Clip a signed integer into the -(2^p),(2^p-1) range.
Definition: common.h:265
av_sat_add32
#define av_sat_add32
Definition: common.h:129
av_clip_c
static av_always_inline av_const int av_clip_c(int a, int amin, int amax)
Clip a signed integer value into the amin-amax range.
Definition: common.h:177
error.h
av_clipl_int32
#define av_clipl_int32
Definition: common.h:117
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
attributes.h
internal.h
av_clipl_int32_c
static av_always_inline av_const int32_t av_clipl_int32_c(int64_t a)
Clip a signed 64-bit integer value into the -2147483648,2147483647 range.
Definition: common.h:253
av_always_inline
#define av_always_inline
Definition: attributes.h:49
av_popcount_c
static av_always_inline av_const int av_popcount_c(uint32_t x)
Count number of bits set to one in x.
Definition: common.h:431
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_sat_add32_c
static av_always_inline int av_sat_add32_c(int a, int b)
Add two signed 32-bit values with saturation.
Definition: common.h:303
av_popcount64_c
static av_always_inline av_const int av_popcount64_c(uint64_t x)
Count number of bits set to one in x.
Definition: common.h:445
U
#define U(x)
Definition: vpx_arith.h:37
mem.h
av_sat_add64_c
static av_always_inline int64_t av_sat_add64_c(int64_t a, int64_t b)
Add two signed 64-bit values with saturation.
Definition: common.h:351
av_clip_int16_c
static av_always_inline av_const int16_t av_clip_int16_c(int a)
Clip a signed integer value into the -32768,32767 range.
Definition: common.h:242
av_sat_sub64_c
static av_always_inline int64_t av_sat_sub64_c(int64_t a, int64_t b)
Subtract two signed 64-bit values with saturation.
Definition: common.h:370
int32_t
int32_t
Definition: audioconvert.c:56
av_sat_dsub32_c
static av_always_inline int av_sat_dsub32_c(int a, int b)
Subtract a doubled value from another value with saturation at both stages.
Definition: common.h:339
av_parity_c
static av_always_inline av_const int av_parity_c(uint32_t v)
Definition: common.h:450
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
av_ceil_log2_c
static av_always_inline av_const int av_ceil_log2_c(int x)
Compute ceil(log2(x)).
Definition: common.h:421
av_clip_int8_c
static av_always_inline av_const int8_t av_clip_int8_c(int a)
Clip a signed integer value into the -128,127 range.
Definition: common.h:220
intmath.h