static inline void write_back_motion(H264Context *h, int mb_type){
    MpegEncContext * const s = &h->s;
    const int b_xy = 4*s->mb_x + 4*s->mb_y*h->b_stride; //try mb2b(8)_xy
    const int b8_xy= 4*h->mb_xy;
    int list;

    if(!USES_LIST(mb_type, 0))
        fill_rectangle(&s->current_picture.ref_index[0][b8_xy], 2, 2, 2, (uint8_t)LIST_NOT_USED, 1);

    for(list=0; list<h->list_count; list++){
        int y, b_stride;
        int16_t (*mv_dst)[2];
        int16_t (*mv_src)[2];

        if(!USES_LIST(mb_type, list))
            continue;

        b_stride = h->b_stride;
        mv_dst   = &s->current_picture.motion_val[list][b_xy];
        mv_src   = &h->mv_cache[list][scan8[0]];
        for(y=0; y<4; y++){
            AV_COPY128(mv_dst + y*b_stride, mv_src + 8*y);
        }
        if( CABAC ) {
            uint8_t (*mvd_dst)[2] = &h->mvd_table[list][FMO ? 8*h->mb_xy : h->mb2br_xy[h->mb_xy]];
            uint8_t (*mvd_src)[2] = &h->mvd_cache[list][scan8[0]];
            if(IS_SKIP(mb_type))
                AV_ZERO128(mvd_dst);
            else{
            AV_COPY64(mvd_dst, mvd_src + 8*3);
                AV_COPY16(mvd_dst + 3 + 3, mvd_src + 3 + 8*0);
                AV_COPY16(mvd_dst + 3 + 2, mvd_src + 3 + 8*1);
                AV_COPY16(mvd_dst + 3 + 1, mvd_src + 3 + 8*2);
            }
        }

        {
            int8_t *ref_index = &s->current_picture.ref_index[list][b8_xy];
            ref_index[0+0*2]= h->ref_cache[list][scan8[0]];
            ref_index[1+0*2]= h->ref_cache[list][scan8[4]];
            ref_index[0+1*2]= h->ref_cache[list][scan8[8]];
            ref_index[1+1*2]= h->ref_cache[list][scan8[12]];
        }
    }

    if(h->slice_type_nos == AV_PICTURE_TYPE_B && CABAC){
        if(IS_8X8(mb_type)){
            uint8_t *direct_table = &h->direct_table[4*h->mb_xy];
            direct_table[1] = h->sub_mb_type[1]>>1;
            direct_table[2] = h->sub_mb_type[2]>>1;
            direct_table[3] = h->sub_mb_type[3]>>1;
        }
    }
}