Commit f0b7d999 authored by Nathan Egge's avatar Nathan Egge Committed by Ronald S. Bultje

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.
parent 45d4fde6
...@@ -2165,7 +2165,7 @@ static int decode_sb(Dav1dTileContext *const t, const enum BlockLevel bl, ...@@ -2165,7 +2165,7 @@ static int decode_sb(Dav1dTileContext *const t, const enum BlockLevel bl,
const Av1Block *const b = &f->frame_thread.b[t->by * f->b4_stride + t->bx]; const Av1Block *const b = &f->frame_thread.b[t->by * f->b4_stride + t->bx];
is_split = b->bl != bl; is_split = b->bl != bl;
} else { } 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) if (DEBUG_BLOCK_INFO)
printf("poc=%d,y=%d,x=%d,bl=%d,ctx=%d,bp=%d: r=%d\n", 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, f->frame_hdr->frame_offset, t->by, t->bx, bl, ctx,
...@@ -2193,7 +2193,7 @@ static int decode_sb(Dav1dTileContext *const t, const enum BlockLevel bl, ...@@ -2193,7 +2193,7 @@ static int decode_sb(Dav1dTileContext *const t, const enum BlockLevel bl,
const Av1Block *const b = &f->frame_thread.b[t->by * f->b4_stride + t->bx]; const Av1Block *const b = &f->frame_thread.b[t->by * f->b4_stride + t->bx];
is_split = b->bl != bl; is_split = b->bl != bl;
} else { } 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) if (f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I422 && !is_split)
return 1; return 1;
if (DEBUG_BLOCK_INFO) if (DEBUG_BLOCK_INFO)
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "src/msac.h" #include "src/msac.h"
#define EC_PROB_SHIFT 6
#define EC_MIN_PROB 4 // must be <= (1<<EC_PROB_SHIFT)/16 #define EC_MIN_PROB 4 // must be <= (1<<EC_PROB_SHIFT)/16
#define EC_WIN_SIZE (sizeof(ec_win) << 3) #define EC_WIN_SIZE (sizeof(ec_win) << 3)
...@@ -115,7 +116,7 @@ unsigned msac_decode_bool(MsacContext *const s, const unsigned f) { ...@@ -115,7 +116,7 @@ unsigned msac_decode_bool(MsacContext *const s, const unsigned f) {
uint16_t r = s->rng; uint16_t r = s->rng;
unsigned ret; unsigned ret;
assert((dif >> (EC_WIN_SIZE - 16)) < r); 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); vw = v << (EC_WIN_SIZE - 16);
ret = dif >= vw; ret = dif >= vw;
dif -= ret*vw; dif -= ret*vw;
...@@ -179,7 +180,7 @@ unsigned msac_decode_symbol_adapt(MsacContext *const c, ...@@ -179,7 +180,7 @@ unsigned msac_decode_symbol_adapt(MsacContext *const c,
} }
unsigned msac_decode_bool_adapt(MsacContext *const c, uint16_t *const cdf) { 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){ if(c->allow_update_cdf){
// update_cdf() specialized for boolean CDFs // update_cdf() specialized for boolean CDFs
......
...@@ -43,8 +43,6 @@ typedef struct MsacContext { ...@@ -43,8 +43,6 @@ typedef struct MsacContext {
int allow_update_cdf; int allow_update_cdf;
} MsacContext; } MsacContext;
#define EC_PROB_SHIFT 6
void msac_init(MsacContext *c, const uint8_t *data, size_t sz, int disable_cdf_update_flag); 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, unsigned msac_decode_symbol(MsacContext *s, const uint16_t *cdf,
const unsigned n_symbols); const unsigned n_symbols);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment