35 |
35 |
36 #ifndef UCX_H |
36 #ifndef UCX_H |
37 #define UCX_H |
37 #define UCX_H |
38 |
38 |
39 /** Major UCX version as integer constant. */ |
39 /** Major UCX version as integer constant. */ |
40 #define UCX_VERSION_MAJOR 1 |
40 #define UCX_VERSION_MAJOR 2 |
41 |
41 |
42 /** Minor UCX version as integer constant. */ |
42 /** Minor UCX version as integer constant. */ |
43 #define UCX_VERSION_MINOR 0 |
43 #define UCX_VERSION_MINOR 0 |
44 |
44 |
45 /** Version constant which ensures to increase monotonically. */ |
45 /** Version constant which ensures to increase monotonically. */ |
129 * destination, the length of one element, the element count and a pointer to |
129 * destination, the length of one element, the element count and a pointer to |
130 * the source. |
130 * the source. |
131 */ |
131 */ |
132 typedef size_t(*read_func)(void*, size_t, size_t, void*); |
132 typedef size_t(*read_func)(void*, size_t, size_t, void*); |
133 |
133 |
|
134 |
|
135 |
|
136 #if __GNUC__ >= 5 || defined(__clang__) |
|
137 #define UCX_MUL_BUILTIN |
|
138 |
|
139 #if __WORDSIZE == 32 |
|
140 /** |
|
141 * Alias for <code>__builtin_umul_overflow</code>. |
|
142 * |
|
143 * Performs a multiplication of size_t values and checks for overflow. |
|
144 * |
|
145 * @param a first operand |
|
146 * @param b second operand |
|
147 * @param result a pointer to a size_t, where the result should |
|
148 * be stored |
|
149 * @return zero, if no overflow occurred and the result is correct, non-zero |
|
150 * otherwise |
|
151 */ |
|
152 #define ucx_szmul(a, b, result) __builtin_umul_overflow(a, b, result) |
|
153 #else /* __WORDSIZE != 32 */ |
|
154 /** |
|
155 * Alias for <code>__builtin_umull_overflow</code>. |
|
156 * |
|
157 * Performs a multiplication of size_t values and checks for overflow. |
|
158 * |
|
159 * @param a first operand |
|
160 * @param b second operand |
|
161 * @param result a pointer to a size_t, where the result should |
|
162 * be stored |
|
163 * @return zero, if no overflow occurred and the result is correct, non-zero |
|
164 * otherwise |
|
165 */ |
|
166 #define ucx_szmul(a, b, result) __builtin_umull_overflow(a, b, result) |
|
167 #endif /* __WORDSIZE */ |
|
168 |
|
169 #else /* no GNUC or clang bultin */ |
|
170 |
|
171 /** |
|
172 * Performs a multiplication of size_t values and checks for overflow. |
|
173 * |
|
174 * This is a custom implementation in case there is no compiler builtin |
|
175 * available. |
|
176 * |
|
177 * @param a first operand |
|
178 * @param b second operand |
|
179 * @param result a pointer to a size_t, where the result should |
|
180 * be stored |
|
181 * @return zero, if no overflow occurred and the result is correct, non-zero |
|
182 * otherwise |
|
183 */ |
|
184 #define ucx_szmul(a, b, result) ucx_szmul_impl(a, b, result) |
|
185 |
|
186 int ucx_szmul_impl(size_t a, size_t b, size_t *result); |
|
187 |
|
188 #endif |
|
189 |
134 #ifdef __cplusplus |
190 #ifdef __cplusplus |
135 } |
191 } |
136 #endif |
192 #endif |
137 |
193 |
138 #endif /* UCX_H */ |
194 #endif /* UCX_H */ |