]> code.delx.au - pulseaudio/blob - src/pulsecore/vector.h
Merge commit 'origin/master-tx'
[pulseaudio] / src / pulsecore / vector.h
1 /***
2 This file is part of PulseAudio.
3
4 Copyright 2004-2006 Lennart Poettering
5 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
6
7 PulseAudio is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published
9 by the Free Software Foundation; either version 2.1 of the License,
10 or (at your option) any later version.
11
12 PulseAudio is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with PulseAudio; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA.
21 ***/
22
23 #include <inttypes.h>
24
25 /* First, define HAVE_VECTOR if we have the gcc vector extensions at all */
26 #if defined(__SSE2__) || defined(__ALTIVEC__)
27 #define HAVE_VECTOR
28
29
30 /* This is supposed to be portable to different SIMD instruction
31 * sets. We define vector types for different base types: uint8_t,
32 * int16_t, int32_t, float. The vector type is a union. The fields .i,
33 * .u, .f are arrays for accessing the separate elements of a
34 * vector. .v is a gcc vector type of the right format. .m is the
35 * vector in the type the SIMD extenstion specific intrinsics API
36 * expects. PA_xxx_VECTOR_SIZE is the size of the
37 * entries. PA_xxxx_VECTOR_MAKE constructs a gcc vector variable with
38 * the same value in all elements. */
39
40 #ifdef __SSE2__
41
42 #include <xmmintrin.h>
43 #include <emmintrin.h>
44
45 #define PA_UINT8_VECTOR_SIZE 16
46 #define PA_INT16_VECTOR_SIZE 8
47 #define PA_INT32_VECTOR_SIZE 4
48 #define PA_FLOAT_VECTOR_SIZE 4
49
50 #define PA_UINT8_VECTOR_MAKE(x) (pa_v16qi) { x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x }
51 #define PA_INT16_VECTOR_MAKE(x) (pa_v8hi) { x, x, x, x, x, x, x, x }
52 #define PA_INT32_VECTOR_MAKE(x) (pa_v4si) { x, x, x, x }
53 #define PA_FLOAT_VECTOR_MAKE(x) (pa_v4fi) { x, x, x, x }
54
55 #endif
56
57 /* uint8_t vector */
58 typedef uint8_t pa_v16qi __attribute__ ((vector_size (PA_UINT8_VECTOR_SIZE * sizeof(uint8_t))));
59 typedef union pa_uint8_vector {
60 uint8_t u[PA_UINT8_VECTOR_SIZE];
61 pa_v16qi v;
62 #ifdef __SSE2__
63 __m128i m;
64 #endif
65 } pa_uint8_vector_t;
66
67 /* int16_t vector*/
68 typedef int16_t pa_v8hi __attribute__ ((vector_size (PA_INT16_VECTOR_SIZE * sizeof(int16_t))));
69 typedef union pa_int16_vector {
70 int16_t i[PA_INT16_VECTOR_SIZE];
71 pa_v8hi v;
72 #ifdef __SSE2__
73 __m128i m;
74 #endif
75 } pa_int16_vector_t;
76
77 /* int32_t vector */
78 typedef int32_t pa_v4si __attribute__ ((vector_size (PA_INT32_VECTOR_SIZE * sizeof(int32_t))));
79 typedef union pa_int32_vector {
80 int32_t i[PA_INT32_VECTOR_SIZE];
81 pa_v4si v;
82 #ifdef __SSE2__
83 __m128i m;
84 #endif
85 } pa_int32_vector_t;
86
87 /* float vector */
88 typedef float pa_v4sf __attribute__ ((vector_size (PA_FLOAT_VECTOR_SIZE * sizeof(float))));
89 typedef union pa_float_vector {
90 float f[PA_FLOAT_VECTOR_SIZE];
91 pa_v4sf v;
92 #ifdef __SSE2__
93 __m128 m;
94 #endif
95 } pa_float_vector_t;
96
97 #endif