From 8d651ab1fc2eda5d68590bae05ba7117f4a86e6e Mon Sep 17 00:00:00 2001 From: Matthew Date: Sun, 21 Sep 2025 17:09:12 +1000 Subject: [PATCH] fix asm instruction, make scratch allocator able to work per frame --- alloc.d | 30 ++++++++++++++++++++---------- util.d | 2 +- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/alloc.d b/alloc.d index 5757c0e..e55530a 100644 --- a/alloc.d +++ b/alloc.d @@ -15,8 +15,9 @@ const DEFAULT_ALIGNMENT = (void *).sizeof * 2; struct Scratch { - Arena arena; - bool init; + Arena[] arenas; + u64 index; + bool init; } struct ArenaPool @@ -188,25 +189,34 @@ Free(T)(T* ptr) } void -ResetScratch(u64 size) +ResetScratch(u64 size, u64 count) { - if(!g_scratch.init) + with(g_scratch) { - g_scratch.arena = CreateArena(size); - g_scratch.init = true; - } + if(!init) + { + arenas = AllocArray!(Arena)(count); + for(u64 i = 0; i < count; i += 1) + { + arenas[i] = CreateArena(size); + } - Reset(&g_scratch.arena); + g_scratch.init = true; + } + + index = index % count; + Reset(&arenas[index]); + } } T* ScratchAlloc(T)() { - return Alloc!(T)(&g_scratch.arena); + return Alloc!(T)(&g_scratch.arenas[g_scratch.index]); } T[] ScratchAlloc(T)(u64 count) { - return AllocArray!(T)(&g_scratch.arena, count); + return AllocArray!(T)(&g_scratch.arenas[g_scratch.index], count); } diff --git a/util.d b/util.d index 7967305..91d8ec3 100644 --- a/util.d +++ b/util.d @@ -836,7 +836,7 @@ MemCpy(void* dst_p, void* src_p, u64 length) movdqu XMM3, [R8+48]; add R9, i; - movdqu [R9+00], XMM0; + movups [R9+00], XMM0; movups [R9+16], XMM1; movups [R9+32], XMM2; movups [R9+48], XMM3;