Vc 1.4.5
SIMD Vector Classes for C++
 
Loading...
Searching...
No Matches
macros.h
1/* This file is part of the Vc library. {{{
2Copyright © 2010-2015 Matthias Kretz <kretz@kde.org>
3
4Redistribution and use in source and binary forms, with or without
5modification, are permitted provided that the following conditions are met:
6 * Redistributions of source code must retain the above copyright
7 notice, this list of conditions and the following disclaimer.
8 * Redistributions in binary form must reproduce the above copyright
9 notice, this list of conditions and the following disclaimer in the
10 documentation and/or other materials provided with the distribution.
11 * Neither the names of contributing organizations nor the
12 names of its contributors may be used to endorse or promote products
13 derived from this software without specific prior written permission.
14
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
19DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
26}}}*/
27
28#ifndef VC_COMMON_MACROS_H_
29#define VC_COMMON_MACROS_H_
30
31#include "../global.h"
32
33
34#ifdef Vc_MSVC
35#define Vc_ALIGNED_TYPEDEF(n_, type_, new_type_) \
36 typedef __declspec(align(n_)) type_ new_type_
37#elif __GNUC__
38#define Vc_ALIGNED_TYPEDEF(n_, type_, new_type_) \
39 typedef type_ new_type_[[gnu::aligned(n_)]]
40#else // the following is actually ill-formed according to C++1[14]
41#define Vc_ALIGNED_TYPEDEF(n_, type_, new_type_) \
42 using new_type_ alignas(sizeof(n_)) = type_
43#endif
44
45// On Windows (WIN32) we might see macros called min and max. Just undefine them and hope
46// noone (re)defines them (NOMINMAX should help).
47#ifdef WIN32
48#define NOMINMAX 1
49#if defined min
50#undef min
51#endif
52#if defined max
53#undef max
54#endif
55#endif // WIN32
56
57#if defined Vc_GCC && Vc_GCC >= 0x60000
58// GCC 6 drops all attributes on types passed as template arguments. This is important
59// if a may_alias gets lost and therefore needs to be readded in the implementation of
60// the class template.
61#define Vc_TEMPLATES_DROP_ATTRIBUTES 1
62#endif
63
64#if defined Vc_CLANG || defined Vc_APPLECLANG
65# define Vc_UNREACHABLE __builtin_unreachable
66# define Vc_NEVER_INLINE [[gnu::noinline]]
67# define Vc_INTRINSIC_L inline
68# define Vc_INTRINSIC_R __attribute__((always_inline))
69# define Vc_INTRINSIC Vc_INTRINSIC_L Vc_INTRINSIC_R
70# define Vc_FLATTEN
71# define Vc_CONST __attribute__((const))
72# define Vc_CONST_L
73# define Vc_CONST_R Vc_CONST
74# define Vc_PURE __attribute__((pure))
75# define Vc_PURE_L
76# define Vc_PURE_R Vc_PURE
77# define Vc_MAY_ALIAS __attribute__((may_alias))
78# define Vc_ALWAYS_INLINE_L inline
79# define Vc_ALWAYS_INLINE_R __attribute__((always_inline))
80# define Vc_ALWAYS_INLINE Vc_ALWAYS_INLINE_L Vc_ALWAYS_INLINE_R
81# define Vc_IS_UNLIKELY(x) __builtin_expect(x, 0)
82# define Vc_IS_LIKELY(x) __builtin_expect(x, 1)
83# define Vc_RESTRICT __restrict__
84# define Vc_DEPRECATED(msg)
85# define Vc_DEPRECATED_ALIAS(msg)
86# define Vc_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
87#elif defined(__GNUC__)
88# define Vc_UNREACHABLE __builtin_unreachable
89# if defined Vc_GCC && !defined __OPTIMIZE__
90# define Vc_MAY_ALIAS
91# else
92# define Vc_MAY_ALIAS __attribute__((__may_alias__))
93# endif
94# define Vc_INTRINSIC_R __attribute__((__always_inline__, __artificial__))
95# define Vc_INTRINSIC_L inline
96# define Vc_INTRINSIC Vc_INTRINSIC_L Vc_INTRINSIC_R
97# define Vc_FLATTEN __attribute__((__flatten__))
98# define Vc_ALWAYS_INLINE_L inline
99# define Vc_ALWAYS_INLINE_R __attribute__((__always_inline__))
100# define Vc_ALWAYS_INLINE Vc_ALWAYS_INLINE_L Vc_ALWAYS_INLINE_R
101# ifdef Vc_ICC
102// ICC miscompiles if there are functions marked as pure or const
103# define Vc_PURE
104# define Vc_CONST
105# define Vc_NEVER_INLINE
106# else
107# define Vc_NEVER_INLINE [[gnu::noinline]]
108# define Vc_PURE __attribute__((__pure__))
109# define Vc_CONST __attribute__((__const__))
110# endif
111# define Vc_CONST_L
112# define Vc_CONST_R Vc_CONST
113# define Vc_PURE_L
114# define Vc_PURE_R Vc_PURE
115# define Vc_IS_UNLIKELY(x) __builtin_expect(x, 0)
116# define Vc_IS_LIKELY(x) __builtin_expect(x, 1)
117# define Vc_RESTRICT __restrict__
118# ifdef Vc_ICC
119# define Vc_DEPRECATED(msg)
120# define Vc_DEPRECATED_ALIAS(msg)
121# else
122# define Vc_DEPRECATED(msg) __attribute__((__deprecated__(msg)))
123# define Vc_DEPRECATED_ALIAS(msg) __attribute__((__deprecated__(msg)))
124# endif
125# define Vc_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
126#else
127# define Vc_NEVER_INLINE
128# define Vc_FLATTEN
129# ifdef Vc_PURE
130# undef Vc_PURE
131# endif
132# define Vc_MAY_ALIAS
133# ifdef Vc_MSVC
134# define Vc_ALWAYS_INLINE inline __forceinline
135# define Vc_ALWAYS_INLINE_L Vc_ALWAYS_INLINE
136# define Vc_ALWAYS_INLINE_R
137# define Vc_CONST __declspec(noalias)
138# define Vc_CONST_L Vc_CONST
139# define Vc_CONST_R
140# define Vc_PURE /*Vc_CONST*/
141# define Vc_PURE_L Vc_PURE
142# define Vc_PURE_R
143# define Vc_INTRINSIC inline __forceinline
144# define Vc_INTRINSIC_L Vc_INTRINSIC
145# define Vc_INTRINSIC_R
146namespace Vc_VERSIONED_NAMESPACE {
147namespace detail
148{
149static Vc_INTRINSIC void unreachable() { __assume(0); }
150} // namespace detail
151}
152# define Vc_UNREACHABLE Vc::detail::unreachable
153# else
154# define Vc_ALWAYS_INLINE
155# define Vc_ALWAYS_INLINE_L
156# define Vc_ALWAYS_INLINE_R
157# define Vc_CONST
158# define Vc_CONST_L
159# define Vc_CONST_R
160# define Vc_PURE
161# define Vc_PURE_L
162# define Vc_PURE_R
163# define Vc_INTRINSIC
164# define Vc_INTRINSIC_L
165# define Vc_INTRINSIC_R
166# define Vc_UNREACHABLE std::abort
167# endif
168# define Vc_IS_UNLIKELY(x) x
169# define Vc_IS_LIKELY(x) x
170# define Vc_RESTRICT __restrict
171# define Vc_DEPRECATED(msg) __declspec(deprecated(msg))
172# define Vc_DEPRECATED_ALIAS(msg)
173# define Vc_WARN_UNUSED_RESULT
174#endif
175
176#ifdef Vc_CXX14
177#undef Vc_DEPRECATED
178#define Vc_DEPRECATED(msg_) [[deprecated(msg_)]]
179#endif
180
181#define Vc_NOTHING_EXPECTING_SEMICOLON static_assert(true, "")
182
183#define Vc_FREE_STORE_OPERATORS_ALIGNED(align_) \
184 \
185 \
186 \
187 Vc_ALWAYS_INLINE void *operator new(size_t size) \
188 { \
189 return Vc::Common::aligned_malloc<align_>(size); \
190 } \
191 \
192 Vc_ALWAYS_INLINE void *operator new(size_t, void *p) { return p; } \
193 \
194 Vc_ALWAYS_INLINE void *operator new[](size_t size) \
195 { \
196 return Vc::Common::aligned_malloc<align_>(size); \
197 } \
198 \
199 Vc_ALWAYS_INLINE void *operator new[](size_t, void *p) { return p; } \
200 \
201 Vc_ALWAYS_INLINE void operator delete(void *ptr, size_t) { Vc::Common::free(ptr); } \
202 \
203 Vc_ALWAYS_INLINE void operator delete(void *, void *) {} \
204 \
205 Vc_ALWAYS_INLINE void operator delete[](void *ptr, size_t) \
206 { \
207 Vc::Common::free(ptr); \
208 } \
209 \
210 Vc_ALWAYS_INLINE void operator delete[](void *, void *) {} \
211 \
212 Vc_NOTHING_EXPECTING_SEMICOLON
213
214#ifdef Vc_ASSERT
215#define Vc_EXTERNAL_ASSERT 1
216#else
217#ifdef NDEBUG
218#define Vc_ASSERT(x)
219#else
220#include <assert.h>
221#define Vc_ASSERT(x) assert(x);
222#endif
223#endif
224
225#if defined Vc_CLANG || defined Vc_APPLECLANG
226#define Vc_HAS_BUILTIN(x) __has_builtin(x)
227#else
228#define Vc_HAS_BUILTIN(x) 0
229#endif
230
231#define Vc_CAT_HELPER_(a, b, c, d) a##b##c##d
232#define Vc_CAT(a, b, c, d) Vc_CAT_HELPER_(a, b, c, d)
233
234#define Vc_CAT_IMPL(a, b) a##b
235#define Vc_CAT2(a, b) Vc_CAT_IMPL(a, b)
236
237#define Vc_APPLY_IMPL_1_(macro, a, b, c, d, e) macro(a)
238#define Vc_APPLY_IMPL_2_(macro, a, b, c, d, e) macro(a, b)
239#define Vc_APPLY_IMPL_3_(macro, a, b, c, d, e) macro(a, b, c)
240#define Vc_APPLY_IMPL_4_(macro, a, b, c, d, e) macro(a, b, c, d)
241#define Vc_APPLY_IMPL_5_(macro, a, b, c, d, e) macro(a, b, c, d, e)
242
243#define Vc_LIST_FLOAT_VECTOR_TYPES(size, macro, a, b, c, d) \
244 size(macro, double_v, a, b, c, d) \
245 size(macro, float_v, a, b, c, d)
246#define Vc_LIST_INT_VECTOR_TYPES(size, macro, a, b, c, d) \
247 size(macro, int_v, a, b, c, d) \
248 size(macro, uint_v, a, b, c, d) \
249 size(macro, short_v, a, b, c, d) \
250 size(macro, ushort_v, a, b, c, d)
251#define Vc_LIST_VECTOR_TYPES(size, macro, a, b, c, d) \
252 Vc_LIST_FLOAT_VECTOR_TYPES(size, macro, a, b, c, d) \
253 Vc_LIST_INT_VECTOR_TYPES(size, macro, a, b, c, d)
254#define Vc_LIST_COMPARES(size, macro, a, b, c, d) \
255 size(macro, ==, a, b, c, d) \
256 size(macro, !=, a, b, c, d) \
257 size(macro, <=, a, b, c, d) \
258 size(macro, >=, a, b, c, d) \
259 size(macro, < , a, b, c, d) \
260 size(macro, > , a, b, c, d)
261#define Vc_LIST_LOGICAL(size, macro, a, b, c, d) \
262 size(macro, &&, a, b, c, d) \
263 size(macro, ||, a, b, c, d)
264#define Vc_LIST_BINARY(size, macro, a, b, c, d) \
265 size(macro, |, a, b, c, d) \
266 size(macro, &, a, b, c, d) \
267 size(macro, ^, a, b, c, d)
268#define Vc_LIST_SHIFTS(size, macro, a, b, c, d) \
269 size(macro, <<, a, b, c, d) \
270 size(macro, >>, a, b, c, d)
271#define Vc_LIST_ARITHMETICS(size, macro, a, b, c, d) \
272 size(macro, +, a, b, c, d) \
273 size(macro, -, a, b, c, d) \
274 size(macro, *, a, b, c, d) \
275 size(macro, /, a, b, c, d) \
276 size(macro, %, a, b, c, d)
277
278#define Vc_APPLY_0(_list, macro) _list(Vc_APPLY_IMPL_1_, macro, 0, 0, 0, 0) Vc_NOTHING_EXPECTING_SEMICOLON
279#define Vc_APPLY_1(_list, macro, a) _list(Vc_APPLY_IMPL_2_, macro, a, 0, 0, 0) Vc_NOTHING_EXPECTING_SEMICOLON
280#define Vc_APPLY_2(_list, macro, a, b) _list(Vc_APPLY_IMPL_3_, macro, a, b, 0, 0) Vc_NOTHING_EXPECTING_SEMICOLON
281#define Vc_APPLY_3(_list, macro, a, b, c) _list(Vc_APPLY_IMPL_4_, macro, a, b, c, 0) Vc_NOTHING_EXPECTING_SEMICOLON
282#define Vc_APPLY_4(_list, macro, a, b, c, d) _list(Vc_APPLY_IMPL_5_, macro, a, b, c, d) Vc_NOTHING_EXPECTING_SEMICOLON
283
284#define Vc_ALL_COMPARES(macro) Vc_APPLY_0(Vc_LIST_COMPARES, macro)
285#define Vc_ALL_LOGICAL(macro) Vc_APPLY_0(Vc_LIST_LOGICAL, macro)
286#define Vc_ALL_BINARY(macro) Vc_APPLY_0(Vc_LIST_BINARY, macro)
287#define Vc_ALL_SHIFTS(macro) Vc_APPLY_0(Vc_LIST_SHIFTS, macro)
288#define Vc_ALL_ARITHMETICS(macro) Vc_APPLY_0(Vc_LIST_ARITHMETICS, macro)
289#define Vc_ALL_FLOAT_VECTOR_TYPES(macro) Vc_APPLY_0(Vc_LIST_FLOAT_VECTOR_TYPES, macro)
290#define Vc_ALL_VECTOR_TYPES(macro) Vc_APPLY_0(Vc_LIST_VECTOR_TYPES, macro)
291
292#define Vc_EXACT_TYPE(_test, _reference, _type) \
293 typename std::enable_if<std::is_same<_test, _reference>::value, _type>::type
294
295#define Vc_make_unique(name) Vc_CAT(Vc_,name,_,__LINE__)
296
297#if defined(Vc_NO_NOEXCEPT)
298#define Vc_NOEXCEPT throw()
299#else
300#define Vc_NOEXCEPT noexcept
301#endif
302
303#ifdef Vc_NO_ALWAYS_INLINE
304#undef Vc_ALWAYS_INLINE
305#undef Vc_ALWAYS_INLINE_L
306#undef Vc_ALWAYS_INLINE_R
307#define Vc_ALWAYS_INLINE inline
308#define Vc_ALWAYS_INLINE_L inline
309#define Vc_ALWAYS_INLINE_R
310#undef Vc_INTRINSIC
311#undef Vc_INTRINSIC_L
312#undef Vc_INTRINSIC_R
313#define Vc_INTRINSIC inline
314#define Vc_INTRINSIC_L inline
315#define Vc_INTRINSIC_R
316#endif
317
318#endif // VC_COMMON_MACROS_H_