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
13751375 const int log2_mul_step = ((int[]){ 1, 8, 1, 1, 1, 1})[f->remap_optimizer];
13761376 const int bruteforce_count = ((int[]){ 0, 0, 0, 1, 1, 1})[f->remap_optimizer];
13771377 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];
13781379
13791380 av_assert0 (pixel_num <= 65536);
13801381
@@ -1390,7 +1391,9 @@ static void encode_float32_remap(FFV1Context *f, FFV1SliceContext *sc, · 9 unmodified lines
13901391 int last_mul_index = -1;
13911392 int mul_count = 1 << log2_mul_count;
13921393
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);
13941397 for (int i= 0; i<pixel_num; i++) {
13951398 int64_t val = sc->unit[p][i].val;
13961399 int mul_index = (val + 1LL)*mul_count >> 32;
@@ -1424,7 +1427,10 @@ static void encode_float32_remap(FFV1Context *f, FFV1SliceContext *sc, · 27 unmodified lines
14241427 score *= score;
14251428 if (mul_index != last_mul_index)
14261429 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);
14281434 }
14291435 }
14301436 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