From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id BDDBB4061B for ; Fri, 27 May 2022 18:52:27 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9FDD868B5C8; Fri, 27 May 2022 21:52:24 +0300 (EEST) Received: from vie01a-dmta-at03-3.mx.upcmail.net (vie01a-dmta-at03-3.mx.upcmail.net [62.179.121.153]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5A1F768B465 for ; Fri, 27 May 2022 21:52:18 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-at03.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1nuf4F-0008PS-0W for ffmpeg-devel@ffmpeg.org; Fri, 27 May 2022 20:52:11 +0200 Received: from ren-mail-psmtp-mg02. ([80.109.253.241]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id uf2tnnywZ8s8Uuf4EnaFbN; Fri, 27 May 2022 20:52:10 +0200 Received: from localhost ([213.47.68.29]) by ren-mail-psmtp-mg02. with ESMTP id uf4EnNY5C8eSWuf4En3tMi; Fri, 27 May 2022 20:52:10 +0200 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.68.29 X-CNFS-Analysis: v=2.4 cv=KKE5sHJo c=1 sm=1 tr=0 ts=62911dda a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=DN7DJRnDEp9Geyvkar4A:9 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 27 May 2022 20:52:09 +0200 Message-Id: <20220527185209.11644-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 X-CMAE-Envelope: MS4wfHxHc268zuixF7x6/FfCnUDKAw8UD3nEj12k9nb0Y6+WYV0NJcijOA6/UyU8Od8YEtqIhYVcktaEnu0gywtmsI32mCIx0FAR1lbi0hEBs0+0LyQwydrr TzbrGokgVKi7uZszKJuvqCdgmczYweJQQChZtb94sP0OBS2Yvn1eUWIvlDo/kUpDFROZN4KAiqpHyA== Subject: [FFmpeg-devel] [PATCH] avcodec/ffv1enc: Eliminate float/double from find_best_state() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: log2() remains, this can either be replaced by a integer implementation or the table hardcoded if needed Signed-off-by: Michael Niedermayer --- libavcodec/ffv1enc.c | 25 ++++++++++++------------- tests/ref/vsynth/vsynth1-ffv1-2pass | 4 ++-- tests/ref/vsynth/vsynth2-ffv1-2pass | 4 ++-- tests/ref/vsynth/vsynth3-ffv1-2pass | 4 ++-- tests/ref/vsynth/vsynth_lena-ffv1-2pass | 4 ++-- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index cee2627eed..311f377b1e 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -140,32 +140,31 @@ static void find_best_state(uint8_t best_state[256][256], const uint8_t one_state[256]) { int i, j, k, m; - double l2tab[256]; + uint32_t l2tab[256]; for (i = 1; i < 256; i++) - l2tab[i] = log2(i / 256.0); + l2tab[i] = log2(i / 256.0) * ((-1<<31) / 8); for (i = 0; i < 256; i++) { - double best_len[256]; - double p = i / 256.0; + uint64_t best_len[256]; for (j = 0; j < 256; j++) - best_len[j] = 1 << 30; + best_len[j] = UINT64_MAX; for (j = FFMAX(i - 10, 1); j < FFMIN(i + 11, 256); j++) { - double occ[256] = { 0 }; - double len = 0; - occ[j] = 1.0; + uint32_t occ[256] = { 0 }; + uint64_t len = 0; + occ[j] = UINT32_MAX; if (!one_state[j]) continue; for (k = 0; k < 256; k++) { - double newocc[256] = { 0 }; + uint32_t newocc[256] = { 0 }; for (m = 1; m < 256; m++) if (occ[m]) { - len -=occ[m]*( p *l2tab[ m] - + (1-p)*l2tab[256-m]); + len += (occ[m]*(( i *(uint64_t)l2tab[ m] + + (256-i)*(uint64_t)l2tab[256-m])>>8)) >> 8; } if (len < best_len[k]) { best_len[k] = len; @@ -173,8 +172,8 @@ static void find_best_state(uint8_t best_state[256][256], } for (m = 1; m < 256; m++) if (occ[m]) { - newocc[ one_state[ m]] += occ[m] * p; - newocc[256 - one_state[256 - m]] += occ[m] * (1 - p); + newocc[ one_state[ m]] += occ[m] * (uint64_t) i >> 8; + newocc[256 - one_state[256 - m]] += occ[m] * (uint64_t)(256 - i) >> 8; } memcpy(occ, newocc, sizeof(occ)); } diff --git a/tests/ref/vsynth/vsynth1-ffv1-2pass b/tests/ref/vsynth/vsynth1-ffv1-2pass index c27c9691d2..477a1bf49e 100644 --- a/tests/ref/vsynth/vsynth1-ffv1-2pass +++ b/tests/ref/vsynth/vsynth1-ffv1-2pass @@ -1,4 +1,4 @@ -7332cfda96233acc7178b09868c07ad7 *tests/data/fate/vsynth1-ffv1-2pass.avi -2382244 tests/data/fate/vsynth1-ffv1-2pass.avi +266ff859dade888a2c0cfddb29260186 *tests/data/fate/vsynth1-ffv1-2pass.avi +2382240 tests/data/fate/vsynth1-ffv1-2pass.avi c5ccac874dbf808e9088bc3107860042 *tests/data/fate/vsynth1-ffv1-2pass.out.rawvideo stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 7603200/ 7603200 diff --git a/tests/ref/vsynth/vsynth2-ffv1-2pass b/tests/ref/vsynth/vsynth2-ffv1-2pass index 26c20db24d..e14eb1a94e 100644 --- a/tests/ref/vsynth/vsynth2-ffv1-2pass +++ b/tests/ref/vsynth/vsynth2-ffv1-2pass @@ -1,4 +1,4 @@ -2f5af924c6f7de1d4c34ec2dc9fca4ac *tests/data/fate/vsynth2-ffv1-2pass.avi -3530664 tests/data/fate/vsynth2-ffv1-2pass.avi +97b5dc666896cbaf98cec3acfbe0f3fc *tests/data/fate/vsynth2-ffv1-2pass.avi +3530654 tests/data/fate/vsynth2-ffv1-2pass.avi 36d7ca943916e1743cefa609eba0205c *tests/data/fate/vsynth2-ffv1-2pass.out.rawvideo stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 7603200/ 7603200 diff --git a/tests/ref/vsynth/vsynth3-ffv1-2pass b/tests/ref/vsynth/vsynth3-ffv1-2pass index dd0fd615f4..dd7943c9ac 100644 --- a/tests/ref/vsynth/vsynth3-ffv1-2pass +++ b/tests/ref/vsynth/vsynth3-ffv1-2pass @@ -1,4 +1,4 @@ -5b658e65541539248035c17da5eada3a *tests/data/fate/vsynth3-ffv1-2pass.avi -53522 tests/data/fate/vsynth3-ffv1-2pass.avi +96a6700731a71ee2e05c207e2334ade7 *tests/data/fate/vsynth3-ffv1-2pass.avi +53520 tests/data/fate/vsynth3-ffv1-2pass.avi a038ad7c3c09f776304ef7accdea9c74 *tests/data/fate/vsynth3-ffv1-2pass.out.rawvideo stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 86700/ 86700 diff --git a/tests/ref/vsynth/vsynth_lena-ffv1-2pass b/tests/ref/vsynth/vsynth_lena-ffv1-2pass index 9ece86aaa3..ef49a9f5a6 100644 --- a/tests/ref/vsynth/vsynth_lena-ffv1-2pass +++ b/tests/ref/vsynth/vsynth_lena-ffv1-2pass @@ -1,4 +1,4 @@ -2e1833cf75da113a6fabbaae07ddd455 *tests/data/fate/vsynth_lena-ffv1-2pass.avi -3490450 tests/data/fate/vsynth_lena-ffv1-2pass.avi +c46df7f2b5770564475710f1086cdff6 *tests/data/fate/vsynth_lena-ffv1-2pass.avi +3490446 tests/data/fate/vsynth_lena-ffv1-2pass.avi dde5895817ad9d219f79a52d0bdfb001 *tests/data/fate/vsynth_lena-ffv1-2pass.out.rawvideo stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 7603200/ 7603200 -- 2.17.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".