annotate intmath.h @ 977:2cbad2391250 libavutil

intmath: whitespace cosmetics
author mru
date Wed, 07 Jul 2010 17:27:39 +0000
parents 3790c30fc3ad
children 009d2ce554b2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
807
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
1 /*
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
2 * Copyright (c) 2010 Mans Rullgard <mans@mansr.com>
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
3 *
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
4 * This file is part of FFmpeg.
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
5 *
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
6 * FFmpeg is free software; you can redistribute it and/or
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
9 * version 2.1 of the License, or (at your option) any later version.
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
10 *
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
11 * FFmpeg is distributed in the hope that it will be useful,
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
14 * Lesser General Public License for more details.
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
15 *
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
17 * License along with FFmpeg; if not, write to the Free Software
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
19 */
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
20
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
21 #ifndef AVUTIL_INTMATH_H
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
22 #define AVUTIL_INTMATH_H
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
23
870
3790c30fc3ad Fix build on configurations without fast av_log2()
mru
parents: 865
diff changeset
24 #include <stdint.h>
807
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
25 #include "config.h"
870
3790c30fc3ad Fix build on configurations without fast av_log2()
mru
parents: 865
diff changeset
26 #include "attributes.h"
807
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
27
816
d87093e4b925 Move FASTDIV macro to intmath.h
mru
parents: 807
diff changeset
28 extern const uint32_t ff_inverse[257];
d87093e4b925 Move FASTDIV macro to intmath.h
mru
parents: 807
diff changeset
29
d87093e4b925 Move FASTDIV macro to intmath.h
mru
parents: 807
diff changeset
30 #if ARCH_ARM
d87093e4b925 Move FASTDIV macro to intmath.h
mru
parents: 807
diff changeset
31 # include "arm/intmath.h"
d87093e4b925 Move FASTDIV macro to intmath.h
mru
parents: 807
diff changeset
32 #elif ARCH_X86
d87093e4b925 Move FASTDIV macro to intmath.h
mru
parents: 807
diff changeset
33 # include "x86/intmath.h"
d87093e4b925 Move FASTDIV macro to intmath.h
mru
parents: 807
diff changeset
34 #endif
d87093e4b925 Move FASTDIV macro to intmath.h
mru
parents: 807
diff changeset
35
807
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
36 #if HAVE_FAST_CLZ && AV_GCC_VERSION_AT_LEAST(3,4)
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
37
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
38 #ifndef av_log2
977
2cbad2391250 intmath: whitespace cosmetics
mru
parents: 870
diff changeset
39 # define av_log2(x) (31 - __builtin_clz((x)|1))
2cbad2391250 intmath: whitespace cosmetics
mru
parents: 870
diff changeset
40 # ifndef av_log2_16bit
2cbad2391250 intmath: whitespace cosmetics
mru
parents: 870
diff changeset
41 # define av_log2_16bit av_log2
2cbad2391250 intmath: whitespace cosmetics
mru
parents: 870
diff changeset
42 # endif
807
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
43 #endif /* av_log2 */
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
44
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
45 #endif /* AV_GCC_VERSION_AT_LEAST(3,4) */
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
46
816
d87093e4b925 Move FASTDIV macro to intmath.h
mru
parents: 807
diff changeset
47 #ifndef FASTDIV
977
2cbad2391250 intmath: whitespace cosmetics
mru
parents: 870
diff changeset
48 # if CONFIG_FASTDIV
2cbad2391250 intmath: whitespace cosmetics
mru
parents: 870
diff changeset
49 # define FASTDIV(a,b) ((uint32_t)((((uint64_t)a) * ff_inverse[b]) >> 32))
2cbad2391250 intmath: whitespace cosmetics
mru
parents: 870
diff changeset
50 # else
2cbad2391250 intmath: whitespace cosmetics
mru
parents: 870
diff changeset
51 # define FASTDIV(a,b) ((a) / (b))
2cbad2391250 intmath: whitespace cosmetics
mru
parents: 870
diff changeset
52 # endif
816
d87093e4b925 Move FASTDIV macro to intmath.h
mru
parents: 807
diff changeset
53 #endif /* FASTDIV */
d87093e4b925 Move FASTDIV macro to intmath.h
mru
parents: 807
diff changeset
54
870
3790c30fc3ad Fix build on configurations without fast av_log2()
mru
parents: 865
diff changeset
55 /*
3790c30fc3ad Fix build on configurations without fast av_log2()
mru
parents: 865
diff changeset
56 * Get definition of av_log2_c from common.h. In the event we got
3790c30fc3ad Fix build on configurations without fast av_log2()
mru
parents: 865
diff changeset
57 * here through common.h including this file, including it again will
3790c30fc3ad Fix build on configurations without fast av_log2()
mru
parents: 865
diff changeset
58 * be a no-op due to multi-inclusion guards, so we must duplicate the
3790c30fc3ad Fix build on configurations without fast av_log2()
mru
parents: 865
diff changeset
59 * fallback defines here.
3790c30fc3ad Fix build on configurations without fast av_log2()
mru
parents: 865
diff changeset
60 */
3790c30fc3ad Fix build on configurations without fast av_log2()
mru
parents: 865
diff changeset
61
3790c30fc3ad Fix build on configurations without fast av_log2()
mru
parents: 865
diff changeset
62 #include "common.h"
3790c30fc3ad Fix build on configurations without fast av_log2()
mru
parents: 865
diff changeset
63
3790c30fc3ad Fix build on configurations without fast av_log2()
mru
parents: 865
diff changeset
64 #ifndef av_log2
3790c30fc3ad Fix build on configurations without fast av_log2()
mru
parents: 865
diff changeset
65 # define av_log2 av_log2_c
3790c30fc3ad Fix build on configurations without fast av_log2()
mru
parents: 865
diff changeset
66 #endif
3790c30fc3ad Fix build on configurations without fast av_log2()
mru
parents: 865
diff changeset
67 #ifndef av_log2_16bit
3790c30fc3ad Fix build on configurations without fast av_log2()
mru
parents: 865
diff changeset
68 # define av_log2_16bit av_log2_16bit_c
3790c30fc3ad Fix build on configurations without fast av_log2()
mru
parents: 865
diff changeset
69 #endif
3790c30fc3ad Fix build on configurations without fast av_log2()
mru
parents: 865
diff changeset
70
865
41db9ae634fe Move ff_sqrt() to libavutil/intmath.h
mru
parents: 816
diff changeset
71 extern const uint8_t ff_sqrt_tab[256];
41db9ae634fe Move ff_sqrt() to libavutil/intmath.h
mru
parents: 816
diff changeset
72
41db9ae634fe Move ff_sqrt() to libavutil/intmath.h
mru
parents: 816
diff changeset
73 static inline av_const unsigned int ff_sqrt(unsigned int a)
41db9ae634fe Move ff_sqrt() to libavutil/intmath.h
mru
parents: 816
diff changeset
74 {
41db9ae634fe Move ff_sqrt() to libavutil/intmath.h
mru
parents: 816
diff changeset
75 unsigned int b;
41db9ae634fe Move ff_sqrt() to libavutil/intmath.h
mru
parents: 816
diff changeset
76
41db9ae634fe Move ff_sqrt() to libavutil/intmath.h
mru
parents: 816
diff changeset
77 if (a < 255) return (ff_sqrt_tab[a + 1] - 1) >> 4;
41db9ae634fe Move ff_sqrt() to libavutil/intmath.h
mru
parents: 816
diff changeset
78 else if (a < (1 << 12)) b = ff_sqrt_tab[a >> 4] >> 2;
41db9ae634fe Move ff_sqrt() to libavutil/intmath.h
mru
parents: 816
diff changeset
79 #if !CONFIG_SMALL
41db9ae634fe Move ff_sqrt() to libavutil/intmath.h
mru
parents: 816
diff changeset
80 else if (a < (1 << 14)) b = ff_sqrt_tab[a >> 6] >> 1;
41db9ae634fe Move ff_sqrt() to libavutil/intmath.h
mru
parents: 816
diff changeset
81 else if (a < (1 << 16)) b = ff_sqrt_tab[a >> 8] ;
41db9ae634fe Move ff_sqrt() to libavutil/intmath.h
mru
parents: 816
diff changeset
82 #endif
41db9ae634fe Move ff_sqrt() to libavutil/intmath.h
mru
parents: 816
diff changeset
83 else {
41db9ae634fe Move ff_sqrt() to libavutil/intmath.h
mru
parents: 816
diff changeset
84 int s = av_log2_16bit(a >> 16) >> 1;
41db9ae634fe Move ff_sqrt() to libavutil/intmath.h
mru
parents: 816
diff changeset
85 unsigned int c = a >> (s + 2);
41db9ae634fe Move ff_sqrt() to libavutil/intmath.h
mru
parents: 816
diff changeset
86 b = ff_sqrt_tab[c >> (s + 8)];
41db9ae634fe Move ff_sqrt() to libavutil/intmath.h
mru
parents: 816
diff changeset
87 b = FASTDIV(c,b) + (b << s);
41db9ae634fe Move ff_sqrt() to libavutil/intmath.h
mru
parents: 816
diff changeset
88 }
41db9ae634fe Move ff_sqrt() to libavutil/intmath.h
mru
parents: 816
diff changeset
89
41db9ae634fe Move ff_sqrt() to libavutil/intmath.h
mru
parents: 816
diff changeset
90 return b - (a < b * b);
41db9ae634fe Move ff_sqrt() to libavutil/intmath.h
mru
parents: 816
diff changeset
91 }
41db9ae634fe Move ff_sqrt() to libavutil/intmath.h
mru
parents: 816
diff changeset
92
807
36cc11e07d9b Optimise av_log2 with clz when available
mru
parents:
diff changeset
93 #endif /* AVUTIL_INTMATH_H */