-
Notifications
You must be signed in to change notification settings - Fork 154
Fix mkFixedPointSquareRooter and add safe-guard to mkSquareRooter #148
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this. I apologize that your submission on the forums fell through the cracks. I have some test cases that confirm that mkSquareRooter
only works for even sizes and that mkFixedSizeSquareRooter
is broken, and that your version does work. I'm not familiar with this design or algorithm, so I can't say if this is the best way to fix it; but it seems reasonable to accept it (with a few cleanups). Since it was broken, I expect that no one was using it, so there's no one to mind.
I showed your changes to someone who is more familiar with the module. He welcomes this fix but thinks it is written in an unnecessarily complicated way. He proposes the following patch (to the original code):
In place of this proviso that your version needs:
this version only needs this proviso:
which I think is just a roundabout way to require that What do you think of this version? I have not had a chance to digest these new changes, yet, to understand the difference. |
Looks like it implements the same logic as mine but in a much less convoluted way. Please say thanks to this person. These I have force-pushed a new commit integrating the suggested changes to my other fixes. |
Thanks again for this. I hacked together some tests for these modules, which I'll add to the testsuite (in The tests include random inputs on a few instances of each module and a check that each result is within expected error. For |
This patch:
Adds provisos as a safe-guard to
mkSquareRooter
, forcing the designer to choose an even number of bits for the integer type (UInt#(m)
). The implementation works inm/2
iterations and doesn't seem to work for odd values ofm
.Fixes the logic which computes the amount of shift in
mkFixedPointSquareRooter
, which currently gives results far off from what would be expected (e.g. sqrt(0.5)==0.0 and sqrt(0.25)==0.0).Fixes the test bench, which currently displays the runtime computed values as "expected", and compile-time computed values as the operation result. Also, adds two new test values for
mkFixedPointSquareRooter
.I don't know if my solution is optimal. I have written it some years ago and submitted it to the forums when Bluespec was proprietary. Suggestions are welcome!