Skip to content

LATX: 修复 AVX 访存宽度和权限检查,新增严格掩码访存开关 - #573

Merged
LaurenIsACoder merged 3 commits into
lat-opensource:masterfrom
xiezyang:avx-memory-fixes-master
Dec 2, 2026
Merged

LaurenIsACoder merged 3 commits into
lat-opensource:masterfrom
xiezyang:avx-memory-fixes-master

Conversation

@xiezyang

@xiezyang xiezyang commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary / 变更说明

本 PR 包含三个独立提交:

  1. 修正两条转换指令的读取宽度(455ddde357d)

    • LSX 路径的 VCVTPS2PD xmm,m64、VCVTDQ2PD xmm,m64 改为读取指令要求的 8 字节,避免原来读取 16 字节时触及操作数之后的不可访问地址。
  2. 让 Gather 默认只读取 mask 选中的元素(9718a7214ad)

    • LASX 路径跳过未选中元素,避免访问本来不应读取的地址。
    • LASX、LSX 路径均检查选中元素的读取权限,并逐项保存结果、清除对应 mask 元素,保留异常前已完成的状态。
    • 此修复默认生效,无需开启 LATX_MASKED_MEMORY。
  3. 为连续地址的掩码读写添加可选开关(c1ccd6525a8)

    • 新增 LATX_MASKED_MEMORY=0/1 和 -latx-masked-memory 参数,默认值为 0,与 LATX_MT 独立。
    • 适用于 MASKMOVQ/DQU、VMASKMOVDQU、VMASKMOVPS/PD、VPMASKMOVD/Q。
    • 开启后,全零 mask 不访存,全选使用准确宽度的向量访问,部分选中时只逐元素读写选中位置。
    • 默认保留原有访存方式,因为部分掩码可能将一次向量访问拆成多次较小的访问。
    • 开启后直接关闭整个进程的 AOT,不生成也不加载 AOT 缓存。参考 LATX_MT、LATX_SOFTFPU 的处理,即使显式设置 LATX_AOT=1 或 -latx-aot 1,也不能在严格掩码访存开启时重新启用 AOT。

Validation / 验证

验证版本:c1ccd6525a88f6712d0f296d10b9b905c54cace0。

环境:LoongArch64 Linux、16 KiB 宿主页,覆盖 x86_64 和 i386 客户程序。运行时显式设置 LATX_SOFTFPU=0、LATX_SOFTFPU_FAST=0,并在两种客户架构的实际翻译入口确认均为 0。地址与页权限检查另行覆盖 LATX_MT=0/1/2。

构建或测试 结果
开启 AVX、AOT 的两种客户架构构建,ninja -j6 通过
完整 lat-pr-fast 55/55 通过,无失败、跳过或超时
掩码访存和 Gather 专项 24/24 通过,无失败、跳过或超时
环境变量、命令行参数及参数顺序的实际配置检查 14/14 通过
开启严格掩码访存后禁用 AOT 的针对性回归 旧版本失败,当前版本通过

专项覆盖 LASX、强制 LSX、掩码开关 0/1 和 LATX_MT=0/1/2:

  • 开关为 0:验证 JIT、冷 AOT 和热 AOT,通过实际加载标记确认缓存已加载。
  • 开关为 1:显式请求开启 AOT,验证仍按严格访存执行,不加载已有缓存,也不生成或修改 AOT 缓存。
  • 配置检查覆盖两种命令行参数顺序,确认不能绕过 AOT 禁用要求。

限制:完整权限异常和 Gather 异常恢复矩阵在 JIT 下验证;AOT 覆盖开关为 0 时的结果和缓存加载。本轮未开展性能测量、真实应用验证、关闭 AVX 配置的重复构建或独立 4 KiB 宿主页环境验证。

Checklist / 检查项

  • I have read CONTRIBUTING.md. / 我已阅读 CONTRIBUTING.md。
  • Every commit contains a DCO sign-off (git commit -s). / 每个提交都包含 DCO 签署(git commit -s)。
  • I have included relevant build or test results, or explained why they are not applicable. / 我已提供相关构建或测试结果,或说明了不适用的原因。

Load exactly 64 bits for VCVTPS2PD xmm,m64 and VCVTDQ2PD xmm,m64 in the LSX translator, rather than touching the following eight bytes. Leave the 256-bit forms reading their full 128-bit source.

Signed-off-by: Zhaoyang Xie <xie_zyang@163.com>
@xiezyang
xiezyang force-pushed the avx-memory-fixes-master branch 2 times, most recently from 5b690c4 to efea52f Compare December 2, 2026 06:39
Always skip masked-off AVX2 gather elements in the LASX path and check
read permission only for selected elements. Preserve each completed
result and clear its mask element before attempting the next load, so a
later fault can resume without repeating completed accesses. Apply the
same permission and fault-progress rules to the LSX path.

Keep gather behavior independent of the masked-memory option. Cover
integer and floating-point gathers, both guest ABIs, mask combinations,
protected addresses, page checks, partial-fault recovery, LSX and AOT.

Signed-off-by: Zhaoyang Xie <xie_zyang@163.com>
@xiezyang
xiezyang force-pushed the avx-memory-fixes-master branch from efea52f to 799d693 Compare December 2, 2026 09:58
Add LATX_MASKED_MEMORY and -latx-masked-memory with a default of zero.
Control continuous masked loads and stores: MASKMOVQ/DQU, VMASKMOVDQU,
VMASKMOVPS/PD and VPMASKMOVD/Q. When enabled, skip all memory for a zero
mask, use an exact-width vector access for a full mask, and access only
selected elements otherwise. Keep the bulk read/filter and
read-modify-write policy when disabled.

Share the LSX and LASX mask implementations and delay committing load
destinations until every selected load succeeds. Disable AOT when strict
masked memory is enabled, following the SOFTFPU and MT option handling;
a later AOT option cannot override this restriction. Keep the ordinary
AOT cache names and verify that strict mode neither generates nor loads
AOT caches, while ordinary mode still supports cold and hot AOT.

Keep AVX2 gather fixes unconditional and verify their full fault-suppression
and recovery matrix with either option value. Document the option's scope,
AOT restriction and possible cost of splitting vector accesses into smaller
accesses.

Signed-off-by: Zhaoyang Xie <xie_zyang@163.com>
@xiezyang
xiezyang force-pushed the avx-memory-fixes-master branch from 799d693 to c1ccd65 Compare December 2, 2026 11:34
@xiezyang
xiezyang marked this pull request as ready for review December 2, 2026 11:40
@LaurenIsACoder
LaurenIsACoder merged commit 9ef37b0 into lat-opensource:master Dec 2, 2026
26 checks passed
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.

2 participants