133 |
133 |
134 |
134 |
135 |
135 |
136 #if defined(__GNUC__) || defined(__clang__) |
136 #if defined(__GNUC__) || defined(__clang__) |
137 #define UCX_MUL_BUILTIN |
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 */ |
138 #define ucx_szmul(a, b, result) __builtin_umull_overflow(a, b, result) |
166 #define ucx_szmul(a, b, result) __builtin_umull_overflow(a, b, result) |
139 #else |
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 */ |
140 int ucx_szmul(size_t a, size_t b, size_t *result); |
184 int ucx_szmul(size_t a, size_t b, size_t *result); |
|
185 |
141 #endif |
186 #endif |
142 |
187 |
143 #ifdef __cplusplus |
188 #ifdef __cplusplus |
144 } |
189 } |
145 #endif |
190 #endif |