blob: e786275f5d495496ca1c8d761a39499846a0a3ef [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15/*
16 Copyright (c) 2005 Eliot Dresselhaus
17
18 Permission is hereby granted, free of charge, to any person obtaining
19 a copy of this software and associated documentation files (the
20 "Software"), to deal in the Software without restriction, including
21 without limitation the rights to use, copy, modify, merge, publish,
22 distribute, sublicense, and/or sell copies of the Software, and to
23 permit persons to whom the Software is furnished to do so, subject to
24 the following conditions:
25
26 The above copyright notice and this permission notice shall be
27 included in all copies or substantial portions of the Software.
28
29 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
33 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
34 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
35 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36*/
37
38#ifndef included_clib_vector_h
39#define included_clib_vector_h
40
41#include <vppinfra/clib.h>
42
43/* Vector types. */
44
Christophe Fontaine33e81952016-12-19 14:41:52 +010045#if defined (__MMX__) || defined (__IWMMXT__) || defined (__aarch64__)
Ed Warnickecb9cada2015-12-08 15:45:58 -070046#define CLIB_HAVE_VEC64
47#endif
48
Gabriel Ganneb81831d2017-12-05 17:33:37 +010049#if defined (__aarch64__) && defined(__ARM_NEON)
50#define CLIB_HAVE_VEC128
51#endif
52
Ed Warnickecb9cada2015-12-08 15:45:58 -070053#if defined (__SSE2__) && __GNUC__ >= 4
54#define CLIB_HAVE_VEC128
55#endif
56
57#if defined (__ALTIVEC__)
58#define CLIB_HAVE_VEC128
59#endif
60
Damjan Marionb79d8862017-11-10 20:20:32 +010061#if defined (__AVX__)
62#define CLIB_HAVE_VEC256
63#endif
64
65#if defined (__AVX512F__)
66#define CLIB_HAVE_VEC512
67#endif
68
Ed Warnickecb9cada2015-12-08 15:45:58 -070069/* 128 implies 64 */
70#ifdef CLIB_HAVE_VEC128
71#define CLIB_HAVE_VEC64
72#endif
73
74#define _vector_size(n) __attribute__ ((vector_size (n)))
75
Ed Warnickecb9cada2015-12-08 15:45:58 -070076#ifdef CLIB_HAVE_VEC64
77/* Signed 64 bit. */
78typedef char i8x8 _vector_size (8);
79typedef short i16x4 _vector_size (8);
80typedef int i32x2 _vector_size (8);
81
82/* Unsigned 64 bit. */
83typedef unsigned char u8x8 _vector_size (8);
84typedef unsigned short u16x4 _vector_size (8);
85typedef unsigned int u32x2 _vector_size (8);
86
87/* Floating point 64 bit. */
88typedef float f32x2 _vector_size (8);
89#endif /* CLIB_HAVE_VEC64 */
90
91#ifdef CLIB_HAVE_VEC128
92/* Signed 128 bit. */
93typedef i8 i8x16 _vector_size (16);
94typedef i16 i16x8 _vector_size (16);
95typedef i32 i32x4 _vector_size (16);
96typedef long long i64x2 _vector_size (16);
97
98/* Unsigned 128 bit. */
99typedef u8 u8x16 _vector_size (16);
100typedef u16 u16x8 _vector_size (16);
101typedef u32 u32x4 _vector_size (16);
102typedef u64 u64x2 _vector_size (16);
103
104typedef f32 f32x4 _vector_size (16);
105typedef f64 f64x2 _vector_size (16);
Damjan Marion34d77912016-10-20 10:08:03 +0100106
107/* Signed 256 bit. */
108typedef i8 i8x32 _vector_size (32);
109typedef i16 i16x16 _vector_size (32);
110typedef i32 i32x8 _vector_size (32);
111typedef long long i64x4 _vector_size (32);
112
113/* Unsigned 256 bit. */
114typedef u8 u8x32 _vector_size (32);
115typedef u16 u16x16 _vector_size (32);
116typedef u32 u32x8 _vector_size (32);
117typedef u64 u64x4 _vector_size (32);
118
119typedef f32 f32x8 _vector_size (32);
120typedef f64 f64x4 _vector_size (32);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700121#endif /* CLIB_HAVE_VEC128 */
122
Damjan Marionb79d8862017-11-10 20:20:32 +0100123#ifdef CLIB_HAVE_VEC512
124/* Signed 512 bit. */
125typedef i8 i8x64 _vector_size (64);
126typedef i16 i16x32 _vector_size (64);
127typedef i32 i32x16 _vector_size (64);
128typedef long long i64x8 _vector_size (64);
129
130/* Unsigned 512 bit. */
131typedef u8 u8x64 _vector_size (64);
132typedef u16 u16x32 _vector_size (64);
133typedef u32 u32x16 _vector_size (64);
134typedef u64 u64x8 _vector_size (64);
135
136typedef f32 f32x16 _vector_size (64);
137typedef f64 f64x8 _vector_size (64);
138#endif /* CLIB_HAVE_VEC512 */
139
Ed Warnickecb9cada2015-12-08 15:45:58 -0700140/* Vector word sized types. */
141#ifndef CLIB_VECTOR_WORD_BITS
Dave Barachc3799992016-08-15 11:12:27 -0400142#ifdef CLIB_HAVE_VEC128
143#define CLIB_VECTOR_WORD_BITS 128
144#else
145#define CLIB_VECTOR_WORD_BITS 64
146#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -0700147#endif /* CLIB_VECTOR_WORD_BITS */
148
149/* Vector word sized types. */
150#if CLIB_VECTOR_WORD_BITS == 128
Dave Barachc3799992016-08-15 11:12:27 -0400151typedef i8 i8x _vector_size (16);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700152typedef i16 i16x _vector_size (16);
153typedef i32 i32x _vector_size (16);
154typedef i64 i64x _vector_size (16);
Dave Barachc3799992016-08-15 11:12:27 -0400155typedef u8 u8x _vector_size (16);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700156typedef u16 u16x _vector_size (16);
157typedef u32 u32x _vector_size (16);
158typedef u64 u64x _vector_size (16);
159#endif
160#if CLIB_VECTOR_WORD_BITS == 64
Dave Barachc3799992016-08-15 11:12:27 -0400161typedef i8 i8x _vector_size (8);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700162typedef i16 i16x _vector_size (8);
163typedef i32 i32x _vector_size (8);
164typedef i64 i64x _vector_size (8);
Dave Barachc3799992016-08-15 11:12:27 -0400165typedef u8 u8x _vector_size (8);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700166typedef u16 u16x _vector_size (8);
167typedef u32 u32x _vector_size (8);
168typedef u64 u64x _vector_size (8);
169#endif
170
171#undef _vector_size
172
173#define VECTOR_WORD_TYPE(t) t##x
174#define VECTOR_WORD_TYPE_LEN(t) (sizeof (VECTOR_WORD_TYPE(t)) / sizeof (t))
175
176/* Union types. */
177#if (defined(CLIB_HAVE_VEC128) || defined(CLIB_HAVE_VEC64))
178
179#define _(t) \
180 typedef union { \
181 t##x as_##t##x; \
182 t as_##t[VECTOR_WORD_TYPE_LEN (t)]; \
183 } t##x##_union_t;
184
Dave Barachc3799992016-08-15 11:12:27 -0400185_(u8);
186_(u16);
187_(u32);
188_(u64);
189_(i8);
190_(i16);
191_(i32);
192_(i64);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700193
194#undef _
195
196#endif
197
198#ifdef CLIB_HAVE_VEC64
199
200#define _(t,n) \
201 typedef union { \
202 t##x##n as_##t##x##n; \
203 t as_##t[n]; \
204 } t##x##n##_union_t; \
205
Dave Barachc3799992016-08-15 11:12:27 -0400206_(u8, 8);
207_(u16, 4);
208_(u32, 2);
209_(i8, 8);
210_(i16, 4);
211_(i32, 2);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700212
213#undef _
214
215#endif
216
217#ifdef CLIB_HAVE_VEC128
218
219#define _(t,n) \
220 typedef union { \
221 t##x##n as_##t##x##n; \
222 t as_##t[n]; \
223 } t##x##n##_union_t; \
224
Dave Barachc3799992016-08-15 11:12:27 -0400225_(u8, 16);
226_(u16, 8);
227_(u32, 4);
228_(u64, 2);
229_(i8, 16);
230_(i16, 8);
231_(i32, 4);
232_(i64, 2);
233_(f32, 4);
234_(f64, 2);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700235
236#undef _
237
238#endif
239
240/* When we don't have vector types, still define e.g. u32x4_union_t but as an array. */
241#if !defined(CLIB_HAVE_VEC128) && !defined(CLIB_HAVE_VEC64)
242
243#define _(t,n) \
244 typedef union { \
245 t as_##t[n]; \
246 } t##x##n##_union_t; \
247
Dave Barachc3799992016-08-15 11:12:27 -0400248_(u8, 16);
249_(u16, 8);
250_(u32, 4);
251_(u64, 2);
252_(i8, 16);
253_(i16, 8);
254_(i32, 4);
255_(i64, 2);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700256
257#undef _
258
259#endif
260
261#if defined (__SSE2__) && __GNUC__ >= 4
262#include <vppinfra/vector_sse2.h>
263#endif
264
265#if defined (__ALTIVEC__)
266#include <vppinfra/vector_altivec.h>
267#endif
268
269#if defined (__IWMMXT__)
270#include <vppinfra/vector_iwmmxt.h>
271#endif
272
Christophe Fontaine33e81952016-12-19 14:41:52 +0100273#if defined (__aarch64__)
274#include <vppinfra/vector_neon.h>
275#endif
276
Ed Warnickecb9cada2015-12-08 15:45:58 -0700277#if (defined(CLIB_HAVE_VEC128) || defined(CLIB_HAVE_VEC64))
278#include <vppinfra/vector_funcs.h>
279#endif
280
281#endif /* included_clib_vector_h */
Dave Barachc3799992016-08-15 11:12:27 -0400282
283/*
284 * fd.io coding-style-patch-verification: ON
285 *
286 * Local Variables:
287 * eval: (c-set-style "gnu")
288 * End:
289 */