-
Notifications
You must be signed in to change notification settings - Fork 117
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
Incorrect FCVT.W.D Signed Integer Conversion for Negative Double-Precision Input #145
Comments
I would expect that |
Also @Sufyan-Ahmed1, please provide some more information, what is your setup, simulator in use, etc? |
The input operand in question (0xC1E0000000000000) is a double precision FP number with sign bit set, an exponent (with bias) of 31, and a 0 mantissa, which corresponds to the real number
I assume that Lines 240 to 242 in 0ad2cd7
However, AFAICT these do no harm, since these upper 32 bits will be disregarded anyways. |
@Sufyan-Ahmed1 The purpose of this statement, as indicated by the comment just above it, is to convert an absolute integer result to a signed integer result in two's complement notation: Lines 599 to 601 in 0ad2cd7
For this particular value, the statement has no effect, because the lower 32 bits (the relevant portion) of Spike is probably sign-extending the 32-bit result to 64-bit when printing it, but only the lower 32 bits are relevant here, so the result is correct. |
According to the RV64I spec, 32-bit results are to be sign-extended on RV64:
Even unsigned 32-bit values are sign-extended in RV64I. I believe there is an issue somewhere as the rounded_abs shouldn't be sign-extended itself, maybe we just hit a corner case with the largest magnitude negative integer (which doesn't have a positive unsigned counterpart) |
Hi @michael-platzer RTL Behavior: It is evident that the RTL performs a 2's complement operation on the absolute result. However, I am concerned about how this would impact scenarios involving a series of conversion instructions. Specifically, if the subsequent instruction processes the 64-bit register produced by the current instruction (e.g., 0x000000080000000), could this potentially propagate a bug? Spike Discrepancy: While the RTL’s output seems mathematically correct, spike generates the result with sign negation. I am not entirely sure about their implementation, but this behavior appears inconsistent with the RTL. |
Yes, this is where I stuck, because I was running regressions against spike as standard on Vivado and thus, when these mismatches are leading to test failure. |
I am running some torture_tests regressions on Vivado against spike as standard, and thus, when this corner case hit, test lead to failure. |
Ok, I see. In that case, the sign extension should probably happen after the conversion from absolute to signed result. I agree that it is a corner case. However, the largest magnitude negative signed integer does actually have a positive unsigned counterpart: |
What is the purpose of this statement? if this is inverting the obtained answer...
assign rounded_int_res = rounded_sign ? unsigned'(-rounded_abs) : rounded_abs;
The text was updated successfully, but these errors were encountered: