ref: f0b7d999ddec54f321d435f5dc94a83dccb76cff
parent: 45d4fde63754a685a6ba69c012b6f4db528664a0
author: Nathan E. Egge <unlord@xiph.org>
date: Wed Dec 26 12:42:20 EST 2018
Internalize the EC_PROB_SHIFT precision reduction All of the msac decode functions use 15-bit CDFs with the exception of msac_decode_bool_prob() which takes a (15 - EC_PROB_SHIFT)-bit probability. This patch internalizes the reduction in precision from the EC_SMALL_MUL experiment (hiding the define) and gives msac calls a consistent API.
--- a/src/decode.c
+++ b/src/decode.c
@@ -2165,7 +2165,7 @@
const Av1Block *const b = &f->frame_thread.b[t->by * f->b4_stride + t->bx];
is_split = b->bl != bl;
} else {
- is_split = msac_decode_bool(&t->ts->msac, gather_top_partition_prob(pc, bl) >> EC_PROB_SHIFT);
+ is_split = msac_decode_bool(&t->ts->msac, gather_top_partition_prob(pc, bl));
if (DEBUG_BLOCK_INFO)
printf("poc=%d,y=%d,x=%d,bl=%d,ctx=%d,bp=%d: r=%d\n",
f->frame_hdr->frame_offset, t->by, t->bx, bl, ctx,
@@ -2193,7 +2193,7 @@
const Av1Block *const b = &f->frame_thread.b[t->by * f->b4_stride + t->bx];
is_split = b->bl != bl;
} else {
- is_split = msac_decode_bool(&t->ts->msac, gather_left_partition_prob(pc, bl) >> EC_PROB_SHIFT);
+ is_split = msac_decode_bool(&t->ts->msac, gather_left_partition_prob(pc, bl));
if (f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I422 && !is_split)
return 1;
if (DEBUG_BLOCK_INFO)
--- a/src/msac.c
+++ b/src/msac.c
@@ -34,6 +34,7 @@
#include "src/msac.h"
+#define EC_PROB_SHIFT 6
#define EC_MIN_PROB 4 // must be <= (1<<EC_PROB_SHIFT)/16
#define EC_WIN_SIZE (sizeof(ec_win) << 3)
@@ -115,7 +116,7 @@
uint16_t r = s->rng;
unsigned ret;
assert((dif >> (EC_WIN_SIZE - 16)) < r);
- v = ((r >> 8) * f >> (7 - EC_PROB_SHIFT)) + EC_MIN_PROB;
+ v = ((r >> 8) * (f >> EC_PROB_SHIFT) >> (7 - EC_PROB_SHIFT)) + EC_MIN_PROB;
vw = v << (EC_WIN_SIZE - 16);
ret = dif >= vw;
dif -= ret*vw;
@@ -179,7 +180,7 @@
}
unsigned msac_decode_bool_adapt(MsacContext *const c, uint16_t *const cdf) {
- const unsigned bit = msac_decode_bool(c, *cdf >> EC_PROB_SHIFT);
+ const unsigned bit = msac_decode_bool(c, *cdf);
if(c->allow_update_cdf){
// update_cdf() specialized for boolean CDFs
--- a/src/msac.h
+++ b/src/msac.h
@@ -43,8 +43,6 @@
int allow_update_cdf;
} MsacContext;
-#define EC_PROB_SHIFT 6
-
void msac_init(MsacContext *c, const uint8_t *data, size_t sz, int disable_cdf_update_flag);
unsigned msac_decode_symbol(MsacContext *s, const uint16_t *cdf,
const unsigned n_symbols);