-
Notifications
You must be signed in to change notification settings - Fork 173
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
Sail incorrectly sets flags on fcvtmod.w.d #388
Comments
The problem seems to be in line 748 of
This line sets invalid flag if the exponent is 32 or more. As I understand the code, it would set invalid for inputs >= 1.0 x 2^32 or <= -1.0 x 2^32. According to the Zfa specification, "Floating-point exception flags are raised the same as they would be for FCVT.W.D with the same input operand." According to the unprivileged specification Table 11.4, the invalid exception should be set for inputs > 2^31 - 1 or < -2^31. |
For comparison, the relevant spike code is:
|
Hmm, I think the cover points missed this one, another edge case. We need
to review edge cases
…On Thursday, March 7, 2024, David Harris ***@***.***> wrote:
For comparison, the relevant spike code is:
https://github.com/riscv-software-src/riscv-isa-sim/blob/
581e0da68541a20e6ba385acd2b9dcee2358176e/riscv/insns/fcvtmod_w_d.h#L1
/* Handle overflows
*/ if (true_exp > 31 || frac > (sign ? 0x80000000ull : 0x7fffffff)) { /*
Overflow, for which this operation raises invalid.
*/ invalid = true; inexact = false; /* invalid takes precedence */
}
—
Reply to this email directly, view it on GitHub
<#388 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHPXVJQBHKGXMJTHTN57GX3YW7HRHAVCNFSM6AAAAABBZL2HDSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBSGIZTGMBTGU>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
fcvtmod.w.d sets the flags differently in Sail and Spike on one of the test cases in the draft Zfa riscv-arch-test rv32i_m/D_Zfa/src/fcvtmod.w.d_b22-01.S at inst_34. I believe Sail is incorrect.
Performing fcvtmod.w.d on 0xc1ee9b7e5fc9eba4 sets the inexact flag from Sail, but the invalid flag from Spike. This number is an ordinary negative double-precision floating-point number (-4.10806e+09) that is outside the range that can be represented by a 32-bit 2's complement number. According to the IEEE754-2019 spec at page 39, "When a numeric operand would convert to an integer outside the range of the destination format, the invalid operation exception shall be signaled if this situation cannot otherwise be indicated. When the value of the conversion operation’s result differs from its operand value, yet is representable in the destination format, some conversion operations are specified below to signal the inexact exception and others to not signal the inexact exception." According to the riscv-zfa fcvtmod.w.d spec in Section 26.4, "Floating-point exception flags are raised the same as they would be for FCVT.W.D with the same input operand." Therefore, it seems that the Invalid operation flag should be set, as Spike does.
I've attached a test case called my.elf that was generated by riscof when compiling this test. The issue can be reproduced with:
For reference, the test is:
my.elf.gz
The text was updated successfully, but these errors were encountered: