From: Michael Niedermayer Date: Thu, 22 Aug 2002 19:41:39 +0000 (+0000) Subject: faster ff_sqrt() X-Git-Tag: v0.5~17409 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f36db5dfd3c3cfd5d2e9feb0462c18431183cff5;p=platform%2Fupstream%2Flibav.git faster ff_sqrt() Originally committed as revision 859 to svn://svn.ffmpeg.org/ffmpeg/trunk --- diff --git a/libavcodec/common.c b/libavcodec/common.c index 63d17b6..fde12d9 100644 --- a/libavcodec/common.c +++ b/libavcodec/common.c @@ -20,6 +20,13 @@ */ #include "avcodec.h" +const UINT8 ff_sqrt_tab[128]={ + 0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11 +}; + void init_put_bits(PutBitContext *s, UINT8 *buffer, int buffer_size, void *opaque, diff --git a/libavcodec/common.h b/libavcodec/common.h index bacc647..c301089 100644 --- a/libavcodec/common.h +++ b/libavcodec/common.h @@ -901,6 +901,8 @@ static inline int clip(int a, int amin, int amax) } /* math */ +extern const UINT8 ff_sqrt_tab[128]; + int ff_gcd(int a, int b); static inline int ff_sqrt(int a) @@ -908,7 +910,9 @@ static inline int ff_sqrt(int a) int ret=0; int s; int ret_sq=0; - + + if(a<128) return ff_sqrt_tab[a]; + for(s=15; s>=0; s--){ int b= ret_sq + (1<<(s*2)) + (ret<