TX_SIZE contexts simplification.
Reduces TX_SIZE contexts to 2 for each kind. The code is
cleaner and there is hardly any performance difference with
more than two contexts.
Results: almost neutral
Change-Id: I17656bd6db76224ae2856adf882504560e7dbaa4
diff --git a/vp9/common/vp9_entropymode.c b/vp9/common/vp9_entropymode.c
index 7a87cfe..7ae5279 100644
--- a/vp9/common/vp9_entropymode.c
+++ b/vp9/common/vp9_entropymode.c
@@ -149,24 +149,36 @@
{ 235, 248 },
};
-const vp9_prob vp9_default_tx_probs_32x32p[TX_SIZE_MAX_SB]
+#if TX_SIZE_CONTEXTS == 2
+const vp9_prob vp9_default_tx_probs_32x32p[TX_SIZE_CONTEXTS]
[TX_SIZE_MAX_SB - 1] = {
- { 16, 64, 96, },
- { 32, 64, 96, },
- { 32, 64, 96, },
- { 32, 64, 96, },
+ { 16, 32, 64, },
+ { 16, 32, 64, },
};
-const vp9_prob vp9_default_tx_probs_16x16p[TX_SIZE_MAX_SB - 1]
+const vp9_prob vp9_default_tx_probs_16x16p[TX_SIZE_CONTEXTS]
[TX_SIZE_MAX_SB - 2] = {
- { 32, 96, },
- { 64, 96, },
- { 64, 96, },
+ { 32, 64, },
+ { 32, 64, },
};
-const vp9_prob vp9_default_tx_probs_8x8p[TX_SIZE_MAX_SB - 2]
+const vp9_prob vp9_default_tx_probs_8x8p[TX_SIZE_CONTEXTS]
[TX_SIZE_MAX_SB - 3] = {
- { 96, },
- { 96, },
+ { 64, },
+ { 64, },
};
+#else
+const vp9_prob vp9_default_tx_probs_32x32p[TX_SIZE_CONTEXTS]
+ [TX_SIZE_MAX_SB - 1] = {
+ { 16, 32, 64, },
+};
+const vp9_prob vp9_default_tx_probs_16x16p[TX_SIZE_CONTEXTS]
+ [TX_SIZE_MAX_SB - 2] = {
+ { 32, 64, },
+};
+const vp9_prob vp9_default_tx_probs_8x8p[TX_SIZE_CONTEXTS]
+ [TX_SIZE_MAX_SB - 3] = {
+ { 64, },
+};
+#endif
void tx_counts_to_branch_counts_32x32(unsigned int *tx_count_32x32p,
unsigned int (*ct_32x32p)[2]) {
@@ -438,7 +450,7 @@
unsigned int branch_ct_8x8p[TX_SIZE_MAX_SB - 3][2];
unsigned int branch_ct_16x16p[TX_SIZE_MAX_SB - 2][2];
unsigned int branch_ct_32x32p[TX_SIZE_MAX_SB - 1][2];
- for (i = 0; i < TX_SIZE_MAX_SB - 2; ++i) {
+ for (i = 0; i < TX_SIZE_CONTEXTS; ++i) {
tx_counts_to_branch_counts_8x8(cm->fc.tx_count_8x8p[i],
branch_ct_8x8p);
for (j = 0; j < TX_SIZE_MAX_SB - 3; ++j) {
@@ -452,7 +464,7 @@
cm->fc.pre_tx_probs_8x8p[i][j], prob, factor);
}
}
- for (i = 0; i < TX_SIZE_MAX_SB - 1; ++i) {
+ for (i = 0; i < TX_SIZE_CONTEXTS; ++i) {
tx_counts_to_branch_counts_16x16(cm->fc.tx_count_16x16p[i],
branch_ct_16x16p);
for (j = 0; j < TX_SIZE_MAX_SB - 2; ++j) {
@@ -466,7 +478,7 @@
cm->fc.pre_tx_probs_16x16p[i][j], prob, factor);
}
}
- for (i = 0; i < TX_SIZE_MAX_SB; ++i) {
+ for (i = 0; i < TX_SIZE_CONTEXTS; ++i) {
tx_counts_to_branch_counts_32x32(cm->fc.tx_count_32x32p[i],
branch_ct_32x32p);
for (j = 0; j < TX_SIZE_MAX_SB - 1; ++j) {
diff --git a/vp9/common/vp9_entropymode.h b/vp9/common/vp9_entropymode.h
index 3e8d566..96e498e 100644
--- a/vp9/common/vp9_entropymode.h
+++ b/vp9/common/vp9_entropymode.h
@@ -15,6 +15,7 @@
#include "vp9/common/vp9_treecoder.h"
#define SUBMVREF_COUNT 5
+#define TX_SIZE_CONTEXTS 2
// #define MODE_STATS
@@ -77,11 +78,11 @@
extern const vp9_prob vp9_switchable_interp_prob[VP9_SWITCHABLE_FILTERS + 1]
[VP9_SWITCHABLE_FILTERS - 1];
-extern const vp9_prob vp9_default_tx_probs_32x32p[TX_SIZE_MAX_SB]
+extern const vp9_prob vp9_default_tx_probs_32x32p[TX_SIZE_CONTEXTS]
[TX_SIZE_MAX_SB - 1];
-extern const vp9_prob vp9_default_tx_probs_16x16p[TX_SIZE_MAX_SB - 1]
+extern const vp9_prob vp9_default_tx_probs_16x16p[TX_SIZE_CONTEXTS]
[TX_SIZE_MAX_SB - 2];
-extern const vp9_prob vp9_default_tx_probs_8x8p[TX_SIZE_MAX_SB - 2]
+extern const vp9_prob vp9_default_tx_probs_8x8p[TX_SIZE_CONTEXTS]
[TX_SIZE_MAX_SB - 3];
extern void tx_counts_to_branch_counts_32x32(unsigned int *tx_count_32x32p,
diff --git a/vp9/common/vp9_onyxc_int.h b/vp9/common/vp9_onyxc_int.h
index d91483d..583e50e 100644
--- a/vp9/common/vp9_onyxc_int.h
+++ b/vp9/common/vp9_onyxc_int.h
@@ -90,15 +90,15 @@
unsigned int single_ref_count[REF_CONTEXTS][2][2];
unsigned int comp_ref_count[REF_CONTEXTS][2];
- vp9_prob tx_probs_32x32p[TX_SIZE_MAX_SB][TX_SIZE_MAX_SB - 1];
- vp9_prob tx_probs_16x16p[TX_SIZE_MAX_SB - 1][TX_SIZE_MAX_SB - 2];
- vp9_prob tx_probs_8x8p[TX_SIZE_MAX_SB - 2][TX_SIZE_MAX_SB - 3];
- vp9_prob pre_tx_probs_32x32p[TX_SIZE_MAX_SB][TX_SIZE_MAX_SB - 1];
- vp9_prob pre_tx_probs_16x16p[TX_SIZE_MAX_SB - 1][TX_SIZE_MAX_SB - 2];
- vp9_prob pre_tx_probs_8x8p[TX_SIZE_MAX_SB - 2][TX_SIZE_MAX_SB - 3];
- unsigned int tx_count_32x32p[TX_SIZE_MAX_SB][TX_SIZE_MAX_SB];
- unsigned int tx_count_16x16p[TX_SIZE_MAX_SB - 1][TX_SIZE_MAX_SB - 1];
- unsigned int tx_count_8x8p[TX_SIZE_MAX_SB - 2][TX_SIZE_MAX_SB - 2];
+ vp9_prob tx_probs_32x32p[TX_SIZE_CONTEXTS][TX_SIZE_MAX_SB - 1];
+ vp9_prob tx_probs_16x16p[TX_SIZE_CONTEXTS][TX_SIZE_MAX_SB - 2];
+ vp9_prob tx_probs_8x8p[TX_SIZE_CONTEXTS][TX_SIZE_MAX_SB - 3];
+ vp9_prob pre_tx_probs_32x32p[TX_SIZE_CONTEXTS][TX_SIZE_MAX_SB - 1];
+ vp9_prob pre_tx_probs_16x16p[TX_SIZE_CONTEXTS][TX_SIZE_MAX_SB - 2];
+ vp9_prob pre_tx_probs_8x8p[TX_SIZE_CONTEXTS][TX_SIZE_MAX_SB - 3];
+ unsigned int tx_count_32x32p[TX_SIZE_CONTEXTS][TX_SIZE_MAX_SB];
+ unsigned int tx_count_16x16p[TX_SIZE_CONTEXTS][TX_SIZE_MAX_SB - 1];
+ unsigned int tx_count_8x8p[TX_SIZE_CONTEXTS][TX_SIZE_MAX_SB - 2];
vp9_prob mbskip_probs[MBSKIP_CONTEXTS];
vp9_prob pre_mbskip_probs[MBSKIP_CONTEXTS];
diff --git a/vp9/common/vp9_pred_common.c b/vp9/common/vp9_pred_common.c
index f7c9f2c..c930565 100644
--- a/vp9/common/vp9_pred_common.c
+++ b/vp9/common/vp9_pred_common.c
@@ -349,7 +349,8 @@
}
case PRED_TX_SIZE: {
- int above_context = TX_16X16, left_context = TX_16X16;
+#if TX_SIZE_CONTEXTS == 2
+ int above_context, left_context;
int max_tx_size;
if (mi->mbmi.sb_type < BLOCK_SIZE_SB8X8)
max_tx_size = TX_4X4;
@@ -359,6 +360,7 @@
max_tx_size = TX_16X16;
else
max_tx_size = TX_32X32;
+ above_context = left_context = max_tx_size;
if (above_in_image) {
above_context = (above_mi->mbmi.mb_skip_coeff ?
max_tx_size : above_mi->mbmi.txfm_size);
@@ -373,9 +375,10 @@
if (!above_in_image) {
above_context = left_context;
}
- pred_context = (above_context + left_context + 1) >> 1;
- if (pred_context > max_tx_size)
- pred_context = max_tx_size;
+ pred_context = (above_context + left_context > max_tx_size);
+#else
+ pred_context = 0;
+#endif
break;
}
diff --git a/vp9/decoder/vp9_decodframe.c b/vp9/decoder/vp9_decodframe.c
index 880fd79..1bc7696 100644
--- a/vp9/decoder/vp9_decodframe.c
+++ b/vp9/decoder/vp9_decodframe.c
@@ -59,21 +59,21 @@
pc->txfm_mode += vp9_read_bit(r);
if (pc->txfm_mode == TX_MODE_SELECT) {
int i, j;
- for (i = 0; i < TX_SIZE_MAX_SB - 2; ++i) {
+ for (i = 0; i < TX_SIZE_CONTEXTS; ++i) {
for (j = 0; j < TX_SIZE_MAX_SB - 3; ++j) {
if (vp9_read(r, VP9_DEF_UPDATE_PROB))
pc->fc.tx_probs_8x8p[i][j] =
vp9_read_prob_diff_update(r, pc->fc.tx_probs_8x8p[i][j]);
}
}
- for (i = 0; i < TX_SIZE_MAX_SB - 1; ++i) {
+ for (i = 0; i < TX_SIZE_CONTEXTS; ++i) {
for (j = 0; j < TX_SIZE_MAX_SB - 2; ++j) {
if (vp9_read(r, VP9_DEF_UPDATE_PROB))
pc->fc.tx_probs_16x16p[i][j] =
vp9_read_prob_diff_update(r, pc->fc.tx_probs_16x16p[i][j]);
}
}
- for (i = 0; i < TX_SIZE_MAX_SB; ++i) {
+ for (i = 0; i < TX_SIZE_CONTEXTS; ++i) {
for (j = 0; j < TX_SIZE_MAX_SB - 1; ++j) {
if (vp9_read(r, VP9_DEF_UPDATE_PROB))
pc->fc.tx_probs_32x32p[i][j] =
diff --git a/vp9/encoder/vp9_bitstream.c b/vp9/encoder/vp9_bitstream.c
index ede067e..5f4aa8f 100644
--- a/vp9/encoder/vp9_bitstream.c
+++ b/vp9/encoder/vp9_bitstream.c
@@ -52,9 +52,9 @@
#define vp9_cost_upd256 ((int)(vp9_cost_one(upd) - vp9_cost_zero(upd)))
#ifdef MODE_STATS
-int64_t tx_count_32x32p_stats[TX_SIZE_MAX_SB][TX_SIZE_MAX_SB];
-int64_t tx_count_16x16p_stats[TX_SIZE_MAX_SB - 1][TX_SIZE_MAX_SB - 1];
-int64_t tx_count_8x8p_stats[TX_SIZE_MAX_SB - 2][TX_SIZE_MAX_SB - 2];
+int64_t tx_count_32x32p_stats[TX_SIZE_CONTEXTS][TX_SIZE_MAX_SB];
+int64_t tx_count_16x16p_stats[TX_SIZE_CONTEXTS][TX_SIZE_MAX_SB - 1];
+int64_t tx_count_8x8p_stats[TX_SIZE_CONTEXTS][TX_SIZE_MAX_SB - 2];
void init_tx_count_stats() {
vp9_zero(tx_count_32x32p_stats);
@@ -64,17 +64,17 @@
static void update_tx_count_stats(VP9_COMMON *cm) {
int i, j;
- for (i = 0; i < TX_SIZE_MAX_SB; i++) {
+ for (i = 0; i < TX_SIZE_CONTEXTS; i++) {
for (j = 0; j < TX_SIZE_MAX_SB; j++) {
tx_count_32x32p_stats[i][j] += cm->fc.tx_count_32x32p[i][j];
}
}
- for (i = 0; i < TX_SIZE_MAX_SB - 1; i++) {
+ for (i = 0; i < TX_SIZE_CONTEXTS; i++) {
for (j = 0; j < TX_SIZE_MAX_SB - 1; j++) {
tx_count_16x16p_stats[i][j] += cm->fc.tx_count_16x16p[i][j];
}
}
- for (i = 0; i < TX_SIZE_MAX_SB - 2; i++) {
+ for (i = 0; i < TX_SIZE_CONTEXTS; i++) {
for (j = 0; j < TX_SIZE_MAX_SB - 2; j++) {
tx_count_8x8p_stats[i][j] += cm->fc.tx_count_8x8p[i][j];
}
@@ -89,27 +89,30 @@
fwrite(tx_count_8x8p_stats, sizeof(tx_count_8x8p_stats), 1, fp);
fclose(fp);
- printf("vp9_default_tx_count_32x32p[TX_SIZE_MAX_SB][TX_SIZE_MAX_SB] = {\n");
- for (i = 0; i < TX_SIZE_MAX_SB; i++) {
- printf("{ ");
+ printf(
+ "vp9_default_tx_count_32x32p[TX_SIZE_CONTEXTS][TX_SIZE_MAX_SB] = {\n");
+ for (i = 0; i < TX_SIZE_CONTEXTS; i++) {
+ printf(" { ");
for (j = 0; j < TX_SIZE_MAX_SB; j++) {
printf("%"PRId64", ", tx_count_32x32p_stats[i][j]);
}
printf("},\n");
}
printf("};\n");
- printf("vp9_default_tx_count_16x16p[TX_SIZE_MAX_SB-1][TX_SIZE_MAX_SB-1] = {\n");
- for (i = 0; i < TX_SIZE_MAX_SB - 1; i++) {
- printf("{ ");
+ printf(
+ "vp9_default_tx_count_16x16p[TX_SIZE_CONTEXTS][TX_SIZE_MAX_SB-1] = {\n");
+ for (i = 0; i < TX_SIZE_CONTEXTS; i++) {
+ printf(" { ");
for (j = 0; j < TX_SIZE_MAX_SB - 1; j++) {
printf("%"PRId64", ", tx_count_16x16p_stats[i][j]);
}
printf("},\n");
}
printf("};\n");
- printf("vp9_default_tx_count_8x8p[TX_SIZE_MAX_SB-2][TX_SIZE_MAX_SB-2] = {\n");
- for (i = 0; i < TX_SIZE_MAX_SB - 2; i++) {
- printf("{ ");
+ printf(
+ "vp9_default_tx_count_8x8p[TX_SIZE_CONTEXTS][TX_SIZE_MAX_SB-2] = {\n");
+ for (i = 0; i < TX_SIZE_CONTEXTS; i++) {
+ printf(" { ");
for (j = 0; j < TX_SIZE_MAX_SB - 2; j++) {
printf("%"PRId64", ", tx_count_8x8p_stats[i][j]);
}
@@ -1301,7 +1304,7 @@
unsigned int ct_32x32p[TX_SIZE_MAX_SB - 1][2];
- for (i = 0; i < TX_SIZE_MAX_SB - 2; i++) {
+ for (i = 0; i < TX_SIZE_CONTEXTS; i++) {
tx_counts_to_branch_counts_8x8(cm->fc.tx_count_8x8p[i],
ct_8x8p);
for (j = 0; j < TX_SIZE_MAX_SB - 3; j++) {
@@ -1309,7 +1312,7 @@
VP9_DEF_UPDATE_PROB, ct_8x8p[j]);
}
}
- for (i = 0; i < TX_SIZE_MAX_SB - 1; i++) {
+ for (i = 0; i < TX_SIZE_CONTEXTS; i++) {
tx_counts_to_branch_counts_16x16(cm->fc.tx_count_16x16p[i],
ct_16x16p);
for (j = 0; j < TX_SIZE_MAX_SB - 2; j++) {
@@ -1317,7 +1320,7 @@
VP9_DEF_UPDATE_PROB, ct_16x16p[j]);
}
}
- for (i = 0; i < TX_SIZE_MAX_SB; i++) {
+ for (i = 0; i < TX_SIZE_CONTEXTS; i++) {
tx_counts_to_branch_counts_32x32(cm->fc.tx_count_32x32p[i],
ct_32x32p);
for (j = 0; j < TX_SIZE_MAX_SB - 1; j++) {
diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c
index 1ab08bc..f2f85e2 100644
--- a/vp9/encoder/vp9_encodeframe.c
+++ b/vp9/encoder/vp9_encodeframe.c
@@ -1869,28 +1869,28 @@
int count16x16_16x16p = 0, count16x16_lp = 0;
int count32x32 = 0;
- for (i = 0; i < TX_SIZE_MAX_SB; i++)
+ for (i = 0; i < TX_SIZE_CONTEXTS; i++)
count4x4 += cm->fc.tx_count_32x32p[i][TX_4X4];
- for (i = 0; i < TX_SIZE_MAX_SB - 1; i++)
+ for (i = 0; i < TX_SIZE_CONTEXTS; i++)
count4x4 += cm->fc.tx_count_16x16p[i][TX_4X4];
- for (i = 0; i < TX_SIZE_MAX_SB - 2; i++)
+ for (i = 0; i < TX_SIZE_CONTEXTS; i++)
count4x4 += cm->fc.tx_count_8x8p[i][TX_4X4];
- for (i = 0; i < TX_SIZE_MAX_SB; i++)
+ for (i = 0; i < TX_SIZE_CONTEXTS; i++)
count8x8_lp += cm->fc.tx_count_32x32p[i][TX_8X8];
- for (i = 0; i < TX_SIZE_MAX_SB - 1; i++)
+ for (i = 0; i < TX_SIZE_CONTEXTS; i++)
count8x8_lp += cm->fc.tx_count_16x16p[i][TX_8X8];
- for (i = 0; i < TX_SIZE_MAX_SB - 2; i++)
+ for (i = 0; i < TX_SIZE_CONTEXTS; i++)
count8x8_8x8p += cm->fc.tx_count_8x8p[i][TX_8X8];
- for (i = 0; i < TX_SIZE_MAX_SB - 1; i++)
+ for (i = 0; i < TX_SIZE_CONTEXTS; i++)
count16x16_16x16p += cm->fc.tx_count_16x16p[i][TX_16X16];
- for (i = 0; i < TX_SIZE_MAX_SB; i++)
+ for (i = 0; i < TX_SIZE_CONTEXTS; i++)
count16x16_lp += cm->fc.tx_count_32x32p[i][TX_16X16];
- for (i = 0; i < TX_SIZE_MAX_SB; i++)
+ for (i = 0; i < TX_SIZE_CONTEXTS; i++)
count32x32 += cm->fc.tx_count_32x32p[i][TX_32X32];
if (count4x4 == 0 && count16x16_lp == 0 && count16x16_16x16p == 0 &&
diff --git a/vp9/encoder/vp9_onyx_int.h b/vp9/encoder/vp9_onyx_int.h
index 2fd6bbd..2b20f00 100644
--- a/vp9/encoder/vp9_onyx_int.h
+++ b/vp9/encoder/vp9_onyx_int.h
@@ -89,9 +89,9 @@
int inter_mode_counts[INTER_MODE_CONTEXTS][VP9_INTER_MODES - 1][2];
vp9_prob inter_mode_probs[INTER_MODE_CONTEXTS][VP9_INTER_MODES - 1];
- vp9_prob tx_probs_8x8p[TX_SIZE_MAX_SB - 2][TX_SIZE_MAX_SB - 3];
- vp9_prob tx_probs_16x16p[TX_SIZE_MAX_SB - 1][TX_SIZE_MAX_SB - 2];
- vp9_prob tx_probs_32x32p[TX_SIZE_MAX_SB][TX_SIZE_MAX_SB - 1];
+ vp9_prob tx_probs_8x8p[TX_SIZE_CONTEXTS][TX_SIZE_MAX_SB - 3];
+ vp9_prob tx_probs_16x16p[TX_SIZE_CONTEXTS][TX_SIZE_MAX_SB - 2];
+ vp9_prob tx_probs_32x32p[TX_SIZE_CONTEXTS][TX_SIZE_MAX_SB - 1];
vp9_prob mbskip_probs[MBSKIP_CONTEXTS];
} CODING_CONTEXT;