aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Talavera <jesse@jesse.tg>2023-12-26 16:09:39 -0500
committerGitHub <noreply@github.com>2023-12-26 22:09:39 +0100
commitcbd65a131ed4eb6938964e57de3385ca890b6091 (patch)
tree1846cf00bd11fbfc133ccc670f5b5f49f02c1e76
parentab8938a6950f613c0f255788b483ef683e5e0851 (diff)
Add `alignas` specifiers to some arrays based on how they're accessed (#1933)
* Align some two-element `u32` arrays as `u64`s - To pacify "unaligned read/write" warnings from UBSan * Align some more arrays based on how they're accessed
-rw-r--r--src/GPU.h36
-rw-r--r--src/NDS.h14
2 files changed, 25 insertions, 25 deletions
diff --git a/src/GPU.h b/src/GPU.h
index e070db7..780d5e0 100644
--- a/src/GPU.h
+++ b/src/GPU.h
@@ -536,18 +536,18 @@ public:
u8 VRAMCNT[9] {};
u8 VRAMSTAT = 0;
- u8 Palette[2*1024] {};
- u8 OAM[2*1024] {};
-
- u8 VRAM_A[128*1024] {};
- u8 VRAM_B[128*1024] {};
- u8 VRAM_C[128*1024] {};
- u8 VRAM_D[128*1024] {};
- u8 VRAM_E[ 64*1024] {};
- u8 VRAM_F[ 16*1024] {};
- u8 VRAM_G[ 16*1024] {};
- u8 VRAM_H[ 32*1024] {};
- u8 VRAM_I[ 16*1024] {};
+ alignas(u64) u8 Palette[2*1024] {};
+ alignas(u64) u8 OAM[2*1024] {};
+
+ alignas(u64) u8 VRAM_A[128*1024] {};
+ alignas(u64) u8 VRAM_B[128*1024] {};
+ alignas(u64) u8 VRAM_C[128*1024] {};
+ alignas(u64) u8 VRAM_D[128*1024] {};
+ alignas(u64) u8 VRAM_E[ 64*1024] {};
+ alignas(u64) u8 VRAM_F[ 16*1024] {};
+ alignas(u64) u8 VRAM_G[ 16*1024] {};
+ alignas(u64) u8 VRAM_H[ 32*1024] {};
+ alignas(u64) u8 VRAM_I[ 16*1024] {};
u8* const VRAM[9] = {VRAM_A, VRAM_B, VRAM_C, VRAM_D, VRAM_E, VRAM_F, VRAM_G, VRAM_H, VRAM_I};
u32 const VRAMMask[9] = {0x1FFFF, 0x1FFFF, 0x1FFFF, 0x1FFFF, 0xFFFF, 0x3FFF, 0x3FFF, 0x7FFF, 0x3FFF};
@@ -596,14 +596,14 @@ public:
u8 VRAMFlat_AOBJ[256*1024] {};
u8 VRAMFlat_BOBJ[128*1024] {};
- u8 VRAMFlat_ABGExtPal[32*1024] {};
- u8 VRAMFlat_BBGExtPal[32*1024] {};
+ alignas(u16) u8 VRAMFlat_ABGExtPal[32*1024] {};
+ alignas(u16) u8 VRAMFlat_BBGExtPal[32*1024] {};
- u8 VRAMFlat_AOBJExtPal[8*1024] {};
- u8 VRAMFlat_BOBJExtPal[8*1024] {};
+ alignas(u16) u8 VRAMFlat_AOBJExtPal[8*1024] {};
+ alignas(u16) u8 VRAMFlat_BOBJExtPal[8*1024] {};
- u8 VRAMFlat_Texture[512*1024] {};
- u8 VRAMFlat_TexPal[128*1024] {};
+ alignas(u64) u8 VRAMFlat_Texture[512*1024] {};
+ alignas(u64) u8 VRAMFlat_TexPal[128*1024] {};
private:
void ResetVRAMCache() noexcept;
void AssignFramebuffers() noexcept;
diff --git a/src/NDS.h b/src/NDS.h
index 23b1f88..f9df2d6 100644
--- a/src/NDS.h
+++ b/src/NDS.h
@@ -259,8 +259,8 @@ public: // TODO: Encapsulate the rest of these members
u16 PowerControl9;
u16 ExMemCnt[2];
- u8 ROMSeed0[2*8];
- u8 ROMSeed1[2*8];
+ alignas(u32) u8 ROMSeed0[2*8];
+ alignas(u32) u8 ROMSeed1[2*8];
protected:
// These BIOS arrays should be declared *before* the component objects (JIT, SPI, etc.)
@@ -489,12 +489,12 @@ private:
FIFO<u32, 16> IPCFIFO9; // FIFO in which the ARM9 writes
FIFO<u32, 16> IPCFIFO7;
u16 DivCnt;
- u32 DivNumerator[2];
- u32 DivDenominator[2];
- u32 DivQuotient[2];
- u32 DivRemainder[2];
+ alignas(u64) u32 DivNumerator[2];
+ alignas(u64) u32 DivDenominator[2];
+ alignas(u64) u32 DivQuotient[2];
+ alignas(u64) u32 DivRemainder[2];
u16 SqrtCnt;
- u32 SqrtVal[2];
+ alignas(u64) u32 SqrtVal[2];
u32 SqrtRes;
u16 KeyCnt[2];
bool Running;