#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)
staticinlinevoid ctx_refill(MsacContext *const s) { const uint8_t *buf_pos = s->buf_pos; const uint8_t *buf_end = s->buf_end; int c = EC_WIN_SIZE - s->cnt - 24;
ec_win dif = s->dif; do { if (buf_pos >= buf_end) { // set remaining bits to 1;
dif |= ~(~(ec_win)0xff << c); break;
}
dif |= (ec_win)(*buf_pos++ ^ 0xff) << c;
c -= 8;
} while (c >= 0);
s->dif = dif;
s->cnt = EC_WIN_SIZE - c - 24;
s->buf_pos = buf_pos;
}
int dav1d_msac_decode_subexp(MsacContext *const s, constint ref, constint n, unsigned k)
{
assert(n >> k == 8);
unsigned a = 0; if (dav1d_msac_decode_bool_equi(s)) { if (dav1d_msac_decode_bool_equi(s))
k += dav1d_msac_decode_bool_equi(s) + 1;
a = 1 << k;
} constunsigned v = dav1d_msac_decode_bools(s, k) + a; return ref * 2 <= n ? inv_recenter(ref, v) :
n - 1 - inv_recenter(n - 1 - ref, v);
}
#if !(HAVE_ASM && TRIM_DSP_FUNCTIONS && ( \
ARCH_AARCH64 || \
(ARCH_ARM && (defined(__ARM_NEON) || defined(__APPLE__) || defined(_WIN32))) \
)) /* Takes updated dif and range values, renormalizes them so that * 32768 <= rng < 65536 (reading more bytes from the stream into dif if * necessary), and stores them back in the decoder context. * dif: The new value of dif.
* rng: The new value of the range. */ staticinlinevoid ctx_norm(MsacContext *const s, const ec_win dif, constunsigned rng)
{ constint d = 15 ^ (31 ^ clz(rng)); constint cnt = s->cnt;
assert(rng <= 65535U);
s->dif = dif << d;
s->rng = rng << d;
s->cnt = cnt - d; // unsigned compare avoids redundant refills at eob if ((unsigned)cnt < (unsigned)d)
ctx_refill(s);
}
unsigned dav1d_msac_decode_bool_equi_c(MsacContext *const s) { constunsigned r = s->rng;
ec_win dif = s->dif;
assert((dif >> (EC_WIN_SIZE - 16)) < r); // When the probability is 1/2, f = 16384 >> EC_PROB_SHIFT = 256 and we can // replace the multiply with a simple shift. unsigned v = ((r >> 8) << 7) + EC_MIN_PROB; const ec_win vw = (ec_win)v << (EC_WIN_SIZE - 16); constunsigned ret = dif >= vw;
dif -= ret * vw;
v += ret * (r - 2 * v);
ctx_norm(s, dif, v); return !ret;
}
/* Decode a single binary value. * f: The probability that the bit is one
* Return: The value decoded (0 or 1). */ unsigned dav1d_msac_decode_bool_c(MsacContext *const s, constunsigned f) { constunsigned r = s->rng;
ec_win dif = s->dif;
assert((dif >> (EC_WIN_SIZE - 16)) < r); unsigned v = ((r >> 8) * (f >> EC_PROB_SHIFT) >> (7 - EC_PROB_SHIFT)) + EC_MIN_PROB; const ec_win vw = (ec_win)v << (EC_WIN_SIZE - 16); constunsigned ret = dif >= vw;
dif -= ret * vw;
v += ret * (r - 2 * v);
ctx_norm(s, dif, v); return !ret;
}
/* Decodes a symbol given an inverse cumulative distribution function (CDF)
* table in Q15. */ unsigned dav1d_msac_decode_symbol_adapt_c(MsacContext *const s,
uint16_t *const cdf, const size_t n_symbols)
{ constunsigned c = s->dif >> (EC_WIN_SIZE - 16), r = s->rng >> 8; unsigned u, v = s->rng, val = -1;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.