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 

Compilation Issue with $bitstoreal, $realtobits

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



Joined: 05 May 2009
Posts: 2

PostPosted: Tue May 05, 2009 8:31 pm    Post subject: Compilation Issue with $bitstoreal, $realtobits Reply with quote

Hi All,

I am trying to implement Gaussian Elimination and the code needs to work with Real values. More especifically, I'm trying to use $bitstoreal to get values from array of Registers and $realtobits to store values back to registers.

For some reasons, I can not compile the code to generate veriog file. Below is the part of my code that is giving trouble. If I comment out some statements, the compiler works fine. I have indicated such statements in the code.

Can you suggest me about whether I'm missing something and/or whether there is a way around this problem? I am also wondering about whether using arrays of registers and real-value functions at the same time is responsible for not generating verilog file.

=== CODE:
Code:


Reg#(Bit#(64)) matrix_A[4][5];
   
for(Integer i=0; i<4; i=i+1)
    for(Integer j=0; j<5; j=j+1)
          matrix_A[i][j]<-mkRegU;
   
//... more code
(* execution_order = "load_matrix_A, load_matrix_B, do_elimination" *)
   
// ... more code to load Matrix-A and Matrix-B with Integer values
   
rule do_elimination (ctr == 10);
     Real mult_factor;   
     Real calc_value;
      
    // Dummy values
    Integer iloop = 2; Integer jloop = 3; Integer kloop = 0;   
    mult_factor = 1.2;
               
    let tmp_Matrix = matrix_A[0][0];
    tmp_Matrix[63:0] = 0;
      
    calc_value = $bitstoreal(matrix_A[iloop][kloop]) - (mult_factor *
                           $bitstoreal(matrix_A[jloop][kloop]));

    tmp_Matrix = $realtobits(calc_value);   
       //When the above line is commented out, the compiler generates .v pretty fast
      
      //The following line has the same issue
      //tmp_Matrix = $realtobits($bitstoreal(matrix_A[iloop][kloop]) - (mult_factor * $bitstoreal(matrix_A[jloop][kloop])));
      
     matrix_A[iloop][jloop] <= tmp_Matrix;
      
endrule:do_elimination


== CODE ENDS

For compilation, I'm using:
bsc -verilog Attempt3.bsv;

I also tried the following compiler option without any success:
bsc -sim -g mkTb Attempt3.bsv;
Back to top
View user's profile Send private message
quark
Site Admin


Joined: 02 Nov 2007
Posts: 496

PostPosted: Wed May 06, 2009 12:14 pm    Post subject: Reply with quote

BSC only supports compile-time Real numbers. That is, static computation of Real numbers or Real numbers as module parameters. It does not support dynamic use of Real numbers. That is, mathematical functions (like add, multiply, etc) and conversion or inspection functions (like $realtobits) cannot occur at simulation time. They must complete at compilation time.

If you want real numbers in your simulation, you have two options.

(1) If you only need simulation (and not synthesizable), then you can use import-BDPI to import C functions which perform the math. You would import functions like:
Code:
import "BDPI" function Bit#(64) realAdd(Bit#(64), Bit#(64));
import "BDPI" function Bit#(64) realMul(Bit#(64), Bit#(64));

These imported C functions can be used in both Verilog simulation and Bluesim simulation.

(2) You can also create a synthesizable data type for IEEE numbers and write real hardware functions for performing the adds and multiplies. You would do it in the same way that the FixedPoint library implements fixed point numbers (so you could use the FixedPoint code as a starting point).
Back to top
View user's profile Send private message
joydip



Joined: 05 May 2009
Posts: 2

PostPosted: Wed May 06, 2009 5:00 pm    Post subject: Reply with quote

Thanks for the suggestions. I will use FixedPoint library package for synthesis. It works fine with preliminary test-code.

Joydip
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