You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
libexopt/include/exopt.h

66 lines
1.6 KiB

#ifndef _EXOPT_H
#define _EXOPT_H
#define _EO__OPT_OLD_ASSUME //XXX: __attribute__((gnu::assume(X))) fails to build
#define _EXOPT_INTERNAL_PREFIX _exopt__
#ifdef __cplusplus
# define _exopt__cpp 1
# define _exopt__c 1
extern "C" {
#else
# define _exopt__cpp 0
# define _exopt__c 1
#endif
#define _EO_PASTE_(x,y) x##y
#define _EO_PASTE(x,y) _EO_PASTE_(x,y)
#define _EO(X) _EO_PASTE(_EXOPT_INTERNAL_PREFIX, X)
#define _exopt__internal __attribute__((visibility("internal")))
#define _exopt__readonly __attribute__((__pure__))
#define _exopt__pure __attribute__((__const__))
#ifdef DEBUG
# define _exopt__DEBUG 1
#else
# define _exopt__DEBUG 0
#endif
#ifdef RELEASE
# define _exopt__RELEASE 1
#else
# define _exopt__RELEASE 0
#endif
#ifdef _EO__OPT_OLD_ASSUME
# define _EO_ASSUME(X) ({ if(! (X)) __builtin_unreachable(); })
#endif
#define _EO_FIXED_INT(B) _BitInt(B)
#define _EO_GNU_ATTR(...) __attribute__((__VA_ARGS__))
#if _EO(cpp)
# define _EO_ATTR(...) [[__VA_ARGS__]]
# define _EO_SHARES_LAYOUT(T, U) (sizeof(T) == sizeof(U) && alignof(T) == alignof(U))
# ifndef _EO_ASSUME
# define _EO_ASSUME(X) [[gnu::assume(X)]]
# endif
# define _exopt__restrict __restrict__
#else /* C */
# define _EO_ATTR(...) __attribute__((__VA_ARGS__))
# define _EO_SHARES_LAYOUT(T, U) (sizeof(T) == sizeof(U) && alignof(T) == alignof(U))
# define _EO_SHARES_LAYOUT(T, U) (sizeof(T) == sizeof(U) && _Alignof(T) == _Alignof(U))
# ifndef _EO_ASSUME
# define _EO_ASSUME(X) __attribute__((assume(X)))
# endif
# define _exopt__restrict restrict
#endif
#ifdef __cplusplus
}
#endif
#endif /* _EXOPT_H */