00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef AVUTIL_INTMATH_H
00022 #define AVUTIL_INTMATH_H
00023
00024 #include <stdint.h>
00025
00026 #include "config.h"
00027 #include "attributes.h"
00028
00029 #if ARCH_ARM
00030 # include "arm/intmath.h"
00031 #endif
00032
00038 #if ARCH_ARM
00039 # include "arm/intmath.h"
00040 #endif
00041
00042 #if HAVE_FAST_CLZ && AV_GCC_VERSION_AT_LEAST(3,4)
00043
00044 #ifndef ff_log2
00045 # define ff_log2(x) (31 - __builtin_clz((x)|1))
00046 # ifndef ff_log2_16bit
00047 # define ff_log2_16bit av_log2
00048 # endif
00049 #endif
00050
00051 #endif
00052
00053 extern const uint8_t ff_log2_tab[256];
00054
00055 #ifndef ff_log2
00056 #define ff_log2 ff_log2_c
00057 static av_always_inline av_const int ff_log2_c(unsigned int v)
00058 {
00059 int n = 0;
00060 if (v & 0xffff0000) {
00061 v >>= 16;
00062 n += 16;
00063 }
00064 if (v & 0xff00) {
00065 v >>= 8;
00066 n += 8;
00067 }
00068 n += ff_log2_tab[v];
00069
00070 return n;
00071 }
00072 #endif
00073
00074 #ifndef ff_log2_16bit
00075 #define ff_log2_16bit ff_log2_16bit_c
00076 static av_always_inline av_const int ff_log2_16bit_c(unsigned int v)
00077 {
00078 int n = 0;
00079 if (v & 0xff00) {
00080 v >>= 8;
00081 n += 8;
00082 }
00083 n += ff_log2_tab[v];
00084
00085 return n;
00086 }
00087 #endif
00088
00089 #define av_log2 ff_log2
00090 #define av_log2_16bit ff_log2_16bit
00091
00101 #if HAVE_FAST_CLZ && AV_GCC_VERSION_AT_LEAST(3,4)
00102 #ifndef ff_ctz
00103 #define ff_ctz(v) __builtin_ctz(v)
00104 #endif
00105 #endif
00106
00107 #ifndef ff_ctz
00108 #define ff_ctz ff_ctz_c
00109 static av_always_inline av_const int ff_ctz_c(int v)
00110 {
00111 int c;
00112
00113 if (v & 0x1)
00114 return 0;
00115
00116 c = 1;
00117 if (!(v & 0xffff)) {
00118 v >>= 16;
00119 c += 16;
00120 }
00121 if (!(v & 0xff)) {
00122 v >>= 8;
00123 c += 8;
00124 }
00125 if (!(v & 0xf)) {
00126 v >>= 4;
00127 c += 4;
00128 }
00129 if (!(v & 0x3)) {
00130 v >>= 2;
00131 c += 2;
00132 }
00133 c -= v & 0x1;
00134
00135 return c;
00136 }
00137 #endif
00138
00145 int av_ctz(int v);
00146
00150 #endif