From bd3dd72262772f1b2dfd8335630163f2e3bfacac Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Tue, 16 Oct 2007 15:29:59 +0100 Subject: [PATCH] [pdiff] Reorganise the inner loops of the convolution. Reorder the indices and introduce a couple of temporary accumulators to improve cache access. --- test/pdiff/lpyramid.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/test/pdiff/lpyramid.c b/test/pdiff/lpyramid.c index b81d67d78..366b0e460 100644 --- a/test/pdiff/lpyramid.c +++ b/test/pdiff/lpyramid.c @@ -20,7 +20,7 @@ #include struct _lpyramid { - /* Succesively blurred versions of the original image */ + /* Successively blurred versions of the original image */ float *levels[MAX_PYR_LEVELS]; int width; @@ -28,29 +28,32 @@ struct _lpyramid { }; static void -convolve (lpyramid_t *pyramid, float *a, float *b) +convolve (lpyramid_t *pyramid, float *a, const float *b) /* convolves image b with the filter kernel and stores it in a */ { - int y,x,i,j,nx,ny; + int y,x,i,j; const float Kernel[] = {0.05f, 0.25f, 0.4f, 0.25f, 0.05f}; int width = pyramid->width; int height = pyramid->height; for (y=0; y=height) ny=2*height - ny - 1; + ny *= width; + for (i=-2; i<=2; i++) { + int nx=x+i; if (nx<0) nx=-nx; - if (ny<0) ny=-ny; if (nx>=width) nx=2*width - nx - 1; - if (ny>=height) ny=2*height - ny - 1; - a[index] += Kernel[i+2] * Kernel[j+2] * b[ny * width + nx]; + sum_i += Kernel[i+2] * b[ny + nx]; } + sum += sum_i * Kernel[j+2]; } + *a++ = sum; } } }