python / python/cpython

Improve macOS AArch64 JIT stencils by relaxing GOT loads

Offen
#157,435 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

interpreter-core OS-mac topic-JIT type-feature
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Proposal:

The AArch64 JIT has support for optimising pairs of instructions that load an address through the global offset table (GOT).
On Linux, the JIT optimiser recognises assembly like:

adrp x9, :got:__PyRuntime
ldr  x9, [x9, :got_lo12:__PyRuntime]

https://github.com/python/cpython/blob/0ba7be9a18e8b03af1c046d676f71be9208e06d4/Tools/jit/_optimizers.py#L586-L591

On macOS, Clang uses a different syntax recognised by the Mach-O linker:

adrp x9, __PyRuntime@GOTPAGE
ldr  x9, [x9, __PyRuntime@GOTPAGEOFF]

We can add support for this using the existing patch_aarch64_33rx() function just by adjusting the regex which would enable the same optimisation we already use on Linux:

adrp x9, <__PyRuntime page>
add  x9, x9, <page offset>

This is a natural followup to #157040. I have a small patch ready once jit development is unblocked.

Benchmark:

On my M5 MacBook Pro this shows a 1.16% improvement on the pyperformance suite though results are very noisy. Probably best to re-run with the official benchmarking runners.

Expand for full benchmarking results

Image

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

#148598, #148501, #157040 /cc @diegorusso

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne in Tools/jit/_optimizers.py bei patch_aarch64_33rx() und vergleiche das bestehende Linux-GOT-load-Muster mit der hier beschriebenen macOS-Syntax von Clang. Aktualisiere die Matching-Logik so, dass die bestehende AArch64-Optimierung angewendet wird, und führe anschließend die pyperformance-Suite oder die offiziellen Benchmarking-Runner aus, um das Ergebnis zu prüfen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
macos, python
Bereich
compilers, performance
Issue-Typ
Feature
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Aktiv
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
72/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.