From e594377b8ad8a71751d30dbb91bd6e5e70e69a1d Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Tue, 9 Jul 2019 12:57:12 +0100 Subject: [PATCH] Pull out the #defines from bits. --- src/ds/bits.h | 68 +---------------------------------------------- src/ds/defines.h | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 67 deletions(-) create mode 100644 src/ds/defines.h diff --git a/src/ds/bits.h b/src/ds/bits.h index e6721cd..dff0b2a 100644 --- a/src/ds/bits.h +++ b/src/ds/bits.h @@ -3,77 +3,11 @@ #include #include -#ifdef _MSC_VER -# include -# include -# define ALWAYSINLINE __forceinline -# define NOINLINE __declspec(noinline) -# define HEADER_GLOBAL __declspec(selectany) -# define likely(x) !!(x) -# define unlikely(x) !!(x) -# define SNMALLOC_SLOW_PATH NOINLINE -# define SNMALLOC_FAST_PATH ALWAYSINLINE -# define SNMALLOC_PURE -#else -# define likely(x) __builtin_expect(!!(x), 1) -# define unlikely(x) __builtin_expect(!!(x), 0) -# include -# include -# define ALWAYSINLINE __attribute__((always_inline)) -# define NOINLINE __attribute__((noinline)) -# define SNMALLOC_SLOW_PATH NOINLINE -# define SNMALLOC_FAST_PATH inline ALWAYSINLINE -# define SNMALLOC_PURE __attribute__((const)) -# ifdef __clang__ -# define HEADER_GLOBAL __attribute__((selectany)) -# else -// GCC does not support selectany, weak is almost the correct -// attribute, but leaves the global variable preemptible. -# define HEADER_GLOBAL __attribute__((weak)) -# endif -#endif - -#if defined(__i386__) || defined(_M_IX86) || defined(_X86_) || \ - defined(__amd64__) || defined(__x86_64__) || defined(_M_X64) || \ - defined(_M_AMD64) -# define PLATFORM_IS_X86 -# if defined(__linux__) && !defined(OPEN_ENCLAVE) -# include -# endif -# if defined(__amd64__) || defined(__x86_64__) || defined(_M_X64) || \ - defined(_M_AMD64) -# define PLATFORM_BITS_64 -# else -# define PLATFORM_BITS_32 -# endif -#endif - -#if defined(_MSC_VER) && defined(PLATFORM_BITS_32) -# include -#endif - -#ifndef __has_builtin -# define __has_builtin(x) 0 -#endif - -#define UNUSED(x) ((void)(x)) - -#ifndef NDEBUG -# define SNMALLOC_ASSUME(x) assert(x) -#else -# if __has_builtin(__builtin_assume) -# define SNMALLOC_ASSUME(x) __builtin_assume((x)) -# else -# define SNMALLOC_ASSUME(x) \ - do \ - { \ - } while (0) -# endif -#endif // #define USE_LZCNT #include "address.h" +#include "defines.h" #include #include diff --git a/src/ds/defines.h b/src/ds/defines.h new file mode 100644 index 0000000..ab20ad6 --- /dev/null +++ b/src/ds/defines.h @@ -0,0 +1,69 @@ +#pragma once + +#ifdef _MSC_VER +# include +# include +# define ALWAYSINLINE __forceinline +# define NOINLINE __declspec(noinline) +# define HEADER_GLOBAL __declspec(selectany) +# define likely(x) !!(x) +# define unlikely(x) !!(x) +# define SNMALLOC_SLOW_PATH NOINLINE +# define SNMALLOC_FAST_PATH ALWAYSINLINE +# define SNMALLOC_PURE +#else +# define likely(x) __builtin_expect(!!(x), 1) +# define unlikely(x) __builtin_expect(!!(x), 0) +# include +# include +# define ALWAYSINLINE __attribute__((always_inline)) +# define NOINLINE __attribute__((noinline)) +# define SNMALLOC_SLOW_PATH NOINLINE +# define SNMALLOC_FAST_PATH inline ALWAYSINLINE +# define SNMALLOC_PURE __attribute__((const)) +# ifdef __clang__ +# define HEADER_GLOBAL __attribute__((selectany)) +# else +// GCC does not support selectany, weak is almost the correct +// attribute, but leaves the global variable preemptible. +# define HEADER_GLOBAL __attribute__((weak)) +# endif +#endif + +#if defined(__i386__) || defined(_M_IX86) || defined(_X86_) || \ + defined(__amd64__) || defined(__x86_64__) || defined(_M_X64) || \ + defined(_M_AMD64) +# define PLATFORM_IS_X86 +# if defined(__linux__) && !defined(OPEN_ENCLAVE) +# include +# endif +# if defined(__amd64__) || defined(__x86_64__) || defined(_M_X64) || \ + defined(_M_AMD64) +# define PLATFORM_BITS_64 +# else +# define PLATFORM_BITS_32 +# endif +#endif + +#if defined(_MSC_VER) && defined(PLATFORM_BITS_32) +# include +#endif + +#ifndef __has_builtin +# define __has_builtin(x) 0 +#endif + +#define UNUSED(x) ((void)(x)) + +#ifndef NDEBUG +# define SNMALLOC_ASSUME(x) assert(x) +#else +# if __has_builtin(__builtin_assume) +# define SNMALLOC_ASSUME(x) __builtin_assume((x)) +# else +# define SNMALLOC_ASSUME(x) \ + do \ + { \ + } while (0) +# endif +#endif