adds documentation for ucx_szmul and 32 bit support

Mon, 14 May 2018 13:13:36 +0200

author
Mike Becker <universe@uap-core.de>
date
Mon, 14 May 2018 13:13:36 +0200
changeset 303
362679052788
parent 302
8628147734d6
child 304
1f9237cfeb26

adds documentation for ucx_szmul and 32 bit support

src/ucx/ucx.h file | annotate | diff | comparison | revisions
     1.1 --- a/src/ucx/ucx.h	Mon May 14 12:54:37 2018 +0200
     1.2 +++ b/src/ucx/ucx.h	Mon May 14 13:13:36 2018 +0200
     1.3 @@ -135,9 +135,54 @@
     1.4  
     1.5  #if defined(__GNUC__) || defined(__clang__)
     1.6  #define UCX_MUL_BUILTIN
     1.7 +
     1.8 +#if __WORDSIZE == 32
     1.9 +/**
    1.10 + * Alias for <code>__builtin_umul_overflow</code>.
    1.11 + * 
    1.12 + * Performs a multiplication of size_t values and checks for overflow.
    1.13 + * 
    1.14 + * @param a first operand
    1.15 + * @param b second operand
    1.16 + * @param result a pointer to a size_t, where the result should
    1.17 + * be stored
    1.18 + * @return zero, if no overflow occurred and the result is correct, non-zero
    1.19 + * otherwise
    1.20 + */
    1.21 +#define ucx_szmul(a, b, result) __builtin_umul_overflow(a, b, result)
    1.22 +#else /* __WORDSIZE != 32 */
    1.23 +/**
    1.24 + * Alias for <code>__builtin_umull_overflow</code>.
    1.25 + * 
    1.26 + * Performs a multiplication of size_t values and checks for overflow.
    1.27 + * 
    1.28 + * @param a first operand
    1.29 + * @param b second operand
    1.30 + * @param result a pointer to a size_t, where the result should
    1.31 + * be stored
    1.32 + * @return zero, if no overflow occurred and the result is correct, non-zero
    1.33 + * otherwise
    1.34 + */
    1.35  #define ucx_szmul(a, b, result) __builtin_umull_overflow(a, b, result)
    1.36 -#else
    1.37 +#endif /* __WORDSIZE */
    1.38 +
    1.39 +#else /* no GNUC or clang bultin */
    1.40 +
    1.41 +/**
    1.42 + * Performs a multiplication of size_t values and checks for overflow.
    1.43 + * 
    1.44 + * This is a custom implementation in case there is no compiler builtin
    1.45 + * available.
    1.46 + * 
    1.47 + * @param a first operand
    1.48 + * @param b second operand
    1.49 + * @param result a pointer to a size_t, where the result should
    1.50 + * be stored
    1.51 + * @return zero, if no overflow occurred and the result is correct, non-zero
    1.52 + * otherwise
    1.53 + */
    1.54  int ucx_szmul(size_t a, size_t b, size_t *result);
    1.55 +
    1.56  #endif
    1.57  
    1.58  #ifdef	__cplusplus

mercurial