follow-up: clean up WebPRescalerXXX dsp function

by removing redundant RFIX macros and using a plain-C fallback.

Change-Id: I52436c672bf20780b6fe3bcf43fe73e1abac10ff
This commit is contained in:
Pascal Massimino 2015-01-10 06:46:00 -08:00 committed by James Zern
parent f8740f0d6c
commit d581ba40ba
4 changed files with 19 additions and 38 deletions

View File

@ -297,6 +297,9 @@ extern void (*WebPRescalerImportRow)(struct WebPRescaler* const wrk,
// Export one row (starting at x_out position) from rescaler. // Export one row (starting at x_out position) from rescaler.
extern void (*WebPRescalerExportRow)(struct WebPRescaler* const wrk, int x_out); 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. // Must be called first before using the above.
WEBP_TSAN_IGNORE_FUNCTION void WebPRescalerDspInit(void); WEBP_TSAN_IGNORE_FUNCTION void WebPRescalerDspInit(void);

View File

@ -18,7 +18,7 @@
#define ROUNDER (1 << (WEBP_RESCALER_RFIX - 1)) #define ROUNDER (1 << (WEBP_RESCALER_RFIX - 1))
#define MULT_FIX(x, y) (((int64_t)(x) * (y) + ROUNDER) >> WEBP_RESCALER_RFIX) #define MULT_FIX(x, y) (((int64_t)(x) * (y) + ROUNDER) >> WEBP_RESCALER_RFIX)
static void ImportRowC(WebPRescaler* const wrk, static void RescalerImportRowC(WebPRescaler* const wrk,
const uint8_t* const src, int channel) { const uint8_t* const src, int channel) {
const int x_stride = wrk->num_channels; const int x_stride = wrk->num_channels;
const int x_out_max = wrk->dst_width * wrk->num_channels; const int x_out_max = wrk->dst_width * wrk->num_channels;
@ -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) { if (wrk->y_accum <= 0) {
uint8_t* const dst = wrk->dst; uint8_t* const dst = wrk->dst;
int32_t* const irow = wrk->irow; int32_t* const irow = wrk->irow;
@ -97,8 +97,8 @@ static volatile VP8CPUInfo rescaler_last_cpuinfo_used =
WEBP_TSAN_IGNORE_FUNCTION void WebPRescalerDspInit(void) { WEBP_TSAN_IGNORE_FUNCTION void WebPRescalerDspInit(void) {
if (rescaler_last_cpuinfo_used == VP8GetCPUInfo) return; if (rescaler_last_cpuinfo_used == VP8GetCPUInfo) return;
WebPRescalerImportRow = ImportRowC; WebPRescalerImportRow = RescalerImportRowC;
WebPRescalerExportRow = ExportRowC; WebPRescalerExportRow = WebPRescalerExportRowC;
if (VP8GetCPUInfo != NULL) { if (VP8GetCPUInfo != NULL) {
#if defined(WEBP_USE_MIPS32) #if defined(WEBP_USE_MIPS32)
if (VP8GetCPUInfo(kMIPS32)) { if (VP8GetCPUInfo(kMIPS32)) {

View File

@ -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) { static void ExportRow(WebPRescaler* const wrk, int x_out) {
if (wrk->y_accum <= 0) { if (wrk->y_accum <= 0) {
uint8_t* const dst = wrk->dst; uint8_t* const dst = wrk->dst;
@ -172,21 +169,13 @@ static void ExportRow(WebPRescaler* const wrk, int x_out) {
: [temp2]"r"(temp2), [yscale]"r"(yscale), [temp8]"r"(temp8) : [temp2]"r"(temp2), [yscale]"r"(yscale), [temp8]"r"(temp8)
: "memory", "hi", "lo" : "memory", "hi", "lo"
); );
} 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
}
}
wrk->y_accum += wrk->y_add; wrk->y_accum += wrk->y_add;
wrk->dst += wrk->dst_stride; wrk->dst += wrk->dst_stride;
} else {
WebPRescalerExportRowC(wrk, x_out);
}
} }
} }
#undef MULT_FIX
#undef RFIX
#endif // WEBP_USE_MIPS32 #endif // WEBP_USE_MIPS32

View File

@ -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) { static void ExportRow(WebPRescaler* const wrk, int x_out) {
if (wrk->y_accum <= 0) { if (wrk->y_accum <= 0) {
// 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; uint8_t* dst = wrk->dst;
int32_t* irow = wrk->irow; int32_t* irow = wrk->irow;
const int32_t* frow = wrk->frow; const int32_t* frow = wrk->frow;
const int yscale = wrk->fy_scale * (-wrk->y_accum); const int yscale = wrk->fy_scale * (-wrk->y_accum);
const int x_out_max = wrk->dst_width * wrk->num_channels; 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) {
int temp0, temp1, temp3, temp4, temp5, temp6, temp7; int temp0, temp1, temp3, temp4, temp5, temp6, temp7;
const int temp2 = (int)wrk->fxy_scale; const int temp2 = (int)wrk->fxy_scale;
const int rest = (x_out_max - x_out) & 1; const int rest = (x_out_max - x_out) & 1;
@ -190,21 +187,13 @@ static void ExportRow(WebPRescaler* const wrk, int x_out) {
[rest]"r"(rest) [rest]"r"(rest)
: "memory", "hi", "lo" : "memory", "hi", "lo"
); );
} 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
}
}
wrk->y_accum += wrk->y_add; wrk->y_accum += wrk->y_add;
wrk->dst += wrk->dst_stride; wrk->dst += wrk->dst_stride;
} else {
WebPRescalerExportRowC(wrk, x_out);
}
} }
} }
#undef MULT_FIX
#undef RFIX
#endif // WEBP_USE_MIPS_DSP_R2 #endif // WEBP_USE_MIPS_DSP_R2