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 

Parallel read of Vector

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



Joined: 17 Aug 2013
Posts: 9

PostPosted: Mon Dec 28, 2015 9:05 am    Post subject: Parallel read of Vector Reply with quote

Hi i have a vector of registers,
I want to search through the vector in parallel, so i have a rule for each index in the vector and each of the rule checks if the value is what im looking for,
But how can i move the result further? i cant have all the rules write the result to the same place

Thanks
Back to top
View user's profile Send private message Send e-mail
quark
Site Admin


Joined: 02 Nov 2007
Posts: 500

PostPosted: Sun Jan 03, 2016 4:11 pm    Post subject: Re: Parallel read of Vector Reply with quote

All of the rules can write to the same place, but only one value will be written. The mkReg modules in BSC are defined to allow multiple rules to write to the same register:
Code:
rule r1;
  rg <= 1;
endrule

rule r2;
  rg <= 2;
endrule

Both of these rules are allowed to execute in a clock cycle, as long as the resulting state looks like they executed in sequence. Whichever rule executed first in the sequence will have its value over-written by the second rule in the sequence. If there is no other requirement on the sequence order, in the code, then you can specify the order with an attribute:
Code:
(* execution_order="r1,r2" *)

This will give priority to rule 'r2' to write its value last.

If two rules cannot execute in the same clock cycle, that's a different situation. In that case, giving priority to one rule doesn't mean putting it first in the execution order -- only one rule will execute, and the other rule will be blocked and will not execute. For example, here are rules that cannot execute together (because they read and write the same register, not just write):
Code:
rule r1;
  rg <= rg + 1;
endrule

rule r2;
  rg <= rg + 2;
endrule

To specify a priority in this case, you would use an urgency attribute:
Code:
(* descending_urgency="r2,r1" *)

That specifies that 'r1' should have priority to execute, and should block 'r2' (if they conflict).

However, there's no reason that you need to have separate rules. Why not perform it all in one rule?

Here's how I would write it:
Code:
Vector#(N,Reg#(T)) rgs_inp <- replicateM(mkRegU);
Reg#(T) rg_res <- mkRegU;

rule do_lookup;
  T res = null_value;
  for (Integer i=0; i<valueOf(N); i=i+1)
    if (match_func(rgs_inp[i]))
       res = rgs_inp[i];
  rg_res <= res;
endrule

This code will give priority to the register with the highest index (that matches the condition). If you want to give priority to the register with the lowest index, then loop from N-1 down to 0:
Code:
for (Integer i=valueOf(N)-1; i>=0; i=i-1)

Note that, in the for-loop, this code updates a local value. If we tried to write the register in the for-loop, that would be an error because this rule would be trying to write to the register multiple times. By updating a local variable and then writing the register once at the end, we avoid multiple writes in the same rule.

When you write actions in one rule, you are specifying that the actions must always occur together. If you write actions as separate rules, you are specifying that it's OK for some of the actions to execute and others not to execute -- some may execute multiple time before the others ever execute. This is probably not the behavior you intend, so you probably should write it as one rule, to be most correct.
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