RV64 signed DIV/REM restores the sign from bit 31

オープン 初心者向け
#501 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
70/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
領域
hpc

調査の方向性

バグは 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時間
マージ済み PR(30日)
33

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

vortexgpgpu/vortex のほかの issue

vortexgpgpu/vortex の issue をすべて見る

似ている issue

HPC の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。