FFmpeg
audiodsp.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 Luca Barbato <lu_zero@gentoo.org>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file
23  * miscellaneous audio operations
24  */
25 
26 #include "config.h"
27 
28 #include "libavutil/attributes.h"
29 #include "libavutil/cpu.h"
30 #include "libavutil/ppc/cpu.h"
32 
33 #include "libavcodec/audiodsp.h"
34 
35 #if HAVE_ALTIVEC
36 
37 static int32_t scalarproduct_int16_altivec(const int16_t *v1, const int16_t *v2,
38  int order)
39 {
40  int i;
41  LOAD_ZERO;
42  register vec_s16 vec1;
43  register vec_s32 res = vec_splat_s32(0), t;
44  int32_t ires;
45 
46  for (i = 0; i < order; i += 8) {
47  vec1 = vec_unaligned_load(v1);
48  t = vec_msum(vec1, vec_ld(0, v2), zero_s32v);
49  res = vec_sums(t, res);
50  v1 += 8;
51  v2 += 8;
52  }
53  res = vec_splat(res, 3);
54  vec_ste(res, 0, &ires);
55 
56  return ires;
57 }
58 
59 #endif /* HAVE_ALTIVEC */
60 
61 #if HAVE_VSX
62 
63 static int32_t scalarproduct_int16_vsx(const int16_t *v1, const int16_t *v2, int order)
64 {
65  int i;
66  LOAD_ZERO;
67  register vec_s16 vec1;
68  register vec_s32 res = vec_splat_s32(0), t;
69  int32_t ires;
70 
71  for (i = 0; i < order; i += 8) {
72  vec1 = vec_vsx_ld(0, v1);
73  t = vec_msum(vec1, vec_ld(0, v2), zero_s32v);
74  res = vec_sums(t, res);
75  v1 += 8;
76  v2 += 8;
77  }
78  res = vec_splat(res, 3);
79  vec_ste(res, 0, &ires);
80 
81  return ires;
82 }
83 
84 #endif /* HAVE_VSX */
85 
87 {
88 #if HAVE_ALTIVEC
90  return;
91 
92  c->scalarproduct_int16 = scalarproduct_int16_altivec;
93 #endif /* HAVE_ALTIVEC */
94 
95 #if HAVE_VSX
96  if (!PPC_VSX(av_get_cpu_flags()))
97  return;
98 
99  c->scalarproduct_int16 = scalarproduct_int16_vsx;
100 #endif /* HAVE_VSX */
101 }
#define PPC_VSX(flags)
Definition: cpu.h:26
#define vec_s32
Definition: util_altivec.h:39
#define LOAD_ZERO
Definition: util_altivec.h:45
#define zero_s32v
Definition: util_altivec.h:52
Macro definitions for various function/variable attributes.
#define av_cold
Definition: attributes.h:82
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
av_cold void ff_audiodsp_init_ppc(AudioDSPContext *c)
Definition: audiodsp.c:86
#define vec_s16
Definition: util_altivec.h:37
#define PPC_ALTIVEC(flags)
Definition: cpu.h:25
int32_t
int32_t(* scalarproduct_int16)(const int16_t *v1, const int16_t *v2, int len)
Calculate scalar product of two vectors.
Definition: audiodsp.h:29
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:93
Contains misc utility macros and inline functions.