Skip to content

Commit 8a33034

Browse files
authored
GH-130956: Only emit AArch64 trampolines for long jumps (GH-131041)
1 parent 63a638c commit 8a33034

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Optimize the AArch64 code generation for the JIT. Patch by Diego Russo

Python/jit.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,17 @@ void patch_aarch64_trampoline(unsigned char *location, int ordinal, jit_state *s
430430
void
431431
patch_aarch64_trampoline(unsigned char *location, int ordinal, jit_state *state)
432432
{
433+
434+
uint64_t value = (uintptr_t)symbols_map[ordinal];
435+
int64_t range = value - (uintptr_t)location;
436+
437+
// If we are in range of 28 signed bits, we patch the instruction with
438+
// the address of the symbol.
439+
if (range >= -(1 << 27) && range < (1 << 27)) {
440+
patch_aarch64_26r(location, (uintptr_t)value);
441+
return;
442+
}
443+
433444
// Masking is done modulo 32 as the mask is stored as an array of uint32_t
434445
const uint32_t symbol_mask = 1 << (ordinal % 32);
435446
const uint32_t trampoline_mask = state->trampolines.mask[ordinal / 32];
@@ -445,7 +456,6 @@ patch_aarch64_trampoline(unsigned char *location, int ordinal, jit_state *state)
445456
uint32_t *p = (uint32_t*)(state->trampolines.mem + index * TRAMPOLINE_SIZE);
446457
assert((size_t)(index + 1) * TRAMPOLINE_SIZE <= state->trampolines.size);
447458

448-
uint64_t value = (uintptr_t)symbols_map[ordinal];
449459

450460
/* Generate the trampoline
451461
0: 58000048 ldr x8, 8

0 commit comments

Comments
 (0)