Skip to content
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 @@
Improve JIT code generation on Linux targets by reducing the indirect call to external symbols. Patch by Diego Russo.
15 changes: 11 additions & 4 deletions Python/jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,18 +316,25 @@ patch_32(unsigned char *location, uint64_t value)
memcpy(location, &final_value, sizeof(final_value));
}

// 32-bit relative address.
// 32-bit absolute address, sign-extended by the instruction.
void
patch_32r(unsigned char *location, uint64_t value)
patch_32s(unsigned char *location, uint64_t value)
{
value -= (uintptr_t)location;
// Check that we're not out of range of 32 signed bits:
assert((int64_t)value >= -(1LL << 31));
assert((int64_t)value < (1LL << 31));
uint32_t final_value = (uint32_t)value;
int32_t final_value = (int32_t)value;
memcpy(location, &final_value, sizeof(final_value));
}

// 32-bit relative address.
void
patch_32r(unsigned char *location, uint64_t value)
{
value -= (uintptr_t)location;
patch_32s(location, value);
}

// 64-bit absolute address.
void
patch_64(unsigned char *location, uint64_t value)
Expand Down
1 change: 1 addition & 0 deletions Tools/jit/_stencils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class HoleValue(enum.Enum):
"R_AARCH64_MOVW_UABS_G2_NC": "patch_aarch64_16c",
"R_AARCH64_MOVW_UABS_G3": "patch_aarch64_16d",
# x86_64-unknown-linux-gnu:
"R_X86_64_32S": "patch_32s",
"R_X86_64_64": "patch_64",
"R_X86_64_GOTPCRELX": "patch_x86_64_32rx",
"R_X86_64_PLT32": "patch_32r",
Expand Down
4 changes: 2 additions & 2 deletions Tools/jit/_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ def get_target(host: str) -> _COFF32 | _COFF64 | _ELF | _MachO:
host = "aarch64-unknown-linux-gnu"
condition = "defined(__aarch64__) && defined(__linux__)"
# -mno-outline-atomics: Keep intrinsics from being emitted.
args = ["-fpic", "-mno-outline-atomics", "-fno-plt"]
args = ["-fpic", "-mno-outline-atomics"]
optimizer = _optimizers.OptimizerAArch64
target = _ELF(
host, condition, args=args, optimizer=optimizer, frame_pointers=True
Expand Down Expand Up @@ -622,7 +622,7 @@ def get_target(host: str) -> _COFF32 | _COFF64 | _ELF | _MachO:
elif re.fullmatch(r"x86_64-.*-linux-gnu", host):
host = "x86_64-unknown-linux-gnu"
condition = "defined(__x86_64__) && defined(__linux__)"
args = ["-fno-pic", "-mcmodel=medium", "-mlarge-data-threshold=0", "-fno-plt"]
args = ["-fno-pic", "-mcmodel=medium", "-mlarge-data-threshold=0"]
optimizer = _optimizers.OptimizerX86
target = _ELF(
host, condition, args=args, optimizer=optimizer, frame_pointers=True
Expand Down
Loading