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 

Convert a vector to a register

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



Joined: 28 May 2017
Posts: 1

PostPosted: Fri Jun 09, 2017 8:38 am    Post subject: Convert a vector to a register Reply with quote

I have a vector of 4 1-bit registers x ,and a register of 4bits y.

What should I use to assign each bit of x to y in one cycle.

I mean I can do this
Code:

y[0] = x[0];
y[1] = x[1];

and so on. but since in a rule we can have only one write at a time it can't be done in a single cycle
Back to top
View user's profile Send private message
quark
Site Admin


Joined: 02 Nov 2007
Posts: 493

PostPosted: Fri Aug 18, 2017 5:10 pm    Post subject: Re: Convert a vector to a register Reply with quote

You can declare a local variable, which can be written to multiple times, and then you can commit the final value to the register in one write. For example:
Code:
Vector#(4,Reg#(Bit#(1))) x <- replicateM(mkRegU);
Reg#(Vector#(4,Bit#(1))) y <- mkRegU;

rule x_to_y;
  // This won't work
  //for (Integer i=0; i<4; i=i+1)
  //  y[i] <= x[i];

  // Instead, declare a local variable
  Vector#(4,Bit#(1)) new_y;
  // If you needed to, you could even assign the current value to it
  //Vector#(4,Bit#(1)) new_y = y;

  // Write to it in multiple steps
  for (Integer i=0; i<4; i=i+1)
    new_y[i] = x[i];

  // Write the value back to the register
  y <= new_y;
endrule

You
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