mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Consistently do & alignMask, not % alignSize
Also add more unrelated tests for coverage
This commit is contained in:
@@ -128,6 +128,7 @@ void layout_AlignTo(uint32_t alignment, uint32_t alignOfs) {
|
||||
layout_SetAddr(floatingAlignOffset);
|
||||
} else {
|
||||
uint32_t alignSize = 1u << alignment;
|
||||
uint32_t alignMask = alignSize - 1;
|
||||
|
||||
if (alignOfs >= alignSize) {
|
||||
scriptError(
|
||||
@@ -139,8 +140,8 @@ void layout_AlignTo(uint32_t alignment, uint32_t alignOfs) {
|
||||
return;
|
||||
}
|
||||
|
||||
floatingAlignMask = alignSize - 1;
|
||||
floatingAlignOffset = alignOfs % alignSize;
|
||||
floatingAlignMask = alignMask;
|
||||
floatingAlignOffset = alignOfs & alignMask;
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -158,6 +159,7 @@ void layout_AlignTo(uint32_t alignment, uint32_t alignOfs) {
|
||||
|
||||
if (alignment < 16) {
|
||||
uint32_t alignSize = 1u << alignment;
|
||||
uint32_t alignMask = alignSize - 1;
|
||||
|
||||
if (alignOfs >= alignSize) {
|
||||
scriptError(
|
||||
@@ -170,7 +172,7 @@ void layout_AlignTo(uint32_t alignment, uint32_t alignOfs) {
|
||||
}
|
||||
|
||||
assume(pc >= typeInfo.startAddr);
|
||||
length %= alignSize;
|
||||
length &= alignMask;
|
||||
}
|
||||
|
||||
if (uint16_t offset = pc - typeInfo.startAddr; length > typeInfo.size - offset) {
|
||||
|
||||
@@ -54,7 +54,7 @@ static void checkAgainstFixedAddress(Section const &target, Section const &other
|
||||
}
|
||||
}
|
||||
|
||||
static bool checkAgainstFixedAlign(Section const &target, Section const &other, int32_t ofs) {
|
||||
static bool checkAgainstFixedAlign(Section const &target, Section const &other, uint32_t ofs) {
|
||||
if (target.isAddressFixed) {
|
||||
if ((target.org - ofs) & other.alignMask) {
|
||||
fatalTwoAt(
|
||||
@@ -107,10 +107,7 @@ static void checkFragmentCompat(Section &target, Section &other) {
|
||||
target.isAddressFixed = true;
|
||||
target.org = org;
|
||||
} else if (other.isAlignFixed) {
|
||||
int32_t ofs = (other.alignOfs - target.size) % (other.alignMask + 1);
|
||||
if (ofs < 0) {
|
||||
ofs += other.alignMask + 1;
|
||||
}
|
||||
uint32_t ofs = (other.alignOfs - target.size) & other.alignMask;
|
||||
if (checkAgainstFixedAlign(target, other, ofs)) {
|
||||
target.isAlignFixed = true;
|
||||
target.alignMask = other.alignMask;
|
||||
|
||||
Reference in New Issue
Block a user