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 

Floating Point Comparison Conundrum

 
Post new topic   Reply to topic    bluespec.com Forum Index -> Tools: BSC (Bluespec Compiler)
View previous topic :: View next topic  
Author Message
NCCMoore



Joined: 10 Jul 2012
Posts: 6

PostPosted: Tue May 24, 2016 2:14 pm    Post subject: Floating Point Comparison Conundrum Reply with quote

Hello,

I'm having a great deal of difficulty trying to get a module to compile. The problem appears to be my use of floating point comparison operators. Whenever I try to use anything that calls "compare" in FloatingPoint.bsv, I get the following error:

Quote:

Error: "FloatingPoint.bsv", line 956, column 86: (S0015)
Bluespec evaluation-time error: Unordered comparison of type
`FloatingPoint'.
During elaboration of the body of rule `reset_count' at "DELAY.bsv", line
24, column 10.
During elaboration of `mkDELAY' at "DELAY.bsv", line 11, column 10.[/list]


The problem seems to be that the registers being compared may be NaN, even if they have been properly initialized to values that are not NaN. Looking through the source, it doesn't look like I need to call a special function to compare floats or anything like that, so I'd like some advice. What is the correct way to compare two floating point registers/method arguments? Am I experiencing a bug? Is there a work-around?

RSVP!


-Nick[/quote]
Back to top
View user's profile Send private message
quark
Site Admin


Joined: 02 Nov 2007
Posts: 499

PostPosted: Wed May 25, 2016 2:09 pm    Post subject: Re: Floating Point Comparison Conundrum Reply with quote

Hm. It appears that the implementation of the Ord operators is only for compile-time computation. When you try to use them on dynamic values (from registers or other state), you get this error.

My suggestion for a workaround is to not use the comparison operators on dynamic values and instead to use "compareFP'. Instead of the usual LT, GT, or EQ that the "compare" function returns, "compareFP" can return a fourth value, UO, when either input is NaN. By calling "compareFP", you can explicitly specify what the logic should do in that case.

The definition of "compare" for FloatingPoint calls "compareFP" and branches with a case statement on the result. If the inputs are known at compile-time, BSC can execute the appropriate branch. If the inputs are not known (because they will come from registers), then BSC must generate logic for all of the branches, and that includes the UO branch, which triggers an error. You'll need to write your own case statement that doesn't error in the UO branch. If you know that the values will never be NaN, you can tell BSC that the result of that branch doesn't matter, by returning "?" (a don't-care value).
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    bluespec.com Forum Index -> Tools: BSC (Bluespec Compiler) 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