From c147cb2a949d2a5c75804613c45e46c1a2ec8ab1 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Sat, 20 Apr 2024 01:22:04 +0200 Subject: Temporary allocator --- deimos/core/base.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'deimos/core/base.h') diff --git a/deimos/core/base.h b/deimos/core/base.h index 1e9b4a9..f24991d 100644 --- a/deimos/core/base.h +++ b/deimos/core/base.h @@ -5,6 +5,8 @@ #define deimos_StaticAssert(...) static_assert(__VA_ARGS__, #__VA_ARGS__) +#define deimos_Panic(MSG) do { __builtin_trap(); } while (0) + #define deimos_NO_COPY(TYPE) \ TYPE(const TYPE&) = delete; \ TYPE& operator=(const TYPE&) = delete; @@ -56,6 +58,21 @@ struct SourceLocation template T Min(T a, T b) { return (a < b) ? a : b; } template T Max(T a, T b) { return (a > b) ? a : b; } +[[maybe_unused]] static constexpr int64_t Kilobytes = 1024; +[[maybe_unused]] static constexpr int64_t Megabytes = 1024 * 1024; +[[maybe_unused]] static constexpr int64_t Gigabytes = 1024 * 1024 * 1024; + +constexpr int64_t AlignUp(int64_t value, int64_t align) +{ + return __builtin_align_up(value, align); +} + +template +constexpr T* OffsetBytes(T* p, int64_t offset) +{ + return std::bit_cast(std::bit_cast(p) + std::bit_cast(offset)); +} + constexpr void MemoryCopy(void* dst, const void* src, int64_t size) { __builtin_memcpy(dst, src, (size_t)size); -- cgit