mpegvideo_altivec.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002 Dieter Shirley
3  *
4  * dct_unquantize_h263_altivec:
5  * Copyright (c) 2003 Romain Dolbeau <romain@dolbeau.org>
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #include <stdlib.h>
25 #include <stdio.h>
26 
27 #include "libavutil/attributes.h"
28 #include "libavutil/cpu.h"
31 #include "libavcodec/mpegvideo.h"
32 
33 #include "dsputil_altivec.h"
34 
35 /* AltiVec version of dct_unquantize_h263
36  this code assumes `block' is 16 bytes-aligned */
38  int16_t *block, int n, int qscale)
39 {
40  int i, level, qmul, qadd;
41  int nCoeffs;
42 
43  assert(s->block_last_index[n]>=0);
44 
45  qadd = (qscale - 1) | 1;
46  qmul = qscale << 1;
47 
48  if (s->mb_intra) {
49  if (!s->h263_aic) {
50  if (n < 4)
51  block[0] = block[0] * s->y_dc_scale;
52  else
53  block[0] = block[0] * s->c_dc_scale;
54  }else
55  qadd = 0;
56  i = 1;
57  nCoeffs= 63; //does not always use zigzag table
58  } else {
59  i = 0;
60  nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ];
61  }
62 
63  {
64  register const vector signed short vczero = (const vector signed short)vec_splat_s16(0);
65  DECLARE_ALIGNED(16, short, qmul8) = qmul;
66  DECLARE_ALIGNED(16, short, qadd8) = qadd;
67  register vector signed short blockv, qmulv, qaddv, nqaddv, temp1;
68  register vector bool short blockv_null, blockv_neg;
69  register short backup_0 = block[0];
70  register int j = 0;
71 
72  qmulv = vec_splat((vec_s16)vec_lde(0, &qmul8), 0);
73  qaddv = vec_splat((vec_s16)vec_lde(0, &qadd8), 0);
74  nqaddv = vec_sub(vczero, qaddv);
75 
76  // vectorize all the 16 bytes-aligned blocks
77  // of 8 elements
78  for(; (j + 7) <= nCoeffs ; j+=8) {
79  blockv = vec_ld(j << 1, block);
80  blockv_neg = vec_cmplt(blockv, vczero);
81  blockv_null = vec_cmpeq(blockv, vczero);
82  // choose between +qadd or -qadd as the third operand
83  temp1 = vec_sel(qaddv, nqaddv, blockv_neg);
84  // multiply & add (block{i,i+7} * qmul [+-] qadd)
85  temp1 = vec_mladd(blockv, qmulv, temp1);
86  // put 0 where block[{i,i+7} used to have 0
87  blockv = vec_sel(temp1, blockv, blockv_null);
88  vec_st(blockv, j << 1, block);
89  }
90 
91  // if nCoeffs isn't a multiple of 8, finish the job
92  // using good old scalar units.
93  // (we could do it using a truncated vector,
94  // but I'm not sure it's worth the hassle)
95  for(; j <= nCoeffs ; j++) {
96  level = block[j];
97  if (level) {
98  if (level < 0) {
99  level = level * qmul - qadd;
100  } else {
101  level = level * qmul + qadd;
102  }
103  block[j] = level;
104  }
105  }
106 
107  if (i == 1) {
108  // cheat. this avoid special-casing the first iteration
109  block[0] = backup_0;
110  }
111  }
112 }
113 
114 
116 {
117  if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC)) return;
118 
119  if ((s->avctx->dct_algo == FF_DCT_AUTO) ||
120  (s->avctx->dct_algo == FF_DCT_ALTIVEC)) {
123  }
124 }
#define AV_CPU_FLAG_ALTIVEC
standard
Definition: cpu.h:52
const char * s
Definition: avisynth_c.h:668
static void dct_unquantize_h263_altivec(MpegEncContext *s, int16_t *block, int n, int qscale)
int dct_algo
DCT algorithm, see FF_DCT_* below.
void(* dct_unquantize_h263_inter)(struct MpegEncContext *s, int16_t *block, int n, int qscale)
Definition: mpegvideo.h:718
#define DECLARE_ALIGNED(n, t, v)
Definition: mem.h:59
uint8_t raster_end[64]
Definition: dsputil.h:117
mpegvideo header.
int qscale
QP.
Definition: mpegvideo.h:369
int h263_aic
Advanded INTRA Coding (AIC)
Definition: mpegvideo.h:292
Macro definitions for various function/variable attributes.
#define av_cold
Definition: attributes.h:78
#define vec_s16
Definition: types_altivec.h:30
#define FF_DCT_ALTIVEC
av_cold void ff_MPV_common_init_altivec(MpegEncContext *s)
#define FF_DCT_AUTO
int block_last_index[12]
last non zero coefficient in block
Definition: mpegvideo.h:291
FIXME Range Coding of cr are level
Definition: snow.txt:367
ScanTable intra_scantable
Definition: mpegvideo.h:296
synthesis window for stochastic i
void(* dct_unquantize_h263_intra)(struct MpegEncContext *s, int16_t *block, int n, int qscale)
Definition: mpegvideo.h:716
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:30
Contains misc utility macros and inline functions.
MpegEncContext.
Definition: mpegvideo.h:241
struct AVCodecContext * avctx
Definition: mpegvideo.h:243
int16_t(* block)[64]
points to one of the following blocks
Definition: mpegvideo.h:700