1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

Rewrite emu_edge functions to have separate src/dst_stride arguments.

This allows supporting files for which the image stride is smaller than
the max. block size + number of subpel mc taps, e.g. a 64x64 VP9 file
or a 16x16 VP8 file with -fflags +emu_edge.
This commit is contained in:
Ronald S. Bultje 2013-09-20 08:01:19 -04:00
parent f574b4da56
commit face578d56
20 changed files with 666 additions and 683 deletions

View File

@ -405,7 +405,8 @@ static inline void mc_dir_part(AVSContext *h, AVFrame *pic,
|| full_my < 0-extra_height || full_my < 0-extra_height
|| full_mx + 16/*FIXME*/ > pic_width + extra_width || full_mx + 16/*FIXME*/ > pic_width + extra_width
|| full_my + 16/*FIXME*/ > pic_height + extra_height){ || full_my + 16/*FIXME*/ > pic_height + extra_height){
h->vdsp.emulated_edge_mc(h->edge_emu_buffer, src_y - 2 - 2*h->l_stride, h->l_stride, h->vdsp.emulated_edge_mc(h->edge_emu_buffer, h->l_stride,
src_y - 2 - 2*h->l_stride, h->l_stride,
16+5, 16+5/*FIXME*/, full_mx-2, full_my-2, pic_width, pic_height); 16+5, 16+5/*FIXME*/, full_mx-2, full_my-2, pic_width, pic_height);
src_y= h->edge_emu_buffer + 2 + 2*h->l_stride; src_y= h->edge_emu_buffer + 2 + 2*h->l_stride;
emu=1; emu=1;
@ -414,14 +415,14 @@ static inline void mc_dir_part(AVSContext *h, AVFrame *pic,
qpix_op[luma_xy](dest_y, src_y, h->l_stride); //FIXME try variable height perhaps? qpix_op[luma_xy](dest_y, src_y, h->l_stride); //FIXME try variable height perhaps?
if(emu){ if(emu){
h->vdsp.emulated_edge_mc(h->edge_emu_buffer, src_cb, h->c_stride, h->vdsp.emulated_edge_mc(h->edge_emu_buffer, h->c_stride, src_cb, h->c_stride,
9, 9/*FIXME*/, (mx>>3), (my>>3), pic_width>>1, pic_height>>1); 9, 9/*FIXME*/, (mx>>3), (my>>3), pic_width>>1, pic_height>>1);
src_cb= h->edge_emu_buffer; src_cb= h->edge_emu_buffer;
} }
chroma_op(dest_cb, src_cb, h->c_stride, chroma_height, mx&7, my&7); chroma_op(dest_cb, src_cb, h->c_stride, chroma_height, mx&7, my&7);
if(emu){ if(emu){
h->vdsp.emulated_edge_mc(h->edge_emu_buffer, src_cr, h->c_stride, h->vdsp.emulated_edge_mc(h->edge_emu_buffer, h->c_stride, src_cr, h->c_stride,
9, 9/*FIXME*/, (mx>>3), (my>>3), pic_width>>1, pic_height>>1); 9, 9/*FIXME*/, (mx>>3), (my>>3), pic_width>>1, pic_height>>1);
src_cr= h->edge_emu_buffer; src_cr= h->edge_emu_buffer;
} }

View File

@ -1414,7 +1414,8 @@ static int mc_subpel(DiracContext *s, DiracBlock *block, const uint8_t *src[5],
y + p->yblen > p->height+EDGE_WIDTH/2 || y + p->yblen > p->height+EDGE_WIDTH/2 ||
x < 0 || y < 0) { x < 0 || y < 0) {
for (i = 0; i < nplanes; i++) { for (i = 0; i < nplanes; i++) {
ff_emulated_edge_mc(s->edge_emu_buffer[i], src[i], p->stride, ff_emulated_edge_mc(s->edge_emu_buffer[i], p->stride,
src[i], p->stride,
p->xblen, p->yblen, x, y, p->xblen, p->yblen, x, y,
p->width+EDGE_WIDTH/2, p->height+EDGE_WIDTH/2); p->width+EDGE_WIDTH/2, p->height+EDGE_WIDTH/2);
src[i] = s->edge_emu_buffer[i]; src[i] = s->edge_emu_buffer[i];

View File

@ -932,7 +932,7 @@ static av_always_inline void mc_dir_part(H264Context *h, Picture *pic,
full_my < 0 - extra_height || full_my < 0 - extra_height ||
full_mx + 16 /*FIXME*/ > pic_width + extra_width || full_mx + 16 /*FIXME*/ > pic_width + extra_width ||
full_my + 16 /*FIXME*/ > pic_height + extra_height) { full_my + 16 /*FIXME*/ > pic_height + extra_height) {
h->vdsp.emulated_edge_mc(h->edge_emu_buffer, h->vdsp.emulated_edge_mc(h->edge_emu_buffer, h->mb_linesize,
src_y - (2 << pixel_shift) - 2 * h->mb_linesize, src_y - (2 << pixel_shift) - 2 * h->mb_linesize,
h->mb_linesize, h->mb_linesize,
16 + 5, 16 + 5 /*FIXME*/, full_mx - 2, 16 + 5, 16 + 5 /*FIXME*/, full_mx - 2,
@ -951,7 +951,7 @@ static av_always_inline void mc_dir_part(H264Context *h, Picture *pic,
if (chroma_idc == 3 /* yuv444 */) { if (chroma_idc == 3 /* yuv444 */) {
src_cb = pic->f.data[1] + offset; src_cb = pic->f.data[1] + offset;
if (emu) { if (emu) {
h->vdsp.emulated_edge_mc(h->edge_emu_buffer, h->vdsp.emulated_edge_mc(h->edge_emu_buffer, h->mb_linesize,
src_cb - (2 << pixel_shift) - 2 * h->mb_linesize, src_cb - (2 << pixel_shift) - 2 * h->mb_linesize,
h->mb_linesize, h->mb_linesize,
16 + 5, 16 + 5 /*FIXME*/, 16 + 5, 16 + 5 /*FIXME*/,
@ -965,7 +965,7 @@ static av_always_inline void mc_dir_part(H264Context *h, Picture *pic,
src_cr = pic->f.data[2] + offset; src_cr = pic->f.data[2] + offset;
if (emu) { if (emu) {
h->vdsp.emulated_edge_mc(h->edge_emu_buffer, h->vdsp.emulated_edge_mc(h->edge_emu_buffer, h->mb_linesize,
src_cr - (2 << pixel_shift) - 2 * h->mb_linesize, src_cr - (2 << pixel_shift) - 2 * h->mb_linesize,
h->mb_linesize, h->mb_linesize,
16 + 5, 16 + 5 /*FIXME*/, 16 + 5, 16 + 5 /*FIXME*/,
@ -992,7 +992,7 @@ static av_always_inline void mc_dir_part(H264Context *h, Picture *pic,
(my >> ysh) * h->mb_uvlinesize; (my >> ysh) * h->mb_uvlinesize;
if (emu) { if (emu) {
h->vdsp.emulated_edge_mc(h->edge_emu_buffer, src_cb, h->mb_uvlinesize, h->vdsp.emulated_edge_mc(h->edge_emu_buffer, h->mb_uvlinesize, src_cb, h->mb_uvlinesize,
9, 8 * chroma_idc + 1, (mx >> 3), (my >> ysh), 9, 8 * chroma_idc + 1, (mx >> 3), (my >> ysh),
pic_width >> 1, pic_height >> (chroma_idc == 1 /* yuv420 */)); pic_width >> 1, pic_height >> (chroma_idc == 1 /* yuv420 */));
src_cb = h->edge_emu_buffer; src_cb = h->edge_emu_buffer;
@ -1002,7 +1002,7 @@ static av_always_inline void mc_dir_part(H264Context *h, Picture *pic,
mx & 7, (my << (chroma_idc == 2 /* yuv422 */)) & 7); mx & 7, (my << (chroma_idc == 2 /* yuv422 */)) & 7);
if (emu) { if (emu) {
h->vdsp.emulated_edge_mc(h->edge_emu_buffer, src_cr, h->mb_uvlinesize, h->vdsp.emulated_edge_mc(h->edge_emu_buffer, h->mb_uvlinesize, src_cr, h->mb_uvlinesize,
9, 8 * chroma_idc + 1, (mx >> 3), (my >> ysh), 9, 8 * chroma_idc + 1, (mx >> 3), (my >> ysh),
pic_width >> 1, pic_height >> (chroma_idc == 1 /* yuv420 */)); pic_width >> 1, pic_height >> (chroma_idc == 1 /* yuv420 */));
src_cr = h->edge_emu_buffer; src_cr = h->edge_emu_buffer;

View File

@ -2204,7 +2204,8 @@ static inline int hpel_motion_lowres(MpegEncContext *s,
if ((unsigned)src_x > FFMAX( h_edge_pos - (!!sx) - w, 0) || if ((unsigned)src_x > FFMAX( h_edge_pos - (!!sx) - w, 0) ||
(unsigned)src_y > FFMAX((v_edge_pos >> field_based) - (!!sy) - h, 0)) { (unsigned)src_y > FFMAX((v_edge_pos >> field_based) - (!!sy) - h, 0)) {
s->vdsp.emulated_edge_mc(s->edge_emu_buffer, src, s->linesize, w + 1, s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->linesize,
src, s->linesize, w + 1,
(h + 1) << field_based, src_x, (h + 1) << field_based, src_x,
src_y << field_based, src_y << field_based,
h_edge_pos, h_edge_pos,
@ -2306,18 +2307,20 @@ static av_always_inline void mpeg_motion_lowres(MpegEncContext *s,
if ((unsigned) src_x > FFMAX( h_edge_pos - (!!sx) - 2 * block_s, 0) || uvsrc_y<0 || if ((unsigned) src_x > FFMAX( h_edge_pos - (!!sx) - 2 * block_s, 0) || uvsrc_y<0 ||
(unsigned) src_y > FFMAX((v_edge_pos >> field_based) - (!!sy) - h, 0)) { (unsigned) src_y > FFMAX((v_edge_pos >> field_based) - (!!sy) - h, 0)) {
s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->vdsp.emulated_edge_mc(s->edge_emu_buffer, linesize >> field_based, ptr_y,
linesize >> field_based, 17, 17 + field_based, linesize >> field_based, 17, 17 + field_based,
src_x, src_y << field_based, h_edge_pos, src_x, src_y << field_based, h_edge_pos,
v_edge_pos); v_edge_pos);
ptr_y = s->edge_emu_buffer; ptr_y = s->edge_emu_buffer;
if (!CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) { if (!CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) {
uint8_t *uvbuf = s->edge_emu_buffer + 18 * s->linesize; uint8_t *uvbuf = s->edge_emu_buffer + 18 * s->linesize;
s->vdsp.emulated_edge_mc(uvbuf , ptr_cb, uvlinesize >> field_based, 9, s->vdsp.emulated_edge_mc(uvbuf, uvlinesize >> field_based,
ptr_cb, uvlinesize >> field_based, 9,
9 + field_based, 9 + field_based,
uvsrc_x, uvsrc_y << field_based, uvsrc_x, uvsrc_y << field_based,
h_edge_pos >> 1, v_edge_pos >> 1); h_edge_pos >> 1, v_edge_pos >> 1);
s->vdsp.emulated_edge_mc(uvbuf + 16, ptr_cr, uvlinesize >> field_based, 9, s->vdsp.emulated_edge_mc(uvbuf + 16, uvlinesize >> field_based,
ptr_cr, uvlinesize >> field_based, 9,
9 + field_based, 9 + field_based,
uvsrc_x, uvsrc_y << field_based, uvsrc_x, uvsrc_y << field_based,
h_edge_pos >> 1, v_edge_pos >> 1); h_edge_pos >> 1, v_edge_pos >> 1);
@ -2390,7 +2393,7 @@ static inline void chroma_4mv_motion_lowres(MpegEncContext *s,
ptr = ref_picture[1] + offset; ptr = ref_picture[1] + offset;
if ((unsigned) src_x > FFMAX(h_edge_pos - (!!sx) - block_s, 0) || if ((unsigned) src_x > FFMAX(h_edge_pos - (!!sx) - block_s, 0) ||
(unsigned) src_y > FFMAX(v_edge_pos - (!!sy) - block_s, 0)) { (unsigned) src_y > FFMAX(v_edge_pos - (!!sy) - block_s, 0)) {
s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->uvlinesize, ptr, s->uvlinesize,
9, 9, src_x, src_y, h_edge_pos, v_edge_pos); 9, 9, src_x, src_y, h_edge_pos, v_edge_pos);
ptr = s->edge_emu_buffer; ptr = s->edge_emu_buffer;
emu = 1; emu = 1;
@ -2401,7 +2404,8 @@ static inline void chroma_4mv_motion_lowres(MpegEncContext *s,
ptr = ref_picture[2] + offset; ptr = ref_picture[2] + offset;
if (emu) { if (emu) {
s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->uvlinesize,
ptr, s->uvlinesize, 9, 9,
src_x, src_y, h_edge_pos, v_edge_pos); src_x, src_y, h_edge_pos, v_edge_pos);
ptr = s->edge_emu_buffer; ptr = s->edge_emu_buffer;
} }

View File

@ -1819,14 +1819,14 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
uint8_t *ebuf = s->edge_emu_buffer + 32; uint8_t *ebuf = s->edge_emu_buffer + 32;
int cw = (s->width + s->chroma_x_shift) >> s->chroma_x_shift; int cw = (s->width + s->chroma_x_shift) >> s->chroma_x_shift;
int ch = (s->height + s->chroma_y_shift) >> s->chroma_y_shift; int ch = (s->height + s->chroma_y_shift) >> s->chroma_y_shift;
s->vdsp.emulated_edge_mc(ebuf, ptr_y, wrap_y, 16, 16, mb_x * 16, s->vdsp.emulated_edge_mc(ebuf, wrap_y, ptr_y, wrap_y, 16, 16, mb_x * 16,
mb_y * 16, s->width, s->height); mb_y * 16, s->width, s->height);
ptr_y = ebuf; ptr_y = ebuf;
s->vdsp.emulated_edge_mc(ebuf + 18 * wrap_y, ptr_cb, wrap_c, mb_block_width, s->vdsp.emulated_edge_mc(ebuf + 18 * wrap_y, wrap_c, ptr_cb, wrap_c, mb_block_width,
mb_block_height, mb_x * mb_block_width, mb_y * mb_block_height, mb_block_height, mb_x * mb_block_width, mb_y * mb_block_height,
cw, ch); cw, ch);
ptr_cb = ebuf + 18 * wrap_y; ptr_cb = ebuf + 18 * wrap_y;
s->vdsp.emulated_edge_mc(ebuf + 18 * wrap_y + 16, ptr_cr, wrap_c, mb_block_width, s->vdsp.emulated_edge_mc(ebuf + 18 * wrap_y + 16, wrap_c, ptr_cr, wrap_c, mb_block_width,
mb_block_height, mb_x * mb_block_width, mb_y * mb_block_height, mb_block_height, mb_x * mb_block_width, mb_y * mb_block_height,
cw, ch); cw, ch);
ptr_cr = ebuf + 18 * wrap_y + 16; ptr_cr = ebuf + 18 * wrap_y + 16;

View File

@ -63,7 +63,9 @@ static void gmc1_motion(MpegEncContext *s,
if( (unsigned)src_x >= FFMAX(s->h_edge_pos - 17, 0) if( (unsigned)src_x >= FFMAX(s->h_edge_pos - 17, 0)
|| (unsigned)src_y >= FFMAX(s->v_edge_pos - 17, 0)){ || (unsigned)src_y >= FFMAX(s->v_edge_pos - 17, 0)){
s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr, linesize, 17, 17, src_x, src_y, s->h_edge_pos, s->v_edge_pos); s->vdsp.emulated_edge_mc(s->edge_emu_buffer, linesize,
ptr, linesize, 17, 17, src_x, src_y,
s->h_edge_pos, s->v_edge_pos);
ptr= s->edge_emu_buffer; ptr= s->edge_emu_buffer;
} }
@ -100,7 +102,9 @@ static void gmc1_motion(MpegEncContext *s,
ptr = ref_picture[1] + offset; ptr = ref_picture[1] + offset;
if( (unsigned)src_x >= FFMAX((s->h_edge_pos>>1) - 9, 0) if( (unsigned)src_x >= FFMAX((s->h_edge_pos>>1) - 9, 0)
|| (unsigned)src_y >= FFMAX((s->v_edge_pos>>1) - 9, 0)){ || (unsigned)src_y >= FFMAX((s->v_edge_pos>>1) - 9, 0)){
s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); s->vdsp.emulated_edge_mc(s->edge_emu_buffer, uvlinesize,
ptr, uvlinesize, 9, 9, src_x, src_y,
s->h_edge_pos>>1, s->v_edge_pos>>1);
ptr= s->edge_emu_buffer; ptr= s->edge_emu_buffer;
emu=1; emu=1;
} }
@ -108,7 +112,9 @@ static void gmc1_motion(MpegEncContext *s,
ptr = ref_picture[2] + offset; ptr = ref_picture[2] + offset;
if(emu){ if(emu){
s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); s->vdsp.emulated_edge_mc(s->edge_emu_buffer, uvlinesize,
ptr, uvlinesize, 9, 9, src_x, src_y,
s->h_edge_pos>>1, s->v_edge_pos>>1);
ptr= s->edge_emu_buffer; ptr= s->edge_emu_buffer;
} }
s->dsp.gmc1(dest_cr, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding); s->dsp.gmc1(dest_cr, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding);
@ -196,7 +202,8 @@ static inline int hpel_motion(MpegEncContext *s,
if(s->unrestricted_mv && (s->flags&CODEC_FLAG_EMU_EDGE)){ if(s->unrestricted_mv && (s->flags&CODEC_FLAG_EMU_EDGE)){
if( (unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x&1) - 8, 0) if( (unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x&1) - 8, 0)
|| (unsigned)src_y > FFMAX(s->v_edge_pos - (motion_y&1) - 8, 0)){ || (unsigned)src_y > FFMAX(s->v_edge_pos - (motion_y&1) - 8, 0)){
s->vdsp.emulated_edge_mc(s->edge_emu_buffer, src, s->linesize, 9, 9, s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->linesize,
src, s->linesize, 9, 9,
src_x, src_y, s->h_edge_pos, s->v_edge_pos); src_x, src_y, s->h_edge_pos, s->v_edge_pos);
src= s->edge_emu_buffer; src= s->edge_emu_buffer;
emu=1; emu=1;
@ -287,19 +294,19 @@ if(s->quarter_sample)
"MPEG motion vector out of boundary (%d %d)\n", src_x, src_y); "MPEG motion vector out of boundary (%d %d)\n", src_x, src_y);
return; return;
} }
s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->linesize,
17, 17+field_based, ptr_y, s->linesize, 17, 17+field_based,
src_x, src_y<<field_based, src_x, src_y<<field_based,
s->h_edge_pos, s->v_edge_pos); s->h_edge_pos, s->v_edge_pos);
ptr_y = s->edge_emu_buffer; ptr_y = s->edge_emu_buffer;
if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize; uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize;
s->vdsp.emulated_edge_mc(uvbuf , s->vdsp.emulated_edge_mc(uvbuf, s->uvlinesize,
ptr_cb, s->uvlinesize, ptr_cb, s->uvlinesize,
9, 9+field_based, 9, 9+field_based,
uvsrc_x, uvsrc_y<<field_based, uvsrc_x, uvsrc_y<<field_based,
s->h_edge_pos>>1, s->v_edge_pos>>1); s->h_edge_pos>>1, s->v_edge_pos>>1);
s->vdsp.emulated_edge_mc(uvbuf+16, s->vdsp.emulated_edge_mc(uvbuf+16, s->uvlinesize,
ptr_cr, s->uvlinesize, ptr_cr, s->uvlinesize,
9, 9+field_based, 9, 9+field_based,
uvsrc_x, uvsrc_y<<field_based, uvsrc_x, uvsrc_y<<field_based,
@ -501,17 +508,20 @@ static inline void qpel_motion(MpegEncContext *s,
if( (unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x&3) - 16, 0) if( (unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x&3) - 16, 0)
|| (unsigned)src_y > FFMAX( v_edge_pos - (motion_y&3) - h , 0)){ || (unsigned)src_y > FFMAX( v_edge_pos - (motion_y&3) - h , 0)){
s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->linesize,
ptr_y, s->linesize,
17, 17+field_based, src_x, src_y<<field_based, 17, 17+field_based, src_x, src_y<<field_based,
s->h_edge_pos, s->v_edge_pos); s->h_edge_pos, s->v_edge_pos);
ptr_y= s->edge_emu_buffer; ptr_y= s->edge_emu_buffer;
if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
uint8_t *uvbuf= s->edge_emu_buffer + 18*s->linesize; uint8_t *uvbuf= s->edge_emu_buffer + 18*s->linesize;
s->vdsp.emulated_edge_mc(uvbuf, ptr_cb, s->uvlinesize, s->vdsp.emulated_edge_mc(uvbuf, s->uvlinesize,
ptr_cb, s->uvlinesize,
9, 9 + field_based, 9, 9 + field_based,
uvsrc_x, uvsrc_y<<field_based, uvsrc_x, uvsrc_y<<field_based,
s->h_edge_pos>>1, s->v_edge_pos>>1); s->h_edge_pos>>1, s->v_edge_pos>>1);
s->vdsp.emulated_edge_mc(uvbuf + 16, ptr_cr, s->uvlinesize, s->vdsp.emulated_edge_mc(uvbuf + 16, s->uvlinesize,
ptr_cr, s->uvlinesize,
9, 9 + field_based, 9, 9 + field_based,
uvsrc_x, uvsrc_y<<field_based, uvsrc_x, uvsrc_y<<field_based,
s->h_edge_pos>>1, s->v_edge_pos>>1); s->h_edge_pos>>1, s->v_edge_pos>>1);
@ -581,8 +591,8 @@ static void chroma_4mv_motion(MpegEncContext *s,
if(s->flags&CODEC_FLAG_EMU_EDGE){ if(s->flags&CODEC_FLAG_EMU_EDGE){
if( (unsigned)src_x > FFMAX((s->h_edge_pos>>1) - (dxy &1) - 8, 0) if( (unsigned)src_x > FFMAX((s->h_edge_pos>>1) - (dxy &1) - 8, 0)
|| (unsigned)src_y > FFMAX((s->v_edge_pos>>1) - (dxy>>1) - 8, 0)){ || (unsigned)src_y > FFMAX((s->v_edge_pos>>1) - (dxy>>1) - 8, 0)){
s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->uvlinesize,
9, 9, src_x, src_y, ptr, s->uvlinesize, 9, 9, src_x, src_y,
s->h_edge_pos>>1, s->v_edge_pos>>1); s->h_edge_pos>>1, s->v_edge_pos>>1);
ptr= s->edge_emu_buffer; ptr= s->edge_emu_buffer;
emu=1; emu=1;
@ -592,8 +602,8 @@ static void chroma_4mv_motion(MpegEncContext *s,
ptr = ref_picture[2] + offset; ptr = ref_picture[2] + offset;
if(emu){ if(emu){
s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->uvlinesize,
9, 9, src_x, src_y, ptr, s->uvlinesize, 9, 9, src_x, src_y,
s->h_edge_pos>>1, s->v_edge_pos>>1); s->h_edge_pos>>1, s->v_edge_pos>>1);
ptr= s->edge_emu_buffer; ptr= s->edge_emu_buffer;
} }
@ -761,8 +771,8 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s,
if(s->flags&CODEC_FLAG_EMU_EDGE){ if(s->flags&CODEC_FLAG_EMU_EDGE){
if( (unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x&3) - 8, 0) if( (unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x&3) - 8, 0)
|| (unsigned)src_y > FFMAX(s->v_edge_pos - (motion_y&3) - 8, 0)){ || (unsigned)src_y > FFMAX(s->v_edge_pos - (motion_y&3) - 8, 0)){
s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr, s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->linesize,
s->linesize, 9, 9, ptr, s->linesize, 9, 9,
src_x, src_y, src_x, src_y,
s->h_edge_pos, s->v_edge_pos); s->h_edge_pos, s->v_edge_pos);
ptr= s->edge_emu_buffer; ptr= s->edge_emu_buffer;

View File

@ -724,13 +724,16 @@ static inline void rv34_mc(RV34DecContext *r, const int block_type,
uint8_t *uvbuf = s->edge_emu_buffer + 22 * s->linesize; uint8_t *uvbuf = s->edge_emu_buffer + 22 * s->linesize;
srcY -= 2 + 2*s->linesize; srcY -= 2 + 2*s->linesize;
s->vdsp.emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, (width<<3)+6, (height<<3)+6, s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->linesize, srcY, s->linesize,
src_x - 2, src_y - 2, s->h_edge_pos, s->v_edge_pos); (width<<3)+6, (height<<3)+6, src_x - 2, src_y - 2,
s->h_edge_pos, s->v_edge_pos);
srcY = s->edge_emu_buffer + 2 + 2*s->linesize; srcY = s->edge_emu_buffer + 2 + 2*s->linesize;
s->vdsp.emulated_edge_mc(uvbuf , srcU, s->uvlinesize, (width<<2)+1, (height<<2)+1, s->vdsp.emulated_edge_mc(uvbuf, s->uvlinesize, srcU, s->uvlinesize,
uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1); (width<<2)+1, (height<<2)+1, uvsrc_x, uvsrc_y,
s->vdsp.emulated_edge_mc(uvbuf + 16, srcV, s->uvlinesize, (width<<2)+1, (height<<2)+1, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1); s->vdsp.emulated_edge_mc(uvbuf + 16, s->uvlinesize, srcV, s->uvlinesize,
(width<<2)+1, (height<<2)+1, uvsrc_x, uvsrc_y,
s->h_edge_pos >> 1, s->v_edge_pos >> 1);
srcU = uvbuf; srcU = uvbuf;
srcV = uvbuf + 16; srcV = uvbuf + 16;
} }

View File

@ -349,7 +349,9 @@ void ff_snow_pred_block(SnowContext *s, uint8_t *dst, uint8_t *tmp, ptrdiff_t st
src += sx + sy*stride; src += sx + sy*stride;
if( (unsigned)sx >= FFMAX(w - b_w - (HTAPS_MAX-2), 0) if( (unsigned)sx >= FFMAX(w - b_w - (HTAPS_MAX-2), 0)
|| (unsigned)sy >= FFMAX(h - b_h - (HTAPS_MAX-2), 0)){ || (unsigned)sy >= FFMAX(h - b_h - (HTAPS_MAX-2), 0)){
s->vdsp.emulated_edge_mc(tmp + MB_SIZE, src, stride, b_w+HTAPS_MAX-1, b_h+HTAPS_MAX-1, sx, sy, w, h); s->vdsp.emulated_edge_mc(tmp + MB_SIZE, stride, src, stride,
b_w+HTAPS_MAX-1, b_h+HTAPS_MAX-1,
sx, sy, w, h);
src= tmp + MB_SIZE; src= tmp + MB_SIZE;
} }

View File

@ -317,7 +317,8 @@ static inline void svq3_mc_dir_part(SVQ3Context *s,
src = pic->f.data[0] + mx + my * h->linesize; src = pic->f.data[0] + mx + my * h->linesize;
if (emu) { if (emu) {
h->vdsp.emulated_edge_mc(h->edge_emu_buffer, src, h->linesize, h->vdsp.emulated_edge_mc(h->edge_emu_buffer, h->linesize,
src, h->linesize,
width + 1, height + 1, width + 1, height + 1,
mx, my, s->h_edge_pos, s->v_edge_pos); mx, my, s->h_edge_pos, s->v_edge_pos);
src = h->edge_emu_buffer; src = h->edge_emu_buffer;
@ -343,7 +344,8 @@ static inline void svq3_mc_dir_part(SVQ3Context *s,
src = pic->f.data[i] + mx + my * h->uvlinesize; src = pic->f.data[i] + mx + my * h->uvlinesize;
if (emu) { if (emu) {
h->vdsp.emulated_edge_mc(h->edge_emu_buffer, src, h->uvlinesize, h->vdsp.emulated_edge_mc(h->edge_emu_buffer, h->uvlinesize,
src, h->uvlinesize,
width + 1, height + 1, width + 1, height + 1,
mx, my, (s->h_edge_pos >> 1), mx, my, (s->h_edge_pos >> 1),
s->v_edge_pos >> 1); s->v_edge_pos >> 1);

View File

@ -454,15 +454,18 @@ static void vc1_mc_1mv(VC1Context *v, int dir)
uint8_t *uvbuf = s->edge_emu_buffer + 19 * s->linesize; uint8_t *uvbuf = s->edge_emu_buffer + 19 * s->linesize;
srcY -= s->mspel * (1 + s->linesize); srcY -= s->mspel * (1 + s->linesize);
s->vdsp.emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->linesize,
srcY, s->linesize,
17 + s->mspel * 2, 17 + s->mspel * 2, 17 + s->mspel * 2, 17 + s->mspel * 2,
src_x - s->mspel, src_y - s->mspel, src_x - s->mspel, src_y - s->mspel,
s->h_edge_pos, v_edge_pos); s->h_edge_pos, v_edge_pos);
srcY = s->edge_emu_buffer; srcY = s->edge_emu_buffer;
s->vdsp.emulated_edge_mc(uvbuf , srcU, s->uvlinesize, 8 + 1, 8 + 1, s->vdsp.emulated_edge_mc(uvbuf, s->uvlinesize, srcU, s->uvlinesize,
uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, v_edge_pos >> 1); 8 + 1, 8 + 1, uvsrc_x, uvsrc_y,
s->vdsp.emulated_edge_mc(uvbuf + 16, srcV, s->uvlinesize, 8 + 1, 8 + 1, s->h_edge_pos >> 1, v_edge_pos >> 1);
uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, v_edge_pos >> 1); s->vdsp.emulated_edge_mc(uvbuf + 16, s->uvlinesize, srcV, s->uvlinesize,
8 + 1, 8 + 1, uvsrc_x, uvsrc_y,
s->h_edge_pos >> 1, v_edge_pos >> 1);
srcU = uvbuf; srcU = uvbuf;
srcV = uvbuf + 16; srcV = uvbuf + 16;
/* if we deal with range reduction we need to scale source blocks */ /* if we deal with range reduction we need to scale source blocks */
@ -697,7 +700,7 @@ static void vc1_mc_4mv_luma(VC1Context *v, int n, int dir, int avg)
|| (unsigned)(src_y - (s->mspel << fieldmv)) > v_edge_pos - (my & 3) - ((8 + s->mspel * 2) << fieldmv)) { || (unsigned)(src_y - (s->mspel << fieldmv)) > v_edge_pos - (my & 3) - ((8 + s->mspel * 2) << fieldmv)) {
srcY -= s->mspel * (1 + (s->linesize << fieldmv)); srcY -= s->mspel * (1 + (s->linesize << fieldmv));
/* check emulate edge stride and offset */ /* check emulate edge stride and offset */
s->vdsp.emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->linesize, srcY, s->linesize,
9 + s->mspel * 2, (9 + s->mspel * 2) << fieldmv, 9 + s->mspel * 2, (9 + s->mspel * 2) << fieldmv,
src_x - s->mspel, src_y - (s->mspel << fieldmv), src_x - s->mspel, src_y - (s->mspel << fieldmv),
s->h_edge_pos, v_edge_pos); s->h_edge_pos, v_edge_pos);
@ -912,11 +915,11 @@ static void vc1_mc_4mv_chroma(VC1Context *v, int dir)
|| s->h_edge_pos < 18 || v_edge_pos < 18 || s->h_edge_pos < 18 || v_edge_pos < 18
|| (unsigned)uvsrc_x > (s->h_edge_pos >> 1) - 9 || (unsigned)uvsrc_x > (s->h_edge_pos >> 1) - 9
|| (unsigned)uvsrc_y > (v_edge_pos >> 1) - 9) { || (unsigned)uvsrc_y > (v_edge_pos >> 1) - 9) {
s->vdsp.emulated_edge_mc(s->edge_emu_buffer , srcU, s->uvlinesize, s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->uvlinesize, srcU,
8 + 1, 8 + 1, uvsrc_x, uvsrc_y, s->uvlinesize, 8 + 1, 8 + 1, uvsrc_x, uvsrc_y,
s->h_edge_pos >> 1, v_edge_pos >> 1); s->h_edge_pos >> 1, v_edge_pos >> 1);
s->vdsp.emulated_edge_mc(s->edge_emu_buffer + 16, srcV, s->uvlinesize, s->vdsp.emulated_edge_mc(s->edge_emu_buffer + 16, s->uvlinesize, srcV,
8 + 1, 8 + 1, uvsrc_x, uvsrc_y, s->uvlinesize, 8 + 1, 8 + 1, uvsrc_x, uvsrc_y,
s->h_edge_pos >> 1, v_edge_pos >> 1); s->h_edge_pos >> 1, v_edge_pos >> 1);
srcU = s->edge_emu_buffer; srcU = s->edge_emu_buffer;
srcV = s->edge_emu_buffer + 16; srcV = s->edge_emu_buffer + 16;
@ -1033,12 +1036,12 @@ static void vc1_mc_4mv_chroma4(VC1Context *v, int dir, int dir2, int avg)
|| s->h_edge_pos < 10 || v_edge_pos < (5 << fieldmv) || s->h_edge_pos < 10 || v_edge_pos < (5 << fieldmv)
|| (unsigned)uvsrc_x > (s->h_edge_pos >> 1) - 5 || (unsigned)uvsrc_x > (s->h_edge_pos >> 1) - 5
|| (unsigned)uvsrc_y > v_edge_pos - (5 << fieldmv)) { || (unsigned)uvsrc_y > v_edge_pos - (5 << fieldmv)) {
s->vdsp.emulated_edge_mc(s->edge_emu_buffer, srcU, s->uvlinesize, s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->uvlinesize, srcU,
5, (5 << fieldmv), uvsrc_x, uvsrc_y, s->uvlinesize, 5, (5 << fieldmv), uvsrc_x,
s->h_edge_pos >> 1, v_edge_pos); uvsrc_y, s->h_edge_pos >> 1, v_edge_pos);
s->vdsp.emulated_edge_mc(s->edge_emu_buffer + 16, srcV, s->uvlinesize, s->vdsp.emulated_edge_mc(s->edge_emu_buffer + 16, s->uvlinesize, srcV,
5, (5 << fieldmv), uvsrc_x, uvsrc_y, s->uvlinesize, 5, (5 << fieldmv), uvsrc_x,
s->h_edge_pos >> 1, v_edge_pos); uvsrc_y, s->h_edge_pos >> 1, v_edge_pos);
srcU = s->edge_emu_buffer; srcU = s->edge_emu_buffer;
srcV = s->edge_emu_buffer + 16; srcV = s->edge_emu_buffer + 16;
@ -1966,15 +1969,17 @@ static void vc1_interp_mc(VC1Context *v)
uint8_t *uvbuf = s->edge_emu_buffer + 19 * s->linesize; uint8_t *uvbuf = s->edge_emu_buffer + 19 * s->linesize;
srcY -= s->mspel * (1 + s->linesize); srcY -= s->mspel * (1 + s->linesize);
s->vdsp.emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->linesize, srcY, s->linesize,
17 + s->mspel * 2, 17 + s->mspel * 2, 17 + s->mspel * 2, 17 + s->mspel * 2,
src_x - s->mspel, src_y - s->mspel, src_x - s->mspel, src_y - s->mspel,
s->h_edge_pos, v_edge_pos); s->h_edge_pos, v_edge_pos);
srcY = s->edge_emu_buffer; srcY = s->edge_emu_buffer;
s->vdsp.emulated_edge_mc(uvbuf , srcU, s->uvlinesize, 8 + 1, 8 + 1, s->vdsp.emulated_edge_mc(uvbuf, s->uvlinesize, srcU, s->uvlinesize,
uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, v_edge_pos >> 1); 8 + 1, 8 + 1, uvsrc_x, uvsrc_y,
s->vdsp.emulated_edge_mc(uvbuf + 16, srcV, s->uvlinesize, 8 + 1, 8 + 1, s->h_edge_pos >> 1, v_edge_pos >> 1);
uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, v_edge_pos >> 1); s->vdsp.emulated_edge_mc(uvbuf + 16, s->uvlinesize, srcV, s->uvlinesize,
8 + 1, 8 + 1, uvsrc_x, uvsrc_y,
s->h_edge_pos >> 1, v_edge_pos >> 1);
srcU = uvbuf; srcU = uvbuf;
srcV = uvbuf + 16; srcV = uvbuf + 16;
/* if we deal with range reduction we need to scale source blocks */ /* if we deal with range reduction we need to scale source blocks */

View File

@ -30,7 +30,8 @@
#include <stdint.h> #include <stdint.h>
#define EMULATED_EDGE(depth) \ #define EMULATED_EDGE(depth) \
void ff_emulated_edge_mc_ ## depth (uint8_t *buf, const uint8_t *src, ptrdiff_t linesize,\ void ff_emulated_edge_mc_ ## depth(uint8_t *dst, ptrdiff_t dst_stride, \
const uint8_t *src, ptrdiff_t src_stride, \
int block_w, int block_h,\ int block_w, int block_h,\
int src_x, int src_y, int w, int h); int src_x, int src_y, int w, int h);
@ -42,10 +43,12 @@ typedef struct VideoDSPContext {
* Copy a rectangular area of samples to a temporary buffer and replicate * Copy a rectangular area of samples to a temporary buffer and replicate
* the border samples. * the border samples.
* *
* @param buf destination buffer * @param dst destination buffer
* @param dst_stride number of bytes between 2 vertically adjacent samples
* in destination buffer
* @param src source buffer * @param src source buffer
* @param linesize number of bytes between 2 vertically adjacent samples * @param src_stride number of bytes between 2 vertically adjacent samples
* in both the source and destination buffers * in source buffer
* @param block_w width of block * @param block_w width of block
* @param block_h height of block * @param block_h height of block
* @param src_x x coordinate of the top left sample of the block in the * @param src_x x coordinate of the top left sample of the block in the
@ -55,8 +58,9 @@ typedef struct VideoDSPContext {
* @param w width of the source buffer * @param w width of the source buffer
* @param h height of the source buffer * @param h height of the source buffer
*/ */
void (*emulated_edge_mc)(uint8_t *buf, const uint8_t *src, void (*emulated_edge_mc)(uint8_t *dst, ptrdiff_t dst_stride,
ptrdiff_t linesize, int block_w, int block_h, const uint8_t *src, ptrdiff_t src_stride,
int block_w, int block_h,
int src_x, int src_y, int w, int h); int src_x, int src_y, int w, int h);
/** /**

View File

@ -20,8 +20,8 @@
*/ */
#include "bit_depth_template.c" #include "bit_depth_template.c"
void FUNC(ff_emulated_edge_mc)(uint8_t *buf, const uint8_t *src, void FUNC(ff_emulated_edge_mc)(uint8_t *buf, ptrdiff_t buf_stride,
ptrdiff_t linesize, const uint8_t *src, ptrdiff_t src_stride,
int block_w, int block_h, int block_w, int block_h,
int src_x, int src_y, int w, int h) int src_x, int src_y, int w, int h)
{ {
@ -32,12 +32,12 @@ void FUNC(ff_emulated_edge_mc)(uint8_t *buf, const uint8_t *src,
return; return;
if (src_y >= h) { if (src_y >= h) {
src -= src_y * linesize; src -= src_y * src_stride;
src += (h - 1) * linesize; src += (h - 1) * src_stride;
src_y = h - 1; src_y = h - 1;
} else if (src_y <= -block_h) { } else if (src_y <= -block_h) {
src -= src_y * linesize; src -= src_y * src_stride;
src += (1 - block_h) * linesize; src += (1 - block_h) * src_stride;
src_y = 1 - block_h; src_y = 1 - block_h;
} }
if (src_x >= w) { if (src_x >= w) {
@ -56,30 +56,30 @@ void FUNC(ff_emulated_edge_mc)(uint8_t *buf, const uint8_t *src,
av_assert2(start_x < end_x && block_w); av_assert2(start_x < end_x && block_w);
w = end_x - start_x; w = end_x - start_x;
src += start_y * linesize + start_x * sizeof(pixel); src += start_y * src_stride + start_x * sizeof(pixel);
buf += start_x * sizeof(pixel); buf += start_x * sizeof(pixel);
// top // top
for (y = 0; y < start_y; y++) { for (y = 0; y < start_y; y++) {
memcpy(buf, src, w * sizeof(pixel)); memcpy(buf, src, w * sizeof(pixel));
buf += linesize; buf += buf_stride;
} }
// copy existing part // copy existing part
for (; y < end_y; y++) { for (; y < end_y; y++) {
memcpy(buf, src, w * sizeof(pixel)); memcpy(buf, src, w * sizeof(pixel));
src += linesize; src += src_stride;
buf += linesize; buf += buf_stride;
} }
// bottom // bottom
src -= linesize; src -= src_stride;
for (; y < block_h; y++) { for (; y < block_h; y++) {
memcpy(buf, src, w * sizeof(pixel)); memcpy(buf, src, w * sizeof(pixel));
buf += linesize; buf += buf_stride;
} }
buf -= block_h * linesize + start_x * sizeof(pixel); buf -= block_h * buf_stride + start_x * sizeof(pixel);
while (block_h--) { while (block_h--) {
pixel *bufp = (pixel *) buf; pixel *bufp = (pixel *) buf;
@ -92,6 +92,6 @@ void FUNC(ff_emulated_edge_mc)(uint8_t *buf, const uint8_t *src,
for (x = end_x; x < block_w; x++) { for (x = end_x; x < block_w; x++) {
bufp[x] = bufp[end_x - 1]; bufp[x] = bufp[end_x - 1];
} }
buf += linesize; buf += buf_stride;
} }
} }

View File

@ -1549,7 +1549,10 @@ static void render_slice(Vp3DecodeContext *s, int slice)
uint8_t *temp= s->edge_emu_buffer; uint8_t *temp= s->edge_emu_buffer;
if(stride<0) temp -= 8*stride; if(stride<0) temp -= 8*stride;
s->vdsp.emulated_edge_mc(temp, motion_source, stride, 9, 9, src_x, src_y, plane_width, plane_height); s->vdsp.emulated_edge_mc(temp, stride,
motion_source, stride,
9, 9, src_x, src_y,
plane_width, plane_height);
motion_source= temp; motion_source= temp;
} }
} }

View File

@ -339,7 +339,7 @@ static void vp56_mc(VP56Context *s, int b, int plane, uint8_t *src,
if (x<0 || x+12>=s->plane_width[plane] || if (x<0 || x+12>=s->plane_width[plane] ||
y<0 || y+12>=s->plane_height[plane]) { y<0 || y+12>=s->plane_height[plane]) {
s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->vdsp.emulated_edge_mc(s->edge_emu_buffer, stride,
src + s->block_offset[b] + (dy-2)*stride + (dx-2), src + s->block_offset[b] + (dy-2)*stride + (dx-2),
stride, 12, 12, x, y, stride, 12, 12, x, y,
s->plane_width[plane], s->plane_width[plane],

View File

@ -45,7 +45,6 @@ static void free_buffers(VP8Context *s)
pthread_mutex_destroy(&s->thread_data[i].lock); pthread_mutex_destroy(&s->thread_data[i].lock);
#endif #endif
av_freep(&s->thread_data[i].filter_strength); av_freep(&s->thread_data[i].filter_strength);
av_freep(&s->thread_data[i].edge_emu_buffer);
} }
av_freep(&s->thread_data); av_freep(&s->thread_data);
av_freep(&s->macroblocks_base); av_freep(&s->macroblocks_base);
@ -1186,7 +1185,7 @@ void vp8_mc_luma(VP8Context *s, VP8ThreadData *td, uint8_t *dst,
uint8_t *src = ref->f->data[0]; uint8_t *src = ref->f->data[0];
if (AV_RN32A(mv)) { if (AV_RN32A(mv)) {
int src_linesize = linesize;
int mx = (mv->x << 1)&7, mx_idx = subpel_idx[0][mx]; int mx = (mv->x << 1)&7, mx_idx = subpel_idx[0][mx];
int my = (mv->y << 1)&7, my_idx = subpel_idx[0][my]; int my = (mv->y << 1)&7, my_idx = subpel_idx[0][my];
@ -1198,12 +1197,15 @@ void vp8_mc_luma(VP8Context *s, VP8ThreadData *td, uint8_t *dst,
src += y_off * linesize + x_off; src += y_off * linesize + x_off;
if (x_off < mx_idx || x_off >= width - block_w - subpel_idx[2][mx] || if (x_off < mx_idx || x_off >= width - block_w - subpel_idx[2][mx] ||
y_off < my_idx || y_off >= height - block_h - subpel_idx[2][my]) { y_off < my_idx || y_off >= height - block_h - subpel_idx[2][my]) {
s->vdsp.emulated_edge_mc(td->edge_emu_buffer, src - my_idx * linesize - mx_idx, linesize, s->vdsp.emulated_edge_mc(td->edge_emu_buffer, 32,
block_w + subpel_idx[1][mx], block_h + subpel_idx[1][my], src - my_idx * linesize - mx_idx, linesize,
block_w + subpel_idx[1][mx],
block_h + subpel_idx[1][my],
x_off - mx_idx, y_off - my_idx, width, height); x_off - mx_idx, y_off - my_idx, width, height);
src = td->edge_emu_buffer + mx_idx + linesize * my_idx; src = td->edge_emu_buffer + mx_idx + 32 * my_idx;
src_linesize = 32;
} }
mc_func[my_idx][mx_idx](dst, linesize, src, linesize, block_h, mx, my); mc_func[my_idx][mx_idx](dst, linesize, src, src_linesize, block_h, mx, my);
} else { } else {
ff_thread_await_progress(ref, (3 + y_off + block_h) >> 4, 0); ff_thread_await_progress(ref, (3 + y_off + block_h) >> 4, 0);
mc_func[0][0](dst, linesize, src + y_off * linesize + x_off, linesize, block_h, 0, 0); mc_func[0][0](dst, linesize, src + y_off * linesize + x_off, linesize, block_h, 0, 0);
@ -1248,17 +1250,21 @@ void vp8_mc_chroma(VP8Context *s, VP8ThreadData *td, uint8_t *dst1, uint8_t *dst
ff_thread_await_progress(ref, (3 + y_off + block_h + subpel_idx[2][my]) >> 3, 0); ff_thread_await_progress(ref, (3 + y_off + block_h + subpel_idx[2][my]) >> 3, 0);
if (x_off < mx_idx || x_off >= width - block_w - subpel_idx[2][mx] || if (x_off < mx_idx || x_off >= width - block_w - subpel_idx[2][mx] ||
y_off < my_idx || y_off >= height - block_h - subpel_idx[2][my]) { y_off < my_idx || y_off >= height - block_h - subpel_idx[2][my]) {
s->vdsp.emulated_edge_mc(td->edge_emu_buffer, src1 - my_idx * linesize - mx_idx, linesize, s->vdsp.emulated_edge_mc(td->edge_emu_buffer, 32,
block_w + subpel_idx[1][mx], block_h + subpel_idx[1][my], src1 - my_idx * linesize - mx_idx, linesize,
block_w + subpel_idx[1][mx],
block_h + subpel_idx[1][my],
x_off - mx_idx, y_off - my_idx, width, height); x_off - mx_idx, y_off - my_idx, width, height);
src1 = td->edge_emu_buffer + mx_idx + linesize * my_idx; src1 = td->edge_emu_buffer + mx_idx + 32 * my_idx;
mc_func[my_idx][mx_idx](dst1, linesize, src1, linesize, block_h, mx, my); mc_func[my_idx][mx_idx](dst1, linesize, src1, 32, block_h, mx, my);
s->vdsp.emulated_edge_mc(td->edge_emu_buffer, src2 - my_idx * linesize - mx_idx, linesize, s->vdsp.emulated_edge_mc(td->edge_emu_buffer, 32,
block_w + subpel_idx[1][mx], block_h + subpel_idx[1][my], src2 - my_idx * linesize - mx_idx, linesize,
block_w + subpel_idx[1][mx],
block_h + subpel_idx[1][my],
x_off - mx_idx, y_off - my_idx, width, height); x_off - mx_idx, y_off - my_idx, width, height);
src2 = td->edge_emu_buffer + mx_idx + linesize * my_idx; src2 = td->edge_emu_buffer + mx_idx + 32 * my_idx;
mc_func[my_idx][mx_idx](dst2, linesize, src2, linesize, block_h, mx, my); mc_func[my_idx][mx_idx](dst2, linesize, src2, 32, block_h, mx, my);
} else { } else {
mc_func[my_idx][mx_idx](dst1, linesize, src1, linesize, block_h, mx, my); mc_func[my_idx][mx_idx](dst1, linesize, src1, linesize, block_h, mx, my);
mc_func[my_idx][mx_idx](dst2, linesize, src2, linesize, block_h, mx, my); mc_func[my_idx][mx_idx](dst2, linesize, src2, linesize, block_h, mx, my);
@ -1944,10 +1950,6 @@ int ff_vp8_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
s->linesize = curframe->tf.f->linesize[0]; s->linesize = curframe->tf.f->linesize[0];
s->uvlinesize = curframe->tf.f->linesize[1]; s->uvlinesize = curframe->tf.f->linesize[1];
if (!s->thread_data[0].edge_emu_buffer)
for (i = 0; i < MAX_THREADS; i++)
s->thread_data[i].edge_emu_buffer = av_malloc(21*s->linesize);
memset(s->top_nnz, 0, s->mb_width*sizeof(*s->top_nnz)); memset(s->top_nnz, 0, s->mb_width*sizeof(*s->top_nnz));
/* Zero macroblock structures for top/top-left prediction from outside the frame. */ /* Zero macroblock structures for top/top-left prediction from outside the frame. */
if (!s->mb_layout) if (!s->mb_layout)

View File

@ -122,7 +122,7 @@ typedef struct VP8ThreadData {
#endif #endif
int thread_mb_pos; // (mb_y << 16) | (mb_x & 0xFFFF) int thread_mb_pos; // (mb_y << 16) | (mb_x & 0xFFFF)
int wait_mb_pos; // What the current thread is waiting on. int wait_mb_pos; // What the current thread is waiting on.
uint8_t *edge_emu_buffer; DECLARE_ALIGNED(16, uint8_t, edge_emu_buffer)[21*32];
VP8FilterStrength *filter_strength; VP8FilterStrength *filter_strength;
} VP8ThreadData; } VP8ThreadData;

View File

@ -119,8 +119,10 @@ void ff_mspel_motion(MpegEncContext *s,
if(src_x<1 || src_y<1 || src_x + 17 >= s->h_edge_pos if(src_x<1 || src_y<1 || src_x + 17 >= s->h_edge_pos
|| src_y + h+1 >= v_edge_pos){ || src_y + h+1 >= v_edge_pos){
s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr - 1 - s->linesize, s->linesize, 19, 19, s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->linesize,
src_x-1, src_y-1, s->h_edge_pos, s->v_edge_pos); ptr - 1 - s->linesize, s->linesize, 19, 19,
src_x-1, src_y-1,
s->h_edge_pos, s->v_edge_pos);
ptr= s->edge_emu_buffer + 1 + s->linesize; ptr= s->edge_emu_buffer + 1 + s->linesize;
emu=1; emu=1;
} }
@ -159,16 +161,18 @@ void ff_mspel_motion(MpegEncContext *s,
offset = (src_y * uvlinesize) + src_x; offset = (src_y * uvlinesize) + src_x;
ptr = ref_picture[1] + offset; ptr = ref_picture[1] + offset;
if(emu){ if(emu){
s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->uvlinesize,
src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); ptr, s->uvlinesize, 9, 9, src_x, src_y,
s->h_edge_pos>>1, s->v_edge_pos>>1);
ptr= s->edge_emu_buffer; ptr= s->edge_emu_buffer;
} }
pix_op[1][dxy](dest_cb, ptr, uvlinesize, h >> 1); pix_op[1][dxy](dest_cb, ptr, uvlinesize, h >> 1);
ptr = ref_picture[2] + offset; ptr = ref_picture[2] + offset;
if(emu){ if(emu){
s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->uvlinesize,
src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); ptr, s->uvlinesize, 9, 9, src_x, src_y,
s->h_edge_pos>>1, s->v_edge_pos>>1);
ptr= s->edge_emu_buffer; ptr= s->edge_emu_buffer;
} }
pix_op[1][dxy](dest_cr, ptr, uvlinesize, h >> 1); pix_op[1][dxy](dest_cr, ptr, uvlinesize, h >> 1);

View File

@ -405,8 +405,9 @@ void ff_draw_edges_mmx(uint8_t *buf, int wrap, int width, int height,
} }
} }
typedef void emulated_edge_mc_func(uint8_t *dst, const uint8_t *src, typedef void emulated_edge_mc_func(uint8_t *dst, ptrdiff_t dst_stride,
ptrdiff_t linesize, int block_w, int block_h, const uint8_t *src, ptrdiff_t src_linesize,
int block_w, int block_h,
int src_x, int src_y, int w, int h); int src_x, int src_y, int w, int h);
static av_always_inline void gmc(uint8_t *dst, uint8_t *src, static av_always_inline void gmc(uint8_t *dst, uint8_t *src,
@ -454,7 +455,7 @@ static av_always_inline void gmc(uint8_t *dst, uint8_t *src,
src += ix + iy * stride; src += ix + iy * stride;
if (need_emu) { if (need_emu) {
emu_edge_fn(edge_buf, src, stride, w + 1, h + 1, ix, iy, width, height); emu_edge_fn(edge_buf, stride, src, stride, w + 1, h + 1, ix, iy, width, height);
src = edge_buf; src = edge_buf;
} }

View File

@ -23,576 +23,394 @@
SECTION .text SECTION .text
; void ff_emu_edge_core(uint8_t *buf, const uint8_t *src, x86_reg linesize, ; slow vertical extension loop function. Works with variable-width, and
; x86_reg start_y, x86_reg end_y, x86_reg block_h, ; does per-line reading/writing of source data
; x86_reg start_x, x86_reg end_x, x86_reg block_w);
;
; The actual function itself is below. It basically wraps a very simple
; w = end_x - start_x
; if (w) {
; if (w > 22) {
; jump to the slow loop functions
; } else {
; jump to the fast loop functions
; }
; }
;
; ... and then the same for left/right extend also. See below for loop
; function implementations. Fast are fixed-width, slow is variable-width
%macro EMU_EDGE_FUNC 0
%if ARCH_X86_64
%define w_reg r7
cglobal emu_edge_core, 6, 9, 1
mov r8, r5 ; save block_h
%else
%define w_reg r6
cglobal emu_edge_core, 2, 7, 0
mov r4, r4m ; end_y
mov r5, r5m ; block_h
%endif
; start with vertical extend (top/bottom) and body pixel copy
mov w_reg, r7m
sub w_reg, r6m ; w = start_x - end_x
sub r5, r4
%if ARCH_X86_64
sub r4, r3
%else
sub r4, dword r3m
%endif
cmp w_reg, 22
jg .slow_v_extend_loop
%if ARCH_X86_32
mov r2, r2m ; linesize
%endif
sal w_reg, 7 ; w * 128
%ifdef PIC
lea rax, [.emuedge_v_extend_1 - (.emuedge_v_extend_2 - .emuedge_v_extend_1)]
add w_reg, rax
%else
lea w_reg, [.emuedge_v_extend_1 - (.emuedge_v_extend_2 - .emuedge_v_extend_1)+w_reg]
%endif
call w_reg ; fast top extend, body copy and bottom extend
.v_extend_end:
; horizontal extend (left/right)
mov w_reg, r6m ; start_x
sub r0, w_reg
%if ARCH_X86_64
mov r3, r0 ; backup of buf+block_h*linesize
mov r5, r8
%else
mov r0m, r0 ; backup of buf+block_h*linesize
mov r5, r5m
%endif
test w_reg, w_reg
jz .right_extend
cmp w_reg, 22
jg .slow_left_extend_loop
mov r1, w_reg
dec w_reg
; FIXME we can do a if size == 1 here if that makes any speed difference, test me
sar w_reg, 1
sal w_reg, 6
; r0=buf+block_h*linesize,r7(64)/r6(32)=start_x offset for funcs
; r6(rax)/r3(ebx)=val,r2=linesize,r1=start_x,r5=block_h
%ifdef PIC
lea rax, [.emuedge_extend_left_2]
add w_reg, rax
%else
lea w_reg, [.emuedge_extend_left_2+w_reg]
%endif
call w_reg
; now r3(64)/r0(32)=buf,r2=linesize,r8/r5=block_h,r6/r3=val, r7/r6=end_x, r1=block_w
.right_extend:
%if ARCH_X86_32
mov r0, r0m
mov r5, r5m
%endif
mov w_reg, r7m ; end_x
mov r1, r8m ; block_w
mov r4, r1
sub r1, w_reg
jz .h_extend_end ; if (end_x == block_w) goto h_extend_end
cmp r1, 22
jg .slow_right_extend_loop
dec r1
; FIXME we can do a if size == 1 here if that makes any speed difference, test me
sar r1, 1
sal r1, 6
%ifdef PIC
lea rax, [.emuedge_extend_right_2]
add r1, rax
%else
lea r1, [.emuedge_extend_right_2+r1]
%endif
call r1
.h_extend_end:
RET
%if ARCH_X86_64
%define vall al
%define valh ah
%define valw ax
%define valw2 r7w
%define valw3 r3w
%if WIN64
%define valw4 r7w
%else ; unix64
%define valw4 r3w
%endif
%define vald eax
%else
%define vall bl
%define valh bh
%define valw bx
%define valw2 r6w
%define valw3 valw2
%define valw4 valw3
%define vald ebx
%define stack_offset 0x14
%endif
%macro V_COPY_ROW 2 ; type (top/body/bottom), h
.%1_y_loop: ; do {
mov wq, r7mp ; initialize w (r7mp = wmp)
.%1_x_loop: ; do {
movu m0, [srcq+wq] ; m0 = read($mmsize)
movu [dstq+wq], m0 ; write(m0, $mmsize)
add wq, mmsize ; w -= $mmsize
cmp wq, -mmsize ; } while (w > $mmsize);
jl .%1_x_loop
movu m0, [srcq-mmsize] ; m0 = read($mmsize)
movu [dstq-mmsize], m0 ; write(m0, $mmsize)
%ifidn %1, body ; if ($type == body) {
add srcq, src_strideq ; src += src_stride
%endif ; }
add dstq, dst_strideq ; dst += dst_stride
dec %2 ; } while (--$h);
jnz .%1_y_loop
%endmacro %endmacro
; macro to read/write a horizontal number of pixels (%2) to/from registers %macro vvar_fn 0
; on x86-64, - fills xmm0-15 for consecutive sets of 16 pixels ; .----. <- zero
; - if (%2 & 15 == 8) fills the last 8 bytes into rax ; | | <- top is copied from first line in body of source
; - else if (%2 & 8) fills 8 bytes into mm0 ; |----| <- start_y
; - if (%2 & 7 == 4) fills the last 4 bytes into rax ; | | <- body is copied verbatim (line-by-line) from source
; - else if (%2 & 4) fills 4 bytes into mm0-1 ; |----| <- end_y
; - if (%2 & 3 == 3) fills 2 bytes into r7/r3, and 1 into eax ; | | <- bottom is copied from last line in body of source
; (note that we're using r3 for body/bottom because it's a shorter ; '----' <- bh
; opcode, and then the loop fits in 128 bytes) %if ARCH_X86_64
; - else fills remaining bytes into rax cglobal emu_edge_vvar, 7, 8, 1, dst, dst_stride, src, src_stride, \
; on x86-32, - fills mm0-7 for consecutive sets of 8 pixels start_y, end_y, bh, w
; - if (%2 & 7 == 4) fills 4 bytes into ebx %else ; x86-32
; - else if (%2 & 4) fills 4 bytes into mm0-7 cglobal emu_edge_vvar, 1, 6, 1, dst, src, start_y, end_y, bh, w
; - if (%2 & 3 == 3) fills 2 bytes into r6, and 1 into ebx %define src_strideq r3mp
; - else fills remaining bytes into ebx %define dst_strideq r1mp
; writing data out is in the same way mov srcq, r2mp
%macro READ_NUM_BYTES 2 mov start_yq, r4mp
%assign %%src_off 0 ; offset in source buffer mov end_yq, r5mp
%assign %%smidx 0 ; mmx register idx mov bhq, r6mp
%assign %%sxidx 0 ; xmm register idx %endif
sub bhq, end_yq ; bh -= end_q
sub end_yq, start_yq ; end_q -= start_q
add srcq, r7mp ; (r7mp = wmp)
add dstq, r7mp ; (r7mp = wmp)
neg r7mp ; (r7mp = wmp)
test start_yq, start_yq ; if (start_q) {
jz .body
V_COPY_ROW top, start_yq ; v_copy_row(top, start_yq)
.body: ; }
V_COPY_ROW body, end_yq ; v_copy_row(body, end_yq)
test bhq, bhq ; if (bh) {
jz .end
sub srcq, src_strideq ; src -= src_stride
V_COPY_ROW bottom, bhq ; v_copy_row(bottom, bh)
.end: ; }
RET
%endmacro
%if cpuflag(sse) %if ARCH_X86_32
%rep %2/16 INIT_MMX mmx
movups xmm %+ %%sxidx, [r1+%%src_off] vvar_fn
%assign %%src_off %%src_off+16
%assign %%sxidx %%sxidx+1
%endrep ; %2/16
%endif %endif
%if ARCH_X86_64 INIT_XMM sse
%if (%2-%%src_off) == 8 vvar_fn
mov rax, [r1+%%src_off]
%assign %%src_off %%src_off+8
%endif ; (%2-%%src_off) == 8
%endif ; x86-64
%rep (%2-%%src_off)/8 %macro hvar_fn 0
movq mm %+ %%smidx, [r1+%%src_off] cglobal emu_edge_hvar, 5, 6, 1, dst, dst_stride, start_x, n_words, h, w
%assign %%src_off %%src_off+8 lea dstq, [dstq+n_wordsq*2]
%assign %%smidx %%smidx+1 neg n_wordsq
%endrep ; (%2-%%dst_off)/8 lea start_xq, [start_xq+n_wordsq*2]
.y_loop: ; do {
; FIXME also write a ssse3 version using pshufb
movzx wd, byte [dstq+start_xq] ; w = read(1)
imul wd, 0x01010101 ; w *= 0x01010101
movd m0, wd
mov wq, n_wordsq ; initialize w
%if cpuflag(sse)
shufps m0, m0, q0000 ; splat
%else ; mmx
punpckldq m0, m0 ; splat
%endif ; mmx/sse
.x_loop: ; do {
movu [dstq+wq*2], m0 ; write($reg, $mmsize)
add wq, mmsize/2 ; w -= $mmsize/2
cmp wq, -mmsize/2 ; } while (w > $mmsize/2)
jl .x_loop
movu [dstq-mmsize], m0 ; write($reg, $mmsize)
add dstq, dst_strideq ; dst += dst_stride
dec hq ; } while (h--)
jnz .y_loop
RET
%endmacro
%if (%2-%%src_off) == 4 %if ARCH_X86_32
mov vald, [r1+%%src_off] INIT_MMX mmx
%elif (%2-%%src_off) & 4 hvar_fn
movd mm %+ %%smidx, [r1+%%src_off] %endif
%assign %%src_off %%src_off+4
%endif ; (%2-%%src_off) ==/& 4
%if (%2-%%src_off) == 1 INIT_XMM sse
mov vall, [r1+%%src_off] hvar_fn
%elif (%2-%%src_off) == 2
mov valw, [r1+%%src_off] ; macro to read/write a horizontal number of pixels (%2) to/from registers
%elif (%2-%%src_off) == 3 ; on sse, - fills xmm0-15 for consecutive sets of 16 pixels
%ifidn %1, top ; - if (%2 & 8) fills 8 bytes into xmm$next
mov valw2, [r1+%%src_off] ; - if (%2 & 4) fills 4 bytes into xmm$next
; - if (%2 & 3) fills 1, 2 or 4 bytes in eax
; on mmx, - fills mm0-7 for consecutive sets of 8 pixels
; - if (%2 & 4) fills 4 bytes into mm$next
; - if (%2 & 3) fills 1, 2 or 4 bytes in eax
; writing data out is in the same way
%macro READ_NUM_BYTES 2
%assign %%off 0 ; offset in source buffer
%assign %%idx 0 ; mmx/xmm register index
%rep %2/mmsize
movu m %+ %%idx, [srcq+%%off]
%assign %%off %%off+mmsize
%assign %%idx %%idx+1
%endrep ; %2/mmsize
%if mmsize == 16
%if (%2-%%off) >= 8
%if %2 > 16 && (%2-%%off) > 8
movu m %+ %%idx, [srcq+%2-16]
%assign %%off %2
%else
movq m %+ %%idx, [srcq+%%off]
%assign %%off %%off+8
%endif
%assign %%idx %%idx+1
%endif ; (%2-%%off) >= 8
%endif
%if (%2-%%off) >= 4
%if %2 > 8 && (%2-%%off) > 4
movq m %+ %%idx, [srcq+%2-8]
%assign %%off %2
%else
movd m %+ %%idx, [srcq+%%off]
%assign %%off %%off+4
%endif
%assign %%idx %%idx+1
%endif ; (%2-%%off) >= 4
%if (%2-%%off) >= 1
%if %2 >= 4
movd m %+ %%idx, [srcq+%2-4]
%elif (%2-%%off) == 1
mov valb, [srcq+%2-1]
%elif (%2-%%off) == 2
mov valw, [srcq+%2-2]
%elifidn %1, body %elifidn %1, body
mov valw3, [r1+%%src_off] mov vald, [srcq+%2-3]
%elifidn %1, bottom %else
mov valw4, [r1+%%src_off] movd m %+ %%idx, [srcq+%2-3]
%endif ; %1 ==/!= top %endif
mov vall, [r1+%%src_off+2] %endif ; (%2-%%off) >= 1
%endif ; (%2-%%src_off) == 1/2/3
%endmacro ; READ_NUM_BYTES %endmacro ; READ_NUM_BYTES
%macro WRITE_NUM_BYTES 2 %macro WRITE_NUM_BYTES 2
%assign %%dst_off 0 ; offset in destination buffer %assign %%off 0 ; offset in destination buffer
%assign %%dmidx 0 ; mmx register idx %assign %%idx 0 ; mmx/xmm register index
%assign %%dxidx 0 ; xmm register idx
%if cpuflag(sse) %rep %2/mmsize
%rep %2/16 movu [dstq+%%off], m %+ %%idx
movups [r0+%%dst_off], xmm %+ %%dxidx %assign %%off %%off+mmsize
%assign %%dst_off %%dst_off+16 %assign %%idx %%idx+1
%assign %%dxidx %%dxidx+1 %endrep ; %2/mmsize
%endrep ; %2/16
%if mmsize == 16
%if (%2-%%off) >= 8
%if %2 > 16 && (%2-%%off) > 8
movu [dstq+%2-16], m %+ %%idx
%assign %%off %2
%else
movq [dstq+%%off], m %+ %%idx
%assign %%off %%off+8
%endif
%assign %%idx %%idx+1
%endif ; (%2-%%off) >= 8
%endif %endif
%if ARCH_X86_64 %if (%2-%%off) >= 4
%if (%2-%%dst_off) == 8 %if %2 > 8 && (%2-%%off) > 4
mov [r0+%%dst_off], rax movq [dstq+%2-8], m %+ %%idx
%assign %%dst_off %%dst_off+8 %assign %%off %2
%endif ; (%2-%%dst_off) == 8 %else
%endif ; x86-64 movd [dstq+%%off], m %+ %%idx
%assign %%off %%off+4
%endif
%assign %%idx %%idx+1
%endif ; (%2-%%off) >= 4
%rep (%2-%%dst_off)/8 %if (%2-%%off) >= 1
movq [r0+%%dst_off], mm %+ %%dmidx %if %2 >= 4
%assign %%dst_off %%dst_off+8 movd [dstq+%2-4], m %+ %%idx
%assign %%dmidx %%dmidx+1 %elif (%2-%%off) == 1
%endrep ; (%2-%%dst_off)/8 mov [dstq+%2-1], valb
%elif (%2-%%off) == 2
%if (%2-%%dst_off) == 4 mov [dstq+%2-2], valw
mov [r0+%%dst_off], vald
%elif (%2-%%dst_off) & 4
movd [r0+%%dst_off], mm %+ %%dmidx
%assign %%dst_off %%dst_off+4
%endif ; (%2-%%dst_off) ==/& 4
%if (%2-%%dst_off) == 1
mov [r0+%%dst_off], vall
%elif (%2-%%dst_off) == 2
mov [r0+%%dst_off], valw
%elif (%2-%%dst_off) == 3
%ifidn %1, top
mov [r0+%%dst_off], valw2
%elifidn %1, body %elifidn %1, body
mov [r0+%%dst_off], valw3 mov [dstq+%2-3], valw
%elifidn %1, bottom shr vald, 16
mov [r0+%%dst_off], valw4 mov [dstq+%2-1], valb
%endif ; %1 ==/!= top %else
mov [r0+%%dst_off+2], vall movd vald, m %+ %%idx
%endif ; (%2-%%dst_off) == 1/2/3 mov [dstq+%2-3], valw
shr vald, 16
mov [dstq+%2-1], valb
%endif
%endif ; (%2-%%off) >= 1
%endmacro ; WRITE_NUM_BYTES %endmacro ; WRITE_NUM_BYTES
; vertical top/bottom extend and body copy fast loops ; vertical top/bottom extend and body copy fast loops
; these are function pointers to set-width line copy functions, i.e. ; these are function pointers to set-width line copy functions, i.e.
; they read a fixed number of pixels into set registers, and write ; they read a fixed number of pixels into set registers, and write
; those out into the destination buffer ; those out into the destination buffer
; r0=buf,r1=src,r2=linesize,r3(64)/r3m(32)=start_x,r4=end_y,r5=block_h %macro VERTICAL_EXTEND 2
; r6(eax/64)/r3(ebx/32)=val_reg %assign %%n %1
%macro VERTICAL_EXTEND 0 %rep 1+%2-%1
%assign %%n 1 %if %%n <= 3
%rep 22 %if ARCH_X86_64
ALIGN 128 cglobal emu_edge_vfix %+ %%n, 6, 8, 0, dst, dst_stride, src, src_stride, \
.emuedge_v_extend_ %+ %%n: start_y, end_y, val, bh
mov bhq, r6mp ; r6mp = bhmp
%else ; x86-32
cglobal emu_edge_vfix %+ %%n, 0, 6, 0, val, dst, src, start_y, end_y, bh
mov dstq, r0mp
mov srcq, r2mp
mov start_yq, r4mp
mov end_yq, r5mp
mov bhq, r6mp
%define dst_strideq r1mp
%define src_strideq r3mp
%endif ; x86-64/32
%else
%if ARCH_X86_64
cglobal emu_edge_vfix %+ %%n, 7, 7, 1, dst, dst_stride, src, src_stride, \
start_y, end_y, bh
%else ; x86-32
cglobal emu_edge_vfix %+ %%n, 1, 5, 1, dst, src, start_y, end_y, bh
mov srcq, r2mp
mov start_yq, r4mp
mov end_yq, r5mp
mov bhq, r6mp
%define dst_strideq r1mp
%define src_strideq r3mp
%endif ; x86-64/32
%endif
; FIXME move this to c wrapper?
sub bhq, end_yq ; bh -= end_y
sub end_yq, start_yq ; end_y -= start_y
; extend pixels above body ; extend pixels above body
%if ARCH_X86_64 test start_yq, start_yq ; if (start_y) {
test r3 , r3 ; if (!start_y) jz .body_loop
jz .emuedge_copy_body_ %+ %%n %+ _loop ; goto body READ_NUM_BYTES top, %%n ; $variable_regs = read($n)
%else ; ARCH_X86_32 .top_loop: ; do {
cmp dword r3m, 0 WRITE_NUM_BYTES top, %%n ; write($variable_regs, $n)
je .emuedge_copy_body_ %+ %%n %+ _loop add dstq, dst_strideq ; dst += linesize
%endif ; ARCH_X86_64/32 dec start_yq ; } while (--start_y)
READ_NUM_BYTES top, %%n ; read bytes jnz .top_loop ; }
.emuedge_extend_top_ %+ %%n %+ _loop: ; do {
WRITE_NUM_BYTES top, %%n ; write bytes
add r0 , r2 ; dst += linesize
%if ARCH_X86_64
dec r3d
%else ; ARCH_X86_32
dec dword r3m
%endif ; ARCH_X86_64/32
jnz .emuedge_extend_top_ %+ %%n %+ _loop ; } while (--start_y)
; copy body pixels ; copy body pixels
.emuedge_copy_body_ %+ %%n %+ _loop: ; do { .body_loop: ; do {
READ_NUM_BYTES body, %%n ; read bytes READ_NUM_BYTES body, %%n ; $variable_regs = read($n)
WRITE_NUM_BYTES body, %%n ; write bytes WRITE_NUM_BYTES body, %%n ; write($variable_regs, $n)
add r0 , r2 ; dst += linesize add dstq, dst_strideq ; dst += dst_stride
add r1 , r2 ; src += linesize add srcq, src_strideq ; src += src_stride
dec r4d dec end_yq ; } while (--end_y)
jnz .emuedge_copy_body_ %+ %%n %+ _loop ; } while (--end_y) jnz .body_loop
; copy bottom pixels ; copy bottom pixels
test r5 , r5 ; if (!block_h) test bhq, bhq ; if (block_h) {
jz .emuedge_v_extend_end_ %+ %%n ; goto end jz .end
sub r1 , r2 ; src -= linesize sub srcq, src_strideq ; src -= linesize
READ_NUM_BYTES bottom, %%n ; read bytes READ_NUM_BYTES bottom, %%n ; $variable_regs = read($n)
.emuedge_extend_bottom_ %+ %%n %+ _loop: ; do { .bottom_loop: ; do {
WRITE_NUM_BYTES bottom, %%n ; write bytes WRITE_NUM_BYTES bottom, %%n ; write($variable_regs, $n)
add r0 , r2 ; dst += linesize add dstq, dst_strideq ; dst += linesize
dec r5d dec bhq ; } while (--bh)
jnz .emuedge_extend_bottom_ %+ %%n %+ _loop ; } while (--block_h) jnz .bottom_loop ; }
.emuedge_v_extend_end_ %+ %%n: .end:
%if ARCH_X86_64 RET
ret
%else ; ARCH_X86_32
rep ret
%endif ; ARCH_X86_64/32
%assign %%n %%n+1 %assign %%n %%n+1
%endrep %endrep ; 1+%2-%1
%endmacro VERTICAL_EXTEND %endmacro ; VERTICAL_EXTEND
INIT_MMX mmx
VERTICAL_EXTEND 1, 15
%if ARCH_X86_32
VERTICAL_EXTEND 16, 22
%endif
INIT_XMM sse
VERTICAL_EXTEND 16, 22
; left/right (horizontal) fast extend functions ; left/right (horizontal) fast extend functions
; these are essentially identical to the vertical extend ones above, ; these are essentially identical to the vertical extend ones above,
; just left/right separated because number of pixels to extend is ; just left/right separated because number of pixels to extend is
; obviously not the same on both sides. ; obviously not the same on both sides.
; for reading, pixels are placed in eax (x86-64) or ebx (x86-64) in the
; lowest two bytes of the register (so val*0x0101), and are splatted
; into each byte of mm0 as well if n_pixels >= 8
%macro READ_V_PIXEL 2 %macro READ_V_PIXEL 2
mov vall, %2 %if %1 == 2
mov valh, vall movzx valw, byte %2
imul valw, 0x0101
%else
movzx vald, byte %2
imul vald, 0x01010101
%if %1 >= 8 %if %1 >= 8
movd mm0, vald movd m0, vald
%if cpuflag(mmxext) %if mmsize == 16
pshufw mm0, mm0, 0 shufps m0, m0, q0000
%else ; mmx %else
punpcklwd mm0, mm0 punpckldq m0, m0
punpckldq mm0, mm0 %endif
%endif ; sse
%endif ; %1 >= 8 %endif ; %1 >= 8
%endmacro %endif
%endmacro ; READ_V_PIXEL
%macro WRITE_V_PIXEL 2 %macro WRITE_V_PIXEL 2
%assign %%dst_off 0 %assign %%off 0
%rep %1/8 %rep %1/mmsize
movq [%2+%%dst_off], mm0 movu [%2+%%off], m0
%assign %%dst_off %%dst_off+8 %assign %%off %%off+mmsize
%endrep %endrep ; %1/mmsize
%if %1 & 4
%if mmsize == 16
%if %1-%%off >= 8
%if %1 > 16 && %1-%%off > 8
movu [%2+%1-16], m0
%assign %%off %1
%else
movq [%2+%%off], m0
%assign %%off %%off+8
%endif
%endif ; %1-%%off >= 8
%endif
%if %1-%%off >= 4
%if %1 > 8 %% %1-%%off > 4
movq [%2+%1-8], m0
%assign %%off %1
%elif %1 >= 8 && %1-%%off >= 4
movd [%2+%%off], m0
%assign %%off %%off+4
%else
mov [%2+%%off], vald
%assign %%off %%off+4
%endif
%endif ; %1-%%off >= 4
%if %1-%%off >= 2
%if %1 >= 8 %if %1 >= 8
movd [%2+%%dst_off], mm0 movd [%2+%1-4], m0
%else ; %1 < 8 %else
mov [%2+%%dst_off] , valw mov [%2+%%off], valw
mov [%2+%%dst_off+2], valw %endif
%endif ; %1 >=/< 8 %endif ; (%1-%%off)/2
%assign %%dst_off %%dst_off+4 %endmacro ; WRITE_V_PIXEL
%endif ; %1 & 4
%if %1&2
mov [%2+%%dst_off], valw
%endif ; %1 & 2
%endmacro
; r0=buf+block_h*linesize, r1=start_x, r2=linesize, r5=block_h, r6/r3=val %macro H_EXTEND 2
%macro LEFT_EXTEND 0 %assign %%n %1
%assign %%n 2 %rep 1+(%2-%1)/2
%rep 11 cglobal emu_edge_hfix %+ %%n, 4, 5, 1, dst, dst_stride, start_x, bh, val
ALIGN 64 .loop_y: ; do {
.emuedge_extend_left_ %+ %%n: ; do { READ_V_PIXEL %%n, [dstq+start_xq] ; $variable_regs = read($n)
sub r0, r2 ; dst -= linesize WRITE_V_PIXEL %%n, dstq ; write($variable_regs, $n)
READ_V_PIXEL %%n, [r0+r1] ; read pixels add dstq, dst_strideq ; dst += dst_stride
WRITE_V_PIXEL %%n, r0 ; write pixels dec bhq ; } while (--bh)
dec r5 jnz .loop_y
jnz .emuedge_extend_left_ %+ %%n ; } while (--block_h) RET
%if ARCH_X86_64
ret
%else ; ARCH_X86_32
rep ret
%endif ; ARCH_X86_64/32
%assign %%n %%n+2 %assign %%n %%n+2
%endrep %endrep ; 1+(%2-%1)/2
%endmacro ; LEFT_EXTEND %endmacro ; H_EXTEND
; r3/r0=buf+block_h*linesize, r2=linesize, r8/r5=block_h, r0/r6=end_x, r6/r3=val
%macro RIGHT_EXTEND 0
%assign %%n 2
%rep 11
ALIGN 64
.emuedge_extend_right_ %+ %%n: ; do {
%if ARCH_X86_64
sub r3, r2 ; dst -= linesize
READ_V_PIXEL %%n, [r3+w_reg-1] ; read pixels
WRITE_V_PIXEL %%n, r3+r4-%%n ; write pixels
dec r8
%else ; ARCH_X86_32
sub r0, r2 ; dst -= linesize
READ_V_PIXEL %%n, [r0+w_reg-1] ; read pixels
WRITE_V_PIXEL %%n, r0+r4-%%n ; write pixels
dec r5
%endif ; ARCH_X86_64/32
jnz .emuedge_extend_right_ %+ %%n ; } while (--block_h)
%if ARCH_X86_64
ret
%else ; ARCH_X86_32
rep ret
%endif ; ARCH_X86_64/32
%assign %%n %%n+2
%endrep
INIT_MMX mmx
H_EXTEND 2, 14
%if ARCH_X86_32 %if ARCH_X86_32
%define stack_offset 0x10 H_EXTEND 16, 22
%endif
%endmacro ; RIGHT_EXTEND
; below follow the "slow" copy/extend functions, these act on a non-fixed
; width specified in a register, and run a loop to copy the full amount
; of bytes. They are optimized for copying of large amounts of pixels per
; line, so they unconditionally splat data into mm registers to copy 8
; bytes per loop iteration. It could be considered to use xmm for x86-64
; also, but I haven't optimized this as much (i.e. FIXME)
%macro V_COPY_NPX 4-5
%if %0 == 4
test w_reg, %4
jz .%1_skip_%4_px
%else ; %0 == 5
.%1_%4_px_loop:
%endif
%3 %2, [r1+cnt_reg]
%3 [r0+cnt_reg], %2
add cnt_reg, %4
%if %0 == 5
sub w_reg, %4
test w_reg, %5
jnz .%1_%4_px_loop
%endif
.%1_skip_%4_px:
%endmacro
%macro V_COPY_ROW 2
%ifidn %1, bottom
sub r1, linesize
%endif
.%1_copy_loop:
xor cnt_reg, cnt_reg
%if notcpuflag(sse)
%define linesize r2m
V_COPY_NPX %1, mm0, movq, 8, 0xFFFFFFF8
%else ; sse
V_COPY_NPX %1, xmm0, movups, 16, 0xFFFFFFF0
%if ARCH_X86_64
%define linesize r2
V_COPY_NPX %1, rax , mov, 8
%else ; ARCH_X86_32
%define linesize r2m
V_COPY_NPX %1, mm0, movq, 8
%endif ; ARCH_X86_64/32
%endif ; sse
V_COPY_NPX %1, vald, mov, 4
V_COPY_NPX %1, valw, mov, 2
V_COPY_NPX %1, vall, mov, 1
mov w_reg, cnt_reg
%ifidn %1, body
add r1, linesize
%endif
add r0, linesize
dec %2
jnz .%1_copy_loop
%endmacro
%macro SLOW_V_EXTEND 0
.slow_v_extend_loop:
; r0=buf,r1=src,r2(64)/r2m(32)=linesize,r3(64)/r3m(32)=start_x,r4=end_y,r5=block_h
; r8(64)/r3(later-64)/r2(32)=cnt_reg,r6(64)/r3(32)=val_reg,r7(64)/r6(32)=w=end_x-start_x
%if ARCH_X86_64
push r8 ; save old value of block_h
test r3, r3
%define cnt_reg r8
jz .do_body_copy ; if (!start_y) goto do_body_copy
V_COPY_ROW top, r3
%else
cmp dword r3m, 0
%define cnt_reg r2
je .do_body_copy ; if (!start_y) goto do_body_copy
V_COPY_ROW top, dword r3m
%endif %endif
.do_body_copy: INIT_XMM sse
V_COPY_ROW body, r4 H_EXTEND 16, 22
%if ARCH_X86_64
pop r8 ; restore old value of block_h
%define cnt_reg r3
%endif
test r5, r5
%if ARCH_X86_64
jz .v_extend_end
%else
jz .skip_bottom_extend
%endif
V_COPY_ROW bottom, r5
%if ARCH_X86_32
.skip_bottom_extend:
mov r2, r2m
%endif
jmp .v_extend_end
%endmacro
%macro SLOW_LEFT_EXTEND 0
.slow_left_extend_loop:
; r0=buf+block_h*linesize,r2=linesize,r6(64)/r3(32)=val,r5=block_h,r4=cntr,r7/r6=start_x
mov r4, 8
sub r0, linesize
READ_V_PIXEL 8, [r0+w_reg]
.left_extend_8px_loop:
movq [r0+r4-8], mm0
add r4, 8
cmp r4, w_reg
jle .left_extend_8px_loop
sub r4, 8
cmp r4, w_reg
jge .left_extend_loop_end
.left_extend_2px_loop:
mov [r0+r4], valw
add r4, 2
cmp r4, w_reg
jl .left_extend_2px_loop
.left_extend_loop_end:
dec r5
jnz .slow_left_extend_loop
%if ARCH_X86_32
mov r2, r2m
%endif
jmp .right_extend
%endmacro
%macro SLOW_RIGHT_EXTEND 0
.slow_right_extend_loop:
; r3(64)/r0(32)=buf+block_h*linesize,r2=linesize,r4=block_w,r8(64)/r5(32)=block_h,
; r7(64)/r6(32)=end_x,r6/r3=val,r1=cntr
%if ARCH_X86_64
%define buf_reg r3
%define bh_reg r8
%else
%define buf_reg r0
%define bh_reg r5
%endif
lea r1, [r4-8]
sub buf_reg, linesize
READ_V_PIXEL 8, [buf_reg+w_reg-1]
.right_extend_8px_loop:
movq [buf_reg+r1], mm0
sub r1, 8
cmp r1, w_reg
jge .right_extend_8px_loop
add r1, 8
cmp r1, w_reg
je .right_extend_loop_end
.right_extend_2px_loop:
sub r1, 2
mov [buf_reg+r1], valw
cmp r1, w_reg
jg .right_extend_2px_loop
.right_extend_loop_end:
dec bh_reg
jnz .slow_right_extend_loop
jmp .h_extend_end
%endmacro
%macro emu_edge 1
INIT_XMM %1
EMU_EDGE_FUNC
VERTICAL_EXTEND
LEFT_EXTEND
RIGHT_EXTEND
SLOW_V_EXTEND
SLOW_LEFT_EXTEND
SLOW_RIGHT_EXTEND
%endmacro
emu_edge sse
%if ARCH_X86_32
emu_edge mmx
%endif
%macro PREFETCH_FN 1 %macro PREFETCH_FN 1
cglobal prefetch, 3, 3, 0, buf, stride, h cglobal prefetch, 3, 3, 0, buf, stride, h

View File

@ -30,32 +30,126 @@
#include "libavcodec/videodsp.h" #include "libavcodec/videodsp.h"
#if HAVE_YASM #if HAVE_YASM
typedef void emu_edge_core_func(uint8_t *buf, const uint8_t *src, typedef void emu_edge_vfix_func(uint8_t *dst, x86_reg dst_stride,
x86_reg linesize, x86_reg start_y, const uint8_t *src, x86_reg src_stride,
x86_reg end_y, x86_reg block_h, x86_reg start_y, x86_reg end_y, x86_reg bh);
x86_reg start_x, x86_reg end_x, typedef void emu_edge_vvar_func(uint8_t *dst, x86_reg dst_stride,
x86_reg block_w); const uint8_t *src, x86_reg src_stride,
extern emu_edge_core_func ff_emu_edge_core_mmx; x86_reg start_y, x86_reg end_y, x86_reg bh,
extern emu_edge_core_func ff_emu_edge_core_sse; x86_reg w);
static av_always_inline void emulated_edge_mc(uint8_t *buf, const uint8_t *src, extern emu_edge_vfix_func ff_emu_edge_vfix1_mmx;
ptrdiff_t linesize, extern emu_edge_vfix_func ff_emu_edge_vfix2_mmx;
int block_w, int block_h, extern emu_edge_vfix_func ff_emu_edge_vfix3_mmx;
int src_x, int src_y, extern emu_edge_vfix_func ff_emu_edge_vfix4_mmx;
int w, int h, extern emu_edge_vfix_func ff_emu_edge_vfix5_mmx;
emu_edge_core_func *core_fn) extern emu_edge_vfix_func ff_emu_edge_vfix6_mmx;
extern emu_edge_vfix_func ff_emu_edge_vfix7_mmx;
extern emu_edge_vfix_func ff_emu_edge_vfix8_mmx;
extern emu_edge_vfix_func ff_emu_edge_vfix9_mmx;
extern emu_edge_vfix_func ff_emu_edge_vfix10_mmx;
extern emu_edge_vfix_func ff_emu_edge_vfix11_mmx;
extern emu_edge_vfix_func ff_emu_edge_vfix12_mmx;
extern emu_edge_vfix_func ff_emu_edge_vfix13_mmx;
extern emu_edge_vfix_func ff_emu_edge_vfix14_mmx;
extern emu_edge_vfix_func ff_emu_edge_vfix15_mmx;
extern emu_edge_vfix_func ff_emu_edge_vfix16_mmx;
extern emu_edge_vfix_func ff_emu_edge_vfix17_mmx;
extern emu_edge_vfix_func ff_emu_edge_vfix18_mmx;
extern emu_edge_vfix_func ff_emu_edge_vfix19_mmx;
extern emu_edge_vfix_func ff_emu_edge_vfix20_mmx;
extern emu_edge_vfix_func ff_emu_edge_vfix21_mmx;
extern emu_edge_vfix_func ff_emu_edge_vfix22_mmx;
#if ARCH_X86_32
static emu_edge_vfix_func *vfixtbl_mmx[22] = {
&ff_emu_edge_vfix1_mmx, &ff_emu_edge_vfix2_mmx, &ff_emu_edge_vfix3_mmx,
&ff_emu_edge_vfix4_mmx, &ff_emu_edge_vfix5_mmx, &ff_emu_edge_vfix6_mmx,
&ff_emu_edge_vfix7_mmx, &ff_emu_edge_vfix8_mmx, &ff_emu_edge_vfix9_mmx,
&ff_emu_edge_vfix10_mmx, &ff_emu_edge_vfix11_mmx, &ff_emu_edge_vfix12_mmx,
&ff_emu_edge_vfix13_mmx, &ff_emu_edge_vfix14_mmx, &ff_emu_edge_vfix15_mmx,
&ff_emu_edge_vfix16_mmx, &ff_emu_edge_vfix17_mmx, &ff_emu_edge_vfix18_mmx,
&ff_emu_edge_vfix19_mmx, &ff_emu_edge_vfix20_mmx, &ff_emu_edge_vfix21_mmx,
&ff_emu_edge_vfix22_mmx
};
#endif
extern emu_edge_vvar_func ff_emu_edge_vvar_mmx;
extern emu_edge_vfix_func ff_emu_edge_vfix16_sse;
extern emu_edge_vfix_func ff_emu_edge_vfix17_sse;
extern emu_edge_vfix_func ff_emu_edge_vfix18_sse;
extern emu_edge_vfix_func ff_emu_edge_vfix19_sse;
extern emu_edge_vfix_func ff_emu_edge_vfix20_sse;
extern emu_edge_vfix_func ff_emu_edge_vfix21_sse;
extern emu_edge_vfix_func ff_emu_edge_vfix22_sse;
static emu_edge_vfix_func *vfixtbl_sse[22] = {
ff_emu_edge_vfix1_mmx, ff_emu_edge_vfix2_mmx, ff_emu_edge_vfix3_mmx,
ff_emu_edge_vfix4_mmx, ff_emu_edge_vfix5_mmx, ff_emu_edge_vfix6_mmx,
ff_emu_edge_vfix7_mmx, ff_emu_edge_vfix8_mmx, ff_emu_edge_vfix9_mmx,
ff_emu_edge_vfix10_mmx, ff_emu_edge_vfix11_mmx, ff_emu_edge_vfix12_mmx,
ff_emu_edge_vfix13_mmx, ff_emu_edge_vfix14_mmx, ff_emu_edge_vfix15_mmx,
ff_emu_edge_vfix16_sse, ff_emu_edge_vfix17_sse, ff_emu_edge_vfix18_sse,
ff_emu_edge_vfix19_sse, ff_emu_edge_vfix20_sse, ff_emu_edge_vfix21_sse,
ff_emu_edge_vfix22_sse
};
extern emu_edge_vvar_func ff_emu_edge_vvar_sse;
typedef void emu_edge_hfix_func(uint8_t *dst, x86_reg dst_stride,
x86_reg start_x, x86_reg bh);
typedef void emu_edge_hvar_func(uint8_t *dst, x86_reg dst_stride,
x86_reg start_x, x86_reg n_words, x86_reg bh);
extern emu_edge_hfix_func ff_emu_edge_hfix2_mmx;
extern emu_edge_hfix_func ff_emu_edge_hfix4_mmx;
extern emu_edge_hfix_func ff_emu_edge_hfix6_mmx;
extern emu_edge_hfix_func ff_emu_edge_hfix8_mmx;
extern emu_edge_hfix_func ff_emu_edge_hfix10_mmx;
extern emu_edge_hfix_func ff_emu_edge_hfix12_mmx;
extern emu_edge_hfix_func ff_emu_edge_hfix14_mmx;
extern emu_edge_hfix_func ff_emu_edge_hfix16_mmx;
extern emu_edge_hfix_func ff_emu_edge_hfix18_mmx;
extern emu_edge_hfix_func ff_emu_edge_hfix20_mmx;
extern emu_edge_hfix_func ff_emu_edge_hfix22_mmx;
#if ARCH_X86_32
static emu_edge_hfix_func *hfixtbl_mmx[11] = {
ff_emu_edge_hfix2_mmx, ff_emu_edge_hfix4_mmx, ff_emu_edge_hfix6_mmx,
ff_emu_edge_hfix8_mmx, ff_emu_edge_hfix10_mmx, ff_emu_edge_hfix12_mmx,
ff_emu_edge_hfix14_mmx, ff_emu_edge_hfix16_mmx, ff_emu_edge_hfix18_mmx,
ff_emu_edge_hfix20_mmx, ff_emu_edge_hfix22_mmx
};
#endif
extern emu_edge_hvar_func ff_emu_edge_hvar_mmx;
extern emu_edge_hfix_func ff_emu_edge_hfix16_sse;
extern emu_edge_hfix_func ff_emu_edge_hfix18_sse;
extern emu_edge_hfix_func ff_emu_edge_hfix20_sse;
extern emu_edge_hfix_func ff_emu_edge_hfix22_sse;
static emu_edge_hfix_func *hfixtbl_sse[11] = {
ff_emu_edge_hfix2_mmx, ff_emu_edge_hfix4_mmx, ff_emu_edge_hfix6_mmx,
ff_emu_edge_hfix8_mmx, ff_emu_edge_hfix10_mmx, ff_emu_edge_hfix12_mmx,
ff_emu_edge_hfix14_mmx, ff_emu_edge_hfix16_sse, ff_emu_edge_hfix18_sse,
ff_emu_edge_hfix20_sse, ff_emu_edge_hfix22_sse
};
extern emu_edge_hvar_func ff_emu_edge_hvar_sse;
static av_always_inline void emulated_edge_mc(uint8_t *dst, ptrdiff_t dst_stride,
const uint8_t *src, ptrdiff_t src_stride,
x86_reg block_w, x86_reg block_h,
x86_reg src_x, x86_reg src_y,
x86_reg w, x86_reg h,
emu_edge_vfix_func **vfix_tbl,
emu_edge_vvar_func *v_extend_var,
emu_edge_hfix_func **hfix_tbl,
emu_edge_hvar_func *h_extend_var)
{ {
int start_y, start_x, end_y, end_x, src_y_add = 0; x86_reg start_y, start_x, end_y, end_x, src_y_add = 0, p;
if(!w || !h) if(!w || !h)
return; return;
if (src_y >= h) { if (src_y >= h) {
src -= src_y*linesize; src -= src_y*src_stride;
src_y_add = h - 1; src_y_add = h - 1;
src_y = h - 1; src_y = h - 1;
} else if (src_y <= -block_h) { } else if (src_y <= -block_h) {
src -= src_y*linesize; src -= src_y*src_stride;
src_y_add = 1 - block_h; src_y_add = 1 - block_h;
src_y = 1 - block_h; src_y = 1 - block_h;
} }
@ -75,30 +169,59 @@ static av_always_inline void emulated_edge_mc(uint8_t *buf, const uint8_t *src,
av_assert2(start_y < end_y && block_h > 0); av_assert2(start_y < end_y && block_h > 0);
// fill in the to-be-copied part plus all above/below // fill in the to-be-copied part plus all above/below
src += (src_y_add + start_y) * linesize + start_x; src += (src_y_add + start_y) * src_stride + start_x;
buf += start_x; w = end_x - start_x;
core_fn(buf, src, linesize, start_y, end_y, if (w <= 22) {
block_h, start_x, end_x, block_w); vfix_tbl[w - 1](dst + start_x, dst_stride, src, src_stride,
start_y, end_y, block_h);
} else {
v_extend_var(dst + start_x, dst_stride, src, src_stride,
start_y, end_y, block_h, w);
}
// fill left
if (start_x) {
if (start_x <= 22) {
hfix_tbl[(start_x - 1) >> 1](dst, dst_stride, start_x, block_h);
} else {
h_extend_var(dst, dst_stride,
start_x, (start_x + 1) >> 1, block_h);
}
}
// fill right
p = block_w - end_x;
if (p) {
if (p <= 22) {
hfix_tbl[(p - 1) >> 1](dst + end_x - (p & 1), dst_stride,
-!(p & 1), block_h);
} else {
h_extend_var(dst + end_x - (p & 1), dst_stride,
-!(p & 1), (p + 1) >> 1, block_h);
}
}
} }
#if ARCH_X86_32 #if ARCH_X86_32
static av_noinline void emulated_edge_mc_mmx(uint8_t *buf, const uint8_t *src, static av_noinline void emulated_edge_mc_mmx(uint8_t *buf, ptrdiff_t buf_stride,
ptrdiff_t linesize, const uint8_t *src, ptrdiff_t src_stride,
int block_w, int block_h, int block_w, int block_h,
int src_x, int src_y, int w, int h) int src_x, int src_y, int w, int h)
{ {
emulated_edge_mc(buf, src, linesize, block_w, block_h, src_x, src_y, emulated_edge_mc(buf, buf_stride, src, src_stride, block_w, block_h,
w, h, &ff_emu_edge_core_mmx); src_x, src_y, w, h, vfixtbl_mmx, &ff_emu_edge_vvar_mmx,
hfixtbl_mmx, &ff_emu_edge_hvar_mmx);
} }
#endif #endif
static av_noinline void emulated_edge_mc_sse(uint8_t *buf, const uint8_t *src, static av_noinline void emulated_edge_mc_sse(uint8_t *buf, ptrdiff_t buf_stride,
ptrdiff_t linesize, const uint8_t *src, ptrdiff_t src_stride,
int block_w, int block_h, int block_w, int block_h,
int src_x, int src_y, int w, int h) int src_x, int src_y, int w, int h)
{ {
emulated_edge_mc(buf, src, linesize, block_w, block_h, src_x, src_y, emulated_edge_mc(buf, buf_stride, src, src_stride, block_w, block_h,
w, h, &ff_emu_edge_core_sse); src_x, src_y, w, h, vfixtbl_sse, &ff_emu_edge_vvar_sse,
hfixtbl_sse, &ff_emu_edge_hvar_sse);
} }
#endif /* HAVE_YASM */ #endif /* HAVE_YASM */