From f8877bf42d4f88c5ebb92a52bd09ed59ef696514 Mon Sep 17 00:00:00 2001 From: Andrew Mahone Date: Sat, 14 Mar 2009 01:41:02 +0000 Subject: small speedup for scaler on sh-1, via use of hardware multiply instruction where possible git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20322 a1c6a512-1295-4272-9138-f99709370657 --- apps/recorder/resize.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/apps/recorder/resize.c b/apps/recorder/resize.c index 55b8f77ca9..e75638140b 100644 --- a/apps/recorder/resize.c +++ b/apps/recorder/resize.c @@ -60,6 +60,15 @@ #define DEBUGF(...) #endif +#if CONFIG_CPU == SH7034 +/* 16*16->32 bit multiplication is a single instrcution on the SH1 */ +#define MULUQ(a, b) ((uint32_t) (((uint16_t) (a)) * ((uint16_t) (b)))) +#define MULQ(a, b) ((int32_t) (((int16_t) (a)) * ((int16_t) (b)))) +#else +#define MULUQ(a, b) ((a) * (b)) +#define MULQ(a, b) ((a) * (b)) +#endif + /* calculate the maximum dimensions which will preserve the aspect ration of src while fitting in the constraints passed in dst, and store result in dst, returning 0 if rounding and 1 if not rounding. @@ -208,12 +217,12 @@ static bool scale_h_area(void *out_line_ptr, oxe -= ctx->src->width; /* add saved partial pixel from start of area */ - acc = acc * ctx->bm->width + tmp * mul; + acc = MULUQ(acc, ctx->bm->width) + MULUQ(tmp, mul); /* get new pixel , then add its partial coverage to this area */ tmp = *(part->buf); mul = ctx->bm->width - oxe; - acc += tmp * mul; + acc += MULUQ(tmp, mul); /* round, divide, and either store or accumulate to output row */ if (accum) { @@ -402,7 +411,7 @@ static bool scale_h_linear(void *out_line_ptr, struct scaler_context *ctx, ixe -= (ctx->bm->width - 1); val = *(part->buf); inc = -val; - val *= (ctx->bm->width - 1); + val = MULUQ(val, ctx->bm->width - 1); ix += 1; /* If this wasn't the last pixel, add the next one to rgbinc. */ if (ix < (uint32_t)ctx->src->width) { @@ -414,10 +423,10 @@ static bool scale_h_linear(void *out_line_ptr, struct scaler_context *ctx, /* Add a partial step to rgbval, in this pixel isn't precisely aligned with the new source pixel */ - val += inc * ixe; + val += MULQ(inc, ixe); } /* Now multiply the color increment to its proper value */ - inc *= ctx->src->width - 1; + inc = MULQ(inc, ctx->src->width - 1); } else val += inc; /* round and scale values, and accumulate or store to output */ -- cgit v1.2.3