Mon, 14 May 2018 13:13:36 +0200
adds documentation for ucx_szmul and 32 bit support
src/ucx/ucx.h | file | annotate | diff | comparison | revisions |
--- a/src/ucx/ucx.h Mon May 14 12:54:37 2018 +0200 +++ b/src/ucx/ucx.h Mon May 14 13:13:36 2018 +0200 @@ -135,9 +135,54 @@ #if defined(__GNUC__) || defined(__clang__) #define UCX_MUL_BUILTIN + +#if __WORDSIZE == 32 +/** + * Alias for <code>__builtin_umul_overflow</code>. + * + * Performs a multiplication of size_t values and checks for overflow. + * + * @param a first operand + * @param b second operand + * @param result a pointer to a size_t, where the result should + * be stored + * @return zero, if no overflow occurred and the result is correct, non-zero + * otherwise + */ +#define ucx_szmul(a, b, result) __builtin_umul_overflow(a, b, result) +#else /* __WORDSIZE != 32 */ +/** + * Alias for <code>__builtin_umull_overflow</code>. + * + * Performs a multiplication of size_t values and checks for overflow. + * + * @param a first operand + * @param b second operand + * @param result a pointer to a size_t, where the result should + * be stored + * @return zero, if no overflow occurred and the result is correct, non-zero + * otherwise + */ #define ucx_szmul(a, b, result) __builtin_umull_overflow(a, b, result) -#else +#endif /* __WORDSIZE */ + +#else /* no GNUC or clang bultin */ + +/** + * Performs a multiplication of size_t values and checks for overflow. + * + * This is a custom implementation in case there is no compiler builtin + * available. + * + * @param a first operand + * @param b second operand + * @param result a pointer to a size_t, where the result should + * be stored + * @return zero, if no overflow occurred and the result is correct, non-zero + * otherwise + */ int ucx_szmul(size_t a, size_t b, size_t *result); + #endif #ifdef __cplusplus