2002-11-02 12:28:08 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2002 Dieter Shirley
|
|
|
|
*
|
2004-04-16 14:47:37 +02:00
|
|
|
* dct_unquantize_h263_altivec:
|
|
|
|
* Copyright (c) 2003 Romain Dolbeau <romain@dolbeau.org>
|
|
|
|
*
|
2011-03-18 18:35:10 +01:00
|
|
|
* This file is part of Libav.
|
2006-10-07 17:30:46 +02:00
|
|
|
*
|
2011-03-18 18:35:10 +01:00
|
|
|
* Libav is free software; you can redistribute it and/or
|
2002-11-02 12:28:08 +01:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 17:30:46 +02:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2002-11-02 12:28:08 +01:00
|
|
|
*
|
2011-03-18 18:35:10 +01:00
|
|
|
* Libav is distributed in the hope that it will be useful,
|
2002-11-02 12:28:08 +01: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
|
2011-03-18 18:35:10 +01:00
|
|
|
* License along with Libav; if not, write to the Free Software
|
2006-01-12 23:43:26 +01:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2002-11-02 12:28:08 +01:00
|
|
|
*/
|
2003-05-21 19:50:57 +02:00
|
|
|
|
2002-11-02 12:28:08 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2012-05-21 22:24:42 +02:00
|
|
|
|
2013-04-14 14:47:30 +02:00
|
|
|
#include "config.h"
|
2013-02-01 10:31:59 +01:00
|
|
|
#include "libavutil/attributes.h"
|
2010-09-08 17:07:14 +02:00
|
|
|
#include "libavutil/cpu.h"
|
2012-05-21 22:24:42 +02:00
|
|
|
#include "libavutil/ppc/types_altivec.h"
|
|
|
|
#include "libavutil/ppc/util_altivec.h"
|
2008-05-09 13:56:36 +02:00
|
|
|
#include "libavcodec/mpegvideo.h"
|
2010-03-06 23:37:14 +01:00
|
|
|
#include "dsputil_altivec.h"
|
2009-08-24 12:36:13 +02:00
|
|
|
|
2013-04-14 14:47:30 +02:00
|
|
|
#if HAVE_ALTIVEC
|
|
|
|
|
2008-07-20 20:58:30 +02:00
|
|
|
/* AltiVec version of dct_unquantize_h263
|
|
|
|
this code assumes `block' is 16 bytes-aligned */
|
2010-03-06 23:37:14 +01:00
|
|
|
static void dct_unquantize_h263_altivec(MpegEncContext *s,
|
2013-01-20 01:02:29 +01:00
|
|
|
int16_t *block, int n, int qscale)
|
2003-01-12 14:29:24 +01:00
|
|
|
{
|
|
|
|
int i, level, qmul, qadd;
|
|
|
|
int nCoeffs;
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2003-01-12 14:29:24 +01:00
|
|
|
assert(s->block_last_index[n]>=0);
|
2003-01-16 22:54:55 +01:00
|
|
|
|
2003-01-12 14:29:24 +01:00
|
|
|
qadd = (qscale - 1) | 1;
|
|
|
|
qmul = qscale << 1;
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2003-01-12 14:29:24 +01:00
|
|
|
if (s->mb_intra) {
|
|
|
|
if (!s->h263_aic) {
|
2005-12-17 19:14:38 +01:00
|
|
|
if (n < 4)
|
2003-01-12 14:29:24 +01: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 16:09:20 +02:00
|
|
|
nCoeffs= 63; //does not always use zigzag table
|
2003-01-12 14:29:24 +01:00
|
|
|
} else {
|
|
|
|
i = 0;
|
|
|
|
nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ];
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2008-07-20 20:58:30 +02:00
|
|
|
register const vector signed short vczero = (const vector signed short)vec_splat_s16(0);
|
2010-03-06 15:24:59 +01:00
|
|
|
DECLARE_ALIGNED(16, short, qmul8) = qmul;
|
|
|
|
DECLARE_ALIGNED(16, short, qadd8) = qadd;
|
2008-07-20 20:58:30 +02: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 12:36:13 +02: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 20:58:30 +02: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 14:29:24 +01:00
|
|
|
}
|
|
|
|
}
|
2005-12-17 19:14:38 +01:00
|
|
|
|
2008-07-20 20:58:30 +02:00
|
|
|
if (i == 1) {
|
|
|
|
// cheat. this avoid special-casing the first iteration
|
|
|
|
block[0] = backup_0;
|
|
|
|
}
|
2003-01-12 14:29:24 +01:00
|
|
|
}
|
|
|
|
}
|
2007-10-02 14:16:33 +02:00
|
|
|
|
2013-04-14 14:47:30 +02:00
|
|
|
#endif /* HAVE_ALTIVEC */
|
2007-10-02 14:16:33 +02:00
|
|
|
|
2013-04-14 14:47:30 +02:00
|
|
|
av_cold void ff_MPV_common_init_ppc(MpegEncContext *s)
|
2007-10-02 14:16:33 +02:00
|
|
|
{
|
2013-04-14 14:47:30 +02:00
|
|
|
#if HAVE_ALTIVEC
|
2010-09-08 17:07:14 +02:00
|
|
|
if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC)) return;
|
2008-02-18 22:35:31 +01:00
|
|
|
|
2007-10-02 14:16:33 +02:00
|
|
|
if ((s->avctx->dct_algo == FF_DCT_AUTO) ||
|
2008-07-20 20:58:30 +02:00
|
|
|
(s->avctx->dct_algo == FF_DCT_ALTIVEC)) {
|
2007-10-02 14:16:33 +02:00
|
|
|
s->dct_unquantize_h263_intra = dct_unquantize_h263_altivec;
|
|
|
|
s->dct_unquantize_h263_inter = dct_unquantize_h263_altivec;
|
|
|
|
}
|
2013-04-14 14:47:30 +02:00
|
|
|
#endif /* HAVE_ALTIVEC */
|
2007-10-02 14:16:33 +02:00
|
|
|
}
|