This rewrites into the mathematically equivalent expression avoiding sqrt, and results in a very minor speedup.
Tested on x86-64, Haswell, GNU/Linux. Command: ffmpeg -v error -f lavfi -i mandelbrot -f null - old (draw_mandelbrot): 3982389425 decicycles in draw_mandelbrot, 256 runs, 0 skips 7634221782 decicycles in draw_mandelbrot, 512 runs, 0 skips 20576449397 decicycles in draw_mandelbrot, 1024 runs, 0 skips 12949998655 decicycles in draw_mandelbrot, 2048 runs, 0 skips new (draw_mandelbrot): 3966406060 decicycles in draw_mandelbrot, 256 runs, 0 skips 7553322112 decicycles in draw_mandelbrot, 512 runs, 0 skips 20454169970 decicycles in draw_mandelbrot, 1024 runs, 0 skips 12822228615 decicycles in draw_mandelbrot, 2048 runs, 0 skips Signed-off-by: Ganesh Ajjanagadde <gajjanaga...@gmail.com> --- libavfilter/vsrc_mandelbrot.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavfilter/vsrc_mandelbrot.c b/libavfilter/vsrc_mandelbrot.c index 950c5c8..20da8ae 100644 --- a/libavfilter/vsrc_mandelbrot.c +++ b/libavfilter/vsrc_mandelbrot.c @@ -291,7 +291,7 @@ static void draw_mandelbrot(AVFilterContext *ctx, uint32_t *color, int linesize, use_zyklus= (x==0 || s->inner!=BLACK ||color[x-1 + y*linesize] == 0xFF000000); if(use_zyklus) - epsilon= scale*1*sqrt(SQR(x-s->w/2) + SQR(y-s->h/2))/s->w; + epsilon= SQR(scale/s->w)*(SQR(x-s->w/2) + SQR(y-s->h/2)); #define Z_Z2_C(outr,outi,inr,ini)\ outr= inr*inr - ini*ini + cr;\ @@ -300,7 +300,7 @@ static void draw_mandelbrot(AVFilterContext *ctx, uint32_t *color, int linesize, #define Z_Z2_C_ZYKLUS(outr,outi,inr,ini, Z)\ Z_Z2_C(outr,outi,inr,ini)\ if(use_zyklus){\ - if(Z && fabs(s->zyklus[i>>1][0]-outr)+fabs(s->zyklus[i>>1][1]-outi) <= epsilon)\ + if(Z && SQR(fabs(s->zyklus[i>>1][0]-outr)+fabs(s->zyklus[i>>1][1]-outi)) <= epsilon)\ break;\ }\ s->zyklus[i][0]= outr;\ @@ -358,7 +358,7 @@ static void draw_mandelbrot(AVFilterContext *ctx, uint32_t *color, int linesize, if(s->inner==PERIOD){ int j; for(j=i-1; j; j--) - if(SQR(s->zyklus[j][0]-zr) + SQR(s->zyklus[j][1]-zi) < epsilon*epsilon*10) + if(SQR(s->zyklus[j][0]-zr) + SQR(s->zyklus[j][1]-zi) < epsilon*10) break; if(j){ c= i-j; -- 2.6.2 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel