baseline: Decide which instruction implementations to inline into the dispatch loop
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 12/100
- Issue 类型
- 重构
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- cpp
- 领域
- compilers, performance
调研方向
The work is in the Baseline dispatch loops in baseline_execution.cpp and in intx's addmod(), sdivrem() and udivrem(). Start by building with GCC and Clang and checking the inlining decisions the issue describes. Done means a per-instruction inlining choice that is measured on random operands, at several code alignments, with branch-miss counters. This is a performance research task, not a first contribution.
由索引模型根据 Issue 内容生成。
描述
Which instruction implementations are inlined into the Baseline dispatch loops (dispatch_cgoto, dispatch<false>, dispatch<true>) is left to the compilers' inlining heuristics. The same goes for which intx functions are inlined into those implementations. The heuristics weigh code size, not how hot or how expensive an instruction is, so unrelated size changes in evmone or intx move handlers in or out of the loops.
- GCC inlines into
baseline_execution.cppuntil the file has grown by--param inline-unit-growth(40%). It also lets a large function grow only bylarge-function-growth(100%). The dispatch loops sit at this limit:- SAR, LOG1–4, CALLDATACOPY, CODECOPY and EXTCODECOPY are left out.
- LOG0, MCOPY and RETURNDATACOPY move in and out with small changes in intx. For example, a smaller SLT in chfast/intx#453 pulls LOG0 in. The larger
exp()of chfast/intx#455 turns the EXP handler into a call and pulls LOG0 and MCOPY in.
- Clang decides per call site and keeps larger intx functions behind calls. The 256-bit results then take extra copies through memory, see ADDMOD below.
- Relayout: every such change also relayouts the loops, and the dispatch branch prediction depends on the layout. With GCC the chained-MUL benchmark runs in one of two states: 0.46M or 6.4M branch misses per 3 executions, with identical instructions and 1.5–2.4× the cycles.
Options
- Decide per instruction in evmone:
[[gnu::always_inline]],[[gnu::noinline]]or[[gnu::flatten]]on the implementations, possibly different for GCC and Clang. - Raise GCC's budget for
baseline_execution.cpponly:-
Use
--param=inline-unit-growth=100and--param=large-function-growth=200. -
In a prototype at x86-64-v3, this pins the current decisions and inlines the left-out handlers:
change SAR −2…−4% CODECOPY −3…−9% CALLDATACOPY −1…−5% RETURNDATACOPY −1…−4% evm-benchmarks ±2% snailtracer −3.8% .text+6.8 KB (v2), +8.7 KB (v3)
-
- Attributes in intx instead: they also affect intx's other users.
Items to check
Measure each item with per-instruction contracts on random (worst-case) operands, at 3 code alignments, and with branch-miss counters.
- ADDMOD with Clang.
-
What happens:
intx::addmod()(127 instructions) stays out of line. It copies the remainder out of the division result with a 32-byte load right afterudivrem()'s 8-byte stores. The load fails store forwarding, which costs about 11% of the cycles of an ADDMOD loop. The handler then copies the returned value again. -
[[clang::always_inline]]onintx::addmod()(x86-64-v3, 3 code alignments, ADDMOD contracts):modulus change 1–4 words −5…−8% BN254 −16…−18% GCC's code is identical.
-
The same with
[[gnu::always_inline]]: GCC gets slower. GCC already inlines the fast path ofaddmod()into the loop, and with the attribute the whole handler leaves the loop. BN254 +20%; chains of reduced ADDMODs +16% (v3) and +44% (v2). -
Side cost: with a zero modulus, the cheapest case, ADDMOD pays for the handler's frame: +24 cycles.
-
- SDIV/SMOD with Clang.
intx::sdivrem()stays out of line and returns its 64-byte result through memory. The copy of the result fails store forwarding.[[gnu::always_inline]]on it: Clang −10…−18%, GCC at x86-64-v3 up to +4.6% (its handlers then sit behind a call). - EXP with GCC: a call instead of inlined after chfast/intx#455.
- SAR, LOG1–4, CALLDATACOPY, CODECOPY, EXTCODECOPY with GCC: left out by the budget.
- 主要语言
- C++
- 星标
- 979
- 派生
- 340
- 平均合并
- 12 小时 16 分钟
- 30 天内合并 PR
- 25
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ipsilon/evmone 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 82/100
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 56/100
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 57/100
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 52/100
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 35/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 71/100
ROCm/rocm-libraries#16108 ·
维护者通常 2 天内回复
-
asr pass bug intrinsic low priority wrong result
难度 2/5 1-3 小时 新手友好度 67/100
维护者通常 1 天内回复
-
👀 needs triage enhancement
难度 2/5 1-3 小时 新手友好度 72/100
rerun-io/rerun#13021 · 1 条评论 ·
维护者通常 2 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 2 天内回复
-
audit-reference-check
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复