Skip to content

Commit

Permalink
cc_attr.h: add assume() directive
Browse files Browse the repository at this point in the history
Signed-off-by: Steven Noonan <steven@uplinklabs.net>
  • Loading branch information
tycho committed Oct 31, 2015
1 parent 0344bb4 commit 5d3d932
Showing 1 changed file with 45 additions and 10 deletions.
55 changes: 45 additions & 10 deletions source/crisscross/cc_attr.h
Expand Up @@ -12,23 +12,15 @@
#ifndef __included_cc_cc_attr_h
#define __included_cc_cc_attr_h

#if __GNUC__ >= 3
#if defined(__GNUC__) && __GNUC__ >= 3

#ifndef __pure
#define __pure __attribute__ ((pure))
#endif

/*
GCC 3.x doesn't like to inline some of the things that
we use __forceinline on.
*/
#if __GNUC__ > 3
#ifndef __forceinline
#define __forceinline __attribute__ ((always_inline))
#endif
#else
#define __forceinline inline
#endif

#ifndef __noreturn
#define __noreturn __attribute__ ((noreturn))
Expand Down Expand Up @@ -66,21 +58,64 @@
#define unlikely(x) __builtin_expect(!!(x), 0)
#endif

#else
#define assume(x) do { if (!(x)) __builtin_unreachable(); } while (0)

#elif defined(_MSC_VER)

#define assume(x) __assume(x)

#endif

#ifndef __pure
#define __pure
#endif

#ifndef __const
#define __const
#endif

#ifndef __forceinline
#define __forceinline inline
#endif

#ifndef __noreturn
#define __noreturn
#endif

#ifndef __malloc
#define __malloc
#endif

#ifndef __must_check
#define __must_check
#endif

#ifndef __deprecated
#define __deprecated
#endif

#ifndef __used
#define __used
#endif

#ifndef __unused_param
#define __unused_param
#endif

#ifndef __packed
#define __packed
#endif

#ifndef likely
#define likely(x) (x)
#endif

#ifndef unlikely
#define unlikely(x) (x)
#endif

#ifndef assume
#define assume(x)
#endif

#endif

0 comments on commit 5d3d932

Please sign in to comment.