1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-11-11 03:39:59 +00:00

TwoHeadArena Cleanup (#633)

* TwoHeadArena cleanup

* remove params

* remove params

* prettying up the struct a little

* remove unecessary cast
This commit is contained in:
AdamKiddle 2021-01-15 22:18:15 +00:00 committed by GitHub
parent 447c6514b9
commit 9be264da9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 16 deletions

View file

@ -70,9 +70,9 @@ typedef struct {
typedef struct { typedef struct {
/* 0x0000 */ u32 size; /* 0x0000 */ u32 size;
/* 0x0004 */ u8* bufp; /* 0x0004 */ void* bufp;
/* 0x0008 */ u8* head; /* 0x0008 */ void* head;
/* 0x000C */ u8* tail; /* 0x000C */ void* tail;
} TwoHeadArena; // size = 0x10 } TwoHeadArena; // size = 0x10
typedef struct { typedef struct {

View file

@ -78,7 +78,7 @@ void* THA_GetTail(TwoHeadArena* tha) {
void* THA_AllocStart(TwoHeadArena* tha, u32 size) { void* THA_AllocStart(TwoHeadArena* tha, u32 size) {
void* start = tha->head; void* start = tha->head;
tha->head += size; tha->head = (u32)tha->head + size;
return start; return start;
} }
@ -88,7 +88,6 @@ void* THA_AllocStart1(TwoHeadArena* tha) {
void* THA_AllocEnd(TwoHeadArena* tha, u32 size) { void* THA_AllocEnd(TwoHeadArena* tha, u32 size) {
u32 mask; u32 mask;
u32* temp;
if (size == 8) { if (size == 8) {
mask = ~7; mask = ~7;
@ -100,25 +99,24 @@ void* THA_AllocEnd(TwoHeadArena* tha, u32 size) {
mask = (size >= 0x10) ? ~0xF : 0; mask = (size >= 0x10) ? ~0xF : 0;
} }
temp = (u32*)&tha->tail; // required to match tha->tail = (((u32)tha->tail & mask) - size) & mask;
return tha->tail = (void*)(((*temp & mask) - size) & mask); return tha->tail;
} }
void* THA_AllocEndAlign16(TwoHeadArena* tha, u32 size) { void* THA_AllocEndAlign16(TwoHeadArena* tha, u32 size) {
void* ret = (void*)(u32)((((u32)tha->tail & ~0xF) - size) & u32 mask = ~0xF;
((~(0xF & 0xFFFFFFFFFFFFFFFF)) & 0xFFFFFFFFu)); // required to match
tha->tail = ret; tha->tail = (((u32)tha->tail & mask) - size) & (u64)mask;
return ret; return tha->tail;
} }
void* THA_AllocEndAlign(TwoHeadArena* tha, u32 size, u32 mask) { void* THA_AllocEndAlign(TwoHeadArena* tha, u32 size, u32 mask) {
void* ret = (void*)((((u32)tha->tail & mask) - size) & mask); tha->tail = (((u32)tha->tail & mask) - size) & mask;
tha->tail = ret; return tha->tail;
return ret;
} }
s32 THA_GetSize(TwoHeadArena* tha) { s32 THA_GetSize(TwoHeadArena* tha) {
return tha->tail - tha->head; return (u32)tha->tail - (u32)tha->head;
} }
u32 THA_IsCrash(TwoHeadArena* tha) { u32 THA_IsCrash(TwoHeadArena* tha) {
@ -127,7 +125,7 @@ u32 THA_IsCrash(TwoHeadArena* tha) {
void THA_Init(TwoHeadArena* tha) { void THA_Init(TwoHeadArena* tha) {
tha->head = tha->bufp; tha->head = tha->bufp;
tha->tail = tha->bufp + tha->size; tha->tail = (u32)tha->bufp + tha->size;
} }
void THA_Ct(TwoHeadArena* tha, void* ptr, u32 size) { void THA_Ct(TwoHeadArena* tha, void* ptr, u32 size) {