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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 Copyright (c) 2005 Eliot Dresselhaus
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:
26 The above copyright notice and this permission notice shall be
27 included in all copies or substantial portions of the Software.
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.
38 #ifndef included_clib_vector_h
39 #define included_clib_vector_h
41 #include <vppinfra/clib.h>
45 #if defined (__MMX__) || defined (__IWMMXT__) || defined (__aarch64__)
46 #define CLIB_HAVE_VEC64
49 #if defined (__aarch64__) && defined(__ARM_NEON)
50 #define CLIB_HAVE_VEC128
53 #if defined (__SSE2__) && __GNUC__ >= 4
54 #define CLIB_HAVE_VEC128
57 #if defined (__ALTIVEC__)
58 #define CLIB_HAVE_VEC128
62 #define CLIB_HAVE_VEC256
65 #if defined (__AVX512F__)
66 #define CLIB_HAVE_VEC512
70 #ifdef CLIB_HAVE_VEC128
71 #define CLIB_HAVE_VEC64
74 #define _vector_size(n) __attribute__ ((vector_size (n)))
76 #ifdef CLIB_HAVE_VEC64
78 typedef char i8x8 _vector_size (8);
79 typedef short i16x4 _vector_size (8);
80 typedef int i32x2 _vector_size (8);
82 /* Unsigned 64 bit. */
83 typedef unsigned char u8x8 _vector_size (8);
84 typedef unsigned short u16x4 _vector_size (8);
85 typedef unsigned int u32x2 _vector_size (8);
87 /* Floating point 64 bit. */
88 typedef float f32x2 _vector_size (8);
89 #endif /* CLIB_HAVE_VEC64 */
91 #ifdef CLIB_HAVE_VEC128
93 typedef i8 i8x16 _vector_size (16);
94 typedef i16 i16x8 _vector_size (16);
95 typedef i32 i32x4 _vector_size (16);
96 typedef long long i64x2 _vector_size (16);
98 /* Unsigned 128 bit. */
99 typedef u8 u8x16 _vector_size (16);
100 typedef u16 u16x8 _vector_size (16);
101 typedef u32 u32x4 _vector_size (16);
102 typedef u64 u64x2 _vector_size (16);
104 typedef f32 f32x4 _vector_size (16);
105 typedef f64 f64x2 _vector_size (16);
107 /* Signed 256 bit. */
108 typedef i8 i8x32 _vector_size (32);
109 typedef i16 i16x16 _vector_size (32);
110 typedef i32 i32x8 _vector_size (32);
111 typedef long long i64x4 _vector_size (32);
113 /* Unsigned 256 bit. */
114 typedef u8 u8x32 _vector_size (32);
115 typedef u16 u16x16 _vector_size (32);
116 typedef u32 u32x8 _vector_size (32);
117 typedef u64 u64x4 _vector_size (32);
119 typedef f32 f32x8 _vector_size (32);
120 typedef f64 f64x4 _vector_size (32);
121 #endif /* CLIB_HAVE_VEC128 */
123 #ifdef CLIB_HAVE_VEC512
124 /* Signed 512 bit. */
125 typedef i8 i8x64 _vector_size (64);
126 typedef i16 i16x32 _vector_size (64);
127 typedef i32 i32x16 _vector_size (64);
128 typedef long long i64x8 _vector_size (64);
130 /* Unsigned 512 bit. */
131 typedef u8 u8x64 _vector_size (64);
132 typedef u16 u16x32 _vector_size (64);
133 typedef u32 u32x16 _vector_size (64);
134 typedef u64 u64x8 _vector_size (64);
136 typedef f32 f32x16 _vector_size (64);
137 typedef f64 f64x8 _vector_size (64);
138 #endif /* CLIB_HAVE_VEC512 */
140 /* Vector word sized types. */
141 #ifndef CLIB_VECTOR_WORD_BITS
142 #ifdef CLIB_HAVE_VEC128
143 #define CLIB_VECTOR_WORD_BITS 128
145 #define CLIB_VECTOR_WORD_BITS 64
147 #endif /* CLIB_VECTOR_WORD_BITS */
149 /* Vector word sized types. */
150 #if CLIB_VECTOR_WORD_BITS == 128
151 typedef i8 i8x _vector_size (16);
152 typedef i16 i16x _vector_size (16);
153 typedef i32 i32x _vector_size (16);
154 typedef i64 i64x _vector_size (16);
155 typedef u8 u8x _vector_size (16);
156 typedef u16 u16x _vector_size (16);
157 typedef u32 u32x _vector_size (16);
158 typedef u64 u64x _vector_size (16);
160 #if CLIB_VECTOR_WORD_BITS == 64
161 typedef i8 i8x _vector_size (8);
162 typedef i16 i16x _vector_size (8);
163 typedef i32 i32x _vector_size (8);
164 typedef i64 i64x _vector_size (8);
165 typedef u8 u8x _vector_size (8);
166 typedef u16 u16x _vector_size (8);
167 typedef u32 u32x _vector_size (8);
168 typedef u64 u64x _vector_size (8);
173 #define VECTOR_WORD_TYPE(t) t##x
174 #define VECTOR_WORD_TYPE_LEN(t) (sizeof (VECTOR_WORD_TYPE(t)) / sizeof (t))
177 #if (defined(CLIB_HAVE_VEC128) || defined(CLIB_HAVE_VEC64))
182 t as_##t[VECTOR_WORD_TYPE_LEN (t)]; \
198 #ifdef CLIB_HAVE_VEC64
202 t##x##n as_##t##x##n; \
204 } t##x##n##_union_t; \
217 #ifdef CLIB_HAVE_VEC128
221 t##x##n as_##t##x##n; \
223 } t##x##n##_union_t; \
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)
246 } t##x##n##_union_t; \
261 #if defined (__SSE2__) && __GNUC__ >= 4
262 #include <vppinfra/vector_sse2.h>
265 #if defined (__ALTIVEC__)
266 #include <vppinfra/vector_altivec.h>
269 #if defined (__IWMMXT__)
270 #include <vppinfra/vector_iwmmxt.h>
273 #if defined (__aarch64__)
274 #include <vppinfra/vector_neon.h>
277 #if (defined(CLIB_HAVE_VEC128) || defined(CLIB_HAVE_VEC64))
278 #include <vppinfra/vector_funcs.h>
281 #endif /* included_clib_vector_h */
284 * fd.io coding-style-patch-verification: ON
287 * eval: (c-set-style "gnu")