blob: 5da1c19037bcc78dbdc3de840ac21b40f374fa98 [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
49#if defined (__SSE2__) && __GNUC__ >= 4
50#define CLIB_HAVE_VEC128
51#endif
52
53#if defined (__ALTIVEC__)
54#define CLIB_HAVE_VEC128
55#endif
56
Damjan Marionb79d8862017-11-10 20:20:32 +010057#if defined (__AVX__)
58#define CLIB_HAVE_VEC256
59#endif
60
61#if defined (__AVX512F__)
62#define CLIB_HAVE_VEC512
63#endif
64
Ed Warnickecb9cada2015-12-08 15:45:58 -070065/* 128 implies 64 */
66#ifdef CLIB_HAVE_VEC128
67#define CLIB_HAVE_VEC64
68#endif
69
70#define _vector_size(n) __attribute__ ((vector_size (n)))
71
Christophe Fontainefef15b42016-04-09 12:38:49 +090072#if defined (__aarch64__) || defined (__arm__)
Dave Barach61efa142016-01-22 08:23:09 -050073typedef unsigned int u32x4 _vector_size (16);
Christophe Fontaine33e81952016-12-19 14:41:52 +010074typedef u8 u8x16 _vector_size (16);
75typedef u16 u16x8 _vector_size (16);
76typedef u32 u32x4 _vector_size (16);
77typedef u64 u64x2 _vector_size (16);
Dave Barach61efa142016-01-22 08:23:09 -050078#endif
79
Ed Warnickecb9cada2015-12-08 15:45:58 -070080#ifdef CLIB_HAVE_VEC64
81/* Signed 64 bit. */
82typedef char i8x8 _vector_size (8);
83typedef short i16x4 _vector_size (8);
84typedef int i32x2 _vector_size (8);
85
86/* Unsigned 64 bit. */
87typedef unsigned char u8x8 _vector_size (8);
88typedef unsigned short u16x4 _vector_size (8);
89typedef unsigned int u32x2 _vector_size (8);
90
91/* Floating point 64 bit. */
92typedef float f32x2 _vector_size (8);
93#endif /* CLIB_HAVE_VEC64 */
94
95#ifdef CLIB_HAVE_VEC128
96/* Signed 128 bit. */
97typedef i8 i8x16 _vector_size (16);
98typedef i16 i16x8 _vector_size (16);
99typedef i32 i32x4 _vector_size (16);
100typedef long long i64x2 _vector_size (16);
101
102/* Unsigned 128 bit. */
103typedef u8 u8x16 _vector_size (16);
104typedef u16 u16x8 _vector_size (16);
105typedef u32 u32x4 _vector_size (16);
106typedef u64 u64x2 _vector_size (16);
107
108typedef f32 f32x4 _vector_size (16);
109typedef f64 f64x2 _vector_size (16);
Damjan Marion34d77912016-10-20 10:08:03 +0100110
111/* Signed 256 bit. */
112typedef i8 i8x32 _vector_size (32);
113typedef i16 i16x16 _vector_size (32);
114typedef i32 i32x8 _vector_size (32);
115typedef long long i64x4 _vector_size (32);
116
117/* Unsigned 256 bit. */
118typedef u8 u8x32 _vector_size (32);
119typedef u16 u16x16 _vector_size (32);
120typedef u32 u32x8 _vector_size (32);
121typedef u64 u64x4 _vector_size (32);
122
123typedef f32 f32x8 _vector_size (32);
124typedef f64 f64x4 _vector_size (32);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700125#endif /* CLIB_HAVE_VEC128 */
126
Damjan Marionb79d8862017-11-10 20:20:32 +0100127#ifdef CLIB_HAVE_VEC512
128/* Signed 512 bit. */
129typedef i8 i8x64 _vector_size (64);
130typedef i16 i16x32 _vector_size (64);
131typedef i32 i32x16 _vector_size (64);
132typedef long long i64x8 _vector_size (64);
133
134/* Unsigned 512 bit. */
135typedef u8 u8x64 _vector_size (64);
136typedef u16 u16x32 _vector_size (64);
137typedef u32 u32x16 _vector_size (64);
138typedef u64 u64x8 _vector_size (64);
139
140typedef f32 f32x16 _vector_size (64);
141typedef f64 f64x8 _vector_size (64);
142#endif /* CLIB_HAVE_VEC512 */
143
Ed Warnickecb9cada2015-12-08 15:45:58 -0700144/* Vector word sized types. */
145#ifndef CLIB_VECTOR_WORD_BITS
Dave Barachc3799992016-08-15 11:12:27 -0400146#ifdef CLIB_HAVE_VEC128
147#define CLIB_VECTOR_WORD_BITS 128
148#else
149#define CLIB_VECTOR_WORD_BITS 64
150#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -0700151#endif /* CLIB_VECTOR_WORD_BITS */
152
153/* Vector word sized types. */
154#if CLIB_VECTOR_WORD_BITS == 128
Dave Barachc3799992016-08-15 11:12:27 -0400155typedef i8 i8x _vector_size (16);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700156typedef i16 i16x _vector_size (16);
157typedef i32 i32x _vector_size (16);
158typedef i64 i64x _vector_size (16);
Dave Barachc3799992016-08-15 11:12:27 -0400159typedef u8 u8x _vector_size (16);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700160typedef u16 u16x _vector_size (16);
161typedef u32 u32x _vector_size (16);
162typedef u64 u64x _vector_size (16);
163#endif
164#if CLIB_VECTOR_WORD_BITS == 64
Dave Barachc3799992016-08-15 11:12:27 -0400165typedef i8 i8x _vector_size (8);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700166typedef i16 i16x _vector_size (8);
167typedef i32 i32x _vector_size (8);
168typedef i64 i64x _vector_size (8);
Dave Barachc3799992016-08-15 11:12:27 -0400169typedef u8 u8x _vector_size (8);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700170typedef u16 u16x _vector_size (8);
171typedef u32 u32x _vector_size (8);
172typedef u64 u64x _vector_size (8);
173#endif
174
175#undef _vector_size
176
177#define VECTOR_WORD_TYPE(t) t##x
178#define VECTOR_WORD_TYPE_LEN(t) (sizeof (VECTOR_WORD_TYPE(t)) / sizeof (t))
179
180/* Union types. */
181#if (defined(CLIB_HAVE_VEC128) || defined(CLIB_HAVE_VEC64))
182
183#define _(t) \
184 typedef union { \
185 t##x as_##t##x; \
186 t as_##t[VECTOR_WORD_TYPE_LEN (t)]; \
187 } t##x##_union_t;
188
Dave Barachc3799992016-08-15 11:12:27 -0400189_(u8);
190_(u16);
191_(u32);
192_(u64);
193_(i8);
194_(i16);
195_(i32);
196_(i64);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700197
198#undef _
199
200#endif
201
202#ifdef CLIB_HAVE_VEC64
203
204#define _(t,n) \
205 typedef union { \
206 t##x##n as_##t##x##n; \
207 t as_##t[n]; \
208 } t##x##n##_union_t; \
209
Dave Barachc3799992016-08-15 11:12:27 -0400210_(u8, 8);
211_(u16, 4);
212_(u32, 2);
213_(i8, 8);
214_(i16, 4);
215_(i32, 2);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700216
217#undef _
218
219#endif
220
221#ifdef CLIB_HAVE_VEC128
222
223#define _(t,n) \
224 typedef union { \
225 t##x##n as_##t##x##n; \
226 t as_##t[n]; \
227 } t##x##n##_union_t; \
228
Dave Barachc3799992016-08-15 11:12:27 -0400229_(u8, 16);
230_(u16, 8);
231_(u32, 4);
232_(u64, 2);
233_(i8, 16);
234_(i16, 8);
235_(i32, 4);
236_(i64, 2);
237_(f32, 4);
238_(f64, 2);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700239
240#undef _
241
242#endif
243
244/* When we don't have vector types, still define e.g. u32x4_union_t but as an array. */
245#if !defined(CLIB_HAVE_VEC128) && !defined(CLIB_HAVE_VEC64)
246
247#define _(t,n) \
248 typedef union { \
249 t as_##t[n]; \
250 } t##x##n##_union_t; \
251
Dave Barachc3799992016-08-15 11:12:27 -0400252_(u8, 16);
253_(u16, 8);
254_(u32, 4);
255_(u64, 2);
256_(i8, 16);
257_(i16, 8);
258_(i32, 4);
259_(i64, 2);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700260
261#undef _
262
263#endif
264
265#if defined (__SSE2__) && __GNUC__ >= 4
266#include <vppinfra/vector_sse2.h>
267#endif
268
269#if defined (__ALTIVEC__)
270#include <vppinfra/vector_altivec.h>
271#endif
272
273#if defined (__IWMMXT__)
274#include <vppinfra/vector_iwmmxt.h>
275#endif
276
Christophe Fontaine33e81952016-12-19 14:41:52 +0100277#if defined (__aarch64__)
278#include <vppinfra/vector_neon.h>
279#endif
280
Ed Warnickecb9cada2015-12-08 15:45:58 -0700281#if (defined(CLIB_HAVE_VEC128) || defined(CLIB_HAVE_VEC64))
282#include <vppinfra/vector_funcs.h>
283#endif
284
285#endif /* included_clib_vector_h */
Dave Barachc3799992016-08-15 11:12:27 -0400286
287/*
288 * fd.io coding-style-patch-verification: ON
289 *
290 * Local Variables:
291 * eval: (c-set-style "gnu")
292 * End:
293 */