static void await_references(H264Context *h){
    MpegEncContext * const s = &h->s;
    const int mb_xy= h->mb_xy;
    const int mb_type= s->current_picture.mb_type[mb_xy];
    int refs[2][48];
    int nrefs[2] = {0};
    int ref, list;
    memset(refs, -1, sizeof(refs));
    if(IS_16X16(mb_type)){
        get_lowest_part_y(h, refs, 0, 16, 0,
                  IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);
    }else if(IS_16X8(mb_type)){
        get_lowest_part_y(h, refs, 0, 8, 0,
                  IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);
        get_lowest_part_y(h, refs, 8, 8, 8,
                  IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), nrefs);
    }else if(IS_8X16(mb_type)){
        get_lowest_part_y(h, refs, 0, 16, 0,
                  IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);
        get_lowest_part_y(h, refs, 4, 16, 0,
                  IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), nrefs);
    }else{
        int i;
        assert(IS_8X8(mb_type));
        for(i=0; i<4; i++){
            const int sub_mb_type= h->sub_mb_type[i];
            const int n= 4*i;
            int y_offset= (i&2)<<2;
            if(IS_SUB_8X8(sub_mb_type)){
                get_lowest_part_y(h, refs, n  , 8, y_offset,
                          IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);
            }else if(IS_SUB_8X4(sub_mb_type)){
                get_lowest_part_y(h, refs, n  , 4, y_offset,
                          IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);
                get_lowest_part_y(h, refs, n+2, 4, y_offset+4,
                          IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);
            }else if(IS_SUB_4X8(sub_mb_type)){
                get_lowest_part_y(h, refs, n  , 8, y_offset,
                          IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);
                get_lowest_part_y(h, refs, n+1, 8, y_offset,
                          IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);
            }else{
                int j;
                assert(IS_SUB_4X4(sub_mb_type));
                for(j=0; j<4; j++){
                    int sub_y_offset= y_offset + 2*(j&2);
                    get_lowest_part_y(h, refs, n+j, 4, sub_y_offset,
                              IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);
                }
            }
        }
    }
    for(list=h->list_count-1; list>=0; list--){
        for(ref=0; ref<48 && nrefs[list]; ref++){
            int row = refs[list][ref];
            if(row >= 0){
                Picture *ref_pic = &h->ref_list[list][ref];
                int ref_field = ref_pic->reference - 1;
                int ref_field_picture = ref_pic->field_picture;
                int pic_height = 16*s->mb_height >> ref_field_picture;
                row <<= MB_MBAFF;
                nrefs[list]--;
                if(!FIELD_PICTURE && ref_field_picture){
                    ff_thread_await_progress((AVFrame*)ref_pic, FFMIN((row >> 1) - !(row&1), pic_height-1), 1);
                    ff_thread_await_progress((AVFrame*)ref_pic, FFMIN((row >> 1)           , pic_height-1), 0);
                }else if(FIELD_PICTURE && !ref_field_picture){
                    ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row*2 + ref_field    , pic_height-1), 0);
                }else if(FIELD_PICTURE){
                    ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row, pic_height-1), ref_field);
                }else{
                    ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row, pic_height-1), 0);
                }
            }
        }
    }
}
['static int decode_slice(struct AVCodecContext *avctx, void *arg){\n    H264Context *h = *(void**)arg;\n    MpegEncContext * const s = &h->s;\n    const int part_mask= s->partitioned_frame ? (AC_END|AC_ERROR) : 0x7F;\n    int lf_x_start = s->mb_x;\n    s->mb_skip_run= -1;\n    h->is_complex = FRAME_MBAFF || s->picture_structure != PICT_FRAME || s->codec_id != CODEC_ID_H264 ||\n                    (CONFIG_GRAY && (s->flags&CODEC_FLAG_GRAY));\n    if( h->pps.cabac ) {\n        align_get_bits( &s->gb );\n        ff_init_cabac_states( &h->cabac);\n        ff_init_cabac_decoder( &h->cabac,\n                               s->gb.buffer + get_bits_count(&s->gb)/8,\n                               (get_bits_left(&s->gb) + 7)/8);\n        ff_h264_init_cabac_states(h);\n        for(;;){\n            int ret = ff_h264_decode_mb_cabac(h);\n            int eos;\n            if(ret>=0) ff_h264_hl_decode_mb(h);\n            if( ret >= 0 && FRAME_MBAFF ) {\n                s->mb_y++;\n                ret = ff_h264_decode_mb_cabac(h);\n                if(ret>=0) ff_h264_hl_decode_mb(h);\n                s->mb_y--;\n            }\n            eos = get_cabac_terminate( &h->cabac );\n            if((s->workaround_bugs & FF_BUG_TRUNCATED) && h->cabac.bytestream > h->cabac.bytestream_end + 2){\n                ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);\n                if (s->mb_x >= lf_x_start) loop_filter(h, lf_x_start, s->mb_x + 1);\n                return 0;\n            }\n            if( ret < 0 || h->cabac.bytestream > h->cabac.bytestream_end + 2) {\n                av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d, bytestream (%td)\\n", s->mb_x, s->mb_y, h->cabac.bytestream_end - h->cabac.bytestream);\n                ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);\n                return -1;\n            }\n            if( ++s->mb_x >= s->mb_width ) {\n                loop_filter(h, lf_x_start, s->mb_x);\n                s->mb_x = lf_x_start = 0;\n                decode_finish_row(h);\n                ++s->mb_y;\n                if(FIELD_OR_MBAFF_PICTURE) {\n                    ++s->mb_y;\n                    if(FRAME_MBAFF && s->mb_y < s->mb_height)\n                        predict_field_decoding_flag(h);\n                }\n            }\n            if( eos || s->mb_y >= s->mb_height ) {\n                tprintf(s->avctx, "slice end %d %d\\n", get_bits_count(&s->gb), s->gb.size_in_bits);\n                ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);\n                if (s->mb_x > lf_x_start) loop_filter(h, lf_x_start, s->mb_x);\n                return 0;\n            }\n        }\n    } else {\n        for(;;){\n            int ret = ff_h264_decode_mb_cavlc(h);\n            if(ret>=0) ff_h264_hl_decode_mb(h);\n            if(ret>=0 && FRAME_MBAFF){\n                s->mb_y++;\n                ret = ff_h264_decode_mb_cavlc(h);\n                if(ret>=0) ff_h264_hl_decode_mb(h);\n                s->mb_y--;\n            }\n            if(ret<0){\n                av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d\\n", s->mb_x, s->mb_y);\n                ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);\n                return -1;\n            }\n            if(++s->mb_x >= s->mb_width){\n                loop_filter(h, lf_x_start, s->mb_x);\n                s->mb_x = lf_x_start = 0;\n                decode_finish_row(h);\n                ++s->mb_y;\n                if(FIELD_OR_MBAFF_PICTURE) {\n                    ++s->mb_y;\n                    if(FRAME_MBAFF && s->mb_y < s->mb_height)\n                        predict_field_decoding_flag(h);\n                }\n                if(s->mb_y >= s->mb_height){\n                    tprintf(s->avctx, "slice end %d %d\\n", get_bits_count(&s->gb), s->gb.size_in_bits);\n                    if(get_bits_count(&s->gb) == s->gb.size_in_bits ) {\n                        ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);\n                        return 0;\n                    }else{\n                        ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);\n                        return -1;\n                    }\n                }\n            }\n            if(get_bits_count(&s->gb) >= s->gb.size_in_bits && s->mb_skip_run<=0){\n                tprintf(s->avctx, "slice end %d %d\\n", get_bits_count(&s->gb), s->gb.size_in_bits);\n                if(get_bits_count(&s->gb) == s->gb.size_in_bits ){\n                    ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);\n                    if (s->mb_x > lf_x_start) loop_filter(h, lf_x_start, s->mb_x);\n                    return 0;\n                }else{\n                    ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);\n                    return -1;\n                }\n            }\n        }\n    }\n#if 0\n    for(;s->mb_y < s->mb_height; s->mb_y++){\n        for(;s->mb_x < s->mb_width; s->mb_x++){\n            int ret= decode_mb(h);\n            ff_h264_hl_decode_mb(h);\n            if(ret<0){\n                av_log(s->avctx, AV_LOG_ERROR, "error while decoding MB %d %d\\n", s->mb_x, s->mb_y);\n                ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);\n                return -1;\n            }\n            if(++s->mb_x >= s->mb_width){\n                s->mb_x=0;\n                if(++s->mb_y >= s->mb_height){\n                    if(get_bits_count(s->gb) == s->gb.size_in_bits){\n                        ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);\n                        return 0;\n                    }else{\n                        ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);\n                        return -1;\n                    }\n                }\n            }\n            if(get_bits_count(s->?gb) >= s->gb?.size_in_bits){\n                if(get_bits_count(s->gb) == s->gb.size_in_bits){\n                    ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);\n                    return 0;\n                }else{\n                    ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);\n                    return -1;\n                }\n            }\n        }\n        s->mb_x=0;\n        ff_draw_horiz_band(s, 16*s->mb_y, 16);\n    }\n#endif\n    return -1;\n}', 'int ff_h264_decode_mb_cabac(H264Context *h) {\n    MpegEncContext * const s = &h->s;\n    int mb_xy;\n    int mb_type, partition_count, cbp = 0;\n    int dct8x8_allowed= h->pps.transform_8x8_mode;\n    const int pixel_shift = h->pixel_shift;\n    mb_xy = h->mb_xy = s->mb_x + s->mb_y*s->mb_stride;\n    tprintf(s->avctx, "pic:%d mb:%d/%d\\n", h->frame_num, s->mb_x, s->mb_y);\n    if( h->slice_type_nos != AV_PICTURE_TYPE_I ) {\n        int skip;\n        if( FRAME_MBAFF && (s->mb_y&1)==1 && h->prev_mb_skipped )\n            skip = h->next_mb_skipped;\n        else\n            skip = decode_cabac_mb_skip( h, s->mb_x, s->mb_y );\n        if( skip ) {\n            if( FRAME_MBAFF && (s->mb_y&1)==0 ){\n                s->current_picture.mb_type[mb_xy] = MB_TYPE_SKIP;\n                h->next_mb_skipped = decode_cabac_mb_skip( h, s->mb_x, s->mb_y+1 );\n                if(!h->next_mb_skipped)\n                    h->mb_mbaff = h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h);\n            }\n            decode_mb_skip(h);\n            h->cbp_table[mb_xy] = 0;\n            h->chroma_pred_mode_table[mb_xy] = 0;\n            h->last_qscale_diff = 0;\n            return 0;\n        }\n    }\n    if(FRAME_MBAFF){\n        if( (s->mb_y&1) == 0 )\n            h->mb_mbaff =\n            h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h);\n    }\n    h->prev_mb_skipped = 0;\n    fill_decode_neighbors(h, -(MB_FIELD));\n    if( h->slice_type_nos == AV_PICTURE_TYPE_B ) {\n        int ctx = 0;\n        assert(h->slice_type_nos == AV_PICTURE_TYPE_B);\n        if( !IS_DIRECT( h->left_type[0]-1 ) )\n            ctx++;\n        if( !IS_DIRECT( h->top_type-1 ) )\n            ctx++;\n        if( !get_cabac_noinline( &h->cabac, &h->cabac_state[27+ctx] ) ){\n            mb_type= 0;\n        }else if( !get_cabac_noinline( &h->cabac, &h->cabac_state[27+3] ) ) {\n            mb_type= 1 + get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] );\n        }else{\n            int bits;\n            bits = get_cabac_noinline( &h->cabac, &h->cabac_state[27+4] ) << 3;\n            bits+= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] ) << 2;\n            bits+= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] ) << 1;\n            bits+= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] );\n            if( bits < 8 ){\n                mb_type= bits + 3;\n            }else if( bits == 13 ){\n                mb_type= decode_cabac_intra_mb_type(h, 32, 0);\n                goto decode_intra_mb;\n            }else if( bits == 14 ){\n                mb_type= 11;\n            }else if( bits == 15 ){\n                mb_type= 22;\n            }else{\n                bits= ( bits<<1 ) + get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] );\n                mb_type= bits - 4;\n            }\n        }\n            partition_count= b_mb_type_info[mb_type].partition_count;\n            mb_type=         b_mb_type_info[mb_type].type;\n    } else if( h->slice_type_nos == AV_PICTURE_TYPE_P ) {\n        if( get_cabac_noinline( &h->cabac, &h->cabac_state[14] ) == 0 ) {\n            if( get_cabac_noinline( &h->cabac, &h->cabac_state[15] ) == 0 ) {\n                mb_type= 3 * get_cabac_noinline( &h->cabac, &h->cabac_state[16] );\n            } else {\n                mb_type= 2 - get_cabac_noinline( &h->cabac, &h->cabac_state[17] );\n            }\n            partition_count= p_mb_type_info[mb_type].partition_count;\n            mb_type=         p_mb_type_info[mb_type].type;\n        } else {\n            mb_type= decode_cabac_intra_mb_type(h, 17, 0);\n            goto decode_intra_mb;\n        }\n    } else {\n        mb_type= decode_cabac_intra_mb_type(h, 3, 1);\n        if(h->slice_type == AV_PICTURE_TYPE_SI && mb_type)\n            mb_type--;\n        assert(h->slice_type_nos == AV_PICTURE_TYPE_I);\ndecode_intra_mb:\n        partition_count = 0;\n        cbp= i_mb_type_info[mb_type].cbp;\n        h->intra16x16_pred_mode= i_mb_type_info[mb_type].pred_mode;\n        mb_type= i_mb_type_info[mb_type].type;\n    }\n    if(MB_FIELD)\n        mb_type |= MB_TYPE_INTERLACED;\n    h->slice_table[ mb_xy ]= h->slice_num;\n    if(IS_INTRA_PCM(mb_type)) {\n        const int mb_size = (384*h->sps.bit_depth_luma) >> 3;\n        const uint8_t *ptr;\n        ptr= h->cabac.bytestream;\n        if(h->cabac.low&0x1) ptr--;\n        if(CABAC_BITS==16){\n            if(h->cabac.low&0x1FF) ptr--;\n        }\n        memcpy(h->mb, ptr, 2*mb_size/3); ptr+=2*mb_size/3;\n        if(CHROMA){\n            memcpy(h->mb+mb_size/3, ptr, mb_size/3); ptr+=mb_size/3;\n        }\n        ff_init_cabac_decoder(&h->cabac, ptr, h->cabac.bytestream_end - ptr);\n        h->cbp_table[mb_xy] = 0x1ef;\n        h->chroma_pred_mode_table[mb_xy] = 0;\n        s->current_picture.qscale_table[mb_xy]= 0;\n        memset(h->non_zero_count[mb_xy], 16, 32);\n        s->current_picture.mb_type[mb_xy]= mb_type;\n        h->last_qscale_diff = 0;\n        return 0;\n    }\n    if(MB_MBAFF){\n        h->ref_count[0] <<= 1;\n        h->ref_count[1] <<= 1;\n    }\n    fill_decode_caches(h, mb_type);\n    if( IS_INTRA( mb_type ) ) {\n        int i, pred_mode;\n        if( IS_INTRA4x4( mb_type ) ) {\n            if( dct8x8_allowed && get_cabac_noinline( &h->cabac, &h->cabac_state[399 + h->neighbor_transform_size] ) ) {\n                mb_type |= MB_TYPE_8x8DCT;\n                for( i = 0; i < 16; i+=4 ) {\n                    int pred = pred_intra_mode( h, i );\n                    int mode = decode_cabac_mb_intra4x4_pred_mode( h, pred );\n                    fill_rectangle( &h->intra4x4_pred_mode_cache[ scan8[i] ], 2, 2, 8, mode, 1 );\n                }\n            } else {\n                for( i = 0; i < 16; i++ ) {\n                    int pred = pred_intra_mode( h, i );\n                    h->intra4x4_pred_mode_cache[ scan8[i] ] = decode_cabac_mb_intra4x4_pred_mode( h, pred );\n                }\n            }\n            ff_h264_write_back_intra_pred_mode(h);\n            if( ff_h264_check_intra4x4_pred_mode(h) < 0 ) return -1;\n        } else {\n            h->intra16x16_pred_mode= ff_h264_check_intra_pred_mode( h, h->intra16x16_pred_mode );\n            if( h->intra16x16_pred_mode < 0 ) return -1;\n        }\n        if(CHROMA){\n            h->chroma_pred_mode_table[mb_xy] =\n            pred_mode                        = decode_cabac_mb_chroma_pre_mode( h );\n            pred_mode= ff_h264_check_intra_pred_mode( h, pred_mode );\n            if( pred_mode < 0 ) return -1;\n            h->chroma_pred_mode= pred_mode;\n        } else {\n            h->chroma_pred_mode= DC_128_PRED8x8;\n        }\n    } else if( partition_count == 4 ) {\n        int i, j, sub_partition_count[4], list, ref[2][4];\n        if( h->slice_type_nos == AV_PICTURE_TYPE_B ) {\n            for( i = 0; i < 4; i++ ) {\n                h->sub_mb_type[i] = decode_cabac_b_mb_sub_type( h );\n                sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;\n                h->sub_mb_type[i]=      b_sub_mb_type_info[ h->sub_mb_type[i] ].type;\n            }\n            if( IS_DIRECT(h->sub_mb_type[0] | h->sub_mb_type[1] |\n                          h->sub_mb_type[2] | h->sub_mb_type[3]) ) {\n                ff_h264_pred_direct_motion(h, &mb_type);\n                h->ref_cache[0][scan8[4]] =\n                h->ref_cache[1][scan8[4]] =\n                h->ref_cache[0][scan8[12]] =\n                h->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE;\n                    for( i = 0; i < 4; i++ )\n                        fill_rectangle( &h->direct_cache[scan8[4*i]], 2, 2, 8, (h->sub_mb_type[i]>>1)&0xFF, 1 );\n            }\n        } else {\n            for( i = 0; i < 4; i++ ) {\n                h->sub_mb_type[i] = decode_cabac_p_mb_sub_type( h );\n                sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;\n                h->sub_mb_type[i]=      p_sub_mb_type_info[ h->sub_mb_type[i] ].type;\n            }\n        }\n        for( list = 0; list < h->list_count; list++ ) {\n                for( i = 0; i < 4; i++ ) {\n                    if(IS_DIRECT(h->sub_mb_type[i])) continue;\n                    if(IS_DIR(h->sub_mb_type[i], 0, list)){\n                        if( h->ref_count[list] > 1 ){\n                            ref[list][i] = decode_cabac_mb_ref( h, list, 4*i );\n                            if(ref[list][i] >= (unsigned)h->ref_count[list]){\n                                av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\\n", ref[list][i], h->ref_count[list]);\n                                return -1;\n                            }\n                        }else\n                            ref[list][i] = 0;\n                    } else {\n                        ref[list][i] = -1;\n                    }\n                                                       h->ref_cache[list][ scan8[4*i]+1 ]=\n                    h->ref_cache[list][ scan8[4*i]+8 ]=h->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i];\n                }\n        }\n        if(dct8x8_allowed)\n            dct8x8_allowed = get_dct8x8_allowed(h);\n        for(list=0; list<h->list_count; list++){\n            for(i=0; i<4; i++){\n                h->ref_cache[list][ scan8[4*i]   ]=h->ref_cache[list][ scan8[4*i]+1 ];\n                if(IS_DIRECT(h->sub_mb_type[i])){\n                    fill_rectangle(h->mvd_cache[list][scan8[4*i]], 2, 2, 8, 0, 2);\n                    continue;\n                }\n                if(IS_DIR(h->sub_mb_type[i], 0, list) && !IS_DIRECT(h->sub_mb_type[i])){\n                    const int sub_mb_type= h->sub_mb_type[i];\n                    const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1;\n                    for(j=0; j<sub_partition_count[i]; j++){\n                        int mpx, mpy;\n                        int mx, my;\n                        const int index= 4*i + block_width*j;\n                        int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ];\n                        uint8_t (* mvd_cache)[2]= &h->mvd_cache[list][ scan8[index] ];\n                        pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my);\n                        DECODE_CABAC_MB_MVD( h, list, index)\n                        tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n                        if(IS_SUB_8X8(sub_mb_type)){\n                            mv_cache[ 1 ][0]=\n                            mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx;\n                            mv_cache[ 1 ][1]=\n                            mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my;\n                            mvd_cache[ 1 ][0]=\n                            mvd_cache[ 8 ][0]= mvd_cache[ 9 ][0]= mpx;\n                            mvd_cache[ 1 ][1]=\n                            mvd_cache[ 8 ][1]= mvd_cache[ 9 ][1]= mpy;\n                        }else if(IS_SUB_8X4(sub_mb_type)){\n                            mv_cache[ 1 ][0]= mx;\n                            mv_cache[ 1 ][1]= my;\n                            mvd_cache[ 1 ][0]=  mpx;\n                            mvd_cache[ 1 ][1]= mpy;\n                        }else if(IS_SUB_4X8(sub_mb_type)){\n                            mv_cache[ 8 ][0]= mx;\n                            mv_cache[ 8 ][1]= my;\n                            mvd_cache[ 8 ][0]= mpx;\n                            mvd_cache[ 8 ][1]= mpy;\n                        }\n                        mv_cache[ 0 ][0]= mx;\n                        mv_cache[ 0 ][1]= my;\n                        mvd_cache[ 0 ][0]= mpx;\n                        mvd_cache[ 0 ][1]= mpy;\n                    }\n                }else{\n                    fill_rectangle(h->mv_cache [list][ scan8[4*i] ], 2, 2, 8, 0, 4);\n                    fill_rectangle(h->mvd_cache[list][ scan8[4*i] ], 2, 2, 8, 0, 2);\n                }\n            }\n        }\n    } else if( IS_DIRECT(mb_type) ) {\n        ff_h264_pred_direct_motion(h, &mb_type);\n        fill_rectangle(h->mvd_cache[0][scan8[0]], 4, 4, 8, 0, 2);\n        fill_rectangle(h->mvd_cache[1][scan8[0]], 4, 4, 8, 0, 2);\n        dct8x8_allowed &= h->sps.direct_8x8_inference_flag;\n    } else {\n        int list, i;\n        if(IS_16X16(mb_type)){\n            for(list=0; list<h->list_count; list++){\n                if(IS_DIR(mb_type, 0, list)){\n                    int ref;\n                    if(h->ref_count[list] > 1){\n                        ref= decode_cabac_mb_ref(h, list, 0);\n                        if(ref >= (unsigned)h->ref_count[list]){\n                            av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\\n", ref, h->ref_count[list]);\n                            return -1;\n                        }\n                    }else\n                        ref=0;\n                        fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, ref, 1);\n                }\n            }\n            for(list=0; list<h->list_count; list++){\n                if(IS_DIR(mb_type, 0, list)){\n                    int mx,my,mpx,mpy;\n                    pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my);\n                    DECODE_CABAC_MB_MVD( h, list, 0)\n                    tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n                    fill_rectangle(h->mvd_cache[list][ scan8[0] ], 4, 4, 8, pack8to16(mpx,mpy), 2);\n                    fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4);\n                }\n            }\n        }\n        else if(IS_16X8(mb_type)){\n            for(list=0; list<h->list_count; list++){\n                    for(i=0; i<2; i++){\n                        if(IS_DIR(mb_type, i, list)){\n                            int ref;\n                            if(h->ref_count[list] > 1){\n                                ref= decode_cabac_mb_ref( h, list, 8*i );\n                                if(ref >= (unsigned)h->ref_count[list]){\n                                    av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\\n", ref, h->ref_count[list]);\n                                    return -1;\n                                }\n                            }else\n                                ref=0;\n                            fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, ref, 1);\n                        }else\n                            fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, (LIST_NOT_USED&0xFF), 1);\n                    }\n            }\n            for(list=0; list<h->list_count; list++){\n                for(i=0; i<2; i++){\n                    if(IS_DIR(mb_type, i, list)){\n                        int mx,my,mpx,mpy;\n                        pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my);\n                        DECODE_CABAC_MB_MVD( h, list, 8*i)\n                        tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n                        fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack8to16(mpx,mpy), 2);\n                        fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4);\n                    }else{\n                        fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 2);\n                        fill_rectangle(h-> mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4);\n                    }\n                }\n            }\n        }else{\n            assert(IS_8X16(mb_type));\n            for(list=0; list<h->list_count; list++){\n                    for(i=0; i<2; i++){\n                        if(IS_DIR(mb_type, i, list)){\n                            int ref;\n                            if(h->ref_count[list] > 1){\n                                ref= decode_cabac_mb_ref( h, list, 4*i );\n                                if(ref >= (unsigned)h->ref_count[list]){\n                                    av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\\n", ref, h->ref_count[list]);\n                                    return -1;\n                                }\n                            }else\n                                ref=0;\n                            fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, ref, 1);\n                        }else\n                            fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, (LIST_NOT_USED&0xFF), 1);\n                    }\n            }\n            for(list=0; list<h->list_count; list++){\n                for(i=0; i<2; i++){\n                    if(IS_DIR(mb_type, i, list)){\n                        int mx,my,mpx,mpy;\n                        pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my);\n                        DECODE_CABAC_MB_MVD( h, list, 4*i)\n                        tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n                        fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack8to16(mpx,mpy), 2);\n                        fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4);\n                    }else{\n                        fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 2);\n                        fill_rectangle(h-> mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4);\n                    }\n                }\n            }\n        }\n    }\n   if( IS_INTER( mb_type ) ) {\n        h->chroma_pred_mode_table[mb_xy] = 0;\n        write_back_motion( h, mb_type );\n   }\n    if( !IS_INTRA16x16( mb_type ) ) {\n        cbp  = decode_cabac_mb_cbp_luma( h );\n        if(CHROMA)\n            cbp |= decode_cabac_mb_cbp_chroma( h ) << 4;\n    }\n    h->cbp_table[mb_xy] = h->cbp = cbp;\n    if( dct8x8_allowed && (cbp&15) && !IS_INTRA( mb_type ) ) {\n        mb_type |= MB_TYPE_8x8DCT * get_cabac_noinline( &h->cabac, &h->cabac_state[399 + h->neighbor_transform_size] );\n    }\n    s->current_picture.mb_type[mb_xy]= mb_type;\n    if( cbp || IS_INTRA16x16( mb_type ) ) {\n        const uint8_t *scan, *scan8x8;\n        const uint32_t *qmul;\n        if(IS_INTERLACED(mb_type)){\n            scan8x8= s->qscale ? h->field_scan8x8 : h->field_scan8x8_q0;\n            scan= s->qscale ? h->field_scan : h->field_scan_q0;\n        }else{\n            scan8x8= s->qscale ? h->zigzag_scan8x8 : h->zigzag_scan8x8_q0;\n            scan= s->qscale ? h->zigzag_scan : h->zigzag_scan_q0;\n        }\n        if(get_cabac_noinline( &h->cabac, &h->cabac_state[60 + (h->last_qscale_diff != 0)])){\n            int val = 1;\n            int ctx= 2;\n            const int max_qp = 51 + 6*(h->sps.bit_depth_luma-8);\n            while( get_cabac_noinline( &h->cabac, &h->cabac_state[60 + ctx] ) ) {\n                ctx= 3;\n                val++;\n                if(val > 2*max_qp){\n                    av_log(h->s.avctx, AV_LOG_ERROR, "cabac decode of qscale diff failed at %d %d\\n", s->mb_x, s->mb_y);\n                    return -1;\n                }\n            }\n            if( val&0x01 )\n                val=   (val + 1)>>1 ;\n            else\n                val= -((val + 1)>>1);\n            h->last_qscale_diff = val;\n            s->qscale += val;\n            if(((unsigned)s->qscale) > max_qp){\n                if(s->qscale<0) s->qscale+= max_qp+1;\n                else            s->qscale-= max_qp+1;\n            }\n            h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale);\n            h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale);\n        }else\n            h->last_qscale_diff=0;\n        if( IS_INTRA16x16( mb_type ) ) {\n            int i;\n            AV_ZERO128(h->mb_luma_dc+0);\n            AV_ZERO128(h->mb_luma_dc+8);\n            AV_ZERO128(h->mb_luma_dc+16);\n            AV_ZERO128(h->mb_luma_dc+24);\n            decode_cabac_residual_dc( h, h->mb_luma_dc, 0, LUMA_DC_BLOCK_INDEX, scan, 16);\n            if( cbp&15 ) {\n                qmul = h->dequant4_coeff[0][s->qscale];\n                for( i = 0; i < 16; i++ ) {\n                    decode_cabac_residual_nondc(h, h->mb + (16*i << pixel_shift), 1, i, scan + 1, qmul, 15);\n                }\n            } else {\n                fill_rectangle(&h->non_zero_count_cache[scan8[0]], 4, 4, 8, 0, 1);\n            }\n        } else {\n            int i8x8, i4x4;\n            for( i8x8 = 0; i8x8 < 4; i8x8++ ) {\n                if( cbp & (1<<i8x8) ) {\n                    if( IS_8x8DCT(mb_type) ) {\n                        decode_cabac_residual_nondc(h, h->mb + (64*i8x8 << pixel_shift), 5, 4*i8x8,\n                            scan8x8, h->dequant8_coeff[IS_INTRA( mb_type ) ? 0:1][s->qscale], 64);\n                    } else {\n                        qmul = h->dequant4_coeff[IS_INTRA( mb_type ) ? 0:3][s->qscale];\n                        for( i4x4 = 0; i4x4 < 4; i4x4++ ) {\n                            const int index = 4*i8x8 + i4x4;\n                            decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), 2, index, scan, qmul, 16);\n                        }\n                    }\n                } else {\n                    uint8_t * const nnz= &h->non_zero_count_cache[ scan8[4*i8x8] ];\n                    nnz[0] = nnz[1] = nnz[8] = nnz[9] = 0;\n                }\n            }\n        }\n        if( cbp&0x30 ){\n            int c;\n            for( c = 0; c < 2; c++ ) {\n                decode_cabac_residual_dc(h, h->mb + ((256 + 16*4*c) << pixel_shift), 3, CHROMA_DC_BLOCK_INDEX+c, chroma_dc_scan, 4);\n            }\n        }\n        if( cbp&0x20 ) {\n            int c, i;\n            for( c = 0; c < 2; c++ ) {\n                qmul = h->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[c]];\n                for( i = 0; i < 4; i++ ) {\n                    const int index = 16 + 4 * c + i;\n                    decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), 4, index, scan + 1, qmul, 15);\n                }\n            }\n        } else {\n            uint8_t * const nnz= &h->non_zero_count_cache[0];\n            nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] =\n            nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0;\n        }\n    } else {\n        uint8_t * const nnz= &h->non_zero_count_cache[0];\n        fill_rectangle(&nnz[scan8[0]], 4, 4, 8, 0, 1);\n        nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] =\n        nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0;\n        h->last_qscale_diff = 0;\n    }\n    s->current_picture.qscale_table[mb_xy]= s->qscale;\n    write_back_non_zero_count(h);\n    if(MB_MBAFF){\n        h->ref_count[0] >>= 1;\n        h->ref_count[1] >>= 1;\n    }\n    return 0;\n}', 'void ff_h264_hl_decode_mb(H264Context *h){\n    MpegEncContext * const s = &h->s;\n    const int mb_xy= h->mb_xy;\n    const int mb_type= s->current_picture.mb_type[mb_xy];\n    int is_complex = CONFIG_SMALL || h->is_complex || IS_INTRA_PCM(mb_type) || s->qscale == 0;\n    if (is_complex) {\n        hl_decode_mb_complex(h);\n    } else if (h->pixel_shift) {\n        hl_decode_mb_simple_16(h);\n    } else\n        hl_decode_mb_simple_8(h);\n}', 'static void av_noinline hl_decode_mb_complex(H264Context *h){\n    hl_decode_mb_internal(h, 0, h->pixel_shift);\n}', 'static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple, int pixel_shift){\n    MpegEncContext * const s = &h->s;\n    const int mb_x= s->mb_x;\n    const int mb_y= s->mb_y;\n    const int mb_xy= h->mb_xy;\n    const int mb_type= s->current_picture.mb_type[mb_xy];\n    uint8_t  *dest_y, *dest_cb, *dest_cr;\n    int linesize, uvlinesize  ;\n    int i;\n    int *block_offset = &h->block_offset[0];\n    const int transform_bypass = !simple && (s->qscale == 0 && h->sps.transform_bypass);\n    const int is_h264 = !CONFIG_SVQ3_DECODER || simple || s->codec_id == CODEC_ID_H264;\n    void (*idct_add)(uint8_t *dst, DCTELEM *block, int stride);\n    void (*idct_dc_add)(uint8_t *dst, DCTELEM *block, int stride);\n    dest_y  = s->current_picture.data[0] + ((mb_x << pixel_shift) + mb_y * s->linesize  ) * 16;\n    dest_cb = s->current_picture.data[1] + ((mb_x << pixel_shift) + mb_y * s->uvlinesize) * 8;\n    dest_cr = s->current_picture.data[2] + ((mb_x << pixel_shift) + mb_y * s->uvlinesize) * 8;\n    s->dsp.prefetch(dest_y + (s->mb_x&3)*4*s->linesize + (64 << pixel_shift), s->linesize, 4);\n    s->dsp.prefetch(dest_cb + (s->mb_x&7)*s->uvlinesize + (64 << pixel_shift), dest_cr - dest_cb, 2);\n    h->list_counts[mb_xy]= h->list_count;\n    if (!simple && MB_FIELD) {\n        linesize   = h->mb_linesize   = s->linesize * 2;\n        uvlinesize = h->mb_uvlinesize = s->uvlinesize * 2;\n        block_offset = &h->block_offset[24];\n        if(mb_y&1){\n            dest_y -= s->linesize*15;\n            dest_cb-= s->uvlinesize*7;\n            dest_cr-= s->uvlinesize*7;\n        }\n        if(FRAME_MBAFF) {\n            int list;\n            for(list=0; list<h->list_count; list++){\n                if(!USES_LIST(mb_type, list))\n                    continue;\n                if(IS_16X16(mb_type)){\n                    int8_t *ref = &h->ref_cache[list][scan8[0]];\n                    fill_rectangle(ref, 4, 4, 8, (16+*ref)^(s->mb_y&1), 1);\n                }else{\n                    for(i=0; i<16; i+=4){\n                        int ref = h->ref_cache[list][scan8[i]];\n                        if(ref >= 0)\n                            fill_rectangle(&h->ref_cache[list][scan8[i]], 2, 2, 8, (16+ref)^(s->mb_y&1), 1);\n                    }\n                }\n            }\n        }\n    } else {\n        linesize   = h->mb_linesize   = s->linesize;\n        uvlinesize = h->mb_uvlinesize = s->uvlinesize;\n    }\n    if (!simple && IS_INTRA_PCM(mb_type)) {\n        if (pixel_shift) {\n            const int bit_depth = h->sps.bit_depth_luma;\n            int j;\n            GetBitContext gb;\n            init_get_bits(&gb, (uint8_t*)h->mb, 384*bit_depth);\n            for (i = 0; i < 16; i++) {\n                uint16_t *tmp_y  = (uint16_t*)(dest_y  + i*linesize);\n                for (j = 0; j < 16; j++)\n                    tmp_y[j] = get_bits(&gb, bit_depth);\n            }\n            for (i = 0; i < 8; i++) {\n                uint16_t *tmp_cb = (uint16_t*)(dest_cb + i*uvlinesize);\n                for (j = 0; j < 8; j++)\n                    tmp_cb[j] = get_bits(&gb, bit_depth);\n            }\n            for (i = 0; i < 8; i++) {\n                uint16_t *tmp_cr = (uint16_t*)(dest_cr + i*uvlinesize);\n                for (j = 0; j < 8; j++)\n                    tmp_cr[j] = get_bits(&gb, bit_depth);\n            }\n        } else {\n        for (i=0; i<16; i++) {\n            memcpy(dest_y + i*  linesize, h->mb       + i*8, 16);\n        }\n        for (i=0; i<8; i++) {\n            memcpy(dest_cb+ i*uvlinesize, h->mb + 128 + i*4,  8);\n            memcpy(dest_cr+ i*uvlinesize, h->mb + 160 + i*4,  8);\n        }\n        }\n    } else {\n        if(IS_INTRA(mb_type)){\n            if(h->deblocking_filter)\n                xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 1, simple, pixel_shift);\n            if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){\n                h->hpc.pred8x8[ h->chroma_pred_mode ](dest_cb, uvlinesize);\n                h->hpc.pred8x8[ h->chroma_pred_mode ](dest_cr, uvlinesize);\n            }\n            if(IS_INTRA4x4(mb_type)){\n                if(simple || !s->encoding){\n                    if(IS_8x8DCT(mb_type)){\n                        if(transform_bypass){\n                            idct_dc_add =\n                            idct_add    = s->dsp.add_pixels8;\n                        }else{\n                            idct_dc_add = h->h264dsp.h264_idct8_dc_add;\n                            idct_add    = h->h264dsp.h264_idct8_add;\n                        }\n                        for(i=0; i<16; i+=4){\n                            uint8_t * const ptr= dest_y + block_offset[i];\n                            const int dir= h->intra4x4_pred_mode_cache[ scan8[i] ];\n                            if(transform_bypass && h->sps.profile_idc==244 && dir<=1){\n                                h->hpc.pred8x8l_add[dir](ptr, h->mb + (i*16 << pixel_shift), linesize);\n                            }else{\n                                const int nnz = h->non_zero_count_cache[ scan8[i] ];\n                                h->hpc.pred8x8l[ dir ](ptr, (h->topleft_samples_available<<i)&0x8000,\n                                                            (h->topright_samples_available<<i)&0x4000, linesize);\n                                if(nnz){\n                                    if(nnz == 1 && dctcoef_get(h->mb, pixel_shift, i*16))\n                                        idct_dc_add(ptr, h->mb + (i*16 << pixel_shift), linesize);\n                                    else\n                                        idct_add   (ptr, h->mb + (i*16 << pixel_shift), linesize);\n                                }\n                            }\n                        }\n                    }else{\n                        if(transform_bypass){\n                            idct_dc_add =\n                            idct_add    = s->dsp.add_pixels4;\n                        }else{\n                            idct_dc_add = h->h264dsp.h264_idct_dc_add;\n                            idct_add    = h->h264dsp.h264_idct_add;\n                        }\n                        for(i=0; i<16; i++){\n                            uint8_t * const ptr= dest_y + block_offset[i];\n                            const int dir= h->intra4x4_pred_mode_cache[ scan8[i] ];\n                            if(transform_bypass && h->sps.profile_idc==244 && dir<=1){\n                                h->hpc.pred4x4_add[dir](ptr, h->mb + (i*16 << pixel_shift), linesize);\n                            }else{\n                                uint8_t *topright;\n                                int nnz, tr;\n                                uint64_t tr_high;\n                                if(dir == DIAG_DOWN_LEFT_PRED || dir == VERT_LEFT_PRED){\n                                    const int topright_avail= (h->topright_samples_available<<i)&0x8000;\n                                    assert(mb_y || linesize <= block_offset[i]);\n                                    if(!topright_avail){\n                                        if (pixel_shift) {\n                                            tr_high= ((uint16_t*)ptr)[3 - linesize/2]*0x0001000100010001ULL;\n                                            topright= (uint8_t*) &tr_high;\n                                        } else {\n                                        tr= ptr[3 - linesize]*0x01010101;\n                                        topright= (uint8_t*) &tr;\n                                        }\n                                    }else\n                                        topright= ptr + (4 << pixel_shift) - linesize;\n                                }else\n                                    topright= NULL;\n                                h->hpc.pred4x4[ dir ](ptr, topright, linesize);\n                                nnz = h->non_zero_count_cache[ scan8[i] ];\n                                if(nnz){\n                                    if(is_h264){\n                                        if(nnz == 1 && dctcoef_get(h->mb, pixel_shift, i*16))\n                                            idct_dc_add(ptr, h->mb + (i*16 << pixel_shift), linesize);\n                                        else\n                                            idct_add   (ptr, h->mb + (i*16 << pixel_shift), linesize);\n                                    }else\n                                        ff_svq3_add_idct_c(ptr, h->mb + i*16, linesize, s->qscale, 0);\n                                }\n                            }\n                        }\n                    }\n                }\n            }else{\n                h->hpc.pred16x16[ h->intra16x16_pred_mode ](dest_y , linesize);\n                if(is_h264){\n                    if(h->non_zero_count_cache[ scan8[LUMA_DC_BLOCK_INDEX] ]){\n                        if(!transform_bypass)\n                            h->h264dsp.h264_luma_dc_dequant_idct(h->mb, h->mb_luma_dc, h->dequant4_coeff[0][s->qscale][0]);\n                        else{\n                            static const uint8_t dc_mapping[16] = { 0*16, 1*16, 4*16, 5*16, 2*16, 3*16, 6*16, 7*16,\n                                                                    8*16, 9*16,12*16,13*16,10*16,11*16,14*16,15*16};\n                            for(i = 0; i < 16; i++)\n                                dctcoef_set(h->mb, pixel_shift, dc_mapping[i], dctcoef_get(h->mb_luma_dc, pixel_shift, i));\n                        }\n                    }\n                }else\n                    ff_svq3_luma_dc_dequant_idct_c(h->mb, h->mb_luma_dc, s->qscale);\n            }\n            if(h->deblocking_filter)\n                xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 0, simple, pixel_shift);\n        }else if(is_h264){\n            if (pixel_shift) {\n                hl_motion_16(h, dest_y, dest_cb, dest_cr,\n                             s->me.qpel_put, s->dsp.put_h264_chroma_pixels_tab,\n                             s->me.qpel_avg, s->dsp.avg_h264_chroma_pixels_tab,\n                             h->h264dsp.weight_h264_pixels_tab,\n                             h->h264dsp.biweight_h264_pixels_tab);\n            } else\n                hl_motion_8(h, dest_y, dest_cb, dest_cr,\n                            s->me.qpel_put, s->dsp.put_h264_chroma_pixels_tab,\n                            s->me.qpel_avg, s->dsp.avg_h264_chroma_pixels_tab,\n                            h->h264dsp.weight_h264_pixels_tab,\n                            h->h264dsp.biweight_h264_pixels_tab);\n        }\n        if(!IS_INTRA4x4(mb_type)){\n            if(is_h264){\n                if(IS_INTRA16x16(mb_type)){\n                    if(transform_bypass){\n                        if(h->sps.profile_idc==244 && (h->intra16x16_pred_mode==VERT_PRED8x8 || h->intra16x16_pred_mode==HOR_PRED8x8)){\n                            h->hpc.pred16x16_add[h->intra16x16_pred_mode](dest_y, block_offset, h->mb, linesize);\n                        }else{\n                            for(i=0; i<16; i++){\n                                if(h->non_zero_count_cache[ scan8[i] ] || dctcoef_get(h->mb, pixel_shift, i*16))\n                                    s->dsp.add_pixels4(dest_y + block_offset[i], h->mb + (i*16 << pixel_shift), linesize);\n                            }\n                        }\n                    }else{\n                         h->h264dsp.h264_idct_add16intra(dest_y, block_offset, h->mb, linesize, h->non_zero_count_cache);\n                    }\n                }else if(h->cbp&15){\n                    if(transform_bypass){\n                        const int di = IS_8x8DCT(mb_type) ? 4 : 1;\n                        idct_add= IS_8x8DCT(mb_type) ? s->dsp.add_pixels8 : s->dsp.add_pixels4;\n                        for(i=0; i<16; i+=di){\n                            if(h->non_zero_count_cache[ scan8[i] ]){\n                                idct_add(dest_y + block_offset[i], h->mb + (i*16 << pixel_shift), linesize);\n                            }\n                        }\n                    }else{\n                        if(IS_8x8DCT(mb_type)){\n                            h->h264dsp.h264_idct8_add4(dest_y, block_offset, h->mb, linesize, h->non_zero_count_cache);\n                        }else{\n                            h->h264dsp.h264_idct_add16(dest_y, block_offset, h->mb, linesize, h->non_zero_count_cache);\n                        }\n                    }\n                }\n            }else{\n                for(i=0; i<16; i++){\n                    if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){\n                        uint8_t * const ptr= dest_y + block_offset[i];\n                        ff_svq3_add_idct_c(ptr, h->mb + i*16, linesize, s->qscale, IS_INTRA(mb_type) ? 1 : 0);\n                    }\n                }\n            }\n        }\n        if((simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)) && (h->cbp&0x30)){\n            uint8_t *dest[2] = {dest_cb, dest_cr};\n            if(transform_bypass){\n                if(IS_INTRA(mb_type) && h->sps.profile_idc==244 && (h->chroma_pred_mode==VERT_PRED8x8 || h->chroma_pred_mode==HOR_PRED8x8)){\n                    h->hpc.pred8x8_add[h->chroma_pred_mode](dest[0], block_offset + 16, h->mb + (16*16 << pixel_shift), uvlinesize);\n                    h->hpc.pred8x8_add[h->chroma_pred_mode](dest[1], block_offset + 20, h->mb + (20*16 << pixel_shift), uvlinesize);\n                }else{\n                    idct_add = s->dsp.add_pixels4;\n                    for(i=16; i<16+8; i++){\n                        if(h->non_zero_count_cache[ scan8[i] ] || dctcoef_get(h->mb, pixel_shift, i*16))\n                            idct_add   (dest[(i&4)>>2] + block_offset[i], h->mb + (i*16 << pixel_shift), uvlinesize);\n                    }\n                }\n            }else{\n                if(is_h264){\n                    if(h->non_zero_count_cache[ scan8[CHROMA_DC_BLOCK_INDEX+0] ])\n                        h->h264dsp.h264_chroma_dc_dequant_idct(h->mb + (16*16 << pixel_shift)       , h->dequant4_coeff[IS_INTRA(mb_type) ? 1:4][h->chroma_qp[0]][0]);\n                    if(h->non_zero_count_cache[ scan8[CHROMA_DC_BLOCK_INDEX+1] ])\n                        h->h264dsp.h264_chroma_dc_dequant_idct(h->mb + ((16*16+4*16) << pixel_shift), h->dequant4_coeff[IS_INTRA(mb_type) ? 2:5][h->chroma_qp[1]][0]);\n                    h->h264dsp.h264_idct_add8(dest, block_offset,\n                                              h->mb, uvlinesize,\n                                              h->non_zero_count_cache);\n                }else{\n                    h->h264dsp.h264_chroma_dc_dequant_idct(h->mb + 16*16     , h->dequant4_coeff[IS_INTRA(mb_type) ? 1:4][h->chroma_qp[0]][0]);\n                    h->h264dsp.h264_chroma_dc_dequant_idct(h->mb + 16*16+4*16, h->dequant4_coeff[IS_INTRA(mb_type) ? 2:5][h->chroma_qp[1]][0]);\n                    for(i=16; i<16+8; i++){\n                        if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){\n                            uint8_t * const ptr= dest[(i&4)>>2] + block_offset[i];\n                            ff_svq3_add_idct_c(ptr, h->mb + i*16, uvlinesize, ff_h264_chroma_qp[0][s->qscale + 12] - 12, 2);\n                        }\n                    }\n                }\n            }\n        }\n    }\n    if(h->cbp || IS_INTRA(mb_type))\n        s->dsp.clear_blocks(h->mb);\n}', 'hl_motion_fn(1, 16)', 'static av_always_inline void hl_motion(H264Context *h, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,\n                      qpel_mc_func (*qpix_put)[16], h264_chroma_mc_func (*chroma_put),\n                      qpel_mc_func (*qpix_avg)[16], h264_chroma_mc_func (*chroma_avg),\n                      h264_weight_func *weight_op, h264_biweight_func *weight_avg,\n                      int pixel_shift){\n    MpegEncContext * const s = &h->s;\n    const int mb_xy= h->mb_xy;\n    const int mb_type= s->current_picture.mb_type[mb_xy];\n    assert(IS_INTER(mb_type));\n    if(HAVE_PTHREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME))\n        await_references(h);\n    prefetch_motion(h, 0, pixel_shift);\n    if(IS_16X16(mb_type)){\n        mc_part(h, 0, 1, 8, 0, dest_y, dest_cb, dest_cr, 0, 0,\n                qpix_put[0], chroma_put[0], qpix_avg[0], chroma_avg[0],\n                weight_op, weight_avg,\n                IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1),\n                pixel_shift);\n    }else if(IS_16X8(mb_type)){\n        mc_part(h, 0, 0, 4, 8 << pixel_shift, dest_y, dest_cb, dest_cr, 0, 0,\n                qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],\n                &weight_op[1], &weight_avg[1],\n                IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1),\n                pixel_shift);\n        mc_part(h, 8, 0, 4, 8 << pixel_shift, dest_y, dest_cb, dest_cr, 0, 4,\n                qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],\n                &weight_op[1], &weight_avg[1],\n                IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1),\n                pixel_shift);\n    }else if(IS_8X16(mb_type)){\n        mc_part(h, 0, 0, 8, 8*h->mb_linesize, dest_y, dest_cb, dest_cr, 0, 0,\n                qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],\n                &weight_op[2], &weight_avg[2],\n                IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1),\n                pixel_shift);\n        mc_part(h, 4, 0, 8, 8*h->mb_linesize, dest_y, dest_cb, dest_cr, 4, 0,\n                qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],\n                &weight_op[2], &weight_avg[2],\n                IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1),\n                pixel_shift);\n    }else{\n        int i;\n        assert(IS_8X8(mb_type));\n        for(i=0; i<4; i++){\n            const int sub_mb_type= h->sub_mb_type[i];\n            const int n= 4*i;\n            int x_offset= (i&1)<<2;\n            int y_offset= (i&2)<<1;\n            if(IS_SUB_8X8(sub_mb_type)){\n                mc_part(h, n, 1, 4, 0, dest_y, dest_cb, dest_cr, x_offset, y_offset,\n                    qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],\n                    &weight_op[3], &weight_avg[3],\n                    IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n                    pixel_shift);\n            }else if(IS_SUB_8X4(sub_mb_type)){\n                mc_part(h, n  , 0, 2, 4 << pixel_shift, dest_y, dest_cb, dest_cr, x_offset, y_offset,\n                    qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],\n                    &weight_op[4], &weight_avg[4],\n                    IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n                    pixel_shift);\n                mc_part(h, n+2, 0, 2, 4 << pixel_shift, dest_y, dest_cb, dest_cr, x_offset, y_offset+2,\n                    qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],\n                    &weight_op[4], &weight_avg[4],\n                    IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n                    pixel_shift);\n            }else if(IS_SUB_4X8(sub_mb_type)){\n                mc_part(h, n  , 0, 4, 4*h->mb_linesize, dest_y, dest_cb, dest_cr, x_offset, y_offset,\n                    qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],\n                    &weight_op[5], &weight_avg[5],\n                    IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n                    pixel_shift);\n                mc_part(h, n+1, 0, 4, 4*h->mb_linesize, dest_y, dest_cb, dest_cr, x_offset+2, y_offset,\n                    qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],\n                    &weight_op[5], &weight_avg[5],\n                    IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n                    pixel_shift);\n            }else{\n                int j;\n                assert(IS_SUB_4X4(sub_mb_type));\n                for(j=0; j<4; j++){\n                    int sub_x_offset= x_offset + 2*(j&1);\n                    int sub_y_offset= y_offset +   (j&2);\n                    mc_part(h, n+j, 1, 2, 0, dest_y, dest_cb, dest_cr, sub_x_offset, sub_y_offset,\n                        qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],\n                        &weight_op[6], &weight_avg[6],\n                        IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n                        pixel_shift);\n                }\n            }\n        }\n    }\n    prefetch_motion(h, 1, pixel_shift);\n}', 'static void await_references(H264Context *h){\n    MpegEncContext * const s = &h->s;\n    const int mb_xy= h->mb_xy;\n    const int mb_type= s->current_picture.mb_type[mb_xy];\n    int refs[2][48];\n    int nrefs[2] = {0};\n    int ref, list;\n    memset(refs, -1, sizeof(refs));\n    if(IS_16X16(mb_type)){\n        get_lowest_part_y(h, refs, 0, 16, 0,\n                  IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);\n    }else if(IS_16X8(mb_type)){\n        get_lowest_part_y(h, refs, 0, 8, 0,\n                  IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);\n        get_lowest_part_y(h, refs, 8, 8, 8,\n                  IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), nrefs);\n    }else if(IS_8X16(mb_type)){\n        get_lowest_part_y(h, refs, 0, 16, 0,\n                  IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);\n        get_lowest_part_y(h, refs, 4, 16, 0,\n                  IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), nrefs);\n    }else{\n        int i;\n        assert(IS_8X8(mb_type));\n        for(i=0; i<4; i++){\n            const int sub_mb_type= h->sub_mb_type[i];\n            const int n= 4*i;\n            int y_offset= (i&2)<<2;\n            if(IS_SUB_8X8(sub_mb_type)){\n                get_lowest_part_y(h, refs, n  , 8, y_offset,\n                          IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);\n            }else if(IS_SUB_8X4(sub_mb_type)){\n                get_lowest_part_y(h, refs, n  , 4, y_offset,\n                          IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);\n                get_lowest_part_y(h, refs, n+2, 4, y_offset+4,\n                          IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);\n            }else if(IS_SUB_4X8(sub_mb_type)){\n                get_lowest_part_y(h, refs, n  , 8, y_offset,\n                          IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);\n                get_lowest_part_y(h, refs, n+1, 8, y_offset,\n                          IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);\n            }else{\n                int j;\n                assert(IS_SUB_4X4(sub_mb_type));\n                for(j=0; j<4; j++){\n                    int sub_y_offset= y_offset + 2*(j&2);\n                    get_lowest_part_y(h, refs, n+j, 4, sub_y_offset,\n                              IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);\n                }\n            }\n        }\n    }\n    for(list=h->list_count-1; list>=0; list--){\n        for(ref=0; ref<48 && nrefs[list]; ref++){\n            int row = refs[list][ref];\n            if(row >= 0){\n                Picture *ref_pic = &h->ref_list[list][ref];\n                int ref_field = ref_pic->reference - 1;\n                int ref_field_picture = ref_pic->field_picture;\n                int pic_height = 16*s->mb_height >> ref_field_picture;\n                row <<= MB_MBAFF;\n                nrefs[list]--;\n                if(!FIELD_PICTURE && ref_field_picture){\n                    ff_thread_await_progress((AVFrame*)ref_pic, FFMIN((row >> 1) - !(row&1), pic_height-1), 1);\n                    ff_thread_await_progress((AVFrame*)ref_pic, FFMIN((row >> 1)           , pic_height-1), 0);\n                }else if(FIELD_PICTURE && !ref_field_picture){\n                    ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row*2 + ref_field    , pic_height-1), 0);\n                }else if(FIELD_PICTURE){\n                    ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row, pic_height-1), ref_field);\n                }else{\n                    ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row, pic_height-1), 0);\n                }\n            }\n        }\n    }\n}']