RV64 signed DIV/REM restores the sign from bit 31

Aperta Adatta ai principianti
#501 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
70/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Ambito
hpc

Direzione di ricerca

Il bug è in VX_serial_div.sv: il percorso della magnitudine usa il bit WIDTHN-1 / WIDTHD-1 (intorno alle righe 53-56), ma i flag di segno del quoziente e del resto usano il bit 31 (intorno alle righe 82-83). Inizia leggendo entrambi i blocchi, poi compila senza il divisore DPI (SV_DPI non impostato o SYNTHESIS impostato) in modo che VX_serial_div venga esercitato. Fatto quando i test di correzione del segno usano numer[i][WIDTHN-1] e denom[i][WIDTHD-1], e i casi RV64 DIV nell'issue restituiscono il quoziente e il resto attesi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Verilog
Stelle
2.4k
Fork
563
Merge medio
2g 12h
PR unite (30g)
33

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di vortexgpgpu/vortex

Tutte le issue di vortexgpgpu/vortex

Issue simili

Altre issue su HPC

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.