diff --git a/include/bal_attributes.h b/include/bal_attributes.h index 1d2be0d..61debf4 100644 --- a/include/bal_attributes.h +++ b/include/bal_attributes.h @@ -6,6 +6,8 @@ #ifndef BALLISTIC_ATTRIBUTES_H #define BALLISTIC_ATTRIBUTES_H +#include "bal_platform.h" + /*! * BAL_HOT()/BAL_COLD() * Marks a function as hot or cold. Hot makes the compiller optimize it more @@ -15,7 +17,7 @@ * BAL_HOT bal_error_t emit_instruction(...); */ -#if defined(__GNUC__) || defined(__clang__) +#if BAL_COMPILER_GCC #define BAL_HOT __attribute__((hot)) #define BAL_COLD __attribute__((cold)) @@ -34,7 +36,7 @@ * Usage: if (BAL_UNLIKELY(ptr == NULL)) { ... } */ -#if defined(__GNUC__) || defined(__clang__) +#if BAL_COMPILER_GCC #define BAL_LIKELY(x) __builtin_expect(!!(x), 1) #define BAL_UNLIKELY(x) __builtin_expect(!!(x), 0) @@ -53,11 +55,11 @@ * Usage: BAL_ALIGNED(64) struct data { ... }; */ -#if defined(__GNUC__) || defined(__clang__) +#if BAL_COMPILER_GCC #define BAL_ALIGNED(x) __attribute__((aligned(x))) -#elif defined(_MSC_VER) +#elif BAL_COMPILER_MSVC #define BAL_ALIGNED(x) __declspec(align(x)) @@ -73,11 +75,11 @@ * current scope. */ -#if defined(__GNUC__) || defined(__clang__) +#if BAL_COMPILER_GCC #define BAL_RESTRICT __restrict__ -#elif defined(_MSC_VER) +#elif BAL_COMPILER_MSVC #define BAL_RESTRICT __restrict diff --git a/include/bal_platform.h b/include/bal_platform.h new file mode 100644 index 0000000..b66a890 --- /dev/null +++ b/include/bal_platform.h @@ -0,0 +1,24 @@ +#ifndef BALLISTIC_PLATFORM_H +#define BALLISTIC_PLATFORM_H + +#if defined(_WIN32) || defined(_WIN64) + #define BAL_PLATFORM_WINDOWS 1 + #define BAL_PLATFORM_POSIX 0 +#elif defined(__linux__) || defined(__APPLE__) + #define BAL_PLATFORM_WINDOWS 0 + #define BAL_PLATFORM_POSIX 1 +#else + #error "Unknown Platform" +#endif + +#if defined(_MSC_VER) + #define BAL_COMPILER_MSVC 1 + #define BAL_COMPILER_GCC 0 +#elif defined(__GNUC__) || defined(__clang__) + #define BAL_COMPILER_MSVC 0 + #define BAL_COMPILER_GCC 1 +#else + #error "Unknown Compiler" +#endif + +#endif /* BALLISTIC_PLATFORM_H */