From 572354b793a41920da4062d4fd84ecb743b7eccc Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Thu, 21 Jan 2016 20:18:56 +0000 Subject: [PATCH] Allow compiler to vectorise vips_shrinkh Reduce for-loop count in shrinkh macros Don't access loop variable outside loop Remove unnecessary use of ceil from integer --- libvips/resample/shrinkh.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/libvips/resample/shrinkh.c b/libvips/resample/shrinkh.c index 448111d5..d964b6fb 100644 --- a/libvips/resample/shrinkh.c +++ b/libvips/resample/shrinkh.c @@ -111,18 +111,15 @@ vips_shrinkh_start( VipsImage *out, void *a, void *b ) TYPE * restrict q = (TYPE *) out; \ \ for( x = 0; x < width; x++ ) { \ - for( b = 0; b < bands; b++ ) \ + for( b = 0; b < bands; b++ ) { \ sum[b] = 0; \ - \ - for( b = 0; b < bands; b++ ) \ for( x1 = b; x1 < ne; x1 += bands ) \ sum[b] += p[x1]; \ - p += ne; \ - \ - for( b = 0; b < bands; b++ ) \ q[b] = (sum[b] + shrink->xshrink / 2) / \ shrink->xshrink; \ - q += b; \ + } \ + p += ne; \ + q += bands; \ } \ } @@ -134,17 +131,14 @@ vips_shrinkh_start( VipsImage *out, void *a, void *b ) TYPE * restrict q = (TYPE *) out; \ \ for( x = 0; x < width; x++ ) { \ - for( b = 0; b < bands; b++ ) \ + for( b = 0; b < bands; b++ ) { \ sum[b] = 0.0; \ - \ - for( b = 0; b < bands; b++ ) \ for( x1 = b; x1 < ne; x1 += bands ) \ sum[b] += p[x1]; \ - p += ne; \ - \ - for( b = 0; b < bands; b++ ) \ q[b] = sum[b] / shrink->xshrink; \ - q += b; \ + } \ + p += ne; \ + q += bands; \ } \ } @@ -227,7 +221,7 @@ vips_shrinkh_gen( VipsRegion *or, void *vseq, s.left = r->left * shrink->xshrink; s.top = r->top + y; - s.width = ceil( r->width * shrink->xshrink ); + s.width = r->width * shrink->xshrink; s.height = 1; #ifdef DEBUG printf( "shrinkh_gen: requesting line %d\n", s.top );