ref: 9fb690fa9449ae9b14c00739e4393ddbd61270a9
parent: aeb5a5efc840da40c58d579b4e8792cb911bc6ba
author: David Michael Barr <b@rr-dav.id.au>
date: Thu Nov 1 15:38:18 EDT 2018
Match style for update_cdf and remove nsymbs2speed We can simplify as cdfs have at least 2 symbols.
--- a/src/msac.c
+++ b/src/msac.c
@@ -140,24 +140,17 @@
return v < m ? v : (v << 1) - m + msac_decode_bool(c, EC_BOOL_EPROB);
}
-void update_cdf(uint16_t *cdf, unsigned val, unsigned nsymbs) {
- int rate;
+void msac_update_cdf(uint16_t *const cdf, const unsigned val,
+ const unsigned n_symbols)
+{
+ const int rate = 4 + (cdf[n_symbols] > 15) + (cdf[n_symbols] > 31) +
+ (n_symbols > 3);
unsigned i;
-
- static const int nsymbs2speed[17] = {
- 0, 0, 1, 1, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2
- };
- assert(nsymbs < 17);
- rate = 3 + (cdf[nsymbs] > 15) + (cdf[nsymbs] > 31) + nsymbs2speed[nsymbs];
-
for (i = 0; i < val; ++i)
cdf[i] += (32768 - cdf[i]) >> rate;
-
- for (i = val; i < nsymbs - 1; i++)
+ for (i = val; i < n_symbols - 1; i++)
cdf[i] -= cdf[i] >> rate;
-
- cdf[nsymbs] += (cdf[nsymbs] < 32);
+ cdf[n_symbols] += (cdf[n_symbols] < 32);
}
void msac_init(MsacContext *const s, const uint8_t *const data,
--- a/src/msac.h
+++ b/src/msac.h
@@ -52,7 +52,7 @@
unsigned msac_decode_bools(MsacContext *c, unsigned l);
int msac_decode_subexp(MsacContext *c, int ref, int n, unsigned k);
int msac_decode_uniform(MsacContext *c, unsigned n);
-void update_cdf(uint16_t *cdf, unsigned val, unsigned nsymbs);
+void msac_update_cdf(uint16_t *cdf, unsigned val, unsigned n_symbols);
static inline unsigned msac_decode_symbol_adapt(MsacContext *const c,
uint16_t *const cdf,
@@ -59,7 +59,7 @@
const unsigned n_symbols)
{
const unsigned val = msac_decode_symbol(c, cdf, n_symbols);
- update_cdf(cdf, val, n_symbols);
+ msac_update_cdf(cdf, val, n_symbols);
return val;
}
@@ -68,7 +68,7 @@
{
const unsigned bit = msac_decode_bool(c, *cdf >> EC_PROB_SHIFT);
uint16_t bak_cdf[3] = { cdf[0], 0, cdf[1] };
- update_cdf(bak_cdf, bit, 2);
+ msac_update_cdf(bak_cdf, bit, 2);
cdf[0] = bak_cdf[0];
cdf[1] = bak_cdf[2];
return bit;