 |
bluespec.com Bluespec Forums
|
View previous topic :: View next topic |
Author |
Message |
chiraag
Joined: 06 Aug 2011 Posts: 29
|
Posted: Sun Feb 23, 2014 8:25 pm Post subject: Static Elaboration Bug with Numeric Types |
|
|
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 |
|
 |
quark Site Admin
Joined: 02 Nov 2007 Posts: 499
|
Posted: Mon Feb 24, 2014 1:27 am Post subject: Re: Static Elaboration Bug with Numeric Types |
|
|
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 |
|
 |
|
|
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
|
Powered by phpBB © 2001, 2005 phpBB Group
|