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 

testbench problem

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



Joined: 29 May 2012
Posts: 56

PostPosted: Sun Jun 24, 2012 7:28 am    Post subject: testbench problem Reply with quote

hey,
this is my testbench
Code:

import Pmult3::*;
import Vector::*;

(* synthesize *)

module mkTbPmult3();

   Ifc_Pmult3 ifc_pmult3 <- mkPmult3;

   Reg#(Bit#(16)) state <- mkReg(0);



   rule step0(state == 0);



       Bit#(10) x = 'b101;
       Bit#(10) y = 'b011;

       Bit#(4)  exp1= 'b10;
       Bit#(4)  exp2= 'b01;

       ifc_pmult3.mult1(x,y);

       $display("Result is %b", ifc_pmult3.mult2);

       $display("The final exp is %b", ifc_pmult3.exp(exp1, exp2));

       $finish;



   endrule




endmodule



interface Ifc_Pmult3;


method Action mult1(Bit#(10) x, Bit#(10) y);
method Bit#(10) mult2();
method Bit#(4) exp(Bit#(4) exp1, Bit#(4) exp2);


endinterface

(* synthesize *)

module mkPmult3(Ifc_Pmult3);

Reg#(Bit#(10)) result<-mkReg(0);



////////////////////////////////////////////////////////////



method Action mult1(Bit#(10) x, Bit#(10) y);

result<=x*y; // it does not enter in result the x*y value why?

endmethod




I am using an interface module that do multiplcation between two binary numbers but I get this in result:0000000000000 ,zeros all the time despite the fact that I send two numbers differnet from zero as shown above where is the problem Question
Back to top
View user's profile Send private message
flashdisk



Joined: 29 May 2012
Posts: 56

PostPosted: Mon Jun 25, 2012 3:28 am    Post subject: Reply with quote

please I need an answer as fast as possible! Crying or Very sad
Back to top
View user's profile Send private message
quark
Site Admin


Joined: 02 Nov 2007
Posts: 500

PostPosted: Mon Jun 25, 2012 2:13 pm    Post subject: Reply with quote

"result" is a register. The value written to a register is not available to be read until the next clock cycle. When you call "mult2" in the same rule, the value it reads is the old value of the register, before the new value is written.

When the rule executes, the initial value "0" is read from the register and a new value (5 * 3 = 15) is written to the register. But the rule also calls "$finish", so there is never an opportunity to read the value "15" from the register in the next clock cycle.
Back to top
View user's profile Send private message
flashdisk



Joined: 29 May 2012
Posts: 56

PostPosted: Mon Jun 25, 2012 2:24 pm    Post subject: Reply with quote

thanks for ur help,but is there any way to get the result in the same clockcycle ,is there any thing instead of registers?
Back to top
View user's profile Send private message
quark
Site Admin


Joined: 02 Nov 2007
Posts: 500

PostPosted: Mon Jun 25, 2012 2:37 pm    Post subject: Reply with quote

My recommendation is to not use two separate methods. Use one method:
Code:
method Bit#(10) mult1(Bit#(10) x, Bit#(10) y);
   return (x*y);
endmethod

Otherwise, you can instantiate a wire instead of a register. However, you would need to be careful to make sure that a value is read only when one is written. So you might need to use "mkWire" which will include an implicit condition. But I recommend using a single method, as above.
Back to top
View user's profile Send private message
flashdisk



Joined: 29 May 2012
Posts: 56

PostPosted: Mon Jun 25, 2012 2:42 pm    Post subject: Reply with quote

if I but the $finish in another rule step2 will it solve the problem?
I need the 'result' to use in another method if the method returns x*y I will not be able to use the 'x*y' for the other method!
Back to top
View user's profile Send private message
quark
Site Admin


Joined: 02 Nov 2007
Posts: 500

PostPosted: Mon Jun 25, 2012 3:08 pm    Post subject: Reply with quote

If you put the read in another rule, you will still need a signal to indicate that the result came from a computation (in "mult1") -- because you don't want to read the initial value of the register and then finish, you want to wait until data is written first. You can either do this with a FIFO (which will be empty until a value is enqueued into it), or you can record the validity of the value in the register with another bit of state. For instance, you can store a value of type Maybe#(Bit#(10)) in the register, and initialize it with "tagged Invalid". Then, when you write a value, you will write "tagged Valid val".

Alternatively, you can use a wire, and the wire value will be available to be read by more than one method.

Or, you can combine the third method with the first two. Instead of returning one value, the method can return two values (corresponding to both "mult2" and "exp").
Back to top
View user's profile Send private message
flashdisk



Joined: 29 May 2012
Posts: 56

PostPosted: Mon Jun 25, 2012 3:34 pm    Post subject: Reply with quote

Is the WIRE the same as register it meant how can I define a wire that holds 10 bits like the register above?
Back to top
View user's profile Send private message
quark
Site Admin


Joined: 02 Nov 2007
Posts: 500

PostPosted: Tue Jun 26, 2012 6:14 pm    Post subject: Reply with quote

There are several varieties of wire modules, but here is one way:
Code:
Wire#(Bit#(10)) result <- mkWire();
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