diff --git a/src/common/misc/misc_utils.h b/src/common/misc/misc_utils.h index 690e41d..482699f 100644 --- a/src/common/misc/misc_utils.h +++ b/src/common/misc/misc_utils.h @@ -9,10 +9,19 @@ BEGIN_C_LINKAGE #endif // !WAPP_PLATFORM_CPP -#define KB(SIZE) (SIZE * 1024ull) -#define MB(SIZE) (KB(SIZE) * 1024) -#define GB(SIZE) (MB(SIZE) * 1024) -#define TB(SIZE) (GB(SIZE) * 1024) +#define KiB(SIZE) (((u64)SIZE) << 10) +#define MiB(SIZE) (((u64)SIZE) << 20) +#define GiB(SIZE) (((u64)SIZE) << 30) +#define TiB(SIZE) (((u64)SIZE) << 40) +#define PiB(SIZE) (((u64)SIZE) << 50) +#define EiB(SIZE) (((u64)SIZE) << 60) + +#define KB(SIZE) (((u64)SIZE) * 1000llu) +#define MB(SIZE) (KB(SIZE) * 1000llu) +#define GB(SIZE) (MB(SIZE) * 1000llu) +#define TB(SIZE) (GB(SIZE) * 1000llu) +#define PB(SIZE) (TB(SIZE) * 1000llu) +#define EB(SIZE) (PB(SIZE) * 1000llu) #define wapp_misc_utils_padding_size(SIZE) u8 reserved_padding[sizeof(void *) - ((SIZE) % sizeof(void *))] diff --git a/src/os/allocators/arena/mem_arena.c b/src/os/allocators/arena/mem_arena.c index df5cf92..221dee9 100644 --- a/src/os/allocators/arena/mem_arena.c +++ b/src/os/allocators/arena/mem_arena.c @@ -15,7 +15,7 @@ #define DEFAULT_ALIGNMENT (2 * sizeof(void *)) #endif /* ifndef DEFAULT_ALIGNMENT */ -#define ARENA_MINIMUM_CAPACITY KB(16) // Allocate minimum of 4 pages +#define ARENA_MINIMUM_CAPACITY KiB(16) // Allocate minimum of 4 pages struct arena { u8 *buf; diff --git a/src/os/cpath/cpath.c b/src/os/cpath/cpath.c index 0ff737b..7b11362 100644 --- a/src/os/cpath/cpath.c +++ b/src/os/cpath/cpath.c @@ -87,7 +87,7 @@ Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels) { goto RETURN_DIRUP; } - Allocator tmp_arena = wapp_mem_arena_allocator_init(MB(8)); + Allocator tmp_arena = wapp_mem_arena_allocator_init(MiB(8)); if (wapp_mem_allocator_invalid(&tmp_arena)) { goto RETURN_DIRUP; } diff --git a/src/os/shell/commander/commander.c b/src/os/shell/commander/commander.c index 22a0809..f7f2042 100644 --- a/src/os/shell/commander/commander.c +++ b/src/os/shell/commander/commander.c @@ -25,7 +25,7 @@ CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, Str8 *out_bu return CMD_NO_EXIT(SHELL_ERR_INVALID_ARGS); } - Allocator arena = wapp_mem_arena_allocator_init(KB(500)); + Allocator arena = wapp_mem_arena_allocator_init(KiB(500)); Str8 *cmd_str = wapp_str8_join(&arena, cmd, &wapp_str8_lit_ro(" ")); if (!cmd_str) { diff --git a/tests/arena/test_arena.c b/tests/arena/test_arena.c index c603281..9fea642 100644 --- a/tests/arena/test_arena.c +++ b/tests/arena/test_arena.c @@ -2,7 +2,7 @@ #include "wapp.h" #include -#define ARENA_CAPACITY KB(16) +#define ARENA_CAPACITY KiB(16) wapp_intern Arena *arena = NULL; wapp_intern i32 count = 20; @@ -16,7 +16,7 @@ TestFuncResult test_arena_init(void) { TestFuncResult test_arena_init_succeeds_when_reserving_very_large_size(void) { Arena *large_arena = NULL; - u64 capacity = GB(512); + u64 capacity = GiB(512); b8 result = wapp_mem_arena_init(&large_arena, capacity); if (result) { wapp_mem_arena_destroy(&large_arena); diff --git a/tests/arena/test_arena.cc b/tests/arena/test_arena.cc index 0a7abad..a3e0a2e 100644 --- a/tests/arena/test_arena.cc +++ b/tests/arena/test_arena.cc @@ -2,7 +2,7 @@ #include "wapp.h" #include -#define ARENA_CAPACITY KB(16) +#define ARENA_CAPACITY KiB(16) wapp_intern Arena *arena = nullptr; wapp_intern i32 count = 20; @@ -16,7 +16,7 @@ TestFuncResult test_arena_init(void) { TestFuncResult test_arena_init_succeeds_when_reserving_very_large_size(void) { Arena *large_arena = nullptr; - u64 capacity = GB(512); + u64 capacity = GiB(512); b8 result = wapp_mem_arena_init(&large_arena, capacity); if (result) { wapp_mem_arena_destroy(&large_arena); diff --git a/tests/array/test_i32_array.c b/tests/array/test_i32_array.c index 37d1876..6326c44 100644 --- a/tests/array/test_i32_array.c +++ b/tests/array/test_i32_array.c @@ -145,7 +145,7 @@ TestFuncResult test_i32_array_copy_capped(void) { TestFuncResult test_i32_array_alloc_capacity(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(MB(4)); + Allocator allocator = wapp_mem_arena_allocator_init(MiB(4)); u64 capacity = 32; I32Array *array = wapp_array_alloc_capacity(i32, I32Array, &allocator, capacity); @@ -159,7 +159,7 @@ TestFuncResult test_i32_array_alloc_capacity(void) { TestFuncResult test_i32_array_append_alloc(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(MB(4)); + Allocator allocator = wapp_mem_arena_allocator_init(MiB(4)); I32Array array1 = wapp_array(i32, I32Array, 1, 2, 3, 4, 5, 6, 7, 8); I32Array array2 = wapp_array(i32, I32Array, 1, 2); @@ -186,7 +186,7 @@ TestFuncResult test_i32_array_append_alloc(void) { TestFuncResult test_i32_array_extend_alloc(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(MB(4)); + Allocator allocator = wapp_mem_arena_allocator_init(MiB(4)); I32Array array1 = wapp_array(i32, I32Array, 1, 2, 3, 4, 5, 6, 7, 8); I32Array array2 = wapp_array(i32, I32Array, 1, 2); I32Array array3 = wapp_array(i32, I32Array, 1, 2, 3, 4); @@ -205,7 +205,7 @@ TestFuncResult test_i32_array_extend_alloc(void) { TestFuncResult test_i32_array_copy_alloc(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(MB(4)); + Allocator allocator = wapp_mem_arena_allocator_init(MiB(4)); I32Array src = wapp_array(i32, I32Array, 1, 2, 3, 4, 5); I32Array dst1 = wapp_array(i32, I32Array, 1, 2, 3, 4, 5, 6); I32Array dst2 = wapp_array(i32, I32Array, 1, 2); diff --git a/tests/array/test_i32_array.cc b/tests/array/test_i32_array.cc index b3f2944..e653e58 100644 --- a/tests/array/test_i32_array.cc +++ b/tests/array/test_i32_array.cc @@ -147,7 +147,7 @@ TestFuncResult test_i32_array_copy_capped(void) { TestFuncResult test_i32_array_alloc_capacity(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(MB(4)); + Allocator allocator = wapp_mem_arena_allocator_init(MiB(4)); u64 capacity = 32; I32Array *array = wapp_array_alloc_capacity(i32, I32Array, &allocator, capacity); @@ -161,7 +161,7 @@ TestFuncResult test_i32_array_alloc_capacity(void) { TestFuncResult test_i32_array_append_alloc(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(MB(4)); + Allocator allocator = wapp_mem_arena_allocator_init(MiB(4)); I32Array array1 = wapp_array(i32, I32Array, 1, 2, 3, 4, 5, 6, 7, 8); I32Array array2 = wapp_array(i32, I32Array, 1, 2); @@ -189,7 +189,7 @@ TestFuncResult test_i32_array_append_alloc(void) { TestFuncResult test_i32_array_extend_alloc(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(MB(4)); + Allocator allocator = wapp_mem_arena_allocator_init(MiB(4)); I32Array array1 = wapp_array(i32, I32Array, 1, 2, 3, 4, 5, 6, 7, 8); I32Array array2 = wapp_array(i32, I32Array, 1, 2); I32Array array3 = wapp_array(i32, I32Array, 1, 2, 3, 4); @@ -208,7 +208,7 @@ TestFuncResult test_i32_array_extend_alloc(void) { TestFuncResult test_i32_array_copy_alloc(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(MB(4)); + Allocator allocator = wapp_mem_arena_allocator_init(MiB(4)); I32Array src = wapp_array(i32, I32Array, 1, 2, 3, 4, 5); I32Array dst1 = wapp_array(i32, I32Array, 1, 2, 3, 4, 5, 6); I32Array dst2 = wapp_array(i32, I32Array, 1, 2); diff --git a/tests/cpath/test_cpath.c b/tests/cpath/test_cpath.c index 916d669..b5e6e19 100644 --- a/tests/cpath/test_cpath.c +++ b/tests/cpath/test_cpath.c @@ -81,7 +81,7 @@ TestFuncResult test_cpath_join_path(void) { } TestFuncResult test_cpath_dirname(void) { - Allocator arena = wapp_mem_arena_allocator_init(MB(8)); + Allocator arena = wapp_mem_arena_allocator_init(MiB(8)); if (wapp_mem_allocator_invalid(&arena)) { return wapp_tester_result(false); } @@ -129,7 +129,7 @@ TestFuncResult test_cpath_dirname(void) { } TestFuncResult test_cpath_dirup(void) { - Allocator arena = wapp_mem_arena_allocator_init(MB(8)); + Allocator arena = wapp_mem_arena_allocator_init(MiB(8)); if (wapp_mem_allocator_invalid(&arena)) { return wapp_tester_result(false); } diff --git a/tests/cpath/test_cpath.cc b/tests/cpath/test_cpath.cc index 635332a..429c21b 100644 --- a/tests/cpath/test_cpath.cc +++ b/tests/cpath/test_cpath.cc @@ -102,7 +102,7 @@ TestFuncResult test_cpath_join_path(void) { } TestFuncResult test_cpath_dirname(void) { - Allocator arena = wapp_mem_arena_allocator_init(MB(8)); + Allocator arena = wapp_mem_arena_allocator_init(MiB(8)); if (wapp_mem_allocator_invalid(&arena)) { return wapp_tester_result(false); } @@ -152,7 +152,7 @@ TestFuncResult test_cpath_dirname(void) { } TestFuncResult test_cpath_dirup(void) { - Allocator arena = wapp_mem_arena_allocator_init(MB(8)); + Allocator arena = wapp_mem_arena_allocator_init(MiB(8)); if (wapp_mem_allocator_invalid(&arena)) { return wapp_tester_result(false); } diff --git a/tests/str8/test_str8.c b/tests/str8/test_str8.c index 62e5032..9965531 100644 --- a/tests/str8/test_str8.c +++ b/tests/str8/test_str8.c @@ -77,7 +77,7 @@ TestFuncResult test_str8_buf(void) { TestFuncResult test_str8_alloc_buf(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(KB(100)); + Allocator allocator = wapp_mem_arena_allocator_init(KiB(100)); if (wapp_mem_allocator_invalid(&allocator)) { return wapp_tester_result(false); } @@ -105,7 +105,7 @@ TEST_ALLOC_BUF_CLEANUP: TestFuncResult test_str8_alloc_cstr(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(KB(100)); + Allocator allocator = wapp_mem_arena_allocator_init(KiB(100)); if (wapp_mem_allocator_invalid(&allocator)) { return wapp_tester_result(false); } @@ -126,7 +126,7 @@ TestFuncResult test_str8_alloc_cstr(void) { TestFuncResult test_str8_alloc_str8(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(KB(100)); + Allocator allocator = wapp_mem_arena_allocator_init(KiB(100)); if (wapp_mem_allocator_invalid(&allocator)) { return wapp_tester_result(false); } @@ -146,7 +146,7 @@ TestFuncResult test_str8_alloc_str8(void) { TestFuncResult test_str8_alloc_substr(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(KB(100)); + Allocator allocator = wapp_mem_arena_allocator_init(KiB(100)); if (wapp_mem_allocator_invalid(&allocator)) { return wapp_tester_result(false); } @@ -289,7 +289,7 @@ TestFuncResult test_str8_slice(void) { TestFuncResult test_str8_alloc_concat(void) { b8 result; - Allocator arena = wapp_mem_arena_allocator_init(KB(100)); + Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); Str8 str = wapp_str8_lit("Hello world"); Str8 suffix1 = wapp_str8_lit(" from me."); @@ -410,7 +410,7 @@ TestFuncResult test_str8_rfind(void) { TestFuncResult test_str8_split(void) { b8 result; - Allocator arena = wapp_mem_arena_allocator_init(KB(100)); + Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); Str8 str = wapp_str8_lit("hello world from me"); Str8 delim1 = wapp_str8_lit(" "); @@ -467,7 +467,7 @@ TestFuncResult test_str8_split(void) { TestFuncResult test_str8_split_with_max(void) { b8 result; - Allocator arena = wapp_mem_arena_allocator_init(KB(100)); + Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); Str8 str = wapp_str8_lit("hello world from me"); Str8 delim = wapp_str8_lit(" "); @@ -502,7 +502,7 @@ TestFuncResult test_str8_split_with_max(void) { TestFuncResult test_str8_rsplit(void) { b8 result; - Allocator arena = wapp_mem_arena_allocator_init(KB(100)); + Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); Str8 str = wapp_str8_lit("hello world from me"); Str8 delim1 = wapp_str8_lit(" "); @@ -559,7 +559,7 @@ TestFuncResult test_str8_rsplit(void) { TestFuncResult test_str8_rsplit_with_max(void) { b8 result; - Allocator arena = wapp_mem_arena_allocator_init(KB(100)); + Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); Str8 str = wapp_str8_lit("hello world from me"); Str8 delim = wapp_str8_lit(" "); @@ -594,7 +594,7 @@ TestFuncResult test_str8_rsplit_with_max(void) { TestFuncResult test_str8_join(void) { b8 result; - Allocator arena = wapp_mem_arena_allocator_init(KB(100)); + Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); Str8 str = wapp_str8_lit("hello world from me"); Str8 delim1 = wapp_str8_lit(" "); diff --git a/tests/str8/test_str8.cc b/tests/str8/test_str8.cc index 51ad600..68295a0 100644 --- a/tests/str8/test_str8.cc +++ b/tests/str8/test_str8.cc @@ -77,7 +77,7 @@ TestFuncResult test_str8_buf(void) { TestFuncResult test_str8_alloc_buf(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(KB(100)); + Allocator allocator = wapp_mem_arena_allocator_init(KiB(100)); if (wapp_mem_allocator_invalid(&allocator)) { return wapp_tester_result(false); } @@ -105,7 +105,7 @@ TestFuncResult test_str8_alloc_buf(void) { TestFuncResult test_str8_alloc_cstr(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(KB(100)); + Allocator allocator = wapp_mem_arena_allocator_init(KiB(100)); if (wapp_mem_allocator_invalid(&allocator)) { return wapp_tester_result(false); } @@ -126,7 +126,7 @@ TestFuncResult test_str8_alloc_cstr(void) { TestFuncResult test_str8_alloc_str8(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(KB(100)); + Allocator allocator = wapp_mem_arena_allocator_init(KiB(100)); if (wapp_mem_allocator_invalid(&allocator)) { return wapp_tester_result(false); } @@ -146,7 +146,7 @@ TestFuncResult test_str8_alloc_str8(void) { TestFuncResult test_str8_alloc_substr(void) { b8 result; - Allocator allocator = wapp_mem_arena_allocator_init(KB(100)); + Allocator allocator = wapp_mem_arena_allocator_init(KiB(100)); if (wapp_mem_allocator_invalid(&allocator)) { return wapp_tester_result(false); } @@ -289,7 +289,7 @@ TestFuncResult test_str8_slice(void) { TestFuncResult test_str8_alloc_concat(void) { b8 result; - Allocator arena = wapp_mem_arena_allocator_init(KB(100)); + Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); Str8 str = wapp_str8_lit("Hello world"); Str8 suffix1 = wapp_str8_lit(" from me."); @@ -410,7 +410,7 @@ TestFuncResult test_str8_rfind(void) { TestFuncResult test_str8_split(void) { b8 result; - Allocator arena = wapp_mem_arena_allocator_init(KB(100)); + Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); Str8 str = wapp_str8_lit("hello world from me"); Str8 delim1 = wapp_str8_lit(" "); @@ -467,7 +467,7 @@ TestFuncResult test_str8_split(void) { TestFuncResult test_str8_split_with_max(void) { b8 result; - Allocator arena = wapp_mem_arena_allocator_init(KB(100)); + Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); Str8 str = wapp_str8_lit("hello world from me"); Str8 delim = wapp_str8_lit(" "); @@ -502,7 +502,7 @@ TestFuncResult test_str8_split_with_max(void) { TestFuncResult test_str8_rsplit(void) { b8 result; - Allocator arena = wapp_mem_arena_allocator_init(KB(100)); + Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); Str8 str = wapp_str8_lit("hello world from me"); Str8 delim1 = wapp_str8_lit(" "); @@ -559,7 +559,7 @@ TestFuncResult test_str8_rsplit(void) { TestFuncResult test_str8_rsplit_with_max(void) { b8 result; - Allocator arena = wapp_mem_arena_allocator_init(KB(100)); + Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); Str8 str = wapp_str8_lit("hello world from me"); Str8 delim = wapp_str8_lit(" "); @@ -594,7 +594,7 @@ TestFuncResult test_str8_rsplit_with_max(void) { TestFuncResult test_str8_join(void) { b8 result; - Allocator arena = wapp_mem_arena_allocator_init(KB(100)); + Allocator arena = wapp_mem_arena_allocator_init(KiB(100)); Str8 str = wapp_str8_lit("hello world from me"); Str8 delim1 = wapp_str8_lit(" ");