* [FFmpeg-devel] [PATCH] avcodec/ffv1enc: Eliminate float/double from find_best_state()
@ 2022-05-27 18:52 Michael Niedermayer
2022-05-30 7:47 ` Anton Khirnov
0 siblings, 1 reply; 4+ messages in thread
From: Michael Niedermayer @ 2022-05-27 18:52 UTC (permalink / raw)
To: FFmpeg development discussions and patches
log2() remains, this can either be replaced by a integer implementation or the table
hardcoded if needed
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
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".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avcodec/ffv1enc: Eliminate float/double from find_best_state()
2022-05-27 18:52 [FFmpeg-devel] [PATCH] avcodec/ffv1enc: Eliminate float/double from find_best_state() Michael Niedermayer
@ 2022-05-30 7:47 ` Anton Khirnov
2022-05-30 8:16 ` Martin Storsjö
0 siblings, 1 reply; 4+ messages in thread
From: Anton Khirnov @ 2022-05-30 7:47 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting Michael Niedermayer (2022-05-27 20:52:09)
> log2() remains, this can either be replaced by a integer implementation or the table
> hardcoded if needed
>
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
> 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(-)
Fixes 32bit x86 FATE breakage for me.
Thanks.
--
Anton Khirnov
_______________________________________________
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".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avcodec/ffv1enc: Eliminate float/double from find_best_state()
2022-05-30 7:47 ` Anton Khirnov
@ 2022-05-30 8:16 ` Martin Storsjö
2022-05-30 10:14 ` Michael Niedermayer
0 siblings, 1 reply; 4+ messages in thread
From: Martin Storsjö @ 2022-05-30 8:16 UTC (permalink / raw)
To: FFmpeg development discussions and patches,
FFmpeg development discussions and patches
On Mon, 30 May 2022, Anton Khirnov wrote:
> Quoting Michael Niedermayer (2022-05-27 20:52:09)
>> log2() remains, this can either be replaced by a integer implementation or the table
>> hardcoded if needed
>>
>> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
>> ---
>> 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(-)
>
> Fixes 32bit x86 FATE breakage for me.
Thanks, this fixes failures on arm and aarch64 for me, too.
// Martin
_______________________________________________
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".
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avcodec/ffv1enc: Eliminate float/double from find_best_state()
2022-05-30 8:16 ` Martin Storsjö
@ 2022-05-30 10:14 ` Michael Niedermayer
0 siblings, 0 replies; 4+ messages in thread
From: Michael Niedermayer @ 2022-05-30 10:14 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 1208 bytes --]
On Mon, May 30, 2022 at 11:16:41AM +0300, Martin Storsjö wrote:
> On Mon, 30 May 2022, Anton Khirnov wrote:
>
> > Quoting Michael Niedermayer (2022-05-27 20:52:09)
> > > log2() remains, this can either be replaced by a integer implementation or the table
> > > hardcoded if needed
> > >
> > > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > > ---
> > > 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(-)
> >
> > Fixes 32bit x86 FATE breakage for me.
>
> Thanks, this fixes failures on arm and aarch64 for me, too.
will apply
thanks to both of you for testing
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
If you fake or manipulate statistics in a paper in physics you will never
get a job again.
If you fake or manipulate statistics in a paper in medicin you will get
a job for life at the pharma industry.
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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".
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-05-30 10:14 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-27 18:52 [FFmpeg-devel] [PATCH] avcodec/ffv1enc: Eliminate float/double from find_best_state() Michael Niedermayer
2022-05-30 7:47 ` Anton Khirnov
2022-05-30 8:16 ` Martin Storsjö
2022-05-30 10:14 ` Michael Niedermayer
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git