python / python/cpython

Improve macOS AArch64 JIT stencils by relaxing GOT loads

未关闭
#157,435 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

interpreter-core OS-mac topic-JIT type-feature
主要语言
Python
星标
77.2k
派生
36k
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. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 Tools/jit/_optimizers.py 中的 patch_aarch64_33rx() 开始,将现有的 Linux GOT-load 模式与此处描述的 Clang macOS 语法进行比较。更新匹配逻辑,使现有的 AArch64 优化能够应用,然后运行 pyperformance 套件或官方 benchmarking runner 来检查结果。

由索引模型根据 Issue 内容生成。

评估

技术栈
macos, python
领域
compilers, performance
Issue 类型
功能
难度
3/5
预计耗时
1-2 天
活跃度
活跃
描述清晰度
描述清楚
新手友好度
72/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。