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 (__SSE2__) && __GNUC__ >= 4
50 #define CLIB_HAVE_VEC128
53 #if defined (__ALTIVEC__)
54 #define CLIB_HAVE_VEC128
58 #ifdef CLIB_HAVE_VEC128
59 #define CLIB_HAVE_VEC64
62 #define _vector_size(n) __attribute__ ((vector_size (n)))
64 #if defined (__aarch64__) || defined (__arm__)
65 typedef unsigned int u32x4 _vector_size (16);
66 typedef u8 u8x16 _vector_size (16);
67 typedef u16 u16x8 _vector_size (16);
68 typedef u32 u32x4 _vector_size (16);
69 typedef u64 u64x2 _vector_size (16);
72 #ifdef CLIB_HAVE_VEC64
74 typedef char i8x8 _vector_size (8);
75 typedef short i16x4 _vector_size (8);
76 typedef int i32x2 _vector_size (8);
78 /* Unsigned 64 bit. */
79 typedef unsigned char u8x8 _vector_size (8);
80 typedef unsigned short u16x4 _vector_size (8);
81 typedef unsigned int u32x2 _vector_size (8);
83 /* Floating point 64 bit. */
84 typedef float f32x2 _vector_size (8);
85 #endif /* CLIB_HAVE_VEC64 */
87 #ifdef CLIB_HAVE_VEC128
89 typedef i8 i8x16 _vector_size (16);
90 typedef i16 i16x8 _vector_size (16);
91 typedef i32 i32x4 _vector_size (16);
92 typedef long long i64x2 _vector_size (16);
94 /* Unsigned 128 bit. */
95 typedef u8 u8x16 _vector_size (16);
96 typedef u16 u16x8 _vector_size (16);
97 typedef u32 u32x4 _vector_size (16);
98 typedef u64 u64x2 _vector_size (16);
100 typedef f32 f32x4 _vector_size (16);
101 typedef f64 f64x2 _vector_size (16);
103 /* Signed 256 bit. */
104 typedef i8 i8x32 _vector_size (32);
105 typedef i16 i16x16 _vector_size (32);
106 typedef i32 i32x8 _vector_size (32);
107 typedef long long i64x4 _vector_size (32);
109 /* Unsigned 256 bit. */
110 typedef u8 u8x32 _vector_size (32);
111 typedef u16 u16x16 _vector_size (32);
112 typedef u32 u32x8 _vector_size (32);
113 typedef u64 u64x4 _vector_size (32);
115 typedef f32 f32x8 _vector_size (32);
116 typedef f64 f64x4 _vector_size (32);
117 #endif /* CLIB_HAVE_VEC128 */
119 /* Vector word sized types. */
120 #ifndef CLIB_VECTOR_WORD_BITS
121 #ifdef CLIB_HAVE_VEC128
122 #define CLIB_VECTOR_WORD_BITS 128
124 #define CLIB_VECTOR_WORD_BITS 64
126 #endif /* CLIB_VECTOR_WORD_BITS */
128 /* Vector word sized types. */
129 #if CLIB_VECTOR_WORD_BITS == 128
130 typedef i8 i8x _vector_size (16);
131 typedef i16 i16x _vector_size (16);
132 typedef i32 i32x _vector_size (16);
133 typedef i64 i64x _vector_size (16);
134 typedef u8 u8x _vector_size (16);
135 typedef u16 u16x _vector_size (16);
136 typedef u32 u32x _vector_size (16);
137 typedef u64 u64x _vector_size (16);
139 #if CLIB_VECTOR_WORD_BITS == 64
140 typedef i8 i8x _vector_size (8);
141 typedef i16 i16x _vector_size (8);
142 typedef i32 i32x _vector_size (8);
143 typedef i64 i64x _vector_size (8);
144 typedef u8 u8x _vector_size (8);
145 typedef u16 u16x _vector_size (8);
146 typedef u32 u32x _vector_size (8);
147 typedef u64 u64x _vector_size (8);
152 #define VECTOR_WORD_TYPE(t) t##x
153 #define VECTOR_WORD_TYPE_LEN(t) (sizeof (VECTOR_WORD_TYPE(t)) / sizeof (t))
156 #if (defined(CLIB_HAVE_VEC128) || defined(CLIB_HAVE_VEC64))
161 t as_##t[VECTOR_WORD_TYPE_LEN (t)]; \
177 #ifdef CLIB_HAVE_VEC64
181 t##x##n as_##t##x##n; \
183 } t##x##n##_union_t; \
196 #ifdef CLIB_HAVE_VEC128
200 t##x##n as_##t##x##n; \
202 } t##x##n##_union_t; \
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)
225 } t##x##n##_union_t; \
240 #if defined (__SSE2__) && __GNUC__ >= 4
241 #include <vppinfra/vector_sse2.h>
244 #if defined (__ALTIVEC__)
245 #include <vppinfra/vector_altivec.h>
248 #if defined (__IWMMXT__)
249 #include <vppinfra/vector_iwmmxt.h>
252 #if defined (__aarch64__)
253 #include <vppinfra/vector_neon.h>
256 #if (defined(CLIB_HAVE_VEC128) || defined(CLIB_HAVE_VEC64))
257 #include <vppinfra/vector_funcs.h>
260 #endif /* included_clib_vector_h */
263 * fd.io coding-style-patch-verification: ON
266 * eval: (c-set-style "gnu")