bluespec.com Forum Index bluespec.com
Bluespec Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Patch: Fix for bug in mkFixedPointSquareRooter

 
Post new topic   Reply to topic    bluespec.com Forum Index -> Designing with BSV's Rules, Interfaces, ...
View previous topic :: View next topic  
Author Message
matias



Joined: 11 Nov 2013
Posts: 6

PostPosted: Fri Dec 02, 2016 8:39 am    Post subject: Patch: Fix for bug in mkFixedPointSquareRooter Reply with quote

Sorry guys, I don't know if this is the right section of the forum to post this.

The mkFixedPointSquareRooter module which comes in the SquareRoot package is currently broken. It doesn't provide results even close to the expected ones.

Thus, we have reimplemented the logic that computes the amount of shift which needs to be applied over the result of the integer division. The new logic is explained in the comments included in the attached SquareRoot.bsv file.

Besides that, we also did a few other modifications:

  • Added provisos to mkSquareRooter which force the designer to choose an even number of bits for the integer type (UInt#(m)). The implementation works in m/2 iterations and doesn't seem to work for odd values of m.
  • Fixed the test bench, which used to display the runtime computed values as "expected", and compile-time computed values as the operation result.


A point of the code which I'd like to ask quark or someone if it could be improved is this:

Code:
      if (shift >= 0)
         result = result >> shift;
      else  // invert direction if shift is negative
         result = result << (-shift);


Is there any cleaner way to express this? The original code was just "result = result >> shift", but the ">>" operator seems not to accept a negative shift (it just overflows and the result becomes zero).

Attached are the new (fixed) SquareRoot.bsv file, and a diff from the original one which comes in the Bluespec-2014.07.A distribution. Please feel free to use, modify, or derive from my changes in order to fix this issue in a future Bluespec release.



SquareRoot.txt
 Description:
Differences from the original SquareRoot.bsv file (Bluespec-2014.07.A). Sorry for the extension, the forum doesn't allow .diff or .patch.

Download
 Filename:  SquareRoot.txt
 Filesize:  4.15 KB
 Downloaded:  148 Time(s)


SquareRoot.bsv
 Description:
Fixed SquareRoot.bsv

Download
 Filename:  SquareRoot.bsv
 Filesize:  6.84 KB
 Downloaded:  102 Time(s)

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    bluespec.com Forum Index -> Designing with BSV's Rules, Interfaces, ... All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
bluespec.com topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP