blob: 491e7cfe5476beebf5de2e36f5f9776d554f9004 [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
57/* 128 implies 64 */
58#ifdef CLIB_HAVE_VEC128
59#define CLIB_HAVE_VEC64
60#endif
61
62#define _vector_size(n) __attribute__ ((vector_size (n)))
63
Christophe Fontainefef15b42016-04-09 12:38:49 +090064#if defined (__aarch64__) || defined (__arm__)
Dave Barach61efa142016-01-22 08:23:09 -050065typedef unsigned int u32x4 _vector_size (16);
Christophe Fontaine33e81952016-12-19 14:41:52 +010066typedef u8 u8x16 _vector_size (16);
67typedef u16 u16x8 _vector_size (16);
68typedef u32 u32x4 _vector_size (16);
69typedef u64 u64x2 _vector_size (16);
Dave Barach61efa142016-01-22 08:23:09 -050070#endif
71
Ed Warnickecb9cada2015-12-08 15:45:58 -070072#ifdef CLIB_HAVE_VEC64
73/* Signed 64 bit. */
74typedef char i8x8 _vector_size (8);
75typedef short i16x4 _vector_size (8);
76typedef int i32x2 _vector_size (8);
77
78/* Unsigned 64 bit. */
79typedef unsigned char u8x8 _vector_size (8);
80typedef unsigned short u16x4 _vector_size (8);
81typedef unsigned int u32x2 _vector_size (8);
82
83/* Floating point 64 bit. */
84typedef float f32x2 _vector_size (8);
85#endif /* CLIB_HAVE_VEC64 */
86
87#ifdef CLIB_HAVE_VEC128
88/* Signed 128 bit. */
89typedef i8 i8x16 _vector_size (16);
90typedef i16 i16x8 _vector_size (16);
91typedef i32 i32x4 _vector_size (16);
92typedef long long i64x2 _vector_size (16);
93
94/* Unsigned 128 bit. */
95typedef u8 u8x16 _vector_size (16);
96typedef u16 u16x8 _vector_size (16);
97typedef u32 u32x4 _vector_size (16);
98typedef u64 u64x2 _vector_size (16);
99
100typedef f32 f32x4 _vector_size (16);
101typedef f64 f64x2 _vector_size (16);
Damjan Marion34d77912016-10-20 10:08:03 +0100102
103/* Signed 256 bit. */
104typedef i8 i8x32 _vector_size (32);
105typedef i16 i16x16 _vector_size (32);
106typedef i32 i32x8 _vector_size (32);
107typedef long long i64x4 _vector_size (32);
108
109/* Unsigned 256 bit. */
110typedef u8 u8x32 _vector_size (32);
111typedef u16 u16x16 _vector_size (32);
112typedef u32 u32x8 _vector_size (32);
113typedef u64 u64x4 _vector_size (32);
114
115typedef f32 f32x8 _vector_size (32);
116typedef f64 f64x4 _vector_size (32);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700117#endif /* CLIB_HAVE_VEC128 */
118
119/* Vector word sized types. */
120#ifndef CLIB_VECTOR_WORD_BITS
Dave Barachc3799992016-08-15 11:12:27 -0400121#ifdef CLIB_HAVE_VEC128
122#define CLIB_VECTOR_WORD_BITS 128
123#else
124#define CLIB_VECTOR_WORD_BITS 64
125#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -0700126#endif /* CLIB_VECTOR_WORD_BITS */
127
128/* Vector word sized types. */
129#if CLIB_VECTOR_WORD_BITS == 128
Dave Barachc3799992016-08-15 11:12:27 -0400130typedef i8 i8x _vector_size (16);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700131typedef i16 i16x _vector_size (16);
132typedef i32 i32x _vector_size (16);
133typedef i64 i64x _vector_size (16);
Dave Barachc3799992016-08-15 11:12:27 -0400134typedef u8 u8x _vector_size (16);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700135typedef u16 u16x _vector_size (16);
136typedef u32 u32x _vector_size (16);
137typedef u64 u64x _vector_size (16);
138#endif
139#if CLIB_VECTOR_WORD_BITS == 64
Dave Barachc3799992016-08-15 11:12:27 -0400140typedef i8 i8x _vector_size (8);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700141typedef i16 i16x _vector_size (8);
142typedef i32 i32x _vector_size (8);
143typedef i64 i64x _vector_size (8);
Dave Barachc3799992016-08-15 11:12:27 -0400144typedef u8 u8x _vector_size (8);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700145typedef u16 u16x _vector_size (8);
146typedef u32 u32x _vector_size (8);
147typedef u64 u64x _vector_size (8);
148#endif
149
150#undef _vector_size
151
152#define VECTOR_WORD_TYPE(t) t##x
153#define VECTOR_WORD_TYPE_LEN(t) (sizeof (VECTOR_WORD_TYPE(t)) / sizeof (t))
154
155/* Union types. */
156#if (defined(CLIB_HAVE_VEC128) || defined(CLIB_HAVE_VEC64))
157
158#define _(t) \
159 typedef union { \
160 t##x as_##t##x; \
161 t as_##t[VECTOR_WORD_TYPE_LEN (t)]; \
162 } t##x##_union_t;
163
Dave Barachc3799992016-08-15 11:12:27 -0400164_(u8);
165_(u16);
166_(u32);
167_(u64);
168_(i8);
169_(i16);
170_(i32);
171_(i64);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700172
173#undef _
174
175#endif
176
177#ifdef CLIB_HAVE_VEC64
178
179#define _(t,n) \
180 typedef union { \
181 t##x##n as_##t##x##n; \
182 t as_##t[n]; \
183 } t##x##n##_union_t; \
184
Dave Barachc3799992016-08-15 11:12:27 -0400185_(u8, 8);
186_(u16, 4);
187_(u32, 2);
188_(i8, 8);
189_(i16, 4);
190_(i32, 2);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700191
192#undef _
193
194#endif
195
196#ifdef CLIB_HAVE_VEC128
197
198#define _(t,n) \
199 typedef union { \
200 t##x##n as_##t##x##n; \
201 t as_##t[n]; \
202 } t##x##n##_union_t; \
203
Dave Barachc3799992016-08-15 11:12:27 -0400204_(u8, 16);
205_(u16, 8);
206_(u32, 4);
207_(u64, 2);
208_(i8, 16);
209_(i16, 8);
210_(i32, 4);
211_(i64, 2);
212_(f32, 4);
213_(f64, 2);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700214
215#undef _
216
217#endif
218
219/* When we don't have vector types, still define e.g. u32x4_union_t but as an array. */
220#if !defined(CLIB_HAVE_VEC128) && !defined(CLIB_HAVE_VEC64)
221
222#define _(t,n) \
223 typedef union { \
224 t as_##t[n]; \
225 } t##x##n##_union_t; \
226
Dave Barachc3799992016-08-15 11:12:27 -0400227_(u8, 16);
228_(u16, 8);
229_(u32, 4);
230_(u64, 2);
231_(i8, 16);
232_(i16, 8);
233_(i32, 4);
234_(i64, 2);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700235
236#undef _
237
238#endif
239
240#if defined (__SSE2__) && __GNUC__ >= 4
241#include <vppinfra/vector_sse2.h>
242#endif
243
244#if defined (__ALTIVEC__)
245#include <vppinfra/vector_altivec.h>
246#endif
247
248#if defined (__IWMMXT__)
249#include <vppinfra/vector_iwmmxt.h>
250#endif
251
Christophe Fontaine33e81952016-12-19 14:41:52 +0100252#if defined (__aarch64__)
253#include <vppinfra/vector_neon.h>
254#endif
255
Ed Warnickecb9cada2015-12-08 15:45:58 -0700256#if (defined(CLIB_HAVE_VEC128) || defined(CLIB_HAVE_VEC64))
257#include <vppinfra/vector_funcs.h>
258#endif
259
260#endif /* included_clib_vector_h */
Dave Barachc3799992016-08-15 11:12:27 -0400261
262/*
263 * fd.io coding-style-patch-verification: ON
264 *
265 * Local Variables:
266 * eval: (c-set-style "gnu")
267 * End:
268 */