[PATCH 0/4] huffyuvdec cleanup
Mostly continuing the work on the VLC parsing and making sure no superfluous operations are performed. Christophe Gisquet (4): huffyuvdec: clean up macro huffyuvdec: trick for plane decoding, 8bits huffyuvdec: remove superfluous check huffyuvdec: remove superfluous check in BGR code libavcodec/huffyuvdec.c | 90 +++++++++++++++++-------------------------------- 1 file changed, 30 insertions(+), 60 deletions(-) -- 1.8.0.msysgit.0
It's no longer used inside another specific macro, so rename it. Also remove duplicated definition and realign code. --- libavcodec/huffyuvdec.c | 58 ++++++++++++++----------------------------------- 1 file changed, 16 insertions(+), 42 deletions(-) diff --git a/libavcodec/huffyuvdec.c b/libavcodec/huffyuvdec.c index 428f9e1..4c0d297 100644 --- a/libavcodec/huffyuvdec.c +++ b/libavcodec/huffyuvdec.c @@ -559,7 +559,8 @@ static av_cold int decode_init_thread_copy(AVCodecContext *avctx) return 0; } -#define DUAL_INTERN(dst, table, gb, name, bits, max_depth) \ +/** Subset of GET_VLC for use in hand-roller VLC code */ +#define VLC_INTERN(dst, table, gb, name, bits, max_depth) \ code = table[index][0]; \ n = table[index][1]; \ if (max_depth > 1 && n < 0) { \ @@ -597,11 +598,11 @@ static av_cold int decode_init_thread_copy(AVCodecContext *avctx) LAST_SKIP_BITS(name, gb, n); \ } else { \ int nb_bits; \ - DUAL_INTERN(dst0, table1, gb, name, bits, max_depth); \ + VLC_INTERN(dst0, table1, gb, name, bits, max_depth); \ \ UPDATE_CACHE(re, gb); \ index = SHOW_UBITS(name, gb, bits); \ - DUAL_INTERN(dst1, table2, gb, name, bits, max_depth); \ + VLC_INTERN(dst1, table2, gb, name, bits, max_depth); \ } \ } while (0) @@ -720,33 +721,6 @@ static void decode_gray_bitstream(HYuvContext *s, int count) CLOSE_READER(re, &s->gb); } -#define GET_VLC_DUAL(dst0, dst1, name, gb, dtable, table1, table2, \ - bits, max_depth, rsvd ) \ - do { \ - unsigned int index = SHOW_UBITS(name, gb, bits); \ - int code = dtable[index][0]; \ - int n = dtable[index][1]; \ - \ - if (code != rsvd && n>0) { \ - dst0 = code>>8; \ - dst1 = code; \ - LAST_SKIP_BITS(name, gb, n); \ - } else { \ - int nb_bits; \ - DUAL_INTERN(dst0, table1, gb, name, bits, max_depth); \ - \ - UPDATE_CACHE(re, gb); \ - index = SHOW_UBITS(name, gb, bits); \ - DUAL_INTERN(dst1, table2, gb, name, bits, max_depth); \ - } \ - } while (0) - -#define READ_2PIX(dst0, dst1, plane1)\ - UPDATE_CACHE(re, &s->gb); \ - GET_VLC_DUAL(dst0, dst1, re, &s->gb, s->vlc[4+plane1].table, \ - s->vlc[0].table, s->vlc[plane1].table, \ - VLC_BITS, 3, 0xffff) - static av_always_inline void decode_bgr_1(HYuvContext *s, int count, int decorrelate, int alpha) { @@ -768,37 +742,37 @@ static av_always_inline void decode_bgr_1(HYuvContext *s, int count, } else { int nb_bits; if(decorrelate) { - DUAL_INTERN(s->temp[0][4 * i + G], s->vlc[1].table, - &s->gb, re, VLC_BITS, 3); + VLC_INTERN(s->temp[0][4 * i + G], s->vlc[1].table, + &s->gb, re, VLC_BITS, 3); UPDATE_CACHE(re, &s->gb); index = SHOW_UBITS(re, &s->gb, VLC_BITS); - DUAL_INTERN(code, s->vlc[0].table, &s->gb, re, VLC_BITS, 3); + VLC_INTERN(code, s->vlc[0].table, &s->gb, re, VLC_BITS, 3); s->temp[0][4 * i + B] = code + s->temp[0][4 * i + G]; UPDATE_CACHE(re, &s->gb); index = SHOW_UBITS(re, &s->gb, VLC_BITS); - DUAL_INTERN(code, s->vlc[2].table, &s->gb, re, VLC_BITS, 3); + VLC_INTERN(code, s->vlc[2].table, &s->gb, re, VLC_BITS, 3); s->temp[0][4 * i + R] = code + s->temp[0][4 * i + G]; } else { - DUAL_INTERN(s->temp[0][4 * i + B], s->vlc[0].table, - &s->gb, re, VLC_BITS, 3); + VLC_INTERN(s->temp[0][4 * i + B], s->vlc[0].table, + &s->gb, re, VLC_BITS, 3); UPDATE_CACHE(re, &s->gb); index = SHOW_UBITS(re, &s->gb, VLC_BITS); - DUAL_INTERN(s->temp[0][4 * i + G], s->vlc[1].table, - &s->gb, re, VLC_BITS, 3); + VLC_INTERN(s->temp[0][4 * i + G], s->vlc[1].table, + &s->gb, re, VLC_BITS, 3); UPDATE_CACHE(re, &s->gb); index = SHOW_UBITS(re, &s->gb, VLC_BITS); - DUAL_INTERN(s->temp[0][4 * i + R], s->vlc[2].table, - &s->gb, re, VLC_BITS, 3); + VLC_INTERN(s->temp[0][4 * i + R], s->vlc[2].table, + &s->gb, re, VLC_BITS, 3); } if (alpha) { UPDATE_CACHE(re, &s->gb); index = SHOW_UBITS(re, &s->gb, VLC_BITS); - DUAL_INTERN(s->temp[0][4 * i + A], s->vlc[2].table, - &s->gb, re, VLC_BITS, 3); + VLC_INTERN(s->temp[0][4 * i + A], s->vlc[2].table, + &s->gb, re, VLC_BITS, 3); } } } -- 1.8.0.msysgit.0
On Wed, Jun 04, 2014 at 08:48:56PM +0000, Christophe Gisquet wrote:
It's no longer used inside another specific macro, so rename it. Also remove duplicated definition and realign code. --- libavcodec/huffyuvdec.c | 58 ++++++++++++++----------------------------------- 1 file changed, 16 insertions(+), 42 deletions(-)
applied thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB No human being will ever know the Truth, for even if they happen to say it by chance, they would not even known they had done so. -- Xenophanes
10496 -> 9105 cycles. --- libavcodec/huffyuvdec.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/libavcodec/huffyuvdec.c b/libavcodec/huffyuvdec.c index 4c0d297..01c01ce 100644 --- a/libavcodec/huffyuvdec.c +++ b/libavcodec/huffyuvdec.c @@ -637,16 +637,12 @@ static void decode_422_bitstream(HYuvContext *s, int count) /* TODO instead of restarting the read when the code isn't in the first level * of the joint table, jump into the 2nd level of the individual table. */ -#define READ_2PIX_PLANE(dst0, dst1, plane){\ - uint16_t code = get_vlc2(&s->gb, s->vlc[4+plane].table, VLC_BITS, 1);\ - if(code != 0xffff){\ - dst0 = code>>8;\ - dst1 = code;\ - }else{\ - dst0 = get_vlc2(&s->gb, s->vlc[plane].table, VLC_BITS, 3);\ - dst1 = get_vlc2(&s->gb, s->vlc[plane].table, VLC_BITS, 3);\ - }\ -} +#define READ_2PIX_PLANE(dst0, dst1, plane) \ + UPDATE_CACHE(re, &s->gb); \ + GET_VLC_DUAL(dst0, dst1, re, &s->gb, s->vlc[4+plane].table, \ + s->vlc[plane].table, s->vlc[plane].table, \ + VLC_BITS, 3, 0xffff) + #define READ_2PIX_PLANE14(dst0, dst1, plane){\ int16_t code = get_vlc2(&s->gb, s->vlc[4+plane].table, VLC_BITS, 1);\ if(code != (int16_t)0xffff){\ @@ -671,6 +667,7 @@ static void decode_plane_bitstream(HYuvContext *s, int count, int plane) count/=2; if (s->bps <= 8) { + OPEN_READER(re, &s->gb); if (count >= (get_bits_left(&s->gb)) / (31 * 2)) { for (i = 0; i < count && get_bits_left(&s->gb) > 0; i++) { READ_2PIX_PLANE(s->temp[0][2 * i], s->temp[0][2 * i + 1], plane); @@ -680,6 +677,7 @@ static void decode_plane_bitstream(HYuvContext *s, int count, int plane) READ_2PIX_PLANE(s->temp[0][2 * i], s->temp[0][2 * i + 1], plane); } } + CLOSE_READER(re, &s->gb); } else if (s->bps <= 14) { if (count >= (get_bits_left(&s->gb)) / (31 * 2)) { for (i = 0; i < count && get_bits_left(&s->gb) > 0; i++) { -- 1.8.0.msysgit.0
On Wed, Jun 04, 2014 at 08:48:57PM +0000, Christophe Gisquet wrote:
10496 -> 9105 cycles. --- libavcodec/huffyuvdec.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
applied thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Those who are best at talking, realize last or never when they are wrong.
An invalid entry already has the property of having a negative number of bits, so remove the check on the reserved value, and rearrange the code as a consequence. 346800 decicycles in 422, 262079 runs, 65 skips 168197 decicycles in gray, 262077 runs, 67 skips Overall time: 7.878s 319076 decicycles in 422, 262096 runs, 48 skips 159875 decicycles in gray, 262057 runs, 87 skips Overall time: 7.394s --- libavcodec/huffyuvdec.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/libavcodec/huffyuvdec.c b/libavcodec/huffyuvdec.c index 01c01ce..dc803cd 100644 --- a/libavcodec/huffyuvdec.c +++ b/libavcodec/huffyuvdec.c @@ -586,13 +586,13 @@ static av_cold int decode_init_thread_copy(AVCodecContext *avctx) #define GET_VLC_DUAL(dst0, dst1, name, gb, dtable, table1, table2, \ - bits, max_depth, rsvd ) \ + bits, max_depth) \ do { \ unsigned int index = SHOW_UBITS(name, gb, bits); \ - int code = dtable[index][0]; \ - int n = dtable[index][1]; \ + int code, n = dtable[index][1]; \ \ - if (code != rsvd && n>0) { \ + if (n>0) { \ + code = dtable[index][0]; \ dst0 = code>>8; \ dst1 = code; \ LAST_SKIP_BITS(name, gb, n); \ @@ -609,8 +609,7 @@ static av_cold int decode_init_thread_copy(AVCodecContext *avctx) #define READ_2PIX(dst0, dst1, plane1)\ UPDATE_CACHE(re, &s->gb); \ GET_VLC_DUAL(dst0, dst1, re, &s->gb, s->vlc[4+plane1].table, \ - s->vlc[0].table, s->vlc[plane1].table, \ - VLC_BITS, 3, 0xffff) + s->vlc[0].table, s->vlc[plane1].table, VLC_BITS, 3) static void decode_422_bitstream(HYuvContext *s, int count) { @@ -640,8 +639,7 @@ static void decode_422_bitstream(HYuvContext *s, int count) #define READ_2PIX_PLANE(dst0, dst1, plane) \ UPDATE_CACHE(re, &s->gb); \ GET_VLC_DUAL(dst0, dst1, re, &s->gb, s->vlc[4+plane].table, \ - s->vlc[plane].table, s->vlc[plane].table, \ - VLC_BITS, 3, 0xffff) + s->vlc[plane].table, s->vlc[plane].table, VLC_BITS, 3) #define READ_2PIX_PLANE14(dst0, dst1, plane){\ int16_t code = get_vlc2(&s->gb, s->vlc[4+plane].table, VLC_BITS, 1);\ -- 1.8.0.msysgit.0
On Wed, Jun 04, 2014 at 08:48:58PM +0000, Christophe Gisquet wrote:
An invalid entry already has the property of having a negative number of bits, so remove the check on the reserved value, and rearrange the code as a consequence.
346800 decicycles in 422, 262079 runs, 65 skips 168197 decicycles in gray, 262077 runs, 67 skips Overall time: 7.878s
319076 decicycles in 422, 262096 runs, 48 skips 159875 decicycles in gray, 262057 runs, 87 skips Overall time: 7.394s --- libavcodec/huffyuvdec.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
applied thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Democracy is the form of government in which you can choose your dictator
Before: 154861 decicycles After: 152912 decicycles --- libavcodec/huffyuvdec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/huffyuvdec.c b/libavcodec/huffyuvdec.c index dc803cd..6c925d3 100644 --- a/libavcodec/huffyuvdec.c +++ b/libavcodec/huffyuvdec.c @@ -729,10 +729,10 @@ static av_always_inline void decode_bgr_1(HYuvContext *s, int count, UPDATE_CACHE(re, &s->gb); index = SHOW_UBITS(re, &s->gb, VLC_BITS); - code = s->vlc[4].table[index][0]; n = s->vlc[4].table[index][1]; - if (code != -1) { + if (n>0) { + code = s->vlc[4].table[index][0]; *(uint32_t*)&s->temp[0][4 * i] = s->pix_bgr_map[code]; LAST_SKIP_BITS(re, &s->gb, n); } else { -- 1.8.0.msysgit.0
On Wed, Jun 04, 2014 at 08:48:59PM +0000, Christophe Gisquet wrote:
Before: 154861 decicycles After: 152912 decicycles --- libavcodec/huffyuvdec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
applied thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Breaking DRM is a little like attempting to break through a door even though the window is wide open and the only thing in the house is a bunch of things you dont want and which you would get tomorrow for free anyway
participants (2)
-
Christophe Gisquet -
Michael Niedermayer