Vector Optimized Library of Kernels  3.0.0
Architecture-tuned implementations of math kernels
volk_common.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2010, 2011, 2015-2017, 2019, 2020 Free Software Foundation, Inc.
4  *
5  * This file is part of VOLK
6  *
7  * SPDX-License-Identifier: LGPL-3.0-or-later
8  */
9 
10 #ifndef INCLUDED_LIBVOLK_COMMON_H
11 #define INCLUDED_LIBVOLK_COMMON_H
12 
14 // Cross-platform attribute macros
16 #if _MSC_VER
17 #define __VOLK_ATTR_ALIGNED(x) __declspec(align(x))
18 #define __VOLK_ATTR_UNUSED
19 #define __VOLK_ATTR_INLINE __forceinline
20 #define __VOLK_ATTR_DEPRECATED __declspec(deprecated)
21 #define __VOLK_ATTR_EXPORT __declspec(dllexport)
22 #define __VOLK_ATTR_IMPORT __declspec(dllimport)
23 #define __VOLK_PREFETCH(addr)
24 #define __VOLK_ASM __asm
25 #define __VOLK_VOLATILE
26 #elif defined(__clang__)
27 // AppleClang also defines __GNUC__, so do this check first. These
28 // will probably be the same as for __GNUC__, but let's keep them
29 // separate just to be safe.
30 #define __VOLK_ATTR_ALIGNED(x) __attribute__((aligned(x)))
31 #define __VOLK_ATTR_UNUSED __attribute__((unused))
32 #define __VOLK_ATTR_INLINE __attribute__((always_inline))
33 #define __VOLK_ATTR_DEPRECATED __attribute__((deprecated))
34 #define __VOLK_ASM __asm__
35 #define __VOLK_VOLATILE __volatile__
36 #define __VOLK_ATTR_EXPORT __attribute__((visibility("default")))
37 #define __VOLK_ATTR_IMPORT __attribute__((visibility("default")))
38 #define __VOLK_PREFETCH(addr) __builtin_prefetch(addr)
39 #elif defined __GNUC__
40 #define __VOLK_ATTR_ALIGNED(x) __attribute__((aligned(x)))
41 #define __VOLK_ATTR_UNUSED __attribute__((unused))
42 #define __VOLK_ATTR_INLINE __attribute__((always_inline))
43 #define __VOLK_ATTR_DEPRECATED __attribute__((deprecated))
44 #define __VOLK_ASM __asm__
45 #define __VOLK_VOLATILE __volatile__
46 #if __GNUC__ >= 4
47 #define __VOLK_ATTR_EXPORT __attribute__((visibility("default")))
48 #define __VOLK_ATTR_IMPORT __attribute__((visibility("default")))
49 #else
50 #define __VOLK_ATTR_EXPORT
51 #define __VOLK_ATTR_IMPORT
52 #endif
53 #define __VOLK_PREFETCH(addr) __builtin_prefetch(addr)
54 #elif _MSC_VER
55 #define __VOLK_ATTR_ALIGNED(x) __declspec(align(x))
56 #define __VOLK_ATTR_UNUSED
57 #define __VOLK_ATTR_INLINE __forceinline
58 #define __VOLK_ATTR_DEPRECATED __declspec(deprecated)
59 #define __VOLK_ATTR_EXPORT __declspec(dllexport)
60 #define __VOLK_ATTR_IMPORT __declspec(dllimport)
61 #define __VOLK_PREFETCH(addr)
62 #define __VOLK_ASM __asm
63 #define __VOLK_VOLATILE
64 #else
65 #define __VOLK_ATTR_ALIGNED(x)
66 #define __VOLK_ATTR_UNUSED
67 #define __VOLK_ATTR_INLINE
68 #define __VOLK_ATTR_DEPRECATED
69 #define __VOLK_ATTR_EXPORT
70 #define __VOLK_ATTR_IMPORT
71 #define __VOLK_PREFETCH(addr)
72 #define __VOLK_ASM __asm__
73 #define __VOLK_VOLATILE __volatile__
74 #endif
75 
77 // Ignore annoying warnings in MSVC
79 #if defined(_MSC_VER)
80 #pragma warning(disable : 4244) //'conversion' conversion from 'type1' to 'type2',
81  // possible loss of data
82 #pragma warning(disable : 4305) //'identifier' : truncation from 'type1' to 'type2'
83 #endif
84 
86 // C-linkage declaration macros
87 // FIXME: due to the usage of complex.h, require gcc for c-linkage
89 #if defined(__cplusplus) && (__GNUC__)
90 #define __VOLK_DECL_BEGIN extern "C" {
91 #define __VOLK_DECL_END }
92 #else
93 #define __VOLK_DECL_BEGIN
94 #define __VOLK_DECL_END
95 #endif
96 
98 // Define VOLK_API for library symbols
99 // http://gcc.gnu.org/wiki/Visibility
101 #ifdef volk_EXPORTS
102 #define VOLK_API __VOLK_ATTR_EXPORT
103 #else
104 #define VOLK_API __VOLK_ATTR_IMPORT
105 #endif
106 
108 // The bit128 union used by some
110 #include <stdint.h>
111 
112 #ifdef LV_HAVE_SSE
113 #ifdef _WIN32
114 #include <intrin.h>
115 #else
116 #include <x86intrin.h>
117 #endif
118 #endif
119 
120 union bit128 {
121  uint8_t i8[16];
122  uint16_t i16[8];
123  uint32_t i[4];
124  float f[4];
125  double d[2];
126 
127 #ifdef LV_HAVE_SSE
129 #endif
130 
131 #ifdef LV_HAVE_SSE2
134 #endif
135 };
136 
137 union bit256 {
138  uint8_t i8[32];
139  uint16_t i16[16];
140  uint32_t i[8];
141  float f[8];
142  double d[4];
143 
144 #ifdef LV_HAVE_AVX
145  __m256 float_vec;
146  __m256i int_vec;
147  __m256d double_vec;
148 #endif
149 };
150 
151 #define bit128_p(x) ((union bit128*)(x))
152 #define bit256_p(x) ((union bit256*)(x))
153 
155 // log2f
157 #include <math.h>
158 // +-Inf -> +-127.0f in order to match the behaviour of the SIMD kernels
159 static inline float log2f_non_ieee(float f)
160 {
161  float const result = log2f(f);
162  return isinf(result) ? copysignf(127.0f, result) : result;
163 }
164 
166 // Constant used to do log10 calculations as faster log2
168 // precalculated 10.0 / log2f_non_ieee(10.0) to allow for constexpr
169 #define volk_log2to10factor 3.01029995663981209120
170 
171 #endif /*INCLUDED_LIBVOLK_COMMON_H*/
float32x4_t __m128
Definition: sse2neon.h:235
float32x4_t __m128d
Definition: sse2neon.h:242
int64x2_t __m128i
Definition: sse2neon.h:244
Definition: volk_common.h:120
float f[4]
Definition: volk_common.h:124
__m128i int_vec
Definition: volk_common.h:132
__m128d double_vec
Definition: volk_common.h:133
uint8_t i8[16]
Definition: volk_common.h:121
uint32_t i[4]
Definition: volk_common.h:123
double d[2]
Definition: volk_common.h:125
uint16_t i16[8]
Definition: volk_common.h:122
__m128 float_vec
Definition: volk_common.h:128
Definition: volk_common.h:137
float f[8]
Definition: volk_common.h:141
__m256d double_vec
Definition: volk_common.h:147
uint8_t i8[32]
Definition: volk_common.h:138
uint16_t i16[16]
Definition: volk_common.h:139
double d[4]
Definition: volk_common.h:142
uint32_t i[8]
Definition: volk_common.h:140
__m256 float_vec
Definition: volk_common.h:145
__m256i int_vec
Definition: volk_common.h:146
static float log2f_non_ieee(float f)
Definition: volk_common.h:159