RV64 signed DIV/REM restores the sign from bit 31

未关闭 适合新手
#501 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
70/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
领域
hpc

调研方向

Bug 位于 VX_serial_div.sv:幅值路径使用位 WIDTHN-1 / WIDTHD-1(大约第 53-56 行),但商和余数的符号标志使用第 31 位(大约第 82-83 行)。先阅读这两个代码块,然后在没有 DPI 除法器的情况下(SV_DPI 未设置或 SYNTHESIS 已设置)构建,以便执行 VX_serial_div。当符号修正测试使用 numer[i][WIDTHN-1] 和 denom[i][WIDTHD-1],并且 issue 中的 RV64 DIV 用例返回预期的商和余数时,即完成。

由索引模型根据 Issue 内容生成。

描述

On RV64, the synthesizable divider in VX_serial_div takes operand magnitudes using bit WIDTHN-1 / WIDTHD-1, but decides whether to negate the quotient and remainder using bit 31. These bits agree on RV32 and for DIVW / REMW, whose operands are sign-extended from bit 31. They can differ for 64-bit DIV and REM, causing an incorrect result sign.

Two cases with a positive divisor:

  • DIV 0x0000000080000000, 3 should return quotient 0x000000002aaaaaaa, remainder 2. The divider returns quotient 0xffffffffd5555556, remainder -2.
  • DIV 0xffffffff00000000, 2 should return 0xffffffff80000000, remainder 0. The divider returns 0x0000000080000000.

DIVU 0x0000000080000000, 3 returns quotient 0x000000002aaaaaaa, remainder 2. DIVU and REMU do not use this sign-correction logic.

The magnitude path uses the operand’s top bit in VX_serial_div.sv:

wire negate_numer = is_signed && numer[i][WIDTHN-1];
wire negate_denom = is_signed && denom[i][WIDTHD-1];

The quotient and remainder sign-correction flags instead use bit 31 in VX_serial_div.sv:

inv_quot[i] <= (denom[i] != 0) && is_signed && (numer[i][31] ^ denom[i][31]);
inv_rem[i]  <= is_signed && numer[i][31];

For 0x0000000080000000, the magnitude path treats the operand as positive, but the bit-31 tests incorrectly negate the quotient and remainder. For 0xffffffff00000000, the magnitude path takes the absolute value of a negative operand, but the bit-31 test fails to negate the quotient afterward.

The sign-correction tests should use numer[i][WIDTHN-1] and denom[i][WIDTHD-1], matching the magnitude path.

The default rtlsim build does not exercise this divider. VX_define.vh defines IDIV_DPI when SV_DPI is set and SYNTHESIS is not; that path uses DPI division instead of VX_serial_div. The bug affects the synthesizable divider and non-DPI RTL builds.

Environment: commit 1061088aa.

主要语言
Verilog
星标
2.4k
派生
563
平均合并
2 天 12 小时
30 天内合并 PR
33

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

vortexgpgpu/vortex 的其他 Issue

查看 vortexgpgpu/vortex 的全部 Issue

相似的 Issue

更多 HPC Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。