-
Notifications
You must be signed in to change notification settings - Fork 115
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
Underflow flag not set at subnormal/normal boundary #94
Comments
Hi @gregdavill Thanks for reporting this. For FDIV, I submitted an issue in T-Head-Semi/opene906 github repo #5. |
Hey @pascalgouedo, Thanks for confirming. 👍 I was planning on opening a ticket upstream too, but figured I'd submit the PR here first and get input. and since you already have in repo patches applied to the opene906 div/sqrt unit. |
Ah ok. Sorry to have "bypassed" you. |
Ohh. That was detected by testfloat (http://www.jhauser.us/arithmetic/TestFloat-3/doc/TestFloat-general.html). But I didn't mention it in this issue as it's already been reported. testfloat reports it like so:
Thanks for the reminder, I was meaning to open a PR with a fix #97 |
Great. I am going to launch formal verification on it and will let you know. |
I'm not sure I understand the issue correctly. RISC-V mandates detecting tininess after rounding, while your TestFloat results appear to indicate the detection of tininess before rounding. After rounding, the result is exactly This boundary case where an infinitely precise subnormal result is rounded to the smallest normal value is the only difference between detecting tininess before or after rounding - in the former case it will raise the flag while in the latter (and RISC-V) it won't. |
@gregdavill did you run testfloat with the |
Thanks for you comments @stmach, this was picked up with testfloat/softfloat configured with I'm not an expert at the floating point standard, so I may have misinterpreted the spec, and how softfloat handles this. I'm basing this issue and the fix on the wording in the spec, which specifically mentions an unbounded exponent range for detecting tininess before rounding.
This is the lines in softfloat responsible for flagging underflow. It checks this case, if the significant would overflow resulting in a normal result, the rounding bits flag an underflow. |
Hi, |
All right, after some more thought and single-stepping through the SoftFloat execution, I see my error. I have been conflating "rounding" which strictly only concerns limiting precision to Since the infinitely precise results in the examples would not overflow into the normal range from rounding to 24 bits of precision alone, they are indeed still considered tiny after this rounding step, despite later being flushed into the normal range after losing a bit of precision due to being subnormal. Sorry @gregdavill for causing a stir, the devil is (as always with FP) in the details😅 |
No worries, I was also confused when I first saw this error reported by softfloat, because I had the same connection of rounding as you, covering both precision and exponent bits. Thanks for your expertise and taking a further look into this. |
Fixed with release |
Background
I've been running functional tests/validation on this fpu, by running test vectors generated by testfloat. http://www.jhauser.us/arithmetic/TestFloat.html
I've noticed a class of bugs around the underflow flag. Here are some errors produced by testfloat:
This effects the FMA operations using the Multiply operation, (MUL, F[N]MADD, F[N]MSUB). And the DIV operation (Using t-head div/sqrt)
This bug shows up for all rounding modes except RTZ.
Issue
The fact that this does not effect the RTZ rounding mode led me to this statement in the spec:
This bug is the corner case, where the final result is +/-b^emin, but the unbounded exponent range lies strictly between +/-b^emin. In this case it appears that the underflow flag should be set, which is what happens in softfloat, but not happening in the FMA or t-head DIV unit.
In RTZ mode you can never hit the case where you round from a subnormal result into a normal result.
The text was updated successfully, but these errors were encountered: