You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-04 22:03:09 +02:00
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 Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
@ -1375,6 +1375,7 @@ static void encode_float32_remap(FFV1Context *f, FFV1SliceContext *sc,
|
|||||||
const int log2_mul_step = ((int[]){ 1, 8, 1, 1, 1, 1})[f->remap_optimizer];
|
const int log2_mul_step = ((int[]){ 1, 8, 1, 1, 1, 1})[f->remap_optimizer];
|
||||||
const int bruteforce_count = ((int[]){ 0, 0, 0, 1, 1, 1})[f->remap_optimizer];
|
const int bruteforce_count = ((int[]){ 0, 0, 0, 1, 1, 1})[f->remap_optimizer];
|
||||||
const int stair_mode = ((int[]){ 0, 0, 0, 1, 0, 0})[f->remap_optimizer];
|
const int stair_mode = ((int[]){ 0, 0, 0, 1, 0, 0})[f->remap_optimizer];
|
||||||
|
const int magic_log2 = ((int[]){ 1, 1, 1, 1, 0, 0})[f->remap_optimizer];
|
||||||
|
|
||||||
av_assert0 (pixel_num <= 65536);
|
av_assert0 (pixel_num <= 65536);
|
||||||
|
|
||||||
@ -1390,7 +1391,9 @@ static void encode_float32_remap(FFV1Context *f, FFV1SliceContext *sc,
|
|||||||
int last_mul_index = -1;
|
int last_mul_index = -1;
|
||||||
int mul_count = 1 << log2_mul_count;
|
int mul_count = 1 << log2_mul_count;
|
||||||
|
|
||||||
score_sum[log2_mul_count] += log2_mul_count * log2_mul_count;
|
score_sum[log2_mul_count] = 2 * log2_mul_count;
|
||||||
|
if (magic_log2)
|
||||||
|
score_sum[log2_mul_count] = av_float2int((float)mul_count * mul_count);
|
||||||
for (int i= 0; i<pixel_num; i++) {
|
for (int i= 0; i<pixel_num; i++) {
|
||||||
int64_t val = sc->unit[p][i].val;
|
int64_t val = sc->unit[p][i].val;
|
||||||
int mul_index = (val + 1LL)*mul_count >> 32;
|
int mul_index = (val + 1LL)*mul_count >> 32;
|
||||||
@ -1424,6 +1427,9 @@ static void encode_float32_remap(FFV1Context *f, FFV1SliceContext *sc,
|
|||||||
score *= score;
|
score *= score;
|
||||||
if (mul_index != last_mul_index)
|
if (mul_index != last_mul_index)
|
||||||
score *= mul;
|
score *= mul;
|
||||||
|
if (magic_log2) {
|
||||||
|
score_tab[si] += av_float2int(score);
|
||||||
|
} else
|
||||||
score_tab[si] += log2f(score);
|
score_tab[si] += log2f(score);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user