22
22
#define AVUTIL_INTMATH_H
24
24
#include <stdint.h>
25
26
#include "config.h"
26
27
#include "attributes.h"
30
# include "arm/intmath.h"
29
34
* @addtogroup lavu_internal
33
extern const uint32_t ff_inverse[257];
36
# include "arm/intmath.h"
38
# include "x86/intmath.h"
41
38
#if HAVE_FAST_CLZ && AV_GCC_VERSION_AT_LEAST(3,4)
44
# define av_log2(x) (31 - __builtin_clz((x)|1))
45
# ifndef av_log2_16bit
46
# define av_log2_16bit av_log2
41
# define ff_log2(x) (31 - __builtin_clz((x)|1))
42
# ifndef ff_log2_16bit
43
# define ff_log2_16bit av_log2
50
47
#endif /* AV_GCC_VERSION_AT_LEAST(3,4) */
54
# define FASTDIV(a,b) ((uint32_t)((((uint64_t)a) * ff_inverse[b]) >> 32))
56
# define FASTDIV(a,b) ((a) / (b))
62
extern const uint8_t ff_sqrt_tab[256];
64
static inline av_const unsigned int ff_sqrt(unsigned int a)
68
if (a < 255) return (ff_sqrt_tab[a + 1] - 1) >> 4;
69
else if (a < (1 << 12)) b = ff_sqrt_tab[a >> 4] >> 2;
71
else if (a < (1 << 14)) b = ff_sqrt_tab[a >> 6] >> 1;
72
else if (a < (1 << 16)) b = ff_sqrt_tab[a >> 8] ;
75
int s = av_log2_16bit(a >> 16) >> 1;
76
unsigned int c = a >> (s + 2);
77
b = ff_sqrt_tab[c >> (s + 8)];
78
b = FASTDIV(c,b) + (b << s);
81
return b - (a < b * b);
49
extern const uint8_t ff_log2_tab[256];
52
#define ff_log2 ff_log2_c
53
static av_always_inline av_const int ff_log2_c(unsigned int v)
71
#define ff_log2_16bit ff_log2_16bit_c
72
static av_always_inline av_const int ff_log2_16bit_c(unsigned int v)
85
#define av_log2 ff_log2
86
#define av_log2_16bit ff_log2_16bit
93
* @addtogroup lavu_math
97
#if HAVE_FAST_CLZ && AV_GCC_VERSION_AT_LEAST(3,4)
99
#define ff_ctz(v) __builtin_ctz(v)
104
#define ff_ctz ff_ctz_c
105
static av_always_inline av_const int ff_ctz_c(int v)
136
* Trailing zero bit count.
138
* @param v input value. If v is 0, the result is undefined.
139
* @return the number of trailing 0-bits