Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-130956: emit AArch64 trampolines only for long jumps #131041

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Optimize the AArch64 code generation for the JIT. Patch by Diego Russo
12 changes: 11 additions & 1 deletion Python/jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,17 @@ void patch_aarch64_trampoline(unsigned char *location, int ordinal, jit_state *s
void
patch_aarch64_trampoline(unsigned char *location, int ordinal, jit_state *state)
{

uint64_t value = (uintptr_t)symbols_map[ordinal];
int64_t range = value - (uintptr_t)location;

// If we are in range of 28 signed bits, we patch the instruction with
// the address of the symbol.
if (range >= -(1 << 27) && range < (1 << 27)) {
patch_aarch64_26r(location, (uintptr_t)value);
return;
}

// Masking is done modulo 32 as the mask is stored as an array of uint32_t
const uint32_t symbol_mask = 1 << (ordinal % 32);
const uint32_t trampoline_mask = state->trampolines.mask[ordinal / 32];
Expand All @@ -445,7 +456,6 @@ patch_aarch64_trampoline(unsigned char *location, int ordinal, jit_state *state)
uint32_t *p = (uint32_t*)(state->trampolines.mem + index * TRAMPOLINE_SIZE);
assert((size_t)(index + 1) * TRAMPOLINE_SIZE <= state->trampolines.size);

uint64_t value = (uintptr_t)symbols_map[ordinal];

/* Generate the trampoline
0: 58000048 ldr x8, 8
Expand Down
1 change: 1 addition & 0 deletions Tools/jit/_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ def get_target(host: str) -> _COFF | _ELF | _MachO:
# On aarch64 Linux, intrinsics were being emitted and this flag
# was required to disable them.
"-mno-outline-atomics",
"-fplt",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed otherwise trampolines are not generated at all and everything is referenced via the GOT. if you prefer, we can have this as separate PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this seems like this slows Linux down. Let's drop it.

]
target = _ELF(host, alignment=8, args=args)
elif re.fullmatch(r"i686-pc-windows-msvc", host):
Expand Down
Loading