summaryrefslogtreecommitdiff
path: root/source/base/base_core.h
diff options
context:
space:
mode:
authornasr <nsrddyn@gmail.com>2026-10-05 22:02:56 +0200
committernasr <nsrddyn@gmail.com>2026-10-05 22:02:56 +0200
commitf6d3090f7fa76eb8e0dbe060b8490cb49c001c39 (patch)
tree433c773997e51f22738acb8b04c4fd2fc6b1bdc9 /source/base/base_core.h
init: base
Diffstat (limited to 'source/base/base_core.h')
-rw-r--r--source/base/base_core.h141
1 files changed, 141 insertions, 0 deletions
diff --git a/source/base/base_core.h b/source/base/base_core.h
new file mode 100644
index 0000000..a4531a5
--- /dev/null
+++ b/source/base/base_core.h
@@ -0,0 +1,141 @@
1#ifndef BASE_CORE_H
2#define BASE_CORE_H
3
4//- compiler definitions
5#if defined(_MSC_VER)
6#define COMPILER_MSVC 1
7#elif defined(__clang__)
8#define COMPILER_CLANG 1
9#elif defined(__GNUC__)
10#define COMPILER_GCC 1
11#else
12#error Unsupported compiler
13#endif
14
15//- architecture definitions
16
17#if defined(__arm__) || defined(__aarch64__)
18#define ARCH_ARM 1
19#elif defined(__i386__) || defined(__x86_64__)
20#define ARCH_x86_64 1
21#endif
22
23//- compiler definitions
24
25//- core stuff
26
27/* assert an expression and output the file and the line */
28#define internal static
29#define global_variable static
30#define local_persist static
31
32#define arena_align (2 * sizeof(void *))
33
34#define Min(a, b) (((a) < (b)) ? (a) : (b))
35#define Max(a, b) (((a) > (b)) ? (a) : (b))
36
37#define Unused(x) (void)(x)
38#define Nil 0
39
40#define Deprecated __attribute__((__deprecated__))
41
42//- breakpoints
43#if ARCH_ARM
44#define breakpoint() __asm__ volatile("brk #0")
45#elif ARCH_x86_64
46
47#if COMPILER_GCC
48#define breakpoint() __asm__ volatile("int3")
49#endif
50#endif
51
52#if COMPILER_MSVC
53#include <intrin.h>
54#define breakpoint() __debugbreak()
55#endif
56
57//-
58#define MemCpy(dest, src, len) memcpy((dest), (src), (len))
59#define MemSet(dest, len) memset((dest), (1), (len))
60#define MemSetZero(dest, len) memset((dest), (0), (len))
61
62//-
63#if COMPILER_MSVC
64#pragma section("read_only", read)
65#define ReadOnly __declspec(allocate("read_only"))
66#elif COMPILER_GCC || COMPILER_CLANG
67
68#if PLATFORM_APPLE
69#define ReadOnly __attribute__((section("__TEXT,__const")))
70#else
71#define ReadOnly __attribute__((section(".const")))
72#endif // PLATFORM_APPLE
73
74#endif
75
76//-
77
78//- types
79
80typedef uint64_t u64;
81typedef uint32_t u32;
82typedef uint16_t u16;
83typedef uint8_t u8;
84
85typedef int8_t s8;
86typedef int16_t s16;
87
88typedef int32_t s32;
89typedef int64_t s64;
90
91typedef float f32;
92typedef double f64;
93
94typedef s32 b32;
95typedef s16 b16;
96typedef s8 b8;
97
98typedef uintptr_t umm;
99typedef intptr_t smm;
100
101//- disable certain msvc errors
102#if COMPILER_MSVC
103#pragma warning(disable : 6246) // disable the same name within a certain scope
104#endif
105
106//-
107
108#define Assert(expression) _assert(expression)
109
110// NOTE: apparantly in macros this strinifys whataever you put after the #
111#define AssertLog(expression, ...) do { \
112 if (!expression) { \
113 Log("%s:%d: %s\n", __FILE__, __LINE__, #expression); \
114 Log(__VA_ARGS__);\
115 Assert(false);\
116 }\
117 } \
118 while(0)
119
120internal void _assert(bool expression);
121
122
123internal void _assert(bool expression)
124{
125
126 if (!expression) {
127 breakpoint();
128#if COMPILER_MSVC
129 __fastfail(0);
130#else
131 __builtin_trap(); // NOTE: always stop, breakpoint() is empty on arm without DEBUG
132#endif
133 }
134}
135
136
137
138
139
140
141#endif // BASE_CORE_H