From 3de58d7730189c5ae3b33d0097d640bbfc2f357a Mon Sep 17 00:00:00 2001 From: skal Date: Wed, 3 Oct 2012 15:15:58 +0200 Subject: [PATCH] fix the -g/O3 discrepancy for 32bit compile in debug mode, some float operations see their intermediate values stored in memory rather than staying in the FPU (which is 80bit precision). Several fixes are possible (breaking long calculations into atomic steps for instance), but simpler of all is just about turning the cost[] array into float* instead of double*. The code is a tad faster, and i didn't see any major output size difference. Change-Id: I053e6d340850f02761687e072b0782c6734d4bf8 --- src/enc/backward_references.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/enc/backward_references.c b/src/enc/backward_references.c index b8c8ece8..c5474a2d 100644 --- a/src/enc/backward_references.c +++ b/src/enc/backward_references.c @@ -459,8 +459,8 @@ static int BackwardReferencesHashChainDistanceOnly( const int quality = 100; const int pix_count = xsize * ysize; const int use_color_cache = (cache_bits > 0); - double* const cost = - (double*)WebPSafeMalloc((uint64_t)pix_count, sizeof(*cost)); + float* const cost = + (float*)WebPSafeMalloc((uint64_t)pix_count, sizeof(*cost)); CostModel* cost_model = (CostModel*)malloc(sizeof(*cost_model)); HashChain* hash_chain = (HashChain*)malloc(sizeof(*hash_chain)); VP8LColorCache hashers; @@ -481,7 +481,7 @@ static int BackwardReferencesHashChainDistanceOnly( goto Error; } - for (i = 0; i < pix_count; ++i) cost[i] = 1e100; + for (i = 0; i < pix_count; ++i) cost[i] = 1e38f; // We loop one pixel at a time, but store all currently best points to // non-processed locations from this point. @@ -509,10 +509,9 @@ static int BackwardReferencesHashChainDistanceOnly( prev_cost + GetDistanceCost(cost_model, code); int k; for (k = 1; k < len; ++k) { - const double cost_val = - distance_cost + GetLengthCost(cost_model, k); + const double cost_val = distance_cost + GetLengthCost(cost_model, k); if (cost[i + k] > cost_val) { - cost[i + k] = cost_val; + cost[i + k] = (float)cost_val; dist_array[i + k] = k + 1; } }