diff options
author | Nathan Ringo <nathan@remexre.com> | 2024-11-27 20:28:40 -0600 |
---|---|---|
committer | Nathan Ringo <nathan@remexre.com> | 2024-11-27 20:28:40 -0600 |
commit | b252d0de46cf12b8e2521b3eb42da9acc41a4cc1 (patch) | |
tree | 456bfed5547745edacebe8c89194c26f03a25908 /src/platform/3ds.c | |
parent | 62e41dcb40d0450d493a804e7f0ac3e32f35aabf (diff) |
new simpler GC
Diffstat (limited to 'src/platform/3ds.c')
-rw-r--r-- | src/platform/3ds.c | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/src/platform/3ds.c b/src/platform/3ds.c index 5683422..5566121 100644 --- a/src/platform/3ds.c +++ b/src/platform/3ds.c @@ -6,6 +6,7 @@ #include <inttypes.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> /** * These cache-size details are from @@ -16,6 +17,16 @@ size_t get_l1d_size(void) { return 16 * 1024; } size_t get_l3_size(void) { return 2 * 1024 * 1024; } +uintptr_t alloc_gc_region(size_t size) { + void *ptr = malloc(size); + assume(ptr != NULL); + return (uintptr_t)ptr; +} + +void clear_gc_region(uintptr_t addr, size_t size) { + memset((void *)addr, 0, size); +} + void panic_begin(void) { consoleInit(GFX_TOP, NULL); } noreturn void panic_end(void) { @@ -35,6 +46,51 @@ noreturn void panic_end(void) { exit(1); } +static void gc_test(void) { + gc_debug(); + + const struct value ZERO = {.bits = (0 << 2) | TAG_FIXNUM}; + + struct object *values = gc_alloc(64, 0); + struct object *value_slot_counts = gc_alloc(64, 0); + gc_root_push(&values); + gc_root_push(&value_slot_counts); + + for (size_t i = 0; i < 10000000; i++) { + if ((rand() & 0b11) == 0) { + size_t value_slot_count = rand() & 63; + if (!value_slot_count) + value_slot_count = 1; + size_t untraced_slot_count = rand() & 63; + struct value value = + alloc_builtin_object(ZERO, value_slot_count, untraced_slot_count); + size_t i = rand() % 63; + gc_write_value_slot(values, i, value); + gc_write_value_slot(value_slot_counts, i, + integer_of_int(value_slot_count)); + } else { + size_t i = rand() & 63; + struct value value = gc_read_value_slot(values, i); + struct value value_slot_count_value = + gc_read_value_slot(value_slot_counts, i); + if (!value.bits) + continue; + assume(get_tag(value) == TAG_BUILTIN_OBJECT); + assume(get_tag(value_slot_count_value) == TAG_FIXNUM); + struct object *obj = untag_ptr(value); + intptr_t value_slot_count = untag_fixnum(value_slot_count_value); + size_t j = rand() % value_slot_count; + size_t k = rand() % 63; + gc_write_value_slot(obj, j, gc_read_value_slot(values, k)); + } + } + + gc_root_pop(); + gc_root_pop(); + + gc_debug(); +} + int main(int argc, char **argv) { gfxInit(GSP_BGR8_OES, GSP_BGR8_OES, false); @@ -66,7 +122,7 @@ int main(int argc, char **argv) { if (kDown & KEY_START) break; // break in order to return to hbmenu if (kDown & KEY_A) - todo("GM"); + gc_test(); circlePosition pos; hidCircleRead(&pos); |