summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2023-02-05 14:29:41 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2023-02-05 14:29:41 -0400
commitbccb280f6daad2b96cc44f393f275f5030c2c1a7 (patch)
treec419e4152cb9c7196552bbfc19a7875c4289533a /src
parentcf8538d2a5cfb3a697015c1bcdea38f645fed2f5 (diff)
THeap: Get `heap_alloc()`, and the constructor closer to matching
Mostly regalloc issues.
Diffstat (limited to 'src')
-rw-r--r--src/pso/THeap.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/pso/THeap.cpp b/src/pso/THeap.cpp
index 87598b9..2ed961a 100644
--- a/src/pso/THeap.cpp
+++ b/src/pso/THeap.cpp
@@ -57,10 +57,12 @@ void *THeap::heap_zalloc(size_t size) {
// Getting closer, but register allocation issues.
#ifndef MATCHING
void *THeap::heap_alloc(size_t size) {
- const u32 aligned_size = ((heap_offset - 1) + align + size) & -align;
THeap *parent = (THeap *)heap;
THeap *child;
+ u32 size_align = (heap_offset - 1) + align + size;
+ u32 aligned_size = size_align & -align;
goto start;
+
cond:
if (child->alloc_size < aligned_size) {
goto loop_body;
@@ -74,15 +76,14 @@ void *THeap::heap_alloc(size_t size) {
tmp->heap = child->heap;
tmp->alloc_size = child->alloc_size - aligned_size;
child->alloc_size = aligned_size;
- parent->heap = (u8 *)tmp;
+ parent->heap = (u8 *)&tmp->heap;
}
return (void *)&child->align;
loop_body:
parent = child;
start:
- child = (THeap *)parent->heap;
- if (child == NULL) {
+ if (child = (THeap *)parent->heap, child == NULL) {
return NULL;
}
goto cond;
@@ -133,7 +134,7 @@ THeap::~THeap() {
xfree(heap);
}
-// Not sure how to get this matching.
+// Getting closer, still not sure how to match though.
#ifndef MATCHING
THeap::THeap(size_t size, int alignment) {
heap_size = 0;
@@ -141,11 +142,15 @@ THeap::THeap(size_t size, int alignment) {
align = alignment;
heap = (u8 *)xmalloc(heap_size);
if (heap != NULL) {
- THeap *tmp_heap = (THeap *)memset(heap, 0, size);
+ const u32 new_size = size - heap_offset;
+ THeap *tmp_heap;
+ memset(heap, 0, size);
+
+ tmp_heap = (THeap *)heap;
tmp_heap->heap = &heap[heap_offset];
((THeap *)heap)->alloc_size = 0;
tmp_heap->align = 0;
- tmp_heap->heap_size = size - heap_offset;
+ tmp_heap->heap_size = new_size;
}
}
#else