RV64 signed DIV/REM restores the sign from bit 31

Đang mở Phù hợp với người mới
#501 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
70/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Lĩnh vực
hpc

Hướng nghiên cứu

Lỗi nằm trong VX_serial_div.sv: đường xử lý độ lớn dùng bit WIDTHN-1 / WIDTHD-1 (khoảng dòng 53-56), nhưng các cờ dấu của thương và số dư dùng bit 31 (khoảng dòng 82-83). Hãy bắt đầu bằng việc đọc cả hai khối, sau đó build mà không có bộ chia DPI (SV_DPI không được đặt hoặc SYNTHESIS được đặt) để VX_serial_div được chạy. Hoàn thành khi các test hiệu chỉnh dấu dùng numer[i][WIDTHN-1] và denom[i][WIDTHD-1], và các case RV64 DIV trong issue trả về thương và số dư như kỳ vọng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Verilog
Star
2.4k
Fork
563
Merge trung bình
2 ngày 12 giờ
Pull request đã merge (30 ngày)
33

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của vortexgpgpu/vortex

Tất cả issue của vortexgpgpu/vortex

Issue tương tự

Thêm issue về HPC

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.