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 #if defined( __INTEL_COMPILER )
39 # define ff_log2(x) (_bit_scan_reverse((x)|1))
40 # ifndef ff_log2_16bit
41 # define ff_log2_16bit av_log2
44 #elif AV_GCC_VERSION_AT_LEAST(3,4)
46 # define ff_log2(x) (31 - __builtin_clz((x)|1))
47 # ifndef ff_log2_16bit
48 # define ff_log2_16bit av_log2
51 #endif /* AV_GCC_VERSION_AT_LEAST(3,4) */
54 extern const uint8_t ff_log2_tab[256];
57 #define ff_log2 ff_log2_c
58 #if !defined( _MSC_VER )
59 static av_always_inline av_const int ff_log2_c(unsigned int v)
75 static av_always_inline av_const int ff_log2_c(unsigned int v)
78 _BitScanReverse(&n, v|1);
81 #define ff_log2_16bit av_log2
86 #define ff_log2_16bit ff_log2_16bit_c
87 static av_always_inline av_const int ff_log2_16bit_c(unsigned int v)
100 #define av_log2 ff_log2
101 #define av_log2_16bit ff_log2_16bit
104 * @addtogroup lavu_math
109 #if defined( __INTEL_COMPILER )
111 #define ff_ctz(v) _bit_scan_forward(v)
113 #elif AV_GCC_VERSION_AT_LEAST(3,4)
115 #define ff_ctz(v) __builtin_ctz(v)
121 #define ff_ctz ff_ctz_c
122 #if !defined( _MSC_VER )
123 static av_always_inline av_const int ff_ctz_c(int v)
152 static av_always_inline av_const int ff_ctz_c( int v )
155 _BitScanForward(&c, v);
162 * Trailing zero bit count.
164 * @param v input value. If v is 0, the result is undefined.
165 * @return the number of trailing 0-bits
172 #endif /* AVUTIL_INTMATH_H */