Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Mach-O does not support 19 bit branches
  • Loading branch information
markshannon committed Oct 15, 2025
commit 80ea07aa5cc131370c18aadae84b2ac5fd02076e
16 changes: 0 additions & 16 deletions Python/jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ patch_aarch64_21rx(unsigned char *location, uint64_t value)
patch_aarch64_21r(location, value);
}


// 21-bit relative branch.
void
patch_aarch64_19r(unsigned char *location, uint64_t value)
Expand All @@ -350,21 +349,6 @@ patch_aarch64_19r(unsigned char *location, uint64_t value)
set_bits(loc32, 5, value, 2, 19);
}

// 16-bit relative branch.
void
patch_aarch64_14r(unsigned char *location, uint64_t value)
{
uint32_t *loc32 = (uint32_t *)location;
assert(IS_AARCH64_TEST_AND_BRANCH(*loc32));
value -= (uintptr_t)location;
// Check that we're not out of range of 16 signed bits:
assert((int64_t)value >= -(1 << 15));
assert((int64_t)value < (1 << 15));
// Since instructions are 4-byte aligned, only use 14 bits:
assert(get_bits(value, 0, 2) == 0);
set_bits(loc32, 5, value, 2, 14);
}

// 28-bit relative branch.
void
patch_aarch64_26r(unsigned char *location, uint64_t value)
Expand Down
10 changes: 9 additions & 1 deletion Tools/jit/_optimizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,16 @@ def run(self) -> None:
self.path.write_text(self._body())


# Mach-O does not support the 19 bit branch locations needed for branch reordering
class OptimizerAArch64_MachO(Optimizer): # pylint: disable = too-few-public-methods
"""aarch64-apple-darwin"""

# https://developer.arm.com/documentation/ddi0602/2025-03/Base-Instructions/B--Branch-
_re_jump = re.compile(r"\s*b\s+(?P<target>[\w.]+)")


class OptimizerAArch64(Optimizer): # pylint: disable = too-few-public-methods
"""aarch64-apple-darwin/aarch64-pc-windows-msvc/aarch64-unknown-linux-gnu"""
"""aarch64-pc-windows-msvc/aarch64-unknown-linux-gnu"""

_branches = _AARCH64_BRANCHES
_re_branch = re.compile(
Expand Down
2 changes: 1 addition & 1 deletion Tools/jit/_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ def get_target(host: str) -> _COFF32 | _COFF64 | _ELF | _MachO:
if re.fullmatch(r"aarch64-apple-darwin.*", host):
host = "aarch64-apple-darwin"
condition = "defined(__aarch64__) && defined(__APPLE__)"
optimizer = _optimizers.OptimizerAArch64
optimizer = _optimizers.OptimizerAArch64_MachO
target = _MachO(host, condition, optimizer=optimizer)
elif re.fullmatch(r"aarch64-pc-windows-msvc", host):
host = "aarch64-pc-windows-msvc"
Expand Down
Loading