Skip to content

Commit 38b38eb

Browse files
committed
utils: add macro for assume
Clang and GCC allow to provide hints to the compiler, they have similar constructs but they have a different syntax (builtin VS attribute). Add portable macro for it. Signed-off-by: Davide Bettio <davide@uninstall.it>
1 parent bc73bf9 commit 38b38eb

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/libAtomVM/utils.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,26 @@ static inline __attribute__((always_inline)) func_ptr_t cast_void_to_func_ptr(vo
327327
#define UNREACHABLE(...)
328328
#endif
329329

330+
#if defined(__GNUC__) && !defined(__clang__)
331+
#if __GNUC__ >= 13
332+
#define HAVE_ASSUME 1
333+
#define ASSUME(x) __attribute__((assume((x))))
334+
#endif
335+
#endif
336+
337+
#ifndef HAVE_ASSUME
338+
#if defined __has_builtin
339+
#if __has_builtin(__builtin_assume)
340+
#define HAVE_ASSUME 1
341+
#define ASSUME(x) __builtin_assume((x))
342+
#endif
343+
#endif
344+
#endif
345+
346+
#ifndef ASSUME
347+
#define ASSUME(...)
348+
#endif
349+
330350
#ifdef __cplusplus
331351
}
332352
#endif

0 commit comments

Comments
 (0)