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