fpu: detect RV64 FCVT.WU.D overflow on a round-up to 2^32

Open
#500 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@zzf2024 is already working on this.

Since Nov 29, 2026.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Domain
embedded-iot

Research direction

Start in hw/rtl/fpu/VX_fcvt_unit.sv around lines 632-634, at round_carry_out_s5 and f2i_u32_pos_ovf. Trace how input_sign_s5, unpacked_exp_s5, dst_l_s5, and rounded_abs_s5 are formed for RV64 FCVT.WU.D; the pre-round exponent is 31 while rounding carries the magnitude to 2^32. Reproduce with input 0x41effffffff00000 and frm=RNE, then extend the unsigned overflow condition to cover a rounded value of 2^32, expecting 0xffffffffffffffff and NV set. Done means that case and the (2^32-1,2^32) interval are covered by the FPU tests.

Written by the indexing model from the issue text.

Description

On RV64 at commit 1061088aa, FCVT.WU.D of 4294967295.5 (0x41effffffff00000) with frm=RNE returns 0 and raises only NX. RNE rounds this value to 2^32, which is outside the unsigned 32-bit range. The result should be 0xffffffffffffffff and NV should be set.

The overflow check misses this case. On RV64, S_MAN_WIDTH is at least 64, so rounding to 2^32 does not wrap rounded_abs_s5 to zero; meanwhile, the pre-round exponent is 31. The conversion therefore takes the in-range path and writes the low 32 bits of 2^32, which are zero. The same issue affects values in (2^32-1, 2^32) that round to 2^32.

This is distinct from #430, which concerns FCVT.S.D overflow rounding and was fixed by #432. It is also distinct from the f2i_u32_pos_ovf zero-extension issue: that branch is reached only when overflow is detected, while this input does not trigger it.

In hw/rtl/fpu/VX_fcvt_unit.sv, round-up carry is counted as overflow only when the rounded magnitude wraps to zero:

wire round_carry_out_s5 = (rounded_abs_s5 == '0) && (|pre_round_abs_s5);
wire f2i_u32_pos_ovf = !is_signed_s5 && !dst_l_s5 && !input_sign_s5
                    && ((unpacked_exp_s5 >= S_EXP_WIDTH'(32)) || round_carry_out_s5);
Dominant language
Verilog
Stars
2.4k
Forks
563
Avg merge
1d 7h
Merged PRs (30d)
71

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vortexgpgpu/vortex

All issues in vortexgpgpu/vortex

Similar issues

More Embedded & IoT issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.