From 040e8284b666a74cbce20b5c2c96f6e9dde9ea1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= Date: Sat, 21 Sep 2013 22:08:23 +0200 Subject: [PATCH] WIP: have_[al] codeblob lut --- libavcodec/vp9.c | 138 +++++++++++-------------------------------------------- 1 file changed, 28 insertions(+), 110 deletions(-) diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index 510a1a9..cfe2777 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -1427,38 +1427,6 @@ static int decode_mode(AVCodecContext *ctx) } else /* single reference */ { int bit, c; -#if 0 - // FIXME can this codeblob be replaced by some sort of LUT? - // ref=intra?0:ref+1, comp=comp?fixcompref+1:0 - // x=lut[aref][acomp][lref][lcomp]; - // then probably a separate 2d lut for the case where only a - // or l is available, and the fixed constant for neither a nor - // l, so you have c = have_a && have_l ? lut4[...] : - // have_a ? lut2[..] : have_l ? lut2[..] : X; - static const uint8_t lut[4][4][4][4] = { - { - { { a, b, c, d }, { a, b, c, d }, { a, b, c, d }, { a, b, c, d } }, - { { a, b, c, d }, { a, b, c, d }, { a, b, c, d }, { a, b, c, d } }, - { { a, b, c, d }, { a, b, c, d }, { a, b, c, d }, { a, b, c, d } }, - { { a, b, c, d }, { a, b, c, d }, { a, b, c, d }, { a, b, c, d } }, - }, { - { { a, b, c, d }, { a, b, c, d }, { a, b, c, d }, { a, b, c, d } }, - { { a, b, c, d }, { a, b, c, d }, { a, b, c, d }, { a, b, c, d } }, - { { a, b, c, d }, { a, b, c, d }, { a, b, c, d }, { a, b, c, d } }, - { { a, b, c, d }, { a, b, c, d }, { a, b, c, d }, { a, b, c, d } }, - }, { - { { a, b, c, d }, { a, b, c, d }, { a, b, c, d }, { a, b, c, d } }, - { { a, b, c, d }, { a, b, c, d }, { a, b, c, d }, { a, b, c, d } }, - { { a, b, c, d }, { a, b, c, d }, { a, b, c, d }, { a, b, c, d } }, - { { a, b, c, d }, { a, b, c, d }, { a, b, c, d }, { a, b, c, d } }, - }, { - { { a, b, c, d }, { a, b, c, d }, { a, b, c, d }, { a, b, c, d } }, - { { a, b, c, d }, { a, b, c, d }, { a, b, c, d }, { a, b, c, d } }, - { { a, b, c, d }, { a, b, c, d }, { a, b, c, d }, { a, b, c, d } }, - { { a, b, c, d }, { a, b, c, d }, { a, b, c, d }, { a, b, c, d } }, - } - }; -#endif if (have_a && !s->above_intra_ctx[col]) { if (have_l && !s->left_intra_ctx[row7]) { if (s->left_comp_ctx[row7]) { @@ -1498,85 +1466,35 @@ static int decode_mode(AVCodecContext *ctx) if (!bit) { b->ref[0] = 0; } else { - // FIXME can this codeblob be replaced by some sort of LUT? - if (have_a) { - if (have_l) { - if (s->left_intra_ctx[row7]) { - if (s->above_intra_ctx[col]) { - c = 2; - } else if (s->above_comp_ctx[col]) { - c = 1 + 2 * (s->fixcompref == 1 || - s->above_ref_ctx[col] == 1); - } else if (!s->above_ref_ctx[col]) { - c = 3; - } else { - c = 4 * (s->above_ref_ctx[col] == 1); - } - } else if (s->above_intra_ctx[col]) { - if (s->left_intra_ctx[row7]) { - c = 2; - } else if (s->left_comp_ctx[row7]) { - c = 1 + 2 * (s->fixcompref == 1 || - s->left_ref_ctx[row7] == 1); - } else if (!s->left_ref_ctx[row7]) { - c = 3; - } else { - c = 4 * (s->left_ref_ctx[row7] == 1); - } - } else if (s->above_comp_ctx[col]) { - if (s->left_comp_ctx[row7]) { - if (s->left_ref_ctx[row7] == s->above_ref_ctx[col]) { - c = 3 * (s->fixcompref == 1 || - s->left_ref_ctx[row7] == 1); - } else { - c = 2; - } - } else if (!s->left_ref_ctx[row7]) { - c = 1 + 2 * (s->fixcompref == 1 || - s->above_ref_ctx[col] == 1); - } else { - c = 3 * (s->left_ref_ctx[row7] == 1) + - (s->fixcompref == 1 || s->above_ref_ctx[col] == 1); - } - } else if (s->left_comp_ctx[row7]) { - if (!s->above_ref_ctx[col]) { - c = 1 + 2 * (s->fixcompref == 1 || - s->left_ref_ctx[row7] == 1); - } else { - c = 3 * (s->above_ref_ctx[col] == 1) + - (s->fixcompref == 1 || s->left_ref_ctx[row7] == 1); - } - } else if (!s->above_ref_ctx[col]) { - if (!s->left_ref_ctx[row7]) { - c = 3; - } else { - c = 4 * (s->left_ref_ctx[row7] == 1); - } - } else if (!s->left_ref_ctx[row7]) { - c = 4 * (s->above_ref_ctx[col] == 1); - } else { - c = 2 * (s->left_ref_ctx[row7] == 1) + - 2 * (s->above_ref_ctx[col] == 1); - } - } else { - if (s->above_intra_ctx[col] || - (!s->above_comp_ctx[col] && !s->above_ref_ctx[col])) { - c = 2; - } else if (s->above_comp_ctx[col]) { - c = 3 * (s->fixcompref == 1 || s->above_ref_ctx[col] == 1); - } else { - c = 4 * (s->above_ref_ctx[col] == 1); - } - } + static const char c_above_or_left_lut[] = { + 2,2,4,4,0,0,0,0,0,3,3,3,0,3,0,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, + }; + static const char c_above_and_left_lut[] = { + 3,3,4,4,0,0,0,0,1,3,3,3,1,3,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, + 4,4,4,4,2,2,2,2,3,4,4,4,3,4,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, + 0,0,2,2,0,0,0,0,0,1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,2,2,0,0,0,0,0,1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 1,3,3,4,0,1,0,1,0,3,2,2,2,2,2,2,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3, + 3,3,4,4,1,1,1,1,2,2,3,3,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, + 1,3,3,4,0,1,0,1,2,2,2,2,0,3,2,2,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3, + 1,3,3,4,0,1,0,1,2,2,2,2,2,2,0,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3, + 3,3,4,4,0,0,0,0,1,3,3,3,1,3,1,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, + 3,3,4,4,0,0,0,0,1,3,3,3,1,3,1,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, + 3,3,4,4,0,0,0,0,1,3,3,3,1,3,1,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, + 3,3,4,4,0,0,0,0,1,3,3,3,1,3,1,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, + 3,3,4,4,0,0,0,0,1,3,3,3,1,3,1,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, + 3,3,4,4,0,0,0,0,1,3,3,3,1,3,1,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, + 3,3,4,4,0,0,0,0,1,3,3,3,1,3,1,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, + 3,3,4,4,0,0,0,0,1,3,3,3,1,3,1,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, + }; + if (have_a && have_l) { + c = c_above_and_left_lut[s->left_intra_ctx[row7]<<8 | s->left_comp_ctx[row7]<<7 | s->left_ref_ctx[row7]<<5 | + s->above_intra_ctx[col]<<4 | s->above_comp_ctx[col]<<3 | s->above_ref_ctx[col]<<1 | + (s->fixcompref == 1)]; } else if (have_l) { - if (s->left_intra_ctx[row7] || - (!s->left_comp_ctx[row7] && !s->left_ref_ctx[row7])) { - c = 2; - } else if (s->left_comp_ctx[row7]) { - c = 3 * (s->fixcompref == 1 || s->left_ref_ctx[row7] == 1); - } else { - c = 4 * (s->left_ref_ctx[row7] == 1); - } + c = c_above_or_left_lut[s->left_intra_ctx[row7]<<4 | s->left_comp_ctx [row7]<<3 | s->left_ref_ctx[row7]<<1 | (s->fixcompref == 1)]; + } else if (have_a) { + c = c_above_or_left_lut[s->above_intra_ctx[col]<<4 | s->above_comp_ctx [col]<<3 | s->above_ref_ctx[col]<<1 | (s->fixcompref == 1)]; } else { c = 2; } -- 1.8.4