mirror of
https://github.com/pound-emu/ballistic.git
synced 2026-01-31 01:15:21 +01:00
engine: add platform detection header
I do not want compiler attributes like __clang__ or __linux__ scattered everywhere to detect the platform Ballistic is running on, so I added preprocessor directives to make things a lot cleaner. Signed-off-by: Ronald Caesar <github43132@proton.me>
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
24
include/bal_platform.h
Normal file
24
include/bal_platform.h
Normal file
@@ -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 */
|
||||
Reference in New Issue
Block a user