blob: 13d7ba270311943e4e1c20cc42ad87d4bcba8f6a [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
Damjan Marion927b0712018-02-20 08:33:50 +010053#if defined (__SSE4_2__) && __GNUC__ >= 4
Ed Warnickecb9cada2015-12-08 15:45:58 -070054#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/* Signed 64 bit. */
77typedef char i8x8 _vector_size (8);
78typedef short i16x4 _vector_size (8);
79typedef int i32x2 _vector_size (8);
80
81/* Unsigned 64 bit. */
82typedef unsigned char u8x8 _vector_size (8);
83typedef unsigned short u16x4 _vector_size (8);
84typedef unsigned int u32x2 _vector_size (8);
85
86/* Floating point 64 bit. */
87typedef float f32x2 _vector_size (8);
Ed Warnickecb9cada2015-12-08 15:45:58 -070088
Ed Warnickecb9cada2015-12-08 15:45:58 -070089/* Signed 128 bit. */
90typedef i8 i8x16 _vector_size (16);
91typedef i16 i16x8 _vector_size (16);
92typedef i32 i32x4 _vector_size (16);
93typedef long long i64x2 _vector_size (16);
94
95/* Unsigned 128 bit. */
96typedef u8 u8x16 _vector_size (16);
97typedef u16 u16x8 _vector_size (16);
98typedef u32 u32x4 _vector_size (16);
99typedef u64 u64x2 _vector_size (16);
100
101typedef f32 f32x4 _vector_size (16);
102typedef f64 f64x2 _vector_size (16);
Damjan Marion34d77912016-10-20 10:08:03 +0100103
104/* Signed 256 bit. */
105typedef i8 i8x32 _vector_size (32);
106typedef i16 i16x16 _vector_size (32);
107typedef i32 i32x8 _vector_size (32);
108typedef long long i64x4 _vector_size (32);
109
110/* Unsigned 256 bit. */
111typedef u8 u8x32 _vector_size (32);
112typedef u16 u16x16 _vector_size (32);
113typedef u32 u32x8 _vector_size (32);
114typedef u64 u64x4 _vector_size (32);
115
116typedef f32 f32x8 _vector_size (32);
117typedef f64 f64x4 _vector_size (32);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700118
Damjan Marionb79d8862017-11-10 20:20:32 +0100119/* Signed 512 bit. */
120typedef i8 i8x64 _vector_size (64);
121typedef i16 i16x32 _vector_size (64);
122typedef i32 i32x16 _vector_size (64);
123typedef long long i64x8 _vector_size (64);
124
125/* Unsigned 512 bit. */
126typedef u8 u8x64 _vector_size (64);
127typedef u16 u16x32 _vector_size (64);
128typedef u32 u32x16 _vector_size (64);
129typedef u64 u64x8 _vector_size (64);
130
131typedef f32 f32x16 _vector_size (64);
132typedef f64 f64x8 _vector_size (64);
Damjan Marionb79d8862017-11-10 20:20:32 +0100133
Ed Warnickecb9cada2015-12-08 15:45:58 -0700134/* Vector word sized types. */
135#ifndef CLIB_VECTOR_WORD_BITS
Dave Barachc3799992016-08-15 11:12:27 -0400136#ifdef CLIB_HAVE_VEC128
137#define CLIB_VECTOR_WORD_BITS 128
138#else
139#define CLIB_VECTOR_WORD_BITS 64
140#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -0700141#endif /* CLIB_VECTOR_WORD_BITS */
142
143/* Vector word sized types. */
144#if CLIB_VECTOR_WORD_BITS == 128
Dave Barachc3799992016-08-15 11:12:27 -0400145typedef i8 i8x _vector_size (16);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700146typedef i16 i16x _vector_size (16);
147typedef i32 i32x _vector_size (16);
148typedef i64 i64x _vector_size (16);
Dave Barachc3799992016-08-15 11:12:27 -0400149typedef u8 u8x _vector_size (16);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700150typedef u16 u16x _vector_size (16);
151typedef u32 u32x _vector_size (16);
152typedef u64 u64x _vector_size (16);
153#endif
154#if CLIB_VECTOR_WORD_BITS == 64
Dave Barachc3799992016-08-15 11:12:27 -0400155typedef i8 i8x _vector_size (8);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700156typedef i16 i16x _vector_size (8);
157typedef i32 i32x _vector_size (8);
158typedef i64 i64x _vector_size (8);
Dave Barachc3799992016-08-15 11:12:27 -0400159typedef u8 u8x _vector_size (8);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700160typedef u16 u16x _vector_size (8);
161typedef u32 u32x _vector_size (8);
162typedef u64 u64x _vector_size (8);
163#endif
164
165#undef _vector_size
166
167#define VECTOR_WORD_TYPE(t) t##x
168#define VECTOR_WORD_TYPE_LEN(t) (sizeof (VECTOR_WORD_TYPE(t)) / sizeof (t))
169
170/* Union types. */
171#if (defined(CLIB_HAVE_VEC128) || defined(CLIB_HAVE_VEC64))
172
173#define _(t) \
174 typedef union { \
175 t##x as_##t##x; \
176 t as_##t[VECTOR_WORD_TYPE_LEN (t)]; \
177 } t##x##_union_t;
178
Dave Barachc3799992016-08-15 11:12:27 -0400179_(u8);
180_(u16);
181_(u32);
182_(u64);
183_(i8);
184_(i16);
185_(i32);
186_(i64);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700187
188#undef _
189
190#endif
191
192#ifdef CLIB_HAVE_VEC64
193
194#define _(t,n) \
195 typedef union { \
196 t##x##n as_##t##x##n; \
197 t as_##t[n]; \
198 } t##x##n##_union_t; \
199
Dave Barachc3799992016-08-15 11:12:27 -0400200_(u8, 8);
201_(u16, 4);
202_(u32, 2);
203_(i8, 8);
204_(i16, 4);
205_(i32, 2);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700206
207#undef _
208
209#endif
210
211#ifdef CLIB_HAVE_VEC128
212
213#define _(t,n) \
214 typedef union { \
215 t##x##n as_##t##x##n; \
216 t as_##t[n]; \
217 } t##x##n##_union_t; \
218
Dave Barachc3799992016-08-15 11:12:27 -0400219_(u8, 16);
220_(u16, 8);
221_(u32, 4);
222_(u64, 2);
223_(i8, 16);
224_(i16, 8);
225_(i32, 4);
226_(i64, 2);
227_(f32, 4);
228_(f64, 2);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700229
230#undef _
231
232#endif
233
234/* When we don't have vector types, still define e.g. u32x4_union_t but as an array. */
235#if !defined(CLIB_HAVE_VEC128) && !defined(CLIB_HAVE_VEC64)
236
237#define _(t,n) \
238 typedef union { \
239 t as_##t[n]; \
240 } t##x##n##_union_t; \
241
Dave Barachc3799992016-08-15 11:12:27 -0400242_(u8, 16);
243_(u16, 8);
244_(u32, 4);
245_(u64, 2);
246_(i8, 16);
247_(i16, 8);
248_(i32, 4);
249_(i64, 2);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700250
251#undef _
252
253#endif
254
Damjan Marion927b0712018-02-20 08:33:50 +0100255#if defined (__SSE4_2__) && __GNUC__ >= 4
256#include <vppinfra/vector_sse42.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -0700257#endif
258
259#if defined (__ALTIVEC__)
260#include <vppinfra/vector_altivec.h>
261#endif
262
263#if defined (__IWMMXT__)
264#include <vppinfra/vector_iwmmxt.h>
265#endif
266
Christophe Fontaine33e81952016-12-19 14:41:52 +0100267#if defined (__aarch64__)
268#include <vppinfra/vector_neon.h>
269#endif
270
Ed Warnickecb9cada2015-12-08 15:45:58 -0700271#if (defined(CLIB_HAVE_VEC128) || defined(CLIB_HAVE_VEC64))
272#include <vppinfra/vector_funcs.h>
273#endif
274
275#endif /* included_clib_vector_h */
Dave Barachc3799992016-08-15 11:12:27 -0400276
277/*
278 * fd.io coding-style-patch-verification: ON
279 *
280 * Local Variables:
281 * eval: (c-set-style "gnu")
282 * End:
283 */