python / python/cpython

Improve macOS AArch64 JIT stencils by relaxing GOT loads

オープン
#157,435 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

interpreter-core OS-mac topic-JIT type-feature
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Tools/jit/_optimizers.py の patch_aarch64_33rx() から始め、既存の Linux GOT-load パターンと、ここで説明されている Clang の macOS 構文を比較します。既存の AArch64 最適化が適用されるようにマッチングロジックを更新し、その後 pyperformance スイートまたは公式のベンチマークランナーを実行して結果を確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
macos, python
領域
compilers, performance
issue の種類
機能追加
難易度
3/5
見積もり時間
1〜2日
活発さ
活発
明瞭さ
明確に書かれている
初心者へのやさしさ
72/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。