63 // cx_szmul() definition |
63 // cx_szmul() definition |
64 |
64 |
65 #if (__GNUC__ >= 5 || defined(__clang__)) && !defined(CX_NO_SZMUL_BUILTIN) |
65 #if (__GNUC__ >= 5 || defined(__clang__)) && !defined(CX_NO_SZMUL_BUILTIN) |
66 #define CX_SZMUL_BUILTIN |
66 #define CX_SZMUL_BUILTIN |
67 |
67 |
68 #if __WORDSIZE == 32 |
|
69 /** |
68 /** |
70 * Alias for \c __builtin_umul_overflow. |
69 * Alias for \c __builtin_mul_overflow. |
71 * |
70 * |
72 * Performs a multiplication of size_t values and checks for overflow. |
71 * Performs a multiplication of size_t values and checks for overflow. |
73 * |
72 * |
74 * @param a first operand |
73 * @param a first operand |
75 * @param b second operand |
74 * @param b second operand |
76 * @param result a pointer to a size_t, where the result should |
75 * @param result a pointer to a size_t, where the result should |
77 * be stored |
76 * be stored |
78 * @return zero, if no overflow occurred and the result is correct, non-zero |
77 * @return zero, if no overflow occurred and the result is correct, non-zero |
79 * otherwise |
78 * otherwise |
80 */ |
79 */ |
81 #define cx_szmul(a, b, result) __builtin_umul_overflow(a, b, result) |
80 #define cx_szmul(a, b, result) __builtin_mul_overflow(a, b, result) |
82 #else // __WORDSIZE != 32 |
|
83 /** |
|
84 * Alias for \c __builtin_umull_overflow. |
|
85 * |
|
86 * Performs a multiplication of size_t values and checks for overflow. |
|
87 * |
|
88 * @param a first operand |
|
89 * @param b second operand |
|
90 * @param result a pointer to a size_t, where the result should |
|
91 * be stored |
|
92 * @return zero, if no overflow occurred and the result is correct, non-zero |
|
93 * otherwise |
|
94 */ |
|
95 #define cx_szmul(a, b, result) __builtin_umull_overflow(a, b, result) |
|
96 #endif // __WORDSIZE |
|
97 |
81 |
98 #else // no GNUC or clang bultin |
82 #else // no GNUC or clang bultin |
99 |
83 |
100 /** |
84 /** |
101 * Performs a multiplication of size_t values and checks for overflow. |
85 * Performs a multiplication of size_t values and checks for overflow. |