Remove custom rans types

(cherry picked from aom/master commit 11206c60d930be9d29100567aa67f2a65463852a)

Includes renames in a bunch of places not handled by the original
due to differing tree states.

Change-Id: Ic74d9d8850b8c80a51e55e425bbf472a67e2653f
This commit is contained in:
Alex Converse
2016-09-04 13:30:43 +02:00
committed by Pascal Massimino
parent 4ce69de9a6
commit 9ed1a2ff44
10 changed files with 295 additions and 296 deletions

View File

@@ -15,7 +15,7 @@
#include "aom_dsp/ans.h" #include "aom_dsp/ans.h"
#include "aom_dsp/prob.h" #include "aom_dsp/prob.h"
static int find_largest(const AnsP10 *const pdf_tab, int num_syms) { static int find_largest(const aom_cdf_prob *const pdf_tab, int num_syms) {
int largest_idx = -1; int largest_idx = -1;
int largest_p = -1; int largest_p = -1;
int i; int i;
@@ -29,8 +29,9 @@ static int find_largest(const AnsP10 *const pdf_tab, int num_syms) {
return largest_idx; return largest_idx;
} }
void aom_rans_merge_prob8_pdf(AnsP10 *const out_pdf, const AnsP8 node_prob, void aom_rans_merge_prob8_pdf(aom_cdf_prob *const out_pdf,
const AnsP10 *const src_pdf, int in_syms) { const AnsP8 node_prob,
const aom_cdf_prob *const src_pdf, int in_syms) {
int i; int i;
int adjustment = RANS_PRECISION; int adjustment = RANS_PRECISION;
const int round_fact = ANS_P8_PRECISION >> 1; const int round_fact = ANS_P8_PRECISION >> 1;

View File

@@ -26,21 +26,16 @@ extern "C" {
typedef uint8_t AnsP8; typedef uint8_t AnsP8;
#define ANS_P8_PRECISION 256u #define ANS_P8_PRECISION 256u
#define ANS_P8_SHIFT 8 #define ANS_P8_SHIFT 8
typedef uint16_t AnsP10; #define RANS_PRECISION 1024u
#define ANS_P10_PRECISION 1024u
#define RANS_PROB_BITS 10 #define RANS_PROB_BITS 10
#define RANS_PRECISION ANS_P10_PRECISION #define L_BASE (RANS_PRECISION * 4) // L_BASE % precision must be 0
#define L_BASE (ANS_P10_PRECISION * 4) // L_BASE % precision must be 0
#define IO_BASE 256 #define IO_BASE 256
// Range I = { L_BASE, L_BASE + 1, ..., L_BASE * IO_BASE - 1 } // Range I = { L_BASE, L_BASE + 1, ..., L_BASE * IO_BASE - 1 }
// This is now just a boring cdf. void aom_rans_merge_prob8_pdf(aom_cdf_prob *const out_pdf,
typedef uint16_t rans_lut[16]; const AnsP8 node_prob,
const aom_cdf_prob *const src_pdf, int in_syms);
void aom_rans_merge_prob8_pdf(AnsP10 *const out_pdf, const AnsP8 node_prob,
const AnsP10 *const src_pdf, int in_syms);
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"
#endif // __cplusplus #endif // __cplusplus

View File

@@ -62,14 +62,14 @@ static INLINE int uabs_read_bit(struct AnsDecoder *ans) {
struct rans_dec_sym { struct rans_dec_sym {
uint8_t val; uint8_t val;
AnsP10 prob; aom_cdf_prob prob;
AnsP10 cum_prob; // not-inclusive aom_cdf_prob cum_prob; // not-inclusive
}; };
static INLINE void fetch_sym(struct rans_dec_sym *out, const rans_lut cdf, static INLINE void fetch_sym(struct rans_dec_sym *out, const aom_cdf_prob *cdf,
AnsP10 rem) { aom_cdf_prob rem) {
int i; int i;
AnsP10 cum_prob = 0, top_prob; aom_cdf_prob cum_prob = 0, top_prob;
// TODO(skal): if critical, could be a binary search. // TODO(skal): if critical, could be a binary search.
// Or, better, an O(1) alias-table. // Or, better, an O(1) alias-table.
for (i = 0; rem >= (top_prob = cdf[i]); ++i) { for (i = 0; rem >= (top_prob = cdf[i]); ++i) {
@@ -80,7 +80,7 @@ static INLINE void fetch_sym(struct rans_dec_sym *out, const rans_lut cdf,
out->cum_prob = cum_prob; out->cum_prob = cum_prob;
} }
static INLINE int rans_read(struct AnsDecoder *ans, const rans_lut tab) { static INLINE int rans_read(struct AnsDecoder *ans, const aom_cdf_prob *tab) {
unsigned rem; unsigned rem;
unsigned quo; unsigned quo;
struct rans_dec_sym sym; struct rans_dec_sym sym;

View File

@@ -75,8 +75,8 @@ static INLINE void uabs_write(struct AnsCoder *ans, int val, AnsP8 p0) {
} }
struct rans_sym { struct rans_sym {
AnsP10 prob; aom_cdf_prob prob;
AnsP10 cum_prob; // not-inclusive aom_cdf_prob cum_prob; // not-inclusive
}; };
// rANS with normalization // rANS with normalization
@@ -84,7 +84,7 @@ struct rans_sym {
// ANS_P10_PRECISION is m // ANS_P10_PRECISION is m
static INLINE void rans_write(struct AnsCoder *ans, static INLINE void rans_write(struct AnsCoder *ans,
const struct rans_sym *const sym) { const struct rans_sym *const sym) {
const AnsP10 p = sym->prob; const aom_cdf_prob p = sym->prob;
while (ans->state >= L_BASE / RANS_PRECISION * IO_BASE * p) { while (ans->state >= L_BASE / RANS_PRECISION * IO_BASE * p) {
ans->buf[ans->buf_offset++] = ans->state % IO_BASE; ans->buf[ans->buf_offset++] = ans->state % IO_BASE;
ans->state /= IO_BASE; ans->state /= IO_BASE;

View File

@@ -418,7 +418,8 @@ const aom_prob av1_pareto8_full[COEFF_PROB_MODELS][MODEL_NODES] = {
// beta = 8 // beta = 8
// Values for tokens ONE_TOKEN through CATEGORY6_TOKEN included here. // Values for tokens ONE_TOKEN through CATEGORY6_TOKEN included here.
// ZERO_TOKEN and EOB_TOKEN are coded as flags outside this coder. // ZERO_TOKEN and EOB_TOKEN are coded as flags outside this coder.
const AnsP10 av1_pareto8_token_probs[COEFF_PROB_MODELS][ENTROPY_TOKENS - 2] = { const aom_cdf_prob
av1_pareto8_token_probs[COEFF_PROB_MODELS][ENTROPY_TOKENS - 2] = {
{ 4, 4, 4, 4, 8, 15, 30, 57, 103, 795 }, { 4, 4, 4, 4, 8, 15, 30, 57, 103, 795 },
{ 8, 8, 8, 8, 15, 30, 57, 103, 168, 619 }, { 8, 8, 8, 8, 15, 30, 57, 103, 168, 619 },
{ 12, 12, 12, 12, 23, 43, 80, 138, 205, 487 }, { 12, 12, 12, 12, 23, 43, 80, 138, 205, 487 },
@@ -674,7 +675,7 @@ const AnsP10 av1_pareto8_token_probs[COEFF_PROB_MODELS][ENTROPY_TOKENS - 2] = {
{ 1012, 4, 1, 1, 1, 1, 1, 1, 1, 1 }, { 1012, 4, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1015, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, { 1015, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1015, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, { 1015, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
}; };
#endif // CONFIG_ANS #endif // CONFIG_ANS
/* clang-format off */ /* clang-format off */
@@ -2801,7 +2802,8 @@ void av1_model_to_full_probs(const aom_prob *model, aom_prob *full) {
} }
#if CONFIG_ANS #if CONFIG_ANS
static void build_token_cdfs(const aom_prob *pdf_model, rans_lut cdf) { static void build_token_cdfs(const aom_prob *pdf_model,
aom_cdf_prob cdf[ENTROPY_TOKENS]) {
int i, sum = 0; int i, sum = 0;
assert(pdf_model[2] != 0); assert(pdf_model[2] != 0);
for (i = 0; i < ENTROPY_TOKENS - 2; ++i) { for (i = 0; i < ENTROPY_TOKENS - 2; ++i) {

View File

@@ -191,10 +191,10 @@ static INLINE const uint8_t *get_band_translate(TX_SIZE tx_size) {
extern const aom_tree_index av1_coef_con_tree[TREE_SIZE(ENTROPY_TOKENS)]; extern const aom_tree_index av1_coef_con_tree[TREE_SIZE(ENTROPY_TOKENS)];
extern const aom_prob av1_pareto8_full[COEFF_PROB_MODELS][MODEL_NODES]; extern const aom_prob av1_pareto8_full[COEFF_PROB_MODELS][MODEL_NODES];
#if CONFIG_ANS #if CONFIG_ANS
extern const AnsP10 av1_pareto8_token_probs[COEFF_PROB_MODELS] typedef aom_cdf_prob coeff_cdf_model[REF_TYPES][COEF_BANDS][COEFF_CONTEXTS]
[ENTROPY_TOKENS];
extern const aom_cdf_prob av1_pareto8_token_probs[COEFF_PROB_MODELS]
[ENTROPY_TOKENS - 2]; [ENTROPY_TOKENS - 2];
typedef rans_lut coeff_cdf_model[REF_TYPES][COEF_BANDS][COEFF_CONTEXTS];
#endif // CONFIG_ANS #endif // CONFIG_ANS
typedef aom_prob av1_coeff_probs_model[REF_TYPES][COEF_BANDS][COEFF_CONTEXTS] typedef aom_prob av1_coeff_probs_model[REF_TYPES][COEF_BANDS][COEFF_CONTEXTS]

View File

@@ -75,9 +75,9 @@ static int decode_coefs(const MACROBLOCKD *xd, PLANE_TYPE type,
fc->coef_probs[tx_size_ctx][type][ref]; fc->coef_probs[tx_size_ctx][type][ref];
const aom_prob *prob; const aom_prob *prob;
#if CONFIG_ANS #if CONFIG_ANS
const rans_lut(*coef_cdfs)[COEFF_CONTEXTS] = const aom_cdf_prob(*const coef_cdfs)[COEFF_CONTEXTS][ENTROPY_TOKENS] =
fc->coef_cdfs[tx_size_ctx][type][ref]; fc->coef_cdfs[tx_size_ctx][type][ref];
const rans_lut *cdf; const aom_cdf_prob(*cdf)[ENTROPY_TOKENS];
#endif // CONFIG_ANS #endif // CONFIG_ANS
unsigned int(*coef_counts)[COEFF_CONTEXTS][UNCONSTRAINED_NODES + 1]; unsigned int(*coef_counts)[COEFF_CONTEXTS][UNCONSTRAINED_NODES + 1];
unsigned int(*eob_branch_count)[COEFF_CONTEXTS]; unsigned int(*eob_branch_count)[COEFF_CONTEXTS];

View File

@@ -387,7 +387,7 @@ static void set_entropy_context_b(int plane, int block, int blk_row,
static INLINE void add_token(TOKENEXTRA **t, const aom_prob *context_tree, static INLINE void add_token(TOKENEXTRA **t, const aom_prob *context_tree,
#if CONFIG_ANS #if CONFIG_ANS
const rans_lut *token_cdf, const aom_cdf_prob (*token_cdf)[ENTROPY_TOKENS],
#endif // CONFIG_ANS #endif // CONFIG_ANS
int32_t extra, uint8_t token, int32_t extra, uint8_t token,
uint8_t skip_eob_node, unsigned int *counts) { uint8_t skip_eob_node, unsigned int *counts) {
@@ -487,8 +487,8 @@ static void tokenize_b(int plane, int block, int blk_row, int blk_col,
cpi->common.fc->coef_probs[txsize_sqr_map[tx_size]][type][ref]; cpi->common.fc->coef_probs[txsize_sqr_map[tx_size]][type][ref];
#endif // CONFIG_ENTROPY #endif // CONFIG_ENTROPY
#if CONFIG_ANS #if CONFIG_ANS
rans_lut(*const coef_cdfs)[COEFF_CONTEXTS] = aom_cdf_prob(*const coef_cdfs)[COEFF_CONTEXTS][ENTROPY_TOKENS] =
cpi->common.fc->coef_cdfs[txsize_sqr_map[tx_size]][type][ref]; cpi->common.fc->coef_cdfs[tx_size][type][ref];
#endif // CONFIG_ANS #endif // CONFIG_ANS
unsigned int(*const eob_branch)[COEFF_CONTEXTS] = unsigned int(*const eob_branch)[COEFF_CONTEXTS] =
td->counts->eob_branch[txsize_sqr_map[tx_size]][type][ref]; td->counts->eob_branch[txsize_sqr_map[tx_size]][type][ref];
@@ -511,7 +511,7 @@ static void tokenize_b(int plane, int block, int blk_row, int blk_col,
add_token(&t, coef_probs[band[c]][pt], add_token(&t, coef_probs[band[c]][pt],
#if CONFIG_ANS #if CONFIG_ANS
(const rans_lut *)&coef_cdfs[band[c]][pt], (const aom_cdf_prob(*)[ENTROPY_TOKENS]) & coef_cdfs[band[c]][pt],
#endif // CONFIG_ANS #endif // CONFIG_ANS
extra, (uint8_t)token, (uint8_t)skip_eob, counts[band[c]][pt]); extra, (uint8_t)token, (uint8_t)skip_eob, counts[band[c]][pt]);

View File

@@ -37,7 +37,7 @@ typedef struct {
typedef struct { typedef struct {
const aom_prob *context_tree; const aom_prob *context_tree;
#if CONFIG_ANS #if CONFIG_ANS
const rans_lut *token_cdf; const aom_cdf_prob (*token_cdf)[ENTROPY_TOKENS];
#endif // CONFIG_ANS #endif // CONFIG_ANS
EXTRABIT extra; EXTRABIT extra;
uint8_t token; uint8_t token;

View File

@@ -79,13 +79,13 @@ bool check_uabs(const PvVec &pv_vec, uint8_t *buf) {
const rans_sym rans_sym_tab[] = { const rans_sym rans_sym_tab[] = {
{ 67, 0 }, { 99, 67 }, { 575, 166 }, { 283, 741 }, { 67, 0 }, { 99, 67 }, { 575, 166 }, { 283, 741 },
}; };
const int kRansSymbols =
static_cast<int>(sizeof(rans_sym_tab) / sizeof(rans_sym_tab[0]));
std::vector<int> ans_encode_build_vals(const rans_sym *tab, int iters) { std::vector<int> ans_encode_build_vals(const rans_sym *tab, int iters) {
std::vector<int> p_to_sym; std::vector<int> p_to_sym;
int i = 0; for (int i = 0; i < kRansSymbols; ++i) {
while (p_to_sym.size() < RANS_PRECISION) {
p_to_sym.insert(p_to_sym.end(), tab[i].prob, i); p_to_sym.insert(p_to_sym.end(), tab[i].prob, i);
++i;
} }
assert(p_to_sym.size() == RANS_PRECISION); assert(p_to_sym.size() == RANS_PRECISION);
std::vector<int> ret; std::vector<int> ret;
@@ -97,7 +97,8 @@ std::vector<int> ans_encode_build_vals(const rans_sym *tab, int iters) {
return ret; return ret;
} }
void rans_build_dec_tab(const struct rans_sym sym_tab[], rans_lut dec_tab) { void rans_build_dec_tab(const struct rans_sym sym_tab[],
aom_cdf_prob *dec_tab) {
unsigned int sum = 0; unsigned int sum = 0;
for (int i = 0; sum < RANS_PRECISION; ++i) { for (int i = 0; sum < RANS_PRECISION; ++i) {
dec_tab[i] = sum += sym_tab[i].prob; dec_tab[i] = sum += sym_tab[i].prob;
@@ -108,7 +109,7 @@ bool check_rans(const std::vector<int> &sym_vec, const rans_sym *const tab,
uint8_t *buf) { uint8_t *buf) {
AnsCoder a; AnsCoder a;
ans_write_init(&a, buf); ans_write_init(&a, buf);
rans_lut dec_tab; aom_cdf_prob dec_tab[kRansSymbols];
rans_build_dec_tab(tab, dec_tab); rans_build_dec_tab(tab, dec_tab);
std::clock_t start = std::clock(); std::clock_t start = std::clock();