2001-07-30 12:04:34 +03:00
|
|
|
/*
|
2007-07-05 13:37:29 +03:00
|
|
|
* Optimized for ia32 CPUs by Nick Kurshev <nickols_k@mail.ru>
|
2016-04-27 19:45:23 +02:00
|
|
|
* H.263, MPEG-1, MPEG-2 dequantizer & draw_edges by Michael Niedermayer <michaelni@gmx.at>
|
2007-07-05 13:37:29 +03:00
|
|
|
*
|
2006-10-07 18:30:46 +03:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2002-05-26 01:45:33 +03:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 18:30:46 +03:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2001-07-30 12:04:34 +03:00
|
|
|
*
|
2006-10-07 18:30:46 +03:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2001-07-30 12:04:34 +03:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2002-05-26 01:45:33 +03:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2001-07-30 12:04:34 +03:00
|
|
|
*
|
2002-05-26 01:45:33 +03:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2006-10-07 18:30:46 +03:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-01-13 00:43:26 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2001-07-30 12:04:34 +03:00
|
|
|
*/
|
|
|
|
|
2013-02-01 12:31:59 +03:00
|
|
|
#include "libavutil/attributes.h"
|
2010-09-08 18:07:14 +03:00
|
|
|
#include "libavutil/cpu.h"
|
2012-08-08 15:51:52 +03:00
|
|
|
#include "libavutil/x86/asm.h"
|
2013-08-20 15:46:58 +03:00
|
|
|
#include "libavutil/x86/cpu.h"
|
2008-05-09 14:56:36 +03:00
|
|
|
#include "libavcodec/avcodec.h"
|
|
|
|
#include "libavcodec/mpegvideo.h"
|
2015-09-18 00:37:28 +02:00
|
|
|
#include "libavcodec/mpegvideodata.h"
|
2002-09-30 01:44:22 +03:00
|
|
|
|
2013-07-07 02:29:48 +03:00
|
|
|
#if HAVE_MMX_INLINE
|
2012-07-26 06:30:19 +03:00
|
|
|
|
2003-12-14 04:57:00 +02:00
|
|
|
static void dct_unquantize_h263_intra_mmx(MpegEncContext *s,
|
2013-01-20 03:02:29 +03:00
|
|
|
int16_t *block, int n, int qscale)
|
2001-11-03 04:22:48 +02:00
|
|
|
{
|
2008-05-09 00:11:24 +03:00
|
|
|
x86_reg level, qmul, qadd, nCoeffs;
|
2002-09-30 01:44:22 +03:00
|
|
|
|
|
|
|
qmul = qscale << 1;
|
2001-11-03 04:22:48 +02:00
|
|
|
|
2012-12-11 00:48:29 +03:00
|
|
|
av_assert2(s->block_last_index[n]>=0 || s->h263_aic);
|
2005-12-17 20:14:38 +02:00
|
|
|
|
2003-12-14 04:57:00 +02:00
|
|
|
if (!s->h263_aic) {
|
|
|
|
if (n < 4)
|
|
|
|
level = block[0] * s->y_dc_scale;
|
|
|
|
else
|
|
|
|
level = block[0] * s->c_dc_scale;
|
|
|
|
qadd = (qscale - 1) | 1;
|
|
|
|
}else{
|
|
|
|
qadd = 0;
|
|
|
|
level= block[0];
|
2001-11-03 04:22:48 +02:00
|
|
|
}
|
2003-12-14 04:57:00 +02:00
|
|
|
if(s->ac_pred)
|
|
|
|
nCoeffs=63;
|
|
|
|
else
|
2017-06-19 23:47:13 +02:00
|
|
|
nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ];
|
2012-09-25 19:28:44 +03:00
|
|
|
|
2008-10-16 16:34:09 +03:00
|
|
|
__asm__ volatile(
|
2005-12-22 03:10:11 +02:00
|
|
|
"movd %1, %%mm6 \n\t" //qmul
|
|
|
|
"packssdw %%mm6, %%mm6 \n\t"
|
|
|
|
"packssdw %%mm6, %%mm6 \n\t"
|
|
|
|
"movd %2, %%mm5 \n\t" //qadd
|
|
|
|
"pxor %%mm7, %%mm7 \n\t"
|
|
|
|
"packssdw %%mm5, %%mm5 \n\t"
|
|
|
|
"packssdw %%mm5, %%mm5 \n\t"
|
|
|
|
"psubw %%mm5, %%mm7 \n\t"
|
|
|
|
"pxor %%mm4, %%mm4 \n\t"
|
2011-01-16 00:09:35 +02:00
|
|
|
".p2align 4 \n\t"
|
2005-12-22 03:10:11 +02:00
|
|
|
"1: \n\t"
|
|
|
|
"movq (%0, %3), %%mm0 \n\t"
|
|
|
|
"movq 8(%0, %3), %%mm1 \n\t"
|
|
|
|
|
|
|
|
"pmullw %%mm6, %%mm0 \n\t"
|
|
|
|
"pmullw %%mm6, %%mm1 \n\t"
|
|
|
|
|
|
|
|
"movq (%0, %3), %%mm2 \n\t"
|
|
|
|
"movq 8(%0, %3), %%mm3 \n\t"
|
|
|
|
|
|
|
|
"pcmpgtw %%mm4, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
|
|
|
|
"pcmpgtw %%mm4, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
|
|
|
|
|
|
|
|
"pxor %%mm2, %%mm0 \n\t"
|
|
|
|
"pxor %%mm3, %%mm1 \n\t"
|
|
|
|
|
|
|
|
"paddw %%mm7, %%mm0 \n\t"
|
|
|
|
"paddw %%mm7, %%mm1 \n\t"
|
|
|
|
|
|
|
|
"pxor %%mm0, %%mm2 \n\t"
|
|
|
|
"pxor %%mm1, %%mm3 \n\t"
|
|
|
|
|
|
|
|
"pcmpeqw %%mm7, %%mm0 \n\t" // block[i] == 0 ? -1 : 0
|
|
|
|
"pcmpeqw %%mm7, %%mm1 \n\t" // block[i] == 0 ? -1 : 0
|
|
|
|
|
|
|
|
"pandn %%mm2, %%mm0 \n\t"
|
|
|
|
"pandn %%mm3, %%mm1 \n\t"
|
|
|
|
|
|
|
|
"movq %%mm0, (%0, %3) \n\t"
|
|
|
|
"movq %%mm1, 8(%0, %3) \n\t"
|
|
|
|
|
|
|
|
"add $16, %3 \n\t"
|
|
|
|
"jng 1b \n\t"
|
2008-08-24 11:41:20 +03:00
|
|
|
::"r" (block+nCoeffs), "rm"(qmul), "rm" (qadd), "r" (2*(-nCoeffs))
|
2005-12-22 03:10:11 +02:00
|
|
|
: "memory"
|
|
|
|
);
|
2003-12-14 04:57:00 +02:00
|
|
|
block[0]= level;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void dct_unquantize_h263_inter_mmx(MpegEncContext *s,
|
2013-01-20 03:02:29 +03:00
|
|
|
int16_t *block, int n, int qscale)
|
2003-12-14 04:57:00 +02:00
|
|
|
{
|
2008-05-09 00:11:24 +03:00
|
|
|
x86_reg qmul, qadd, nCoeffs;
|
2003-12-14 04:57:00 +02:00
|
|
|
|
|
|
|
qmul = qscale << 1;
|
|
|
|
qadd = (qscale - 1) | 1;
|
|
|
|
|
2013-03-23 00:57:23 +03:00
|
|
|
av_assert2(s->block_last_index[n]>=0 || s->h263_aic);
|
2005-12-17 20:14:38 +02:00
|
|
|
|
2003-12-14 04:57:00 +02:00
|
|
|
nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
|
2012-09-25 19:28:44 +03:00
|
|
|
|
2008-10-16 16:34:09 +03:00
|
|
|
__asm__ volatile(
|
2005-12-22 03:10:11 +02:00
|
|
|
"movd %1, %%mm6 \n\t" //qmul
|
|
|
|
"packssdw %%mm6, %%mm6 \n\t"
|
|
|
|
"packssdw %%mm6, %%mm6 \n\t"
|
|
|
|
"movd %2, %%mm5 \n\t" //qadd
|
|
|
|
"pxor %%mm7, %%mm7 \n\t"
|
|
|
|
"packssdw %%mm5, %%mm5 \n\t"
|
|
|
|
"packssdw %%mm5, %%mm5 \n\t"
|
|
|
|
"psubw %%mm5, %%mm7 \n\t"
|
|
|
|
"pxor %%mm4, %%mm4 \n\t"
|
2011-01-16 00:09:35 +02:00
|
|
|
".p2align 4 \n\t"
|
2005-12-22 03:10:11 +02:00
|
|
|
"1: \n\t"
|
|
|
|
"movq (%0, %3), %%mm0 \n\t"
|
|
|
|
"movq 8(%0, %3), %%mm1 \n\t"
|
|
|
|
|
|
|
|
"pmullw %%mm6, %%mm0 \n\t"
|
|
|
|
"pmullw %%mm6, %%mm1 \n\t"
|
|
|
|
|
|
|
|
"movq (%0, %3), %%mm2 \n\t"
|
|
|
|
"movq 8(%0, %3), %%mm3 \n\t"
|
|
|
|
|
|
|
|
"pcmpgtw %%mm4, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
|
|
|
|
"pcmpgtw %%mm4, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
|
|
|
|
|
|
|
|
"pxor %%mm2, %%mm0 \n\t"
|
|
|
|
"pxor %%mm3, %%mm1 \n\t"
|
|
|
|
|
|
|
|
"paddw %%mm7, %%mm0 \n\t"
|
|
|
|
"paddw %%mm7, %%mm1 \n\t"
|
|
|
|
|
|
|
|
"pxor %%mm0, %%mm2 \n\t"
|
|
|
|
"pxor %%mm1, %%mm3 \n\t"
|
|
|
|
|
|
|
|
"pcmpeqw %%mm7, %%mm0 \n\t" // block[i] == 0 ? -1 : 0
|
|
|
|
"pcmpeqw %%mm7, %%mm1 \n\t" // block[i] == 0 ? -1 : 0
|
|
|
|
|
|
|
|
"pandn %%mm2, %%mm0 \n\t"
|
|
|
|
"pandn %%mm3, %%mm1 \n\t"
|
|
|
|
|
|
|
|
"movq %%mm0, (%0, %3) \n\t"
|
|
|
|
"movq %%mm1, 8(%0, %3) \n\t"
|
|
|
|
|
|
|
|
"add $16, %3 \n\t"
|
|
|
|
"jng 1b \n\t"
|
2008-08-24 11:41:20 +03:00
|
|
|
::"r" (block+nCoeffs), "rm"(qmul), "rm" (qadd), "r" (2*(-nCoeffs))
|
2005-12-22 03:10:11 +02:00
|
|
|
: "memory"
|
|
|
|
);
|
2001-11-03 04:22:48 +02:00
|
|
|
}
|
|
|
|
|
2003-12-14 04:57:00 +02:00
|
|
|
static void dct_unquantize_mpeg1_intra_mmx(MpegEncContext *s,
|
2013-01-20 03:02:29 +03:00
|
|
|
int16_t *block, int n, int qscale)
|
2001-07-30 12:04:34 +03:00
|
|
|
{
|
2008-05-09 00:11:24 +03:00
|
|
|
x86_reg nCoeffs;
|
2003-02-11 18:35:48 +02:00
|
|
|
const uint16_t *quant_matrix;
|
2003-12-14 04:57:00 +02:00
|
|
|
int block0;
|
2002-09-30 01:44:22 +03:00
|
|
|
|
2012-12-11 00:48:29 +03:00
|
|
|
av_assert2(s->block_last_index[n]>=0);
|
2002-09-30 01:44:22 +03:00
|
|
|
|
|
|
|
nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ]+1;
|
2002-01-13 06:59:37 +02:00
|
|
|
|
2005-12-17 20:14:38 +02:00
|
|
|
if (n < 4)
|
2003-12-14 04:57:00 +02:00
|
|
|
block0 = block[0] * s->y_dc_scale;
|
|
|
|
else
|
|
|
|
block0 = block[0] * s->c_dc_scale;
|
2016-04-27 19:45:23 +02:00
|
|
|
/* XXX: only MPEG-1 */
|
2003-12-14 04:57:00 +02:00
|
|
|
quant_matrix = s->intra_matrix;
|
2008-10-16 16:34:09 +03:00
|
|
|
__asm__ volatile(
|
2005-12-22 03:10:11 +02:00
|
|
|
"pcmpeqw %%mm7, %%mm7 \n\t"
|
|
|
|
"psrlw $15, %%mm7 \n\t"
|
|
|
|
"movd %2, %%mm6 \n\t"
|
|
|
|
"packssdw %%mm6, %%mm6 \n\t"
|
|
|
|
"packssdw %%mm6, %%mm6 \n\t"
|
2016-06-27 17:21:04 +02:00
|
|
|
"mov %3, %%"FF_REG_a" \n\t"
|
2011-01-16 00:09:35 +02:00
|
|
|
".p2align 4 \n\t"
|
2005-12-22 03:10:11 +02:00
|
|
|
"1: \n\t"
|
2016-06-27 17:21:04 +02:00
|
|
|
"movq (%0, %%"FF_REG_a"), %%mm0 \n\t"
|
|
|
|
"movq 8(%0, %%"FF_REG_a"), %%mm1\n\t"
|
|
|
|
"movq (%1, %%"FF_REG_a"), %%mm4 \n\t"
|
|
|
|
"movq 8(%1, %%"FF_REG_a"), %%mm5\n\t"
|
2005-12-22 03:10:11 +02:00
|
|
|
"pmullw %%mm6, %%mm4 \n\t" // q=qscale*quant_matrix[i]
|
|
|
|
"pmullw %%mm6, %%mm5 \n\t" // q=qscale*quant_matrix[i]
|
|
|
|
"pxor %%mm2, %%mm2 \n\t"
|
|
|
|
"pxor %%mm3, %%mm3 \n\t"
|
|
|
|
"pcmpgtw %%mm0, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
|
|
|
|
"pcmpgtw %%mm1, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
|
|
|
|
"pxor %%mm2, %%mm0 \n\t"
|
|
|
|
"pxor %%mm3, %%mm1 \n\t"
|
|
|
|
"psubw %%mm2, %%mm0 \n\t" // abs(block[i])
|
|
|
|
"psubw %%mm3, %%mm1 \n\t" // abs(block[i])
|
|
|
|
"pmullw %%mm4, %%mm0 \n\t" // abs(block[i])*q
|
|
|
|
"pmullw %%mm5, %%mm1 \n\t" // abs(block[i])*q
|
|
|
|
"pxor %%mm4, %%mm4 \n\t"
|
|
|
|
"pxor %%mm5, %%mm5 \n\t" // FIXME slow
|
2016-06-27 17:21:04 +02:00
|
|
|
"pcmpeqw (%0, %%"FF_REG_a"), %%mm4 \n\t" // block[i] == 0 ? -1 : 0
|
|
|
|
"pcmpeqw 8(%0, %%"FF_REG_a"), %%mm5\n\t" // block[i] == 0 ? -1 : 0
|
2005-12-22 03:10:11 +02:00
|
|
|
"psraw $3, %%mm0 \n\t"
|
|
|
|
"psraw $3, %%mm1 \n\t"
|
|
|
|
"psubw %%mm7, %%mm0 \n\t"
|
|
|
|
"psubw %%mm7, %%mm1 \n\t"
|
|
|
|
"por %%mm7, %%mm0 \n\t"
|
|
|
|
"por %%mm7, %%mm1 \n\t"
|
|
|
|
"pxor %%mm2, %%mm0 \n\t"
|
|
|
|
"pxor %%mm3, %%mm1 \n\t"
|
|
|
|
"psubw %%mm2, %%mm0 \n\t"
|
|
|
|
"psubw %%mm3, %%mm1 \n\t"
|
|
|
|
"pandn %%mm0, %%mm4 \n\t"
|
|
|
|
"pandn %%mm1, %%mm5 \n\t"
|
2016-06-27 17:21:04 +02:00
|
|
|
"movq %%mm4, (%0, %%"FF_REG_a") \n\t"
|
|
|
|
"movq %%mm5, 8(%0, %%"FF_REG_a")\n\t"
|
2005-12-22 03:10:11 +02:00
|
|
|
|
2016-06-27 17:21:04 +02:00
|
|
|
"add $16, %%"FF_REG_a" \n\t"
|
2005-12-22 03:10:11 +02:00
|
|
|
"js 1b \n\t"
|
2008-08-24 11:41:20 +03:00
|
|
|
::"r" (block+nCoeffs), "r"(quant_matrix+nCoeffs), "rm" (qscale), "g" (-2*nCoeffs)
|
2016-06-27 17:21:04 +02:00
|
|
|
: "%"FF_REG_a, "memory"
|
2005-12-22 03:10:11 +02:00
|
|
|
);
|
2003-12-14 04:57:00 +02:00
|
|
|
block[0]= block0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dct_unquantize_mpeg1_inter_mmx(MpegEncContext *s,
|
2013-01-20 03:02:29 +03:00
|
|
|
int16_t *block, int n, int qscale)
|
2003-12-14 04:57:00 +02:00
|
|
|
{
|
2008-05-09 00:11:24 +03:00
|
|
|
x86_reg nCoeffs;
|
2003-12-14 04:57:00 +02:00
|
|
|
const uint16_t *quant_matrix;
|
|
|
|
|
2012-12-11 00:48:29 +03:00
|
|
|
av_assert2(s->block_last_index[n]>=0);
|
2003-12-14 04:57:00 +02:00
|
|
|
|
|
|
|
nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ]+1;
|
2002-04-17 19:30:31 +03:00
|
|
|
|
2002-04-27 15:30:26 +03:00
|
|
|
quant_matrix = s->inter_matrix;
|
2008-10-16 16:34:09 +03:00
|
|
|
__asm__ volatile(
|
2005-12-22 03:10:11 +02:00
|
|
|
"pcmpeqw %%mm7, %%mm7 \n\t"
|
|
|
|
"psrlw $15, %%mm7 \n\t"
|
|
|
|
"movd %2, %%mm6 \n\t"
|
|
|
|
"packssdw %%mm6, %%mm6 \n\t"
|
|
|
|
"packssdw %%mm6, %%mm6 \n\t"
|
2016-06-27 17:21:04 +02:00
|
|
|
"mov %3, %%"FF_REG_a" \n\t"
|
2011-01-16 00:09:35 +02:00
|
|
|
".p2align 4 \n\t"
|
2005-12-22 03:10:11 +02:00
|
|
|
"1: \n\t"
|
2016-06-27 17:21:04 +02:00
|
|
|
"movq (%0, %%"FF_REG_a"), %%mm0 \n\t"
|
|
|
|
"movq 8(%0, %%"FF_REG_a"), %%mm1\n\t"
|
|
|
|
"movq (%1, %%"FF_REG_a"), %%mm4 \n\t"
|
|
|
|
"movq 8(%1, %%"FF_REG_a"), %%mm5\n\t"
|
2005-12-22 03:10:11 +02:00
|
|
|
"pmullw %%mm6, %%mm4 \n\t" // q=qscale*quant_matrix[i]
|
|
|
|
"pmullw %%mm6, %%mm5 \n\t" // q=qscale*quant_matrix[i]
|
|
|
|
"pxor %%mm2, %%mm2 \n\t"
|
|
|
|
"pxor %%mm3, %%mm3 \n\t"
|
|
|
|
"pcmpgtw %%mm0, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
|
|
|
|
"pcmpgtw %%mm1, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
|
|
|
|
"pxor %%mm2, %%mm0 \n\t"
|
|
|
|
"pxor %%mm3, %%mm1 \n\t"
|
|
|
|
"psubw %%mm2, %%mm0 \n\t" // abs(block[i])
|
|
|
|
"psubw %%mm3, %%mm1 \n\t" // abs(block[i])
|
|
|
|
"paddw %%mm0, %%mm0 \n\t" // abs(block[i])*2
|
|
|
|
"paddw %%mm1, %%mm1 \n\t" // abs(block[i])*2
|
|
|
|
"paddw %%mm7, %%mm0 \n\t" // abs(block[i])*2 + 1
|
|
|
|
"paddw %%mm7, %%mm1 \n\t" // abs(block[i])*2 + 1
|
|
|
|
"pmullw %%mm4, %%mm0 \n\t" // (abs(block[i])*2 + 1)*q
|
|
|
|
"pmullw %%mm5, %%mm1 \n\t" // (abs(block[i])*2 + 1)*q
|
|
|
|
"pxor %%mm4, %%mm4 \n\t"
|
|
|
|
"pxor %%mm5, %%mm5 \n\t" // FIXME slow
|
2016-06-27 17:21:04 +02:00
|
|
|
"pcmpeqw (%0, %%"FF_REG_a"), %%mm4 \n\t" // block[i] == 0 ? -1 : 0
|
|
|
|
"pcmpeqw 8(%0, %%"FF_REG_a"), %%mm5\n\t" // block[i] == 0 ? -1 : 0
|
2005-12-22 03:10:11 +02:00
|
|
|
"psraw $4, %%mm0 \n\t"
|
|
|
|
"psraw $4, %%mm1 \n\t"
|
|
|
|
"psubw %%mm7, %%mm0 \n\t"
|
|
|
|
"psubw %%mm7, %%mm1 \n\t"
|
|
|
|
"por %%mm7, %%mm0 \n\t"
|
|
|
|
"por %%mm7, %%mm1 \n\t"
|
|
|
|
"pxor %%mm2, %%mm0 \n\t"
|
|
|
|
"pxor %%mm3, %%mm1 \n\t"
|
|
|
|
"psubw %%mm2, %%mm0 \n\t"
|
|
|
|
"psubw %%mm3, %%mm1 \n\t"
|
|
|
|
"pandn %%mm0, %%mm4 \n\t"
|
|
|
|
"pandn %%mm1, %%mm5 \n\t"
|
2016-06-27 17:21:04 +02:00
|
|
|
"movq %%mm4, (%0, %%"FF_REG_a") \n\t"
|
|
|
|
"movq %%mm5, 8(%0, %%"FF_REG_a")\n\t"
|
2005-12-22 03:10:11 +02:00
|
|
|
|
2016-06-27 17:21:04 +02:00
|
|
|
"add $16, %%"FF_REG_a" \n\t"
|
2005-12-22 03:10:11 +02:00
|
|
|
"js 1b \n\t"
|
2008-08-24 11:41:20 +03:00
|
|
|
::"r" (block+nCoeffs), "r"(quant_matrix+nCoeffs), "rm" (qscale), "g" (-2*nCoeffs)
|
2016-06-27 17:21:04 +02:00
|
|
|
: "%"FF_REG_a, "memory"
|
2005-12-22 03:10:11 +02:00
|
|
|
);
|
2002-04-17 19:30:31 +03:00
|
|
|
}
|
|
|
|
|
2003-12-14 04:57:00 +02:00
|
|
|
static void dct_unquantize_mpeg2_intra_mmx(MpegEncContext *s,
|
2013-01-20 03:02:29 +03:00
|
|
|
int16_t *block, int n, int qscale)
|
2002-04-17 19:30:31 +03:00
|
|
|
{
|
2008-05-09 00:11:24 +03:00
|
|
|
x86_reg nCoeffs;
|
2003-02-11 18:35:48 +02:00
|
|
|
const uint16_t *quant_matrix;
|
2003-12-14 04:57:00 +02:00
|
|
|
int block0;
|
2005-12-17 20:14:38 +02:00
|
|
|
|
2012-12-11 00:48:29 +03:00
|
|
|
av_assert2(s->block_last_index[n]>=0);
|
2002-09-30 01:44:22 +03:00
|
|
|
|
2015-09-18 00:37:28 +02:00
|
|
|
if (s->q_scale_type) qscale = ff_mpeg2_non_linear_qscale[qscale];
|
|
|
|
else qscale <<= 1;
|
2015-09-17 23:47:06 +02:00
|
|
|
|
2002-09-30 01:44:22 +03:00
|
|
|
if(s->alternate_scan) nCoeffs= 63; //FIXME
|
|
|
|
else nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ];
|
2002-04-17 19:30:31 +03:00
|
|
|
|
2005-12-17 20:14:38 +02:00
|
|
|
if (n < 4)
|
2003-12-14 04:57:00 +02:00
|
|
|
block0 = block[0] * s->y_dc_scale;
|
|
|
|
else
|
|
|
|
block0 = block[0] * s->c_dc_scale;
|
|
|
|
quant_matrix = s->intra_matrix;
|
2008-10-16 16:34:09 +03:00
|
|
|
__asm__ volatile(
|
2005-12-22 03:10:11 +02:00
|
|
|
"pcmpeqw %%mm7, %%mm7 \n\t"
|
|
|
|
"psrlw $15, %%mm7 \n\t"
|
|
|
|
"movd %2, %%mm6 \n\t"
|
|
|
|
"packssdw %%mm6, %%mm6 \n\t"
|
|
|
|
"packssdw %%mm6, %%mm6 \n\t"
|
2016-06-27 17:21:04 +02:00
|
|
|
"mov %3, %%"FF_REG_a" \n\t"
|
2011-01-16 00:09:35 +02:00
|
|
|
".p2align 4 \n\t"
|
2005-12-22 03:10:11 +02:00
|
|
|
"1: \n\t"
|
2016-06-27 17:21:04 +02:00
|
|
|
"movq (%0, %%"FF_REG_a"), %%mm0 \n\t"
|
|
|
|
"movq 8(%0, %%"FF_REG_a"), %%mm1\n\t"
|
|
|
|
"movq (%1, %%"FF_REG_a"), %%mm4 \n\t"
|
|
|
|
"movq 8(%1, %%"FF_REG_a"), %%mm5\n\t"
|
2005-12-22 03:10:11 +02:00
|
|
|
"pmullw %%mm6, %%mm4 \n\t" // q=qscale*quant_matrix[i]
|
|
|
|
"pmullw %%mm6, %%mm5 \n\t" // q=qscale*quant_matrix[i]
|
|
|
|
"pxor %%mm2, %%mm2 \n\t"
|
|
|
|
"pxor %%mm3, %%mm3 \n\t"
|
|
|
|
"pcmpgtw %%mm0, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
|
|
|
|
"pcmpgtw %%mm1, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
|
|
|
|
"pxor %%mm2, %%mm0 \n\t"
|
|
|
|
"pxor %%mm3, %%mm1 \n\t"
|
|
|
|
"psubw %%mm2, %%mm0 \n\t" // abs(block[i])
|
|
|
|
"psubw %%mm3, %%mm1 \n\t" // abs(block[i])
|
|
|
|
"pmullw %%mm4, %%mm0 \n\t" // abs(block[i])*q
|
|
|
|
"pmullw %%mm5, %%mm1 \n\t" // abs(block[i])*q
|
|
|
|
"pxor %%mm4, %%mm4 \n\t"
|
|
|
|
"pxor %%mm5, %%mm5 \n\t" // FIXME slow
|
2016-06-27 17:21:04 +02:00
|
|
|
"pcmpeqw (%0, %%"FF_REG_a"), %%mm4 \n\t" // block[i] == 0 ? -1 : 0
|
|
|
|
"pcmpeqw 8(%0, %%"FF_REG_a"), %%mm5\n\t" // block[i] == 0 ? -1 : 0
|
2015-09-17 23:47:06 +02:00
|
|
|
"psraw $4, %%mm0 \n\t"
|
|
|
|
"psraw $4, %%mm1 \n\t"
|
2005-12-22 03:10:11 +02:00
|
|
|
"pxor %%mm2, %%mm0 \n\t"
|
|
|
|
"pxor %%mm3, %%mm1 \n\t"
|
|
|
|
"psubw %%mm2, %%mm0 \n\t"
|
|
|
|
"psubw %%mm3, %%mm1 \n\t"
|
|
|
|
"pandn %%mm0, %%mm4 \n\t"
|
|
|
|
"pandn %%mm1, %%mm5 \n\t"
|
2016-06-27 17:21:04 +02:00
|
|
|
"movq %%mm4, (%0, %%"FF_REG_a") \n\t"
|
|
|
|
"movq %%mm5, 8(%0, %%"FF_REG_a")\n\t"
|
2005-12-22 03:10:11 +02:00
|
|
|
|
2016-06-27 17:21:04 +02:00
|
|
|
"add $16, %%"FF_REG_a" \n\t"
|
2005-12-22 03:10:11 +02:00
|
|
|
"jng 1b \n\t"
|
2008-08-24 11:41:20 +03:00
|
|
|
::"r" (block+nCoeffs), "r"(quant_matrix+nCoeffs), "rm" (qscale), "g" (-2*nCoeffs)
|
2016-06-27 17:21:04 +02:00
|
|
|
: "%"FF_REG_a, "memory"
|
2005-12-22 03:10:11 +02:00
|
|
|
);
|
2003-12-14 04:57:00 +02:00
|
|
|
block[0]= block0;
|
2007-06-12 12:29:25 +03:00
|
|
|
//Note, we do not do mismatch control for intra as errors cannot accumulate
|
2003-12-14 04:57:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dct_unquantize_mpeg2_inter_mmx(MpegEncContext *s,
|
2013-01-20 03:02:29 +03:00
|
|
|
int16_t *block, int n, int qscale)
|
2003-12-14 04:57:00 +02:00
|
|
|
{
|
2008-05-09 00:11:24 +03:00
|
|
|
x86_reg nCoeffs;
|
2003-12-14 04:57:00 +02:00
|
|
|
const uint16_t *quant_matrix;
|
2005-12-17 20:14:38 +02:00
|
|
|
|
2012-12-11 00:48:29 +03:00
|
|
|
av_assert2(s->block_last_index[n]>=0);
|
2003-12-14 04:57:00 +02:00
|
|
|
|
2015-09-18 00:37:28 +02:00
|
|
|
if (s->q_scale_type) qscale = ff_mpeg2_non_linear_qscale[qscale];
|
|
|
|
else qscale <<= 1;
|
2015-09-17 23:47:06 +02:00
|
|
|
|
2003-12-14 04:57:00 +02:00
|
|
|
if(s->alternate_scan) nCoeffs= 63; //FIXME
|
|
|
|
else nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ];
|
2002-04-17 19:30:31 +03:00
|
|
|
|
2002-04-27 15:30:26 +03:00
|
|
|
quant_matrix = s->inter_matrix;
|
2008-10-16 16:34:09 +03:00
|
|
|
__asm__ volatile(
|
2005-12-22 03:10:11 +02:00
|
|
|
"pcmpeqw %%mm7, %%mm7 \n\t"
|
|
|
|
"psrlq $48, %%mm7 \n\t"
|
|
|
|
"movd %2, %%mm6 \n\t"
|
|
|
|
"packssdw %%mm6, %%mm6 \n\t"
|
|
|
|
"packssdw %%mm6, %%mm6 \n\t"
|
2016-06-27 17:21:04 +02:00
|
|
|
"mov %3, %%"FF_REG_a" \n\t"
|
2011-01-16 00:09:35 +02:00
|
|
|
".p2align 4 \n\t"
|
2005-12-22 03:10:11 +02:00
|
|
|
"1: \n\t"
|
2016-06-27 17:21:04 +02:00
|
|
|
"movq (%0, %%"FF_REG_a"), %%mm0 \n\t"
|
|
|
|
"movq 8(%0, %%"FF_REG_a"), %%mm1\n\t"
|
|
|
|
"movq (%1, %%"FF_REG_a"), %%mm4 \n\t"
|
|
|
|
"movq 8(%1, %%"FF_REG_a"), %%mm5\n\t"
|
2005-12-22 03:10:11 +02:00
|
|
|
"pmullw %%mm6, %%mm4 \n\t" // q=qscale*quant_matrix[i]
|
|
|
|
"pmullw %%mm6, %%mm5 \n\t" // q=qscale*quant_matrix[i]
|
|
|
|
"pxor %%mm2, %%mm2 \n\t"
|
|
|
|
"pxor %%mm3, %%mm3 \n\t"
|
|
|
|
"pcmpgtw %%mm0, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
|
|
|
|
"pcmpgtw %%mm1, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
|
|
|
|
"pxor %%mm2, %%mm0 \n\t"
|
|
|
|
"pxor %%mm3, %%mm1 \n\t"
|
|
|
|
"psubw %%mm2, %%mm0 \n\t" // abs(block[i])
|
|
|
|
"psubw %%mm3, %%mm1 \n\t" // abs(block[i])
|
|
|
|
"paddw %%mm0, %%mm0 \n\t" // abs(block[i])*2
|
|
|
|
"paddw %%mm1, %%mm1 \n\t" // abs(block[i])*2
|
|
|
|
"pmullw %%mm4, %%mm0 \n\t" // abs(block[i])*2*q
|
|
|
|
"pmullw %%mm5, %%mm1 \n\t" // abs(block[i])*2*q
|
|
|
|
"paddw %%mm4, %%mm0 \n\t" // (abs(block[i])*2 + 1)*q
|
|
|
|
"paddw %%mm5, %%mm1 \n\t" // (abs(block[i])*2 + 1)*q
|
|
|
|
"pxor %%mm4, %%mm4 \n\t"
|
|
|
|
"pxor %%mm5, %%mm5 \n\t" // FIXME slow
|
2016-06-27 17:21:04 +02:00
|
|
|
"pcmpeqw (%0, %%"FF_REG_a"), %%mm4 \n\t" // block[i] == 0 ? -1 : 0
|
|
|
|
"pcmpeqw 8(%0, %%"FF_REG_a"), %%mm5\n\t" // block[i] == 0 ? -1 : 0
|
2015-09-17 23:47:06 +02:00
|
|
|
"psrlw $5, %%mm0 \n\t"
|
|
|
|
"psrlw $5, %%mm1 \n\t"
|
2005-12-22 03:10:11 +02:00
|
|
|
"pxor %%mm2, %%mm0 \n\t"
|
|
|
|
"pxor %%mm3, %%mm1 \n\t"
|
|
|
|
"psubw %%mm2, %%mm0 \n\t"
|
|
|
|
"psubw %%mm3, %%mm1 \n\t"
|
|
|
|
"pandn %%mm0, %%mm4 \n\t"
|
|
|
|
"pandn %%mm1, %%mm5 \n\t"
|
|
|
|
"pxor %%mm4, %%mm7 \n\t"
|
|
|
|
"pxor %%mm5, %%mm7 \n\t"
|
2016-06-27 17:21:04 +02:00
|
|
|
"movq %%mm4, (%0, %%"FF_REG_a") \n\t"
|
|
|
|
"movq %%mm5, 8(%0, %%"FF_REG_a")\n\t"
|
2005-12-22 03:10:11 +02:00
|
|
|
|
2016-06-27 17:21:04 +02:00
|
|
|
"add $16, %%"FF_REG_a" \n\t"
|
2005-12-22 03:10:11 +02:00
|
|
|
"jng 1b \n\t"
|
|
|
|
"movd 124(%0, %3), %%mm0 \n\t"
|
|
|
|
"movq %%mm7, %%mm6 \n\t"
|
|
|
|
"psrlq $32, %%mm7 \n\t"
|
|
|
|
"pxor %%mm6, %%mm7 \n\t"
|
|
|
|
"movq %%mm7, %%mm6 \n\t"
|
|
|
|
"psrlq $16, %%mm7 \n\t"
|
|
|
|
"pxor %%mm6, %%mm7 \n\t"
|
|
|
|
"pslld $31, %%mm7 \n\t"
|
|
|
|
"psrlq $15, %%mm7 \n\t"
|
|
|
|
"pxor %%mm7, %%mm0 \n\t"
|
|
|
|
"movd %%mm0, 124(%0, %3) \n\t"
|
|
|
|
|
2008-08-24 11:41:20 +03:00
|
|
|
::"r" (block+nCoeffs), "r"(quant_matrix+nCoeffs), "rm" (qscale), "r" (-2*nCoeffs)
|
2016-06-27 17:21:04 +02:00
|
|
|
: "%"FF_REG_a, "memory"
|
2005-12-22 03:10:11 +02:00
|
|
|
);
|
2001-07-30 12:04:34 +03:00
|
|
|
}
|
|
|
|
|
2013-07-07 02:29:48 +03:00
|
|
|
#endif /* HAVE_MMX_INLINE */
|
2012-07-26 06:30:19 +03:00
|
|
|
|
2014-08-10 18:25:12 +03:00
|
|
|
av_cold void ff_mpv_common_init_x86(MpegEncContext *s)
|
2001-07-30 12:04:34 +03:00
|
|
|
{
|
2013-07-07 02:29:48 +03:00
|
|
|
#if HAVE_MMX_INLINE
|
2013-07-17 21:19:24 +03:00
|
|
|
int cpu_flags = av_get_cpu_flags();
|
2010-08-24 20:47:05 +03:00
|
|
|
|
2013-08-20 15:46:58 +03:00
|
|
|
if (INLINE_MMX(cpu_flags)) {
|
2003-12-14 04:57:00 +02:00
|
|
|
s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_mmx;
|
|
|
|
s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_mmx;
|
|
|
|
s->dct_unquantize_mpeg1_intra = dct_unquantize_mpeg1_intra_mmx;
|
|
|
|
s->dct_unquantize_mpeg1_inter = dct_unquantize_mpeg1_inter_mmx;
|
2015-06-29 21:59:37 +02:00
|
|
|
if (!(s->avctx->flags & AV_CODEC_FLAG_BITEXACT))
|
2006-04-28 20:03:52 +03:00
|
|
|
s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_mmx;
|
2003-12-14 04:57:00 +02:00
|
|
|
s->dct_unquantize_mpeg2_inter = dct_unquantize_mpeg2_inter_mmx;
|
2001-07-31 02:28:35 +03:00
|
|
|
}
|
2013-07-07 02:29:48 +03:00
|
|
|
#endif /* HAVE_MMX_INLINE */
|
2001-07-30 12:04:34 +03:00
|
|
|
}
|