~ubuntu-branches/ubuntu/trusty/gst-libav1.0/trusty-proposed

« back to all changes in this revision

Viewing changes to gst-libs/ext/libav/libavutil/intmath.h

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2013-09-24 17:07:00 UTC
  • mfrom: (1.1.17) (7.1.9 experimental)
  • Revision ID: package-import@ubuntu.com-20130924170700-4dg62s3pwl0pdakz
Tags: 1.2.0-1
* New upstream stable release:
  + debian/control:
    - Build depend on GStreamer and gst-plugins-base >= 1.2.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#define AVUTIL_INTMATH_H
23
23
 
24
24
#include <stdint.h>
 
25
 
25
26
#include "config.h"
26
27
#include "attributes.h"
27
28
 
 
29
#if ARCH_ARM
 
30
#   include "arm/intmath.h"
 
31
#endif
 
32
 
28
33
/**
29
34
 * @addtogroup lavu_internal
30
35
 * @{
31
36
 */
32
37
 
33
 
extern const uint32_t ff_inverse[257];
34
 
 
35
 
#if   ARCH_ARM
36
 
#   include "arm/intmath.h"
37
 
#elif ARCH_X86
38
 
#   include "x86/intmath.h"
39
 
#endif
40
 
 
41
38
#if HAVE_FAST_CLZ && AV_GCC_VERSION_AT_LEAST(3,4)
42
39
 
43
 
#ifndef av_log2
44
 
#   define av_log2(x) (31 - __builtin_clz((x)|1))
45
 
#   ifndef av_log2_16bit
46
 
#      define av_log2_16bit av_log2
 
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
47
44
#   endif
48
 
#endif /* av_log2 */
 
45
#endif /* ff_log2 */
49
46
 
50
47
#endif /* AV_GCC_VERSION_AT_LEAST(3,4) */
51
48
 
52
 
#ifndef FASTDIV
53
 
#   if CONFIG_FASTDIV
54
 
#       define FASTDIV(a,b) ((uint32_t)((((uint64_t)a) * ff_inverse[b]) >> 32))
55
 
#   else
56
 
#       define FASTDIV(a,b) ((a) / (b))
57
 
#   endif
58
 
#endif /* FASTDIV */
59
 
 
60
 
#include "common.h"
61
 
 
62
 
extern const uint8_t ff_sqrt_tab[256];
63
 
 
64
 
static inline av_const unsigned int ff_sqrt(unsigned int a)
65
 
{
66
 
    unsigned int b;
67
 
 
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;
70
 
#if !CONFIG_SMALL
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]   ;
73
 
#endif
74
 
    else {
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);
79
 
    }
80
 
 
81
 
    return b - (a < b * b);
82
 
}
 
49
extern const uint8_t ff_log2_tab[256];
 
50
 
 
51
#ifndef ff_log2
 
52
#define ff_log2 ff_log2_c
 
53
static av_always_inline av_const int ff_log2_c(unsigned int v)
 
54
{
 
55
    int n = 0;
 
56
    if (v & 0xffff0000) {
 
57
        v >>= 16;
 
58
        n += 16;
 
59
    }
 
60
    if (v & 0xff00) {
 
61
        v >>= 8;
 
62
        n += 8;
 
63
    }
 
64
    n += ff_log2_tab[v];
 
65
 
 
66
    return n;
 
67
}
 
68
#endif
 
69
 
 
70
#ifndef ff_log2_16bit
 
71
#define ff_log2_16bit ff_log2_16bit_c
 
72
static av_always_inline av_const int ff_log2_16bit_c(unsigned int v)
 
73
{
 
74
    int n = 0;
 
75
    if (v & 0xff00) {
 
76
        v >>= 8;
 
77
        n += 8;
 
78
    }
 
79
    n += ff_log2_tab[v];
 
80
 
 
81
    return n;
 
82
}
 
83
#endif
 
84
 
 
85
#define av_log2       ff_log2
 
86
#define av_log2_16bit ff_log2_16bit
 
87
 
 
88
/**
 
89
 * @}
 
90
 */
 
91
 
 
92
/**
 
93
 * @addtogroup lavu_math
 
94
 * @{
 
95
 */
 
96
 
 
97
#if HAVE_FAST_CLZ && AV_GCC_VERSION_AT_LEAST(3,4)
 
98
#ifndef ff_ctz
 
99
#define ff_ctz(v) __builtin_ctz(v)
 
100
#endif
 
101
#endif
 
102
 
 
103
#ifndef ff_ctz
 
104
#define ff_ctz ff_ctz_c
 
105
static av_always_inline av_const int ff_ctz_c(int v)
 
106
{
 
107
    int c;
 
108
 
 
109
    if (v & 0x1)
 
110
        return 0;
 
111
 
 
112
    c = 1;
 
113
    if (!(v & 0xffff)) {
 
114
        v >>= 16;
 
115
        c += 16;
 
116
    }
 
117
    if (!(v & 0xff)) {
 
118
        v >>= 8;
 
119
        c += 8;
 
120
    }
 
121
    if (!(v & 0xf)) {
 
122
        v >>= 4;
 
123
        c += 4;
 
124
    }
 
125
    if (!(v & 0x3)) {
 
126
        v >>= 2;
 
127
        c += 2;
 
128
    }
 
129
    c -= v & 0x1;
 
130
 
 
131
    return c;
 
132
}
 
133
#endif
 
134
 
 
135
/**
 
136
 * Trailing zero bit count.
 
137
 *
 
138
 * @param v  input value. If v is 0, the result is undefined.
 
139
 * @return   the number of trailing 0-bits
 
140
 */
 
141
int av_ctz(int v);
83
142
 
84
143
/**
85
144
 * @}