History

avcodec/ffv1enc: replace the remaining log2() by magic

big secret, reading a float as the corresponding integer is a good approximation of log2() for numbers not too close to 1.0. At the same time it maintains strict monotonicity this reduces run time from 19sec to 17sec for the slowest of my testcases (with default remap_optimizer 3) Compression is about the same: -rw-r----- 1 michael michael 497603370 Mar 30 15:23 float-303503-fixed-40-optim-3-1log2F.nut -rw-r----- 1 michael michael 497603374 Mar 28 11:27 float-303503-fixed-40-optim-3b.nut -rw-r----- 1 michael michael 549938852 Mar 28 11:27 float-303503-float16-40-optim-3b.nut -rw-r----- 1 michael michael 549938857 Mar 30 15:23 float-303503-float16-40-optim-3-1log2F.nut -rw-r----- 1 michael michael 1150827841 Mar 28 11:28 float-303503-float-40-optim-3b.nut -rw-r----- 1 michael michael 1150832913 Mar 30 15:22 float-303503-float-40-optim-3ref-log2F2.nut

Michael Niedermayer committed 1 year ago

Commit 4aeaee11 parent 98c17881 file · +8 −2Browse files

Unified · Split

libavcodec/ffv1enc.c+8−2
@@ -1375,6 +1375,7 @@ static void encode_float32_remap(FFV1Context *f, FFV1SliceContext *sc, · 1374 unmodified lines
1375 const int log2_mul_step = ((int[]){ 1, 8, 1, 1, 1, 1})[f->remap_optimizer];1375 const int log2_mul_step = ((int[]){ 1, 8, 1, 1, 1, 1})[f->remap_optimizer];
1376 const int bruteforce_count = ((int[]){ 0, 0, 0, 1, 1, 1})[f->remap_optimizer];1376 const int bruteforce_count = ((int[]){ 0, 0, 0, 1, 1, 1})[f->remap_optimizer];
1377 const int stair_mode = ((int[]){ 0, 0, 0, 1, 0, 0})[f->remap_optimizer];1377 const int stair_mode = ((int[]){ 0, 0, 0, 1, 0, 0})[f->remap_optimizer];
1378 const int magic_log2 = ((int[]){ 1, 1, 1, 1, 0, 0})[f->remap_optimizer];
1378 1379
1379 av_assert0 (pixel_num <= 65536);1380 av_assert0 (pixel_num <= 65536);
1380 1381
@@ -1390,7 +1391,9 @@ static void encode_float32_remap(FFV1Context *f, FFV1SliceContext *sc, · 9 unmodified lines
1390 int last_mul_index = -1;1391 int last_mul_index = -1;
1391 int mul_count = 1 << log2_mul_count;1392 int mul_count = 1 << log2_mul_count;
1392 1393
1393 score_sum[log2_mul_count] += log2_mul_count * log2_mul_count;1394 score_sum[log2_mul_count] = 2 * log2_mul_count;
1395 if (magic_log2)
1396 score_sum[log2_mul_count] = av_float2int((float)mul_count * mul_count);
1394 for (int i= 0; i<pixel_num; i++) {1397 for (int i= 0; i<pixel_num; i++) {
1395 int64_t val = sc->unit[p][i].val;1398 int64_t val = sc->unit[p][i].val;
1396 int mul_index = (val + 1LL)*mul_count >> 32;1399 int mul_index = (val + 1LL)*mul_count >> 32;
@@ -1424,7 +1427,10 @@ static void encode_float32_remap(FFV1Context *f, FFV1SliceContext *sc, · 27 unmodified lines
1424 score *= score;1427 score *= score;
1425 if (mul_index != last_mul_index)1428 if (mul_index != last_mul_index)
1426 score *= mul;1429 score *= mul;
1427 score_tab[si] += log2f(score);1430 if (magic_log2) {
1431 score_tab[si] += av_float2int(score);
1432 } else
1433 score_tab[si] += log2f(score);
1428 }1434 }
1429 }1435 }
1430 last_val = val;1436 last_val = val;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t