Commit 8e67c05f authored by Jingning Han's avatar Jingning Han

Fix tree to cdf index mapping

This fixes the mis-aligned cdf model derived from tree based
model. It resolves the compression performance regression in
dual filter, intra mode, inter mode, and transform block type
coding, when ec-multisymbol is enabled by default.

With dual filter enabled, the performance regression was 3.6%
loss for lowres. This fix brings the performance gains back to 1%
gains.

Change-Id: I80f5485386045908c152c9c11eeacbc650f1e324
parent 9bc1d8de
......@@ -215,16 +215,25 @@ int tree_to_cdf(const aom_tree_index *tree, const aom_prob *probs,
/* This code assumes that tree contains as unique leaf nodes the integer values
0 to len - 1 and produces the forward and inverse mapping tables in ind[]
and inv[] respectively. */
void av1_indices_from_tree(int *ind, int *inv, int len,
const aom_tree_index *tree) {
int i;
int index;
for (i = index = 0; i < TREE_SIZE(len); i++) {
const aom_tree_index j = tree[i];
if (j <= 0) {
inv[index] = -j;
ind[-j] = index++;
static void tree_to_index(int *stack_index, int *ind, int *inv,
const aom_tree_index *tree, int value, int index) {
value *= 2;
do {
const aom_tree_index content = tree[index];
++index;
if (content <= 0) {
inv[*stack_index] = -content;
ind[-content] = *stack_index;
++(*stack_index);
} else {
tree_to_index(stack_index, ind, inv, tree, value, content);
}
}
} while (++value & 1);
}
void av1_indices_from_tree(int *ind, int *inv, const aom_tree_index *tree) {
int stack_index = 0;
tree_to_index(&stack_index, ind, inv, tree, 0, 0);
}
#endif
......@@ -139,8 +139,7 @@ static INLINE void av1_tree_to_cdf(const aom_tree_index *tree,
} \
} while (0)
void av1_indices_from_tree(int *ind, int *inv, int len,
const aom_tree_index *tree);
void av1_indices_from_tree(int *ind, int *inv, const aom_tree_index *tree);
#endif
DECLARE_ALIGNED(16, extern const uint8_t, aom_norm[256]);
......
......@@ -51,23 +51,22 @@ static void initialize_dec(void) {
#endif // CONFIG_EXT_INTER
init_done = 1;
#if CONFIG_EC_MULTISYMBOL
av1_indices_from_tree(av1_intra_mode_ind, av1_intra_mode_inv, INTRA_MODES,
av1_indices_from_tree(av1_intra_mode_ind, av1_intra_mode_inv,
av1_intra_mode_tree);
av1_indices_from_tree(av1_switchable_interp_ind, av1_switchable_interp_inv,
SWITCHABLE_FILTERS, av1_switchable_interp_tree);
av1_switchable_interp_tree);
#if CONFIG_EXT_TX
int s;
for (s = 1; s < EXT_TX_SETS_INTRA; ++s)
av1_indices_from_tree(av1_ext_tx_intra_ind[s], av1_ext_tx_intra_inv[s],
ext_tx_cnt_intra[s], av1_ext_tx_intra_tree[s]);
av1_ext_tx_intra_tree[s]);
for (s = 1; s < EXT_TX_SETS_INTER; ++s)
av1_indices_from_tree(av1_ext_tx_inter_ind[s], av1_ext_tx_inter_inv[s],
ext_tx_cnt_inter[s], av1_ext_tx_inter_tree[s]);
av1_ext_tx_inter_tree[s]);
#else
av1_indices_from_tree(av1_ext_tx_ind, av1_ext_tx_inv, TX_TYPES,
av1_ext_tx_tree);
av1_indices_from_tree(av1_ext_tx_ind, av1_ext_tx_inv, av1_ext_tx_tree);
#endif
av1_indices_from_tree(av1_inter_mode_ind, av1_inter_mode_inv, INTER_MODES,
av1_indices_from_tree(av1_inter_mode_ind, av1_inter_mode_inv,
av1_inter_mode_tree);
#endif
}
......
......@@ -192,24 +192,23 @@ void av1_encode_token_init(void) {
SWITCHABLE_FILTERS are not consecutive, e.g., 0, 1, 2, 3, 4, when doing
an in-order traversal of the av1_switchable_interp_tree structure. */
av1_indices_from_tree(av1_switchable_interp_ind, av1_switchable_interp_inv,
SWITCHABLE_FILTERS, av1_switchable_interp_tree);
av1_switchable_interp_tree);
/* This hack is necessary because the four TX_TYPES are not consecutive,
e.g., 0, 1, 2, 3, when doing an in-order traversal of the av1_ext_tx_tree
structure. */
#if CONFIG_EXT_TX
for (s = 1; s < EXT_TX_SETS_INTRA; ++s)
av1_indices_from_tree(av1_ext_tx_intra_ind[s], av1_ext_tx_intra_inv[s],
ext_tx_cnt_intra[s], av1_ext_tx_intra_tree[s]);
av1_ext_tx_intra_tree[s]);
for (s = 1; s < EXT_TX_SETS_INTER; ++s)
av1_indices_from_tree(av1_ext_tx_inter_ind[s], av1_ext_tx_inter_inv[s],
ext_tx_cnt_inter[s], av1_ext_tx_inter_tree[s]);
av1_ext_tx_inter_tree[s]);
#else
av1_indices_from_tree(av1_ext_tx_ind, av1_ext_tx_inv, TX_TYPES,
av1_ext_tx_tree);
av1_indices_from_tree(av1_ext_tx_ind, av1_ext_tx_inv, av1_ext_tx_tree);
#endif
av1_indices_from_tree(av1_intra_mode_ind, av1_intra_mode_inv, INTRA_MODES,
av1_indices_from_tree(av1_intra_mode_ind, av1_intra_mode_inv,
av1_intra_mode_tree);
av1_indices_from_tree(av1_inter_mode_ind, av1_inter_mode_inv, INTER_MODES,
av1_indices_from_tree(av1_inter_mode_ind, av1_inter_mode_inv,
av1_inter_mode_tree);
#endif
}
......
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