From 4712ce5f59bdad25f548d20cc89c3eed8acb0e10 Mon Sep 17 00:00:00 2001 From: Pauli Oikkonen Date: Thu, 20 Feb 2020 15:12:28 +0200 Subject: [PATCH] Round the fast coeff result instead of flooring --- src/strategies/avx2/quant-avx2.c | 2 +- src/strategies/generic/quant-generic.c | 2 +- src/strategies/strategies-quant.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/strategies/avx2/quant-avx2.c b/src/strategies/avx2/quant-avx2.c index 4e5f0fcd..53ae447c 100644 --- a/src/strategies/avx2/quant-avx2.c +++ b/src/strategies/avx2/quant-avx2.c @@ -850,7 +850,7 @@ static uint32_t fast_coeff_cost_avx2(const coeff_t *coeff, int32_t width, int32_ __m256i sum4 = _mm256_add_epi64 (sum2, sum3); __m128i sum128 = _mm256_castsi256_si128 (sum4); - return _mm_cvtsi128_si32(sum128) >> 8; + return (_mm_cvtsi128_si32(sum128) + (1 << 7)) >> 8; } #endif //COMPILE_INTEL_AVX2 && defined X86_64 diff --git a/src/strategies/generic/quant-generic.c b/src/strategies/generic/quant-generic.c index da8dd336..89e83139 100644 --- a/src/strategies/generic/quant-generic.c +++ b/src/strategies/generic/quant-generic.c @@ -359,7 +359,7 @@ static uint32_t fast_coeff_cost_generic(const coeff_t *coeff, int32_t width, int } sum += weights[curr_abs]; } - return sum >> 8; + return (sum + (1 << 7)) >> 8; } int kvz_strategy_register_quant_generic(void* opaque, uint8_t bitdepth) diff --git a/src/strategies/strategies-quant.h b/src/strategies/strategies-quant.h index 7027cceb..2a11e31d 100644 --- a/src/strategies/strategies-quant.h +++ b/src/strategies/strategies-quant.h @@ -47,7 +47,7 @@ ) // Weights for 4 buckets (coeff 0, coeff 1, coeff 2, coeff >= 3), for QPs from -// 0 to 50 with ultrafast encoding +// MIN_FAST_COEFF_COST_QP to MAX_FAST_COEFF_COST_QP with ultrafast encoding static const uint64_t fast_coeff_cost_wts[FAST_COEFF_QP_COUNT] = { TO_4XQ88(0.134012, 4.207784, 3.431633, 6.556149), TO_4XQ88(0.122972, 4.278606, 3.398710, 6.527168),