Repository navigation
Conversation
JECXZ tests only the low 32 bits of RCX, so the generic path masks off the upper half before the 64-bit compare. When the immediately preceding straight-line instruction fully writes ECX as 32 bits, the host register is already zero-extended; test it directly and drop the mask and its temporary. Restrict the fast path to writers that provably clear the upper half: MOV/MOVZX/MOVSX/LEA/ADC/SBB in both modes, and ADD/SUB/AND/OR/XOR/INC/DEC/ NEG/NOT in 64-bit mode where the translator emits the zero-extension and the following JECXZ keeps ECX live for HBR. All other cases keep the existing masked load. Validated with lat-pr-fast (49/49), a focused decision unit test, 2000 randomized x86-64 differential cases covering the fast and fallback paths, TB-boundary cases, and 32-bit guest cases on latx-i386. A JECXZ-dense microbenchmark removes exactly one host instruction per optimized JECXZ; its wall-time result was neutral, so no product-level gain is claimed. Signed-off-by: Leslie Zhai <xiangzhai83@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary / 变更说明
JECXZ 只检查 RCX 的低 32 位。原实现总是通过
load_ireg_from_ir1(&ecx_ir1_opnd, ZERO_EXTENSION, false)生成bstrpick.d加临时寄存器,再与 0 比较。本变更利用一个局部不变量:若 JECXZ 在同一个 TB 内、且紧邻的前一条指令以
32 位宽度完整写 ECX,则宿主寄存器高 32 位已经被清零,可以直接用 RCX 与 0
比较,省去 mask 指令和临时寄存器。
仅在可证明安全时启用快速路径:
MOV、MOVZX、MOVSX、LEA、ADC、SBB;ADD、SUB、AND、OR、XOR、INC、DEC、NEG、NOT。以下情况保持原 masked load:JECXZ 是 TB 首条指令、前一条是 64 位写、前一条
不是上述白名单指令、或前一条属于指令模式融合。
命中时每条 JECXZ 少一条宿主指令(
bstrpick.d)和一个临时寄存器。Validation / 验证
Builds / 构建
latx-x86_64,-Werror通过;候选二进制重建后哈希一致。latx-i386,-Werror通过;候选二进制重建后哈希一致。Regression tests / 回归测试
新增
tests/unit/test-latx-jecxz-opt.py,覆盖快速/回退判定:ECX 目标、32/64 位写、非白名单指令、模式融合标记、TB 首条指令等。
Semantics / 语义验证
RCX高 32 位非零但ECX == 0、RCX = 0xffffffff00000000、ECX != 0、0x80000000、add/inc回绕等 9 个场景;基线与候选在 default、
LATX_AOT=0 LATX_KZT=0、-d nochain下均通过。CMP/TEST/SHL $0等回退路径;基线、候选输出均与按 x86 语义独立计算的期望值 2000/2000 匹配,并在 default、
LATX_AOT=0、-d nochain三种模式下一致。RCX高 32 位非零;基线与候选均通过。
LATX_AOT=0下均通过。Performance / 性能
JECXZ 密集微基准(8 亿次 JECXZ):
instructions:u恰好减少 800,000,000 条(每条优化 JECXZ 少1 条),分支数不变。
95% CI 跨 0;taken 变体在噪声范围内略慢)。
因此本 PR 只声明指令数/代码量减少,不声明产品级端到端加速。
Checklist / 检查项
CONTRIBUTING.md. / 我已阅读CONTRIBUTING.md。git commit -s). /每个提交都包含 DCO 签署(
git commit -s)。are not applicable. /
我已提供相关构建或测试结果,或说明了不适用的原因。