From dfde8a34e5419ac99265e3ecc2e82f378674128a Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Fri, 26 Oct 2012 14:48:40 -0400 Subject: lavu: add av_ctz() for trailing zero bit count --- libavutil/Makefile | 2 +- libavutil/intmath.c | 39 +++++++++++++++++++++++++++++++++++++ libavutil/intmath.h | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++ libavutil/log2.c | 34 --------------------------------- libavutil/version.h | 2 +- 5 files changed, 96 insertions(+), 36 deletions(-) create mode 100644 libavutil/intmath.c delete mode 100644 libavutil/log2.c (limited to 'libavutil') diff --git a/libavutil/Makefile b/libavutil/Makefile index 45f8e9076c..d4ffd5e7d6 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -67,10 +67,10 @@ OBJS = adler32.o \ float_dsp.o \ imgutils.o \ intfloat_readwrite.o \ + intmath.o \ lfg.o \ lls.o \ log.o \ - log2.o \ log2_tab.o \ mathematics.o \ md5.o \ diff --git a/libavutil/intmath.c b/libavutil/intmath.c new file mode 100644 index 0000000000..8db425c6e9 --- /dev/null +++ b/libavutil/intmath.c @@ -0,0 +1,39 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "intmath.h" + +/* undef these to get the function prototypes from common.h */ +#undef av_log2 +#undef av_log2_16bit +#include "common.h" + +int av_log2(unsigned v) +{ + return ff_log2(v); +} + +int av_log2_16bit(unsigned v) +{ + return ff_log2_16bit(v); +} + +int av_ctz(int v) +{ + return ff_ctz(v); +} diff --git a/libavutil/intmath.h b/libavutil/intmath.h index 2cb313240b..a5ee6525ee 100644 --- a/libavutil/intmath.h +++ b/libavutil/intmath.h @@ -85,6 +85,61 @@ static av_always_inline av_const int ff_log2_16bit_c(unsigned int v) #define av_log2 ff_log2 #define av_log2_16bit ff_log2_16bit +/** + * @} + */ + +/** + * @addtogroup lavu_math + * @{ + */ + +#if HAVE_FAST_CLZ && AV_GCC_VERSION_AT_LEAST(3,4) +#ifndef ff_ctz +#define ff_ctz(v) __builtin_ctz(v) +#endif +#endif + +#ifndef ff_ctz +#define ff_ctz ff_ctz_c +static av_always_inline av_const int ff_ctz_c(int v) +{ + int c; + + if (v & 0x1) + return 0; + + c = 1; + if (!(v & 0xffff)) { + v >>= 16; + c += 16; + } + if (!(v & 0xff)) { + v >>= 8; + c += 8; + } + if (!(v & 0xf)) { + v >>= 4; + c += 4; + } + if (!(v & 0x3)) { + v >>= 2; + c += 2; + } + c -= v & 0x1; + + return c; +} +#endif + +/** + * Trailing zero bit count. + * + * @param v input value. If v is 0, the result is undefined. + * @return the number of trailing 0-bits + */ +int av_ctz(int v); + /** * @} */ diff --git a/libavutil/log2.c b/libavutil/log2.c deleted file mode 100644 index 18c1b40aaa..0000000000 --- a/libavutil/log2.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "intmath.h" - -/* undef these to get the function prototypes from common.h */ -#undef av_log2 -#undef av_log2_16bit -#include "common.h" - -int av_log2(unsigned v) -{ - return ff_log2(v); -} - -int av_log2_16bit(unsigned v) -{ - return ff_log2_16bit(v); -} diff --git a/libavutil/version.h b/libavutil/version.h index ae7fa7abeb..1659dbd537 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -37,7 +37,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 52 -#define LIBAVUTIL_VERSION_MINOR 0 +#define LIBAVUTIL_VERSION_MINOR 1 #define LIBAVUTIL_VERSION_MICRO 0 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ -- cgit v1.2.3