2002-11-02 13:28:08 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2002 Dieter Shirley
|
|
|
|
*
|
2004-04-16 15:47:37 +03:00
|
|
|
* dct_unquantize_h263_altivec:
|
|
|
|
* Copyright (c) 2003 Romain Dolbeau <romain@dolbeau.org>
|
|
|
|
*
|
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-11-02 13:28:08 +02: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.
|
2002-11-02 13:28:08 +02:00
|
|
|
*
|
2006-10-07 18:30:46 +03:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2002-11-02 13:28:08 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* 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
|
2002-11-02 13:28:08 +02:00
|
|
|
*/
|
2003-05-21 20:50:57 +03:00
|
|
|
|
2002-11-02 13:28:08 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2010-09-08 18:07:14 +03:00
|
|
|
#include "libavutil/cpu.h"
|
2008-05-09 14:56:36 +03:00
|
|
|
#include "libavcodec/dsputil.h"
|
|
|
|
#include "libavcodec/mpegvideo.h"
|
2003-05-21 20:50:57 +03:00
|
|
|
|
2007-10-02 14:39:32 +03:00
|
|
|
#include "util_altivec.h"
|
2009-08-24 13:36:13 +03:00
|
|
|
#include "types_altivec.h"
|
2010-03-07 00:37:14 +02:00
|
|
|
#include "dsputil_altivec.h"
|
2009-08-24 13:36:13 +03:00
|
|
|
|
2008-07-20 21:58:30 +03:00
|
|
|
/* AltiVec version of dct_unquantize_h263
|
|
|
|
this code assumes `block' is 16 bytes-aligned */
|
2010-03-07 00:37:14 +02:00
|
|
|
static void dct_unquantize_h263_altivec(MpegEncContext *s,
|
2003-01-12 15:29:24 +02:00
|
|
|
DCTELEM *block, int n, int qscale)
|
|
|
|
{
|
|
|
|
int i, level, qmul, qadd;
|
|
|
|
int nCoeffs;
|
2005-12-17 20:14:38 +02:00
|
|
|
|
2003-01-12 15:29:24 +02:00
|
|
|
assert(s->block_last_index[n]>=0);
|
2003-01-16 23:54:55 +02:00
|
|
|
|
2003-01-12 15:29:24 +02:00
|
|
|
qadd = (qscale - 1) | 1;
|
|
|
|
qmul = qscale << 1;
|
2005-12-17 20:14:38 +02:00
|
|
|
|
2003-01-12 15:29:24 +02:00
|
|
|
if (s->mb_intra) {
|
|
|
|
if (!s->h263_aic) {
|
2005-12-17 20:14:38 +02:00
|
|
|
if (n < 4)
|
2003-01-12 15:29:24 +02:00
|
|
|
block[0] = block[0] * s->y_dc_scale;
|
|
|
|
else
|
|
|
|
block[0] = block[0] * s->c_dc_scale;
|
|
|
|
}else
|
|
|
|
qadd = 0;
|
|
|
|
i = 1;
|
2007-04-07 17:09:20 +03:00
|
|
|
nCoeffs= 63; //does not always use zigzag table
|
2003-01-12 15:29:24 +02:00
|
|
|
} else {
|
|
|
|
i = 0;
|
|
|
|
nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ];
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2008-07-20 21:58:30 +03:00
|
|
|
register const vector signed short vczero = (const vector signed short)vec_splat_s16(0);
|
2010-03-06 16:24:59 +02:00
|
|
|
DECLARE_ALIGNED(16, short, qmul8) = qmul;
|
|
|
|
DECLARE_ALIGNED(16, short, qadd8) = qadd;
|
2008-07-20 21:58:30 +03:00
|
|
|
register vector signed short blockv, qmulv, qaddv, nqaddv, temp1;
|
|
|
|
register vector bool short blockv_null, blockv_neg;
|
|
|
|
register short backup_0 = block[0];
|
|
|
|
register int j = 0;
|
|
|
|
|
2009-08-24 13:36:13 +03:00
|
|
|
qmulv = vec_splat((vec_s16)vec_lde(0, &qmul8), 0);
|
|
|
|
qaddv = vec_splat((vec_s16)vec_lde(0, &qadd8), 0);
|
|
|
|
nqaddv = vec_sub(vczero, qaddv);
|
2008-07-20 21:58:30 +03:00
|
|
|
|
|
|
|
// vectorize all the 16 bytes-aligned blocks
|
|
|
|
// of 8 elements
|
|
|
|
for(; (j + 7) <= nCoeffs ; j+=8) {
|
|
|
|
blockv = vec_ld(j << 1, block);
|
|
|
|
blockv_neg = vec_cmplt(blockv, vczero);
|
|
|
|
blockv_null = vec_cmpeq(blockv, vczero);
|
|
|
|
// choose between +qadd or -qadd as the third operand
|
|
|
|
temp1 = vec_sel(qaddv, nqaddv, blockv_neg);
|
|
|
|
// multiply & add (block{i,i+7} * qmul [+-] qadd)
|
|
|
|
temp1 = vec_mladd(blockv, qmulv, temp1);
|
|
|
|
// put 0 where block[{i,i+7} used to have 0
|
|
|
|
blockv = vec_sel(temp1, blockv, blockv_null);
|
|
|
|
vec_st(blockv, j << 1, block);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if nCoeffs isn't a multiple of 8, finish the job
|
|
|
|
// using good old scalar units.
|
|
|
|
// (we could do it using a truncated vector,
|
|
|
|
// but I'm not sure it's worth the hassle)
|
|
|
|
for(; j <= nCoeffs ; j++) {
|
|
|
|
level = block[j];
|
|
|
|
if (level) {
|
|
|
|
if (level < 0) {
|
|
|
|
level = level * qmul - qadd;
|
|
|
|
} else {
|
|
|
|
level = level * qmul + qadd;
|
|
|
|
}
|
|
|
|
block[j] = level;
|
2003-01-12 15:29:24 +02:00
|
|
|
}
|
|
|
|
}
|
2005-12-17 20:14:38 +02:00
|
|
|
|
2008-07-20 21:58:30 +03:00
|
|
|
if (i == 1) {
|
|
|
|
// cheat. this avoid special-casing the first iteration
|
|
|
|
block[0] = backup_0;
|
|
|
|
}
|
2003-01-12 15:29:24 +02:00
|
|
|
}
|
|
|
|
}
|
2007-10-02 15:16:33 +03:00
|
|
|
|
|
|
|
|
2012-02-15 15:10:33 +03:00
|
|
|
void ff_MPV_common_init_altivec(MpegEncContext *s)
|
2007-10-02 15:16:33 +03:00
|
|
|
{
|
2010-09-08 18:07:14 +03:00
|
|
|
if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC)) return;
|
2008-02-18 23:35:31 +02:00
|
|
|
|
2007-10-02 15:16:33 +03:00
|
|
|
if ((s->avctx->dct_algo == FF_DCT_AUTO) ||
|
2008-07-20 21:58:30 +03:00
|
|
|
(s->avctx->dct_algo == FF_DCT_ALTIVEC)) {
|
2007-10-02 15:16:33 +03:00
|
|
|
s->dct_unquantize_h263_intra = dct_unquantize_h263_altivec;
|
|
|
|
s->dct_unquantize_h263_inter = dct_unquantize_h263_altivec;
|
|
|
|
}
|
|
|
|
}
|