diff options
author | daan <daanl@outlook.com> | 2019-08-10 15:23:43 -0700 |
---|---|---|
committer | daan <daanl@outlook.com> | 2019-08-10 15:23:43 -0700 |
commit | 2fee6f98d711a860830a16a13f2f18402a3cd6a3 (patch) | |
tree | ea2a3831f5df2efc1618ba9604cc3a228bfcb24c /include/mimalloc-internal.h | |
parent | 8ae2492eee3ba35a816c38f85850b414cdce414e (diff) | |
parent | 70648635c6ce3cd0f67f5f03e90ba39627e89bed (diff) |
Merge branch 'master' into dev
Diffstat (limited to 'include/mimalloc-internal.h')
-rw-r--r-- | include/mimalloc-internal.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/include/mimalloc-internal.h b/include/mimalloc-internal.h index 3b45ada..2625187 100644 --- a/include/mimalloc-internal.h +++ b/include/mimalloc-internal.h @@ -116,6 +116,9 @@ bool _mi_page_is_valid(mi_page_t* page); #define mi_likely(x) (x) #endif +#ifndef __has_builtin +#define __has_builtin(x) 0 +#endif #if defined(_MSC_VER) #define mi_decl_noinline __declspec(noinline) @@ -148,9 +151,17 @@ bool _mi_page_is_valid(mi_page_t* page); // Overflow detecting multiply #define MI_MUL_NO_OVERFLOW ((size_t)1 << (4*sizeof(size_t))) // sqrt(SIZE_MAX) static inline bool mi_mul_overflow(size_t size, size_t count, size_t* total) { +#if __has_builtin(__builtin_umul_overflow) || __GNUC__ >= 5 +#if (MI_INTPTR_SIZE == 4) + return __builtin_umul_overflow(size, count, total); +#else + return __builtin_umull_overflow(size, count, total); +#endif +#else /* __builtin_umul_overflow is unavailable */ *total = size * count; return ((size >= MI_MUL_NO_OVERFLOW || count >= MI_MUL_NO_OVERFLOW) && size > 0 && (SIZE_MAX / size) < count); +#endif } // Align a byte size to a size in _machine words_, |