Vector Optimized Library of Kernels  2.2
Architecture-tuned implementations of math kernels
volk_common.h
Go to the documentation of this file.
1 #ifndef INCLUDED_LIBVOLK_COMMON_H
2 #define INCLUDED_LIBVOLK_COMMON_H
3 
5 // Cross-platform attribute macros
7 #if _MSC_VER
8 # define __VOLK_ATTR_ALIGNED(x) __declspec(align(x))
9 # define __VOLK_ATTR_UNUSED
10 # define __VOLK_ATTR_INLINE __forceinline
11 # define __VOLK_ATTR_DEPRECATED __declspec(deprecated)
12 # define __VOLK_ATTR_EXPORT __declspec(dllexport)
13 # define __VOLK_ATTR_IMPORT __declspec(dllimport)
14 # define __VOLK_PREFETCH(addr)
15 # define __VOLK_ASM __asm
16 # define __VOLK_VOLATILE
17 #elif defined(__clang__)
18 // AppleClang also defines __GNUC__, so do this check first. These
19 // will probably be the same as for __GNUC__, but let's keep them
20 // separate just to be safe.
21 # define __VOLK_ATTR_ALIGNED(x) __attribute__((aligned(x)))
22 # define __VOLK_ATTR_UNUSED __attribute__((unused))
23 # define __VOLK_ATTR_INLINE __attribute__((always_inline))
24 # define __VOLK_ATTR_DEPRECATED __attribute__((deprecated))
25 # define __VOLK_ASM __asm__
26 # define __VOLK_VOLATILE __volatile__
27 # define __VOLK_ATTR_EXPORT __attribute__((visibility("default")))
28 # define __VOLK_ATTR_IMPORT __attribute__((visibility("default")))
29 # define __VOLK_PREFETCH(addr) __builtin_prefetch(addr)
30 #elif defined(__GNUC__)
31 # define __VOLK_ATTR_ALIGNED(x) __attribute__((aligned(x)))
32 # define __VOLK_ATTR_UNUSED __attribute__((unused))
33 # define __VOLK_ATTR_INLINE __attribute__((always_inline))
34 # define __VOLK_ATTR_DEPRECATED __attribute__((deprecated))
35 # define __VOLK_ASM __asm__
36 # define __VOLK_VOLATILE __volatile__
37 # if __GNUC__ >= 4
38 # define __VOLK_ATTR_EXPORT __attribute__((visibility("default")))
39 # define __VOLK_ATTR_IMPORT __attribute__((visibility("default")))
40 # else
41 # define __VOLK_ATTR_EXPORT
42 # define __VOLK_ATTR_IMPORT
43 # endif
44 # define __VOLK_PREFETCH(addr) __builtin_prefetch(addr)
45 #else
46 # warning "Unknown compiler. Using default VOLK macros, which may or not work."
47 # define __VOLK_ATTR_ALIGNED(x)
48 # define __VOLK_ATTR_UNUSED
49 # define __VOLK_ATTR_INLINE
50 # define __VOLK_ATTR_DEPRECATED
51 # define __VOLK_ATTR_EXPORT
52 # define __VOLK_ATTR_IMPORT
53 # define __VOLK_PREFETCH(addr)
54 # define __VOLK_ASM __asm__
55 # define __VOLK_VOLATILE __volatile__
56 #endif
57 
59 // Ignore annoying warnings in MSVC
61 #if defined(_MSC_VER)
62 # pragma warning(disable: 4244) //'conversion' conversion from 'type1' to 'type2', possible loss of data
63 # pragma warning(disable: 4305) //'identifier' : truncation from 'type1' to 'type2'
64 #endif
65 
67 // C-linkage declaration macros
68 // FIXME: due to the usage of complex.h, require gcc for c-linkage
70 #if defined(__cplusplus) && (defined(__GNUC__) || defined(__clang__))
71 # define __VOLK_DECL_BEGIN extern "C" {
72 # define __VOLK_DECL_END }
73 #else
74 # define __VOLK_DECL_BEGIN
75 # define __VOLK_DECL_END
76 #endif
77 
79 // Define VOLK_API for library symbols
80 // http://gcc.gnu.org/wiki/Visibility
82 #ifdef volk_EXPORTS
83 # define VOLK_API __VOLK_ATTR_EXPORT
84 #else
85 # define VOLK_API __VOLK_ATTR_IMPORT
86 #endif
87 
89 // The bit128 union used by some
91 #include <stdint.h>
92 
93 #ifdef LV_HAVE_SSE
94 #ifdef _WIN32
95 #include <intrin.h>
96 #else
97 #include <x86intrin.h>
98 #endif
99 #endif
100 
101 union bit128{
102  uint8_t i8[16];
103  uint16_t i16[8];
104  uint32_t i[4];
105  float f[4];
106  double d[2];
107 
108  #ifdef LV_HAVE_SSE
109  __m128 float_vec;
110  #endif
111 
112  #ifdef LV_HAVE_SSE2
113  __m128i int_vec;
114  __m128d double_vec;
115  #endif
116 };
117 
118 union bit256{
119  uint8_t i8[32];
120  uint16_t i16[16];
121  uint32_t i[8];
122  float f[8];
123  double d[4];
124 
125  #ifdef LV_HAVE_AVX
126  __m256 float_vec;
127  __m256i int_vec;
128  __m256d double_vec;
129  #endif
130 };
131 
132 #define bit128_p(x) ((union bit128 *)(x))
133 #define bit256_p(x) ((union bit256 *)(x))
134 
135 #endif /*INCLUDED_LIBVOLK_COMMON_H*/
bit256::int_vec
__m256i int_vec
Definition: volk_common.h:127
bit256::i16
uint16_t i16[16]
Definition: volk_common.h:120
bit128::i8
uint8_t i8[16]
Definition: volk_common.h:102
bit256
Definition: volk_common.h:118
bit256::f
float f[8]
Definition: volk_common.h:122
bit256::i
uint32_t i[8]
Definition: volk_common.h:121
bit128::int_vec
__m128i int_vec
Definition: volk_common.h:113
bit256::i8
uint8_t i8[32]
Definition: volk_common.h:119
bit128::double_vec
__m128d double_vec
Definition: volk_common.h:114
bit128::d
double d[2]
Definition: volk_common.h:106
bit128::i16
uint16_t i16[8]
Definition: volk_common.h:103
bit128::i
uint32_t i[4]
Definition: volk_common.h:104
bit128::f
float f[4]
Definition: volk_common.h:105
bit256::float_vec
__m256 float_vec
Definition: volk_common.h:126
bit256::d
double d[4]
Definition: volk_common.h:123
bit128
Definition: volk_common.h:101
bit256::double_vec
__m256d double_vec
Definition: volk_common.h:128
bit128::float_vec
__m128 float_vec
Definition: volk_common.h:109