From d581ba40ba8129809fed759f6b240b3d20da2892 Mon Sep 17 00:00:00 2001 From: Pascal Massimino Date: Sat, 10 Jan 2015 06:46:00 -0800 Subject: [PATCH] follow-up: clean up WebPRescalerXXX dsp function by removing redundant RFIX macros and using a plain-C fallback. Change-Id: I52436c672bf20780b6fe3bcf43fe73e1abac10ff --- src/dsp/dsp.h | 3 +++ src/dsp/rescaler.c | 10 +++++----- src/dsp/rescaler_mips32.c | 17 +++-------------- src/dsp/rescaler_mips_dsp_r2.c | 27 ++++++++------------------- 4 files changed, 19 insertions(+), 38 deletions(-) diff --git a/src/dsp/dsp.h b/src/dsp/dsp.h index 10467431..c65248bb 100644 --- a/src/dsp/dsp.h +++ b/src/dsp/dsp.h @@ -297,6 +297,9 @@ extern void (*WebPRescalerImportRow)(struct WebPRescaler* const wrk, // Export one row (starting at x_out position) from rescaler. extern void (*WebPRescalerExportRow)(struct WebPRescaler* const wrk, int x_out); +// Plain-C implementation, as fall-back. +extern void WebPRescalerExportRowC(struct WebPRescaler* const wrk, int x_out); + // Must be called first before using the above. WEBP_TSAN_IGNORE_FUNCTION void WebPRescalerDspInit(void); diff --git a/src/dsp/rescaler.c b/src/dsp/rescaler.c index 60e6480f..640b462c 100644 --- a/src/dsp/rescaler.c +++ b/src/dsp/rescaler.c @@ -18,8 +18,8 @@ #define ROUNDER (1 << (WEBP_RESCALER_RFIX - 1)) #define MULT_FIX(x, y) (((int64_t)(x) * (y) + ROUNDER) >> WEBP_RESCALER_RFIX) -static void ImportRowC(WebPRescaler* const wrk, - const uint8_t* const src, int channel) { +static void RescalerImportRowC(WebPRescaler* const wrk, + const uint8_t* const src, int channel) { const int x_stride = wrk->num_channels; const int x_out_max = wrk->dst_width * wrk->num_channels; int x_in = channel; @@ -61,7 +61,7 @@ static void ImportRowC(WebPRescaler* const wrk, } } -static void ExportRowC(WebPRescaler* const wrk, int x_out) { +void WebPRescalerExportRowC(WebPRescaler* const wrk, int x_out) { if (wrk->y_accum <= 0) { uint8_t* const dst = wrk->dst; int32_t* const irow = wrk->irow; @@ -97,8 +97,8 @@ static volatile VP8CPUInfo rescaler_last_cpuinfo_used = WEBP_TSAN_IGNORE_FUNCTION void WebPRescalerDspInit(void) { if (rescaler_last_cpuinfo_used == VP8GetCPUInfo) return; - WebPRescalerImportRow = ImportRowC; - WebPRescalerExportRow = ExportRowC; + WebPRescalerImportRow = RescalerImportRowC; + WebPRescalerExportRow = WebPRescalerExportRowC; if (VP8GetCPUInfo != NULL) { #if defined(WEBP_USE_MIPS32) if (VP8GetCPUInfo(kMIPS32)) { diff --git a/src/dsp/rescaler_mips32.c b/src/dsp/rescaler_mips32.c index 132d57f8..6d6d4378 100644 --- a/src/dsp/rescaler_mips32.c +++ b/src/dsp/rescaler_mips32.c @@ -114,9 +114,6 @@ static void ImportRow(WebPRescaler* const wrk, } } -#define RFIX 30 -#define MULT_FIX(x, y) (((int64_t)(x) * (y) + (1 << (RFIX - 1))) >> RFIX) - static void ExportRow(WebPRescaler* const wrk, int x_out) { if (wrk->y_accum <= 0) { uint8_t* const dst = wrk->dst; @@ -172,22 +169,14 @@ static void ExportRow(WebPRescaler* const wrk, int x_out) { : [temp2]"r"(temp2), [yscale]"r"(yscale), [temp8]"r"(temp8) : "memory", "hi", "lo" ); + wrk->y_accum += wrk->y_add; + wrk->dst += wrk->dst_stride; } else { - for (; x_out < x_out_max; ++x_out) { - const int frac = (int)MULT_FIX(frow[x_out], yscale); - const int v = (int)MULT_FIX(irow[x_out] - frac, wrk->fxy_scale); - dst[x_out] = (!(v & ~0xff)) ? v : (v < 0) ? 0 : 255; - irow[x_out] = frac; // new fractional start - } + WebPRescalerExportRowC(wrk, x_out); } - wrk->y_accum += wrk->y_add; - wrk->dst += wrk->dst_stride; } } -#undef MULT_FIX -#undef RFIX - #endif // WEBP_USE_MIPS32 //------------------------------------------------------------------------------ diff --git a/src/dsp/rescaler_mips_dsp_r2.c b/src/dsp/rescaler_mips_dsp_r2.c index f09d2440..8dd64e53 100644 --- a/src/dsp/rescaler_mips_dsp_r2.c +++ b/src/dsp/rescaler_mips_dsp_r2.c @@ -110,19 +110,16 @@ static void ImportRow(WebPRescaler* const wrk, } } -#define RFIX 30 -#define MULT_FIX(x, y) (((int64_t)(x) * (y) + (1 << (RFIX - 1))) >> RFIX) - static void ExportRow(WebPRescaler* const wrk, int x_out) { if (wrk->y_accum <= 0) { - uint8_t* dst = wrk->dst; - int32_t* irow = wrk->irow; - const int32_t* frow = wrk->frow; - const int yscale = wrk->fy_scale * (-wrk->y_accum); - const int x_out_max = wrk->dst_width * wrk->num_channels; // if wrk->fxy_scale can fit into 32 bits use optimized code, // otherwise use C code if ((wrk->fxy_scale >> 32) == 0) { + uint8_t* dst = wrk->dst; + int32_t* irow = wrk->irow; + const int32_t* frow = wrk->frow; + const int yscale = wrk->fy_scale * (-wrk->y_accum); + const int x_out_max = wrk->dst_width * wrk->num_channels; int temp0, temp1, temp3, temp4, temp5, temp6, temp7; const int temp2 = (int)wrk->fxy_scale; const int rest = (x_out_max - x_out) & 1; @@ -190,22 +187,14 @@ static void ExportRow(WebPRescaler* const wrk, int x_out) { [rest]"r"(rest) : "memory", "hi", "lo" ); + wrk->y_accum += wrk->y_add; + wrk->dst += wrk->dst_stride; } else { - for (; x_out < x_out_max; ++x_out) { - const int frac = (int)MULT_FIX(frow[x_out], yscale); - const int v = (int)MULT_FIX(irow[x_out] - frac, wrk->fxy_scale); - dst[x_out] = (!(v & ~0xff)) ? v : (v < 0) ? 0 : 255; - irow[x_out] = frac; // new fractional start - } + WebPRescalerExportRowC(wrk, x_out); } - wrk->y_accum += wrk->y_add; - wrk->dst += wrk->dst_stride; } } -#undef MULT_FIX -#undef RFIX - #endif // WEBP_USE_MIPS_DSP_R2 //------------------------------------------------------------------------------