fix asm instruction, make scratch allocator able to work per frame

This commit is contained in:
Matthew 2025-09-21 17:09:12 +10:00
parent ff94c5cb5e
commit 8d651ab1fc
2 changed files with 21 additions and 11 deletions

30
alloc.d
View File

@ -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);
}

2
util.d
View File

@ -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;