FFmpeg
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 "config.h"
28 
29 #include "libavutil/attributes.h"
30 #include "libavutil/avassert.h"
31 #include "libavutil/cpu.h"
32 #include "libavutil/mem_internal.h"
33 #include "libavutil/ppc/cpu.h"
35 
36 #include "libavcodec/mpegvideo.h"
38 
39 #if HAVE_ALTIVEC
40 
41 /* AltiVec version of dct_unquantize_h263
42  this code assumes `block' is 16 bytes-aligned */
43 static av_always_inline
44 void dct_unquantize_h263_altivec(int16_t *block, int nb_coeffs, int qadd, int qmul)
45 {
46  register const vector signed short vczero = (const vector signed short)vec_splat_s16(0);
47  DECLARE_ALIGNED(16, short, qmul8) = qmul;
48  DECLARE_ALIGNED(16, short, qadd8) = qadd;
49  register vector signed short blockv, qmulv, qaddv, nqaddv, temp1;
50  register vector bool short blockv_null, blockv_neg;
51 
52  qmulv = vec_splat((vec_s16)vec_lde(0, &qmul8), 0);
53  qaddv = vec_splat((vec_s16)vec_lde(0, &qadd8), 0);
54  nqaddv = vec_sub(vczero, qaddv);
55 
56  // vectorize all the 16 bytes-aligned blocks
57  // of 8 elements
58  for (register int j = 0; j <= nb_coeffs; j += 8) {
59  blockv = vec_ld(j << 1, block);
60  blockv_neg = vec_cmplt(blockv, vczero);
61  blockv_null = vec_cmpeq(blockv, vczero);
62  // choose between +qadd or -qadd as the third operand
63  temp1 = vec_sel(qaddv, nqaddv, blockv_neg);
64  // multiply & add (block{i,i+7} * qmul [+-] qadd)
65  temp1 = vec_mladd(blockv, qmulv, temp1);
66  // put 0 where block[{i,i+7} used to have 0
67  blockv = vec_sel(temp1, blockv, blockv_null);
68  vec_st(blockv, j << 1, block);
69  }
70 }
71 
72 static void dct_unquantize_h263_intra_altivec(const MPVContext *s,
73  int16_t *block, int n, int qscale)
74 {
75  int qadd = (qscale - 1) | 1;
76  int qmul = qscale << 1;
77  int block0 = block[0];
78  if (!s->h263_aic) {
79  block0 *= n < 4 ? s->y_dc_scale : s->c_dc_scale;
80  } else
81  qadd = 0;
82  int nb_coeffs = s->ac_pred ? 63 : s->intra_scantable.raster_end[s->block_last_index[n]];
83 
84  dct_unquantize_h263_altivec(block, nb_coeffs, qadd, qmul);
85 
86  // cheat. this avoid special-casing the first iteration
87  block[0] = block0;
88 }
89 
90 static void dct_unquantize_h263_inter_altivec(const MPVContext *s,
91  int16_t *block, int n, int qscale)
92 {
93  int qadd = (qscale - 1) | 1;
94  int qmul = qscale << 1;
95  av_assert2(s->block_last_index[n]>=0);
96  int nb_coeffs = s->inter_scantable.raster_end[s->block_last_index[n]];
97 
98  dct_unquantize_h263_altivec(block, nb_coeffs, qadd, qmul);
99 }
100 #endif /* HAVE_ALTIVEC */
101 
103 {
104 #if HAVE_ALTIVEC
106  return;
107 
108  s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_altivec;
109  s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_altivec;
110 #endif /* HAVE_ALTIVEC */
111 }
mpegvideo_unquantize.h
mem_internal.h
mpegvideo.h
av_get_cpu_flags
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:109
avassert.h
vec_s16
#define vec_s16
Definition: util_altivec.h:37
av_cold
#define av_cold
Definition: attributes.h:106
s
#define s(width, name)
Definition: cbs_vp9.c:198
ff_mpv_unquantize_init_ppc
av_cold void ff_mpv_unquantize_init_ppc(MPVUnquantDSPContext *s, int bitexact)
Definition: mpegvideo_altivec.c:102
PPC_ALTIVEC
#define PPC_ALTIVEC(flags)
Definition: cpu.h:25
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem_internal.h:104
cpu.h
attributes.h
av_assert2
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:68
av_always_inline
#define av_always_inline
Definition: attributes.h:63
util_altivec.h
cpu.h
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
MPVUnquantDSPContext
Definition: mpegvideo_unquantize.h:34
short
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option keep it simple and lowercase description are short
Definition: writing_filters.txt:89