Skip to content

latx: add opt-in Quicktrans fast translator - #434

Open
rmjskhy wants to merge 22 commits into
lat-opensource:masterfrom
rmjskhy:temp2
Open

rmjskhy wants to merge 22 commits into
lat-opensource:masterfrom
rmjskhy:temp2

Conversation

@rmjskhy

@rmjskhy rmjskhy commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Summary / 变更说明

  • 将 Quicktrans 快速翻译路径接入 LAT 的 x86_64 翻译入口。
  • 增加编译开关 --enable-latx-fast-translator。默认不编译 Quicktrans;使用 ./latxbuild/build64.sh -f 时才编译。
  • 编译 Quicktrans 后,运行时仍需设置 LATX_FAST_TRANSLATOR=1 才会启用快速翻译。
  • Quicktrans 无法解码或翻译某条指令时,重新从当前 TB 开头调用 LAT 原来的 tr_disasm() 解码和翻译。
  • LATX_FAST_TRANSLATOR_STRICT=1 下,Quicktrans 翻译失败时立即停止,便于查找尚未支持的指令。
  • LATX_FAST_TRANSLATOR_TRACE_MISSES=1 下,打印 Quicktrans 的失败位置、阶段和原因,并说明老解码器能否接受该指令。
  • 编译快速翻译路径时,将 option_aot 和 option_load_aot 的默认值设为 0,避免默认生成或加载 Quicktrans 尚未支持的 AOT 代码。
  • 为当前 LAT 分支缺少的 Quicktrans 宿主接口增加兼容处理。依赖这些接口的间接跳转等指令返回“不支持”,随后交给老翻译路径处理。
  • 增加 Quicktrans 子模块及其头文件生成、校验和构建规则。
  • 没有修改 target/i386/latx/translator/ 中原有的指令翻译函数。

Validation / 验证

执行了以下构建和测试:

  • 在 x86 主机执行 make -j2,确认 latx-base-test 已正确编译。

  • 在 LoongArch 主机执行默认构建:

    ./latxbuild/build64.sh -c
    构建通过,Quicktrans 未加入构建。
  • 在 LoongArch 主机执行快速翻译构建:
    ./latxbuild/build64.sh -c -f
    完整构建通过,Quicktrans 生成器和一致性检查均通过。

  • 在 Quicktrans 仓库执行:
    make test
    所有测试通过。

  • 使用 smoke-exit 验证快速翻译入口,日志确认指令实际进入 Quicktrans,程序正常退出。

  • 使用独立的临时 HOME 运行快速翻译版本。未设置 LATX_AOT 时没有生成 AOT 文件,确认 option_aot 和 option_load_aot 默认关闭。

  • 执行 latx-base-test daily 测试:
    LATX_FAST_TRANSLATOR=1 ./run-tests.py
    --latx /mnt/disk_a/lat-github/lat/build64/latx-x86_64
    --tier daily -j 2
    结果:

    • 总计:820
    • 通过:818
    • 预期失败:1,instr-fma,测试已注明 FMA3 VEX 指令尚未完全支持
    • 失败:1,instr-retf
      instr-retf 在关闭 Quicktrans 后仍以相同方式失败,输出为
      FAIL:retfq_target 和 FAIL:retfq_rsp,确认它是目标分支原有问题,不是本次修改引入。
  • git diff --check 通过。
    Checklist / 检查项

  • I have read CONTRIBUTING.md. / 我已阅读 CONTRIBUTING.md。

  • Every commit contains a DCO sign-off (git commit -s). /
    每个提交都包含 DCO 签署(git commit -s)。
    当前提交尚未包含 Signed-off-by。需要由提交作者确认并使用
    git commit --amend --signoff 补充 DCO 签署。

  • I have included relevant build or test results, or explained why they
    are not applicable. /
    我已提供相关构建或测试结果,或说明了不适用的原因。

Build the pinned standalone translator with the LATU host adapter. Add the
required hard/soft x87 and deferred-RSP recovery ABI together with block
selection, strict failure handling and cached runtime options. These pieces
are inseparable when using the current Quicktrans submodule.
Use the machine-code end offset to locate the existing Quicktrans recovery table instead of encoding a duplicate during TB finalization.
Allow the translated instruction-pattern policy to follow the LATU startup option.
Convert hard floating-point operands around BCD helpers and avoid applying the helper stack update twice.
Reuse available operands while computing overflow flags so the legacy translator stays within its temporary-register budget.
Handle large PR_SET_VMA ranges without unnecessary page-by-page work.
Validate eligible single-page Quicktrans blocks under their jump lock. Defer ptrace invalidation notifications across that lock and drain them before executing translated code. Keep the original lookup for unsupported configurations and include the ptrace regression.
Keep page consistency checks in assertion-enabled builds without performing unused page queries in release builds.
Treat search-table encoding exhaustion as code-region exhaustion and use the existing allocation retry instead of reporting an unsupported instruction.
Use compact headers only for strict non-bridge Quicktrans blocks while preserving host-PC lookup and existing alignment for other translation paths.
Do not reuse the shared EGL fallback when EGL initializes first. Resolve GLX functions using the owning GL library to avoid mixing graphics dispatch providers.
…ranslator

Recognize registered one-instruction bridges before entering strict Quicktrans. Their INT3 stubs represent native calls rather than guest breakpoint instructions.
Select Quicktrans by default when compiled in. Preserve the environment override for the legacy path and the existing strict-mode override.
Record the map and bucket sequence on a consistent miss. Skip the second lookup only while RCU protection, writer serialization and the trace state establish that the miss remains valid.
Use per-page lists for single-page translations and retain an interval tree for crossing blocks. Keep all operations under the mapping lock and reclaim empty index nodes.
Narrow label offsets and SMC flags in the supported TBMini configuration. Preserve the previous split allocation footprint to avoid changing block placement.
Let tu_reset_tb initialize fields already covered by that routine. Keep the explicit initialization in builds without TU support.
Use the existing TU and signal-relink flags directly in the protected linking path instead of repeating helper access.
Use the fast reset only in the supported exclusive full-flush context. Guard signal invalidation during the flush, retain sequence updates, and fall back when table capacity differs.
On LoongArch, issue one release fence before relaxed atomic unlocks after all protected writes finish. Keep the regular lock API for thread-sanitizer builds.
Select the reviewed follow-up commits that reuse fetched page permissions and avoid duplicate decoder-field initialization. Keep the public submodule URL and open-source update branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant