Commit 9ed1a2ff authored by Alex Converse's avatar Alex Converse Committed by Pascal Massimino
Browse files

Remove custom rans types

(cherry picked from aom/master commit 11206c60)

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

Change-Id: Ic74d9d8850b8c80a51e55e425bbf472a67e2653f
parent 4ce69de9
......@@ -15,7 +15,7 @@
#include "aom_dsp/ans.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_p = -1;
int i;
......@@ -29,8 +29,9 @@ static int find_largest(const AnsP10 *const pdf_tab, int num_syms) {
return largest_idx;
}
void aom_rans_merge_prob8_pdf(AnsP10 *const out_pdf, const AnsP8 node_prob,
const AnsP10 *const src_pdf, int in_syms) {
void aom_rans_merge_prob8_pdf(aom_cdf_prob *const out_pdf,
const AnsP8 node_prob,
const aom_cdf_prob *const src_pdf, int in_syms) {
int i;
int adjustment = RANS_PRECISION;
const int round_fact = ANS_P8_PRECISION >> 1;
......
......@@ -26,21 +26,16 @@ extern "C" {
typedef uint8_t AnsP8;
#define ANS_P8_PRECISION 256u
#define ANS_P8_SHIFT 8
typedef uint16_t AnsP10;
#define ANS_P10_PRECISION 1024u
#define RANS_PRECISION 1024u
#define RANS_PROB_BITS 10
#define RANS_PRECISION ANS_P10_PRECISION
#define L_BASE (ANS_P10_PRECISION * 4) // L_BASE % precision must be 0
#define L_BASE (RANS_PRECISION * 4) // L_BASE % precision must be 0
#define IO_BASE 256
// Range I = { L_BASE, L_BASE + 1, ..., L_BASE * IO_BASE - 1 }
// This is now just a boring cdf.
typedef uint16_t rans_lut[16];
void aom_rans_merge_prob8_pdf(AnsP10 *const out_pdf, const AnsP8 node_prob,
const AnsP10 *const src_pdf, int in_syms);
void aom_rans_merge_prob8_pdf(aom_cdf_prob *const out_pdf,
const AnsP8 node_prob,
const aom_cdf_prob *const src_pdf, int in_syms);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
......
......@@ -62,14 +62,14 @@ static INLINE int uabs_read_bit(struct AnsDecoder *ans) {
struct rans_dec_sym {
uint8_t val;
AnsP10 prob;
AnsP10 cum_prob; // not-inclusive
aom_cdf_prob prob;
aom_cdf_prob cum_prob; // not-inclusive
};
static INLINE void fetch_sym(struct rans_dec_sym *out, const rans_lut cdf,
AnsP10 rem) {
static INLINE void fetch_sym(struct rans_dec_sym *out, const aom_cdf_prob *cdf,
aom_cdf_prob rem) {
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.
// Or, better, an O(1) alias-table.
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;
}
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 quo;
struct rans_dec_sym sym;
......
......@@ -75,8 +75,8 @@ static INLINE void uabs_write(struct AnsCoder *ans, int val, AnsP8 p0) {
}
struct rans_sym {
AnsP10 prob;
AnsP10 cum_prob; // not-inclusive
aom_cdf_prob prob;
aom_cdf_prob cum_prob; // not-inclusive
};
// rANS with normalization
......@@ -84,7 +84,7 @@ struct rans_sym {
// ANS_P10_PRECISION is m
static INLINE void rans_write(struct AnsCoder *ans,
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) {
ans->buf[ans->buf_offset++] = ans->state % IO_BASE;
ans->state /= IO_BASE;
......
This diff is collapsed.
......@@ -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_prob av1_pareto8_full[COEFF_PROB_MODELS][MODEL_NODES];
#if CONFIG_ANS
extern const AnsP10 av1_pareto8_token_probs[COEFF_PROB_MODELS]
[ENTROPY_TOKENS - 2];
typedef rans_lut coeff_cdf_model[REF_TYPES][COEF_BANDS][COEFF_CONTEXTS];
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];
#endif // CONFIG_ANS
typedef aom_prob av1_coeff_probs_model[REF_TYPES][COEF_BANDS][COEFF_CONTEXTS]
......
......@@ -75,9 +75,9 @@ static int decode_coefs(const MACROBLOCKD *xd, PLANE_TYPE type,
fc->coef_probs[tx_size_ctx][type][ref];
const aom_prob *prob;
#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];
const rans_lut *cdf;
const aom_cdf_prob(*cdf)[ENTROPY_TOKENS];
#endif // CONFIG_ANS
unsigned int(*coef_counts)[COEFF_CONTEXTS][UNCONSTRAINED_NODES + 1];
unsigned int(*eob_branch_count)[COEFF_CONTEXTS];
......
......@@ -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,
#if CONFIG_ANS
const rans_lut *token_cdf,
const aom_cdf_prob (*token_cdf)[ENTROPY_TOKENS],
#endif // CONFIG_ANS
int32_t extra, uint8_t token,
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];
#endif // CONFIG_ENTROPY
#if CONFIG_ANS
rans_lut(*const coef_cdfs)[COEFF_CONTEXTS] =
cpi->common.fc->coef_cdfs[txsize_sqr_map[tx_size]][type][ref];
aom_cdf_prob(*const coef_cdfs)[COEFF_CONTEXTS][ENTROPY_TOKENS] =
cpi->common.fc->coef_cdfs[tx_size][type][ref];
#endif // CONFIG_ANS
unsigned int(*const eob_branch)[COEFF_CONTEXTS] =
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],
#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
extra, (uint8_t)token, (uint8_t)skip_eob, counts[band[c]][pt]);
......
......@@ -37,7 +37,7 @@ typedef struct {
typedef struct {
const aom_prob *context_tree;
#if CONFIG_ANS
const rans_lut *token_cdf;
const aom_cdf_prob (*token_cdf)[ENTROPY_TOKENS];
#endif // CONFIG_ANS
EXTRABIT extra;
uint8_t token;
......
......@@ -79,13 +79,13 @@ bool check_uabs(const PvVec &pv_vec, uint8_t *buf) {
const rans_sym rans_sym_tab[] = {
{ 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> p_to_sym;
int i = 0;
while (p_to_sym.size() < RANS_PRECISION) {
for (int i = 0; i < kRansSymbols; ++i) {
p_to_sym.insert(p_to_sym.end(), tab[i].prob, i);
++i;
}
assert(p_to_sym.size() == RANS_PRECISION);
std::vector<int> ret;
......@@ -97,7 +97,8 @@ std::vector<int> ans_encode_build_vals(const rans_sym *tab, int iters) {
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;
for (int i = 0; sum < RANS_PRECISION; ++i) {
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) {
AnsCoder a;
ans_write_init(&a, buf);
rans_lut dec_tab;
aom_cdf_prob dec_tab[kRansSymbols];
rans_build_dec_tab(tab, dec_tab);
std::clock_t start = std::clock();
......
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