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 #include "config.h"
00026 #include "attributes.h"
00027
00033 extern const uint32_t ff_inverse[257];
00034
00035 #if ARCH_ARM
00036 # include "arm/intmath.h"
00037 #elif ARCH_X86
00038 # include "x86/intmath.h"
00039 #endif
00040
00041 #if HAVE_FAST_CLZ && AV_GCC_VERSION_AT_LEAST(3,4)
00042
00043 #ifndef av_log2
00044 # define av_log2(x) (31 - __builtin_clz((x)|1))
00045 # ifndef av_log2_16bit
00046 # define av_log2_16bit av_log2
00047 # endif
00048 #endif
00049
00050 #endif
00051
00052 #ifndef FASTDIV
00053 # define FASTDIV(a,b) ((uint32_t)((((uint64_t)a) * ff_inverse[b]) >> 32))
00054 #endif
00055
00056 #include "common.h"
00057
00058 extern const uint8_t ff_sqrt_tab[256];
00059
00060 static inline av_const unsigned int ff_sqrt(unsigned int a)
00061 {
00062 unsigned int b;
00063
00064 if (a < 255) return (ff_sqrt_tab[a + 1] - 1) >> 4;
00065 else if (a < (1 << 12)) b = ff_sqrt_tab[a >> 4] >> 2;
00066 #if !CONFIG_SMALL
00067 else if (a < (1 << 14)) b = ff_sqrt_tab[a >> 6] >> 1;
00068 else if (a < (1 << 16)) b = ff_sqrt_tab[a >> 8] ;
00069 #endif
00070 else {
00071 int s = av_log2_16bit(a >> 16) >> 1;
00072 unsigned int c = a >> (s + 2);
00073 b = ff_sqrt_tab[c >> (s + 8)];
00074 b = FASTDIV(c,b) + (b << s);
00075 }
00076
00077 return b - (a < b * b);
00078 }
00079
00083 #endif