From 1a1b9c6f9b35025223b4a7ca68af4ec95ede8f79 Mon Sep 17 00:00:00 2001 From: Anton Mitrofanov Date: Thu, 8 Oct 2009 14:55:26 -0700 Subject: [PATCH] Optimize exp2fix8 Slightly faster and more accurate rounding. --- common/common.h | 6 +++--- encoder/analyse.c | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/common/common.h b/common/common.h index a0afedab..4313db81 100644 --- a/common/common.h +++ b/common/common.h @@ -165,9 +165,9 @@ extern const float x264_log2_lz_lut[32]; * qp to qscale. */ static ALWAYS_INLINE int x264_exp2fix8( float x ) { - if( x >= 512.f/6.f ) return 0; - if( x <= -512.f/6.f ) return 0xffff; - int i = x*(-64.f/6.f) + 512; + int i = x*(-64.f/6.f) + 512.5f; + if( i < 0 ) return 0; + if( i > 1023 ) return 0xffff; return (x264_exp2_lut[i&63]+256) << (i>>6) >> 8; } diff --git a/encoder/analyse.c b/encoder/analyse.c index 2c02af24..74e72bf6 100644 --- a/encoder/analyse.c +++ b/encoder/analyse.c @@ -154,10 +154,10 @@ const int x264_lambda2_tab[52] = { }; const uint8_t x264_exp2_lut[64] = { - 1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 44, 47, - 50, 53, 57, 60, 64, 67, 71, 74, 78, 81, 85, 89, 93, 96, 100, 104, - 108, 112, 116, 120, 124, 128, 132, 137, 141, 145, 150, 154, 159, 163, 168, 172, - 177, 182, 186, 191, 196, 201, 206, 211, 216, 221, 226, 232, 237, 242, 248, 253, + 0, 3, 6, 8, 11, 14, 17, 20, 23, 26, 29, 32, 36, 39, 42, 45, + 48, 52, 55, 58, 62, 65, 69, 72, 76, 80, 83, 87, 91, 94, 98, 102, + 106, 110, 114, 118, 122, 126, 130, 135, 139, 143, 147, 152, 156, 161, 165, 170, + 175, 179, 184, 189, 194, 198, 203, 208, 214, 219, 224, 229, 234, 240, 245, 250 }; const float x264_log2_lut[128] = { -- 2.39.2