Learning BSV‎ > ‎Attributes‎ > ‎

preempts Attribute

Overview

The preempts attribute is used to prevent a rule from firing whenever another rule (or set of rules) fires.

The preempts attribute accepts two elements as arguments. Each element may be either a rule name or a list of rule names. A list of rule names must be separated by commas and enclosed in parentheses. In each cycle, if any of the rule names specified in the first element can be executed and are scheduled to fire, then none of the rules specified in the second element will be allowed to fire.

Attribute Syntax

If r1 will fire, r2 will not.

 (* preempts = "r1, r2" *)

If either r1 or r2 (or both) will fire, r3 will not.

 (* preempts = "(r1, r2), r3" *)

The preempts attribute is similar to the descending_urgency attribute and may occur in the same syntactic positions. The preempts attribute is equivalent to forcing a conflict and adding descending_urgency.

Once difference, is that with the descending_urgency attribute, if two rules do not conflict, then both would be allowed to fire even if an urgency order had been specified; with the preempts attribute, if one rule preempts the other, they can never fire together. If rule1 preempts rule2, then the compiler forces a conflict and gives rule1 priority. If rule1 is able to fire, but is not scheduled to, then rule2 can still fire.

BSV Example

interface IfcCounter#(type t);
method t readCounter;
endinterface

typedef Bit#(16) CounterType;

(* synthesize,
always_ready = "readCounter",
always_enabled= "readCounter" *)
module counter (IfcCounter#(CounterType));

Reg#(CounterType) counter <- mkRegA(1);

/* The preempts attribute will prevent the updateCounter
rule from firing when resetCounter fires */
(* preempts = "resetCounter, updateCounter" *)
rule resetCounter (counter == '1);
action
counter <= 1;
endaction
endrule

rule updateCounter;
action
counter <= counter + 1;
endaction
endrule

method CounterType readCounter;
return counter;
endmethod
endmodule
Comments