Force 32-byte allocations

This commit is contained in:
Luke Benstead 2021-04-18 13:57:00 +01:00
parent 1172086378
commit 9ca68de427
3 changed files with 10 additions and 2 deletions

View File

@ -21,8 +21,8 @@
* destination is properly aligned so we assert that. */ * destination is properly aligned so we assert that. */
#define FASTCPY(dst, src, bytes) \ #define FASTCPY(dst, src, bytes) \
do { \ do { \
if(bytes % 32 == 0 && (uintptr_t) src % 32 == 0) { \ if(bytes % 32 == 0 && ((uintptr_t) src % 4) == 0) { \
assert((uintptr_t) dst % 32 == 0); \ assert(((uintptr_t) dst) % 32 == 0); \
sq_cpy(dst, src, bytes); \ sq_cpy(dst, src, bytes); \
} else { \ } else { \
PERF_WARNING(); \ PERF_WARNING(); \

View File

@ -381,6 +381,10 @@ GLubyte _glInitTextures() {
size_t vram_free = GPUMemoryAvailable(); size_t vram_free = GPUMemoryAvailable();
YALLOC_SIZE = vram_free - PVR_MEM_BUFFER_SIZE; /* Take all but 64kb VRAM */ YALLOC_SIZE = vram_free - PVR_MEM_BUFFER_SIZE; /* Take all but 64kb VRAM */
YALLOC_BASE = GPUMemoryAlloc(YALLOC_SIZE); YALLOC_BASE = GPUMemoryAlloc(YALLOC_SIZE);
/* Ensure memory is aligned */
assert((uintptr_t) YALLOC_BASE % 32 == 0);
yalloc_init(YALLOC_BASE, YALLOC_SIZE); yalloc_init(YALLOC_BASE, YALLOC_SIZE);
return 1; return 1;
} }

View File

@ -7,6 +7,10 @@ typedef struct
{ {
uint32_t prev; // low bit set if free uint32_t prev; // low bit set if free
uint32_t next; // for used blocks: low bit set if unused header at the end uint32_t next; // for used blocks: low bit set if unused header at the end
/* We need user data to be 32-byte aligned, so the header needs
* to be 32 bytes in size (as user data follows the header) */
uint8_t padding[32 - (sizeof(uint32_t) * 2)];
} Header; } Header;
// NOTE: We have 32bit aligned data and 16bit offsets where the lowest bit is used as flag. So we remove the low bit and shift by 1 to address 128k bytes with the 15bit significant offset bits. // NOTE: We have 32bit aligned data and 16bit offsets where the lowest bit is used as flag. So we remove the low bit and shift by 1 to address 128k bytes with the 15bit significant offset bits.