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 

Static Elaboration Bug with Numeric Types

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



Joined: 06 Aug 2011
Posts: 29

PostPosted: Sun Feb 23, 2014 8:25 pm    Post subject: Static Elaboration Bug with Numeric Types Reply with quote

There seems to be a bug with the fromValue function with regards to complicated functions applied to numeric types.

Here is a sample bug:
Code:

typedef TMul#(TMul#(2, TDiv#(1200, 4)), TDiv#(3, 2)) NineHundred;

module mkBugTB(Empty);
    rule fin;
        Bit#(10) ninehundred = fromInteger(valueOf(NineHundred));
        $display($stime, "\t", ninehundred);
        $finish;
    endrule
endmodule


bsc output:
Code:

Error: "BugTB.bsv", line 5, column 44: (T0051)
  Literal 1200 is not a valid Bit#(10).
  During elaboration of the body of rule `fin' at "BugTB.bsv", line 4, column
  10.
  During elaboration of `mkBugTB' at "BugTB.bsv", line 3, column 8.
'bsc' exited with status 1


In this case it is quite clear the typedef evaluates to a value that will eventually fit the specified data type but bsc complains prematurely. It is not easy to reproduce this bug with arbitray expressions. For example:
Code:

typedef TMul#(TMul#(2, TDiv#(1200, 4)), TDiv#(3, 2)) NineHundred; // Error
typedef TMul#(TMul#(2, TDiv#(1200, 4)), TDiv#(3, 3)) SixHundred; // Works


Any ideas?
Back to top
View user's profile Send private message
quark
Site Admin


Joined: 02 Nov 2007
Posts: 495

PostPosted: Mon Feb 24, 2014 1:27 am    Post subject: Re: Static Elaboration Bug with Numeric Types Reply with quote

The behavior is correct. TDiv performs integer division -- when you apply TDiv#(3,2) you cannot get a fractional result like 1.5, so it is not possible to multiply the result by 600 to get 900. The result of the division must either be 1 or 2, and (as documented in the Reference Guide) the Div typeclass (and TDiv type function) uses the ceiling. So TDiv#(3,2) would equal 2. So your definition for NineHundred is in fact the value 1200.
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