2 * Copyright (c) 2010 Mans Rullgard <mans@mansr.com>
4 * This file is part of FFmpeg.
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.
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.
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
21 #ifndef AVUTIL_INTMATH_H
22 #define AVUTIL_INTMATH_H
27 #include "attributes.h"
30 # include "arm/intmath.h"
33 # include "x86/intmath.h"
37 * @addtogroup lavu_internal
42 #if AV_GCC_VERSION_AT_LEAST(3,4)
44 # define ff_log2(x) (31 - __builtin_clz((x)|1))
45 # ifndef ff_log2_16bit
46 # define ff_log2_16bit av_log2
49 #elif defined( __INTEL_COMPILER )
51 # define ff_log2(x) (_bit_scan_reverse((x)|1))
52 # ifndef ff_log2_16bit
53 # define ff_log2_16bit av_log2
57 #endif /* AV_GCC_VERSION_AT_LEAST(3,4) */
59 extern const uint8_t ff_log2_tab[256];
62 #define ff_log2 ff_log2_c
63 #if !defined( _MSC_VER )
64 static av_always_inline av_const int ff_log2_c(unsigned int v)
80 static av_always_inline av_const int ff_log2_c(unsigned int v)
83 _BitScanReverse(&n, v|1);
86 #define ff_log2_16bit av_log2
91 #define ff_log2_16bit ff_log2_16bit_c
92 static av_always_inline av_const int ff_log2_16bit_c(unsigned int v)
105 #define av_log2 ff_log2
106 #define av_log2_16bit ff_log2_16bit
113 * @addtogroup lavu_math
118 #if AV_GCC_VERSION_AT_LEAST(3,4)
120 #define ff_ctz(v) __builtin_ctz(v)
122 #elif defined( __INTEL_COMPILER )
124 #define ff_ctz(v) _bit_scan_forward(v)
130 #define ff_ctz ff_ctz_c
131 #if !defined( _MSC_VER )
132 static av_always_inline av_const int ff_ctz_c(int v)
161 static av_always_inline av_const int ff_ctz_c( int v )
164 _BitScanForward(&c, v);
171 * Trailing zero bit count.
173 * @param v input value. If v is 0, the result is undefined.
174 * @return the number of trailing 0-bits
181 #endif /* AVUTIL_INTMATH_H */