Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cast: fix conversion to signed integer #97

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/fpnew_cast_multi.sv
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,11 @@ module fpnew_cast_multi #(
// By default right shift mantissa to be an integer
denorm_shamt = unsigned'(MAX_INT_WIDTH - 1 - input_exp_q);
// overflow: when converting to unsigned the range is larger by one
if (input_exp_q >= signed'(fpnew_pkg::int_width(int_fmt_q2) - 1 + op_mod_q2)) begin
if ((input_exp_q >= signed'(fpnew_pkg::int_width(int_fmt_q2) - 1 + op_mod_q2)) // Exponent larger than max int range,
&& !(!op_mod_q2 // unless cast to signed int
&& input_sign_q // and input value is larges negative int value
&& (input_exp_q == signed'(fpnew_pkg::int_width(int_fmt_q2) - 1))
&& (input_mant_q == {1'b1, {INT_MAN_WIDTH-1{1'b0}}}))) begin
denorm_shamt = '0; // prevent shifting
of_before_round = 1'b1;
// underflow
Expand Down