Keep PyLong loop carries as twodigits in shifts and division
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
Feature or enhancement
Proposal:
Several functions in longobject.c (v_lshift, v_rshift, and x_divrem) narrowed a loop carry value to digit or sdigit, then widened it again on the next iteration.
On AArch64, that 64-to-32-to-64 conversion inserts an extra mov on the loop-carried critical path. Keeping the carry at two-digit width until the function returns drops that mov and shortens the carry chain. Results are unchanged for valid limbs.
Use v_lshift on AArch64 as an example. The code inside the loop is:
ldr w0, [x4, x2, lsl #2] ; a[i]
mov w3, w3 ; carry chain
lsl x0, x0, x24 ; a[i] << d
orr x0, x0, x3 ; carry chain
and w1, w0, #0x3fffffff
ubfx x3, x0, #30, #32 ; carry chain
str w1, [x26, x2, lsl #2]
add x2, x2, #1
cmp x25, x2
b.ne
removing the narrowing, the code will be optimized to:
ldr w0, [x4, x2, lsl #2] ; a[i]
lsl x0, x0, x24 ; a[i] << d
orr x0, x0, x3 ; carry chain
and w1, w0, #0x3fffffff
str w1, [x26, x2, lsl #2]
add x2, x2, #1
lsr x3, x0, #30 ; carry chain
cmp x25, x2
b.ne
The instruction count on the loop carried chain is reduced from 3 to 2.
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Linked PRs
- gh-157060
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 longobject.c 開始,檢查 v_lshift、v_rshift 和 x_divrem 中的進位處理。比較保留兩位數進位值前後產生的 AArch64 迴圈,然後驗證對於有效 limb 結果保持不變,並確認進位鏈中的指令數量如描述的那樣得到改善。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- c
- 領域
- performance
- Issue 類型
- 功能
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 45/100