49 /** |
49 /** |
50 * Convenience macro for a for loop that counts from zero to n-1. |
50 * Convenience macro for a for loop that counts from zero to n-1. |
51 */ |
51 */ |
52 #define cx_for_n(varname, n) for (size_t varname = 0 ; (varname) < (n) ; (varname)++) |
52 #define cx_for_n(varname, n) for (size_t varname = 0 ; (varname) < (n) ; (varname)++) |
53 |
53 |
54 /* ---------------------- |
54 // cx_szmul() definition |
55 * cx_szmul() definition. |
|
56 * ---------------------- */ |
|
57 |
55 |
58 #if (__GNUC__ >= 5 || defined(__clang__)) && !defined(CX_NO_SZMUL_BUILTIN) |
56 #if (__GNUC__ >= 5 || defined(__clang__)) && !defined(CX_NO_SZMUL_BUILTIN) |
59 #define CX_SZMUL_BUILTIN |
57 #define CX_SZMUL_BUILTIN |
60 |
58 |
61 #if __WORDSIZE == 32 |
59 #if __WORDSIZE == 32 |
70 * be stored |
68 * be stored |
71 * @return zero, if no overflow occurred and the result is correct, non-zero |
69 * @return zero, if no overflow occurred and the result is correct, non-zero |
72 * otherwise |
70 * otherwise |
73 */ |
71 */ |
74 #define cx_szmul(a, b, result) __builtin_umul_overflow(a, b, result) |
72 #define cx_szmul(a, b, result) __builtin_umul_overflow(a, b, result) |
75 #else /* __WORDSIZE != 32 */ |
73 #else // __WORDSIZE != 32 |
76 /** |
74 /** |
77 * Alias for \c __builtin_umull_overflow. |
75 * Alias for \c __builtin_umull_overflow. |
78 * |
76 * |
79 * Performs a multiplication of size_t values and checks for overflow. |
77 * Performs a multiplication of size_t values and checks for overflow. |
80 * |
78 * |
84 * be stored |
82 * be stored |
85 * @return zero, if no overflow occurred and the result is correct, non-zero |
83 * @return zero, if no overflow occurred and the result is correct, non-zero |
86 * otherwise |
84 * otherwise |
87 */ |
85 */ |
88 #define cx_szmul(a, b, result) __builtin_umull_overflow(a, b, result) |
86 #define cx_szmul(a, b, result) __builtin_umull_overflow(a, b, result) |
89 #endif /* __WORDSIZE */ |
87 #endif // __WORDSIZE |
90 |
88 |
91 #else /* no GNUC or clang bultin */ |
89 #else // no GNUC or clang bultin |
92 |
90 |
93 /** |
91 /** |
94 * Performs a multiplication of size_t values and checks for overflow. |
92 * Performs a multiplication of size_t values and checks for overflow. |
95 * |
93 * |
96 * @param a first operand |
94 * @param a first operand |