29 lines
612 B
C
29 lines
612 B
C
#ifndef APFL_INTRINSICS_H
|
|
#define APFL_INTRINSICS_H
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include <stdint.h>
|
|
|
|
#if defined(__GNUC__) && !defined(APFL_NO_INTRINSICS)
|
|
#define APFL_USE_INTRINSICS
|
|
#endif
|
|
|
|
#ifdef APFL_USE_INTRINSICS
|
|
# define MULTIPLY_CHECK_OVERFLOW_SIZE(res, a, b) __builtin_mul_overflow((a), (b), &(res))
|
|
#else
|
|
# define MULTIPLY_CHECK_OVERFLOW_SIZE(res, a, b) \
|
|
( \
|
|
(b) != 0 && (a) > SIZE_MAX / (b) \
|
|
? true \
|
|
: ((res = (a) * (b)), false) \
|
|
)
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|