summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2023-02-07 19:27:39 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2023-02-07 19:27:39 -0400
commit4dffe16fddf03381386699f32d3851e8c8dab7d4 (patch)
tree956420b457f220c6e473e177ca662d1c4325a191 /src
parente679d990b85e0a92e2bb9de32dd229ceb50bb372 (diff)
THeap: Match `heap_alloc()`
Ghidra was very confused about how it looked.
Diffstat (limited to 'src')
-rw-r--r--src/pso/THeap.cpp96
1 files changed, 22 insertions, 74 deletions
diff --git a/src/pso/THeap.cpp b/src/pso/THeap.cpp
index 8dd0894..f724e31 100644
--- a/src/pso/THeap.cpp
+++ b/src/pso/THeap.cpp
@@ -3,9 +3,6 @@
#include <string.h>
#include <global_types.h>
-#undef MATCHING
-#define MATCHING
-
THeap *obj_heap;
THeap *alt_heap;
@@ -63,82 +60,33 @@ void *THeap::heap_zalloc(size_t size) {
return ptr;
}
-// Getting closer, but register allocation issues.
-#ifndef MATCHING
void *THeap::heap_alloc(size_t size) {
heap_node *prev_node = heap_nodes;
heap_node *node;
- u32 size_align = (sizeof(heap_node) - 1) + align + size;
- u32 aligned_size = size_align & -align;
- goto start;
-
- cond:
- if (node->remaining_size < aligned_size) {
- goto loop_body;
- }
-
- top:
- if (aligned_size == node->remaining_size) {
- prev_node->heap = node->heap;
- } else {
- u8 *next_u8 = (u8 *)&node->next;
- heap_node *tmp = &next_u8[aligned_size];
- tmp->next = node->next;
- tmp->remaining_size = node->remaining_size - aligned_size;
- node->remaining_size = aligned_size;
- prev_node->next = tmp;
- }
- return node + 1;
-
- loop_body:
- prev_node = node;
- start:
- if (node = prev_node->next, node == NULL) {
- return NULL;
+ heap_node *tmp;
+
+ u32 aligned_size = (sizeof(heap_node) - 1) + align + size;
+ aligned_size &= -align;
+
+ for (; node = prev_node->next, node != NULL; prev_node = node) {
+ if (node->remaining_size >= aligned_size) {
+ if (aligned_size == node->remaining_size) {
+ prev_node->next = node->next;
+ } else {
+ u8 *next_u8 = (u8 *)&node->next;
+ tmp = (heap_node *)&next_u8[aligned_size];
+
+ tmp->next = node->next;
+ tmp->remaining_size = node->remaining_size - aligned_size;
+
+ node->remaining_size = aligned_size;
+ prev_node->next = tmp;
+ }
+ return node + 1;
+ }
}
- goto cond;
-}
-#else
-asm void *THeap::heap_alloc(size_t size) {
-nofralloc
-/* 80141028 80030008 */ lwz r0, 8(r3)
-/* 8014102C 80630000 */ lwz r3, 0(r3)
-/* 80141030 7CC02214 */ add r6, r0, r4
-/* 80141034 7C0000D0 */ neg r0, r0
-/* 80141038 38C60007 */ addi r6, r6, 0x7
-/* 8014103C 7CC60038 */ and r6, r6, r0
-/* 80141040 48000050 */ b lbl_80141090
-lbl_80141044:
-/* 80141044 80040004 */ lwz r0, 4(r4)
-/* 80141048 7C003040 */ cmplw r0, r6
-/* 8014104C 41800040 */ blt- lbl_8014108c
-/* 80141050 7C060040 */ cmplw r6, r0
-/* 80141054 40820010 */ bne- lbl_80141064
-/* 80141058 80040000 */ lwz r0, 0(r4)
-/* 8014105C 90030000 */ stw r0, 0(r3)
-/* 80141060 48000024 */ b lbl_80141084
-lbl_80141064:
-/* 80141064 80040000 */ lwz r0, 0(r4)
-/* 80141068 7CA43214 */ add r5, r4, r6
-/* 8014106C 90050000 */ stw r0, 0(r5)
-/* 80141070 80040004 */ lwz r0, 4(r4)
-/* 80141074 7C060050 */ subf r0, r6, r0
-/* 80141078 90050004 */ stw r0, 4(r5)
-/* 8014107C 90C40004 */ stw r6, 4(r4)
-/* 80141080 90A30000 */ stw r5, 0(r3)
-lbl_80141084:
-/* 80141084 38640008 */ addi r3, r4, 0x8
-/* 80141088 4E800020 */ blr
-lbl_8014108c:
-/* 8014108C 7C832378 */ mr r3, r4
-lbl_80141090:
-/* 80141090 80830000 */ lwz r4, 0(r3)
-/* 80141094 28040000 */ cmplwi r4, 0
-/* 80141098 4082FFAC */ bne+ lbl_80141044
-/* 8014109C 38600000 */ li r3, 0x0
-/* 801410A0 4E800020 */ blr
+ return NULL;
}
-#endif
THeap::~THeap() {
xfree(heap_nodes);