Skip to content

询问有关rule和descending_urgency的问题 #7

@zchliu

Description

@zchliu

在for循环中展开的rule要如何指定descending_urgency。比如说下面的一个程序,这个程序是将输入的数从小到大排好了序再输出,但是在编译的时候发现for循环里面写的rule发生冲突,虽然说编译器会自动帮我们指定descending_urgency,但是想问一下有没有比较方便的在for循环里面手动指定descending_urgency的方法。

报warning如下:

$ bsvbuild.sh -bs mkTestbench Testbench.bsv 
top module: mkTestbench
top file  : Testbench.bsv

bsc -sim -p +: -g mkTestbench -u Testbench.bsv 
checking package dependencies
compiling ./Utils.bsv
compiling ./Bubblesort.bsv
compiling Testbench.bsv
code generation for mkBubblesort_nt starts
Warning: "Testbench.bsv", line 31, column 8: (G0010)
  Rule "m_rl_swap_i" was treated as more urgent than
  "m_rl_swap_i_1". Conflicts:
    "m_rl_swap_i" cannot fire before "m_rl_swap_i_1":
      calls to m_xs_1.write vs. m_xs_1.read
    "m_rl_swap_i_1" cannot fire before "m_rl_swap_i":
      calls to m_xs_1.write vs. m_xs_1.read
Warning: "Testbench.bsv", line 31, column 8: (G0010)
  Rule "m_rl_swap_i_1" was treated as more urgent than
  "m_rl_swap_i_2". Conflicts:
    "m_rl_swap_i_1" cannot fire before "m_rl_swap_i_2":
      calls to m_xs_2.write vs. m_xs_2.read
    "m_rl_swap_i_2" cannot fire before "m_rl_swap_i_1":
      calls to m_xs_2.write vs. m_xs_2.read
Warning: "Testbench.bsv", line 31, column 8: (G0010)
  Rule "m_rl_swap_i_2" was treated as more urgent than
  "m_rl_swap_i_3". Conflicts:
    "m_rl_swap_i_2" cannot fire before "m_rl_swap_i_3":
      calls to m_xs_3.write vs. m_xs_3.read
    "m_rl_swap_i_3" cannot fire before "m_rl_swap_i_2":
      calls to m_xs_3.write vs. m_xs_3.read
Warning: "Testbench.bsv", line 31, column 8: (G0010)
  Rule "m_rl_swap_i_3" was treated as more urgent than
  "m_rl_swap_i_4". Conflicts:
    "m_rl_swap_i_3" cannot fire before "m_rl_swap_i_4":
      calls to m_xs_4.write vs. m_xs_4.read
    "m_rl_swap_i_4" cannot fire before "m_rl_swap_i_3":
      calls to m_xs_4.write vs. m_xs_4.read
Warning: "Testbench.bsv", line 31, column 8: (G0010)
  Rule "m_rl_swap_i_4" was treated as more urgent than
  "m_rl_swap_i_5". Conflicts:
    "m_rl_swap_i_4" cannot fire before "m_rl_swap_i_5":
      calls to m_xs_5.write vs. m_xs_5.read
    "m_rl_swap_i_5" cannot fire before "m_rl_swap_i_4":
      calls to m_xs_5.write vs. m_xs_5.read
Warning: "Testbench.bsv", line 31, column 8: (G0010)
  Rule "m_rl_swap_i_5" was treated as more urgent than
  "m_rl_swap_i_6". Conflicts:
    "m_rl_swap_i_5" cannot fire before "m_rl_swap_i_6":
      calls to m_xs_6.write vs. m_xs_6.read
    "m_rl_swap_i_6" cannot fire before "m_rl_swap_i_5":
      calls to m_xs_6.write vs. m_xs_6.read
Warning: "Testbench.bsv", line 31, column 8: (G0010)
  Rule "m_rl_swap_i_6" was treated as more urgent than
  "m_rl_swap_i_7". Conflicts:
    "m_rl_swap_i_6" cannot fire before "m_rl_swap_i_7":
      calls to m_xs_7.write vs. m_xs_7.read
    "m_rl_swap_i_7" cannot fire before "m_rl_swap_i_6":
      calls to m_xs_7.write vs. m_xs_7.read
Warning: "Testbench.bsv", line 31, column 8: (G0010)
  Rule "m_rl_swap_i_7" was treated as more urgent than
  "m_rl_swap_i_8". Conflicts:
    "m_rl_swap_i_7" cannot fire before "m_rl_swap_i_8":
      calls to m_xs_8.write vs. m_xs_8.read
    "m_rl_swap_i_8" cannot fire before "m_rl_swap_i_7":
      calls to m_xs_8.write vs. m_xs_8.read
Warning: "Testbench.bsv", line 31, column 8: (G0010)
  Rule "m_rl_swap_i_8" was treated as more urgent than
  "m_rl_swap_i_9". Conflicts:
    "m_rl_swap_i_8" cannot fire before "m_rl_swap_i_9":
      calls to m_xs_9.write vs. m_xs_9.read
    "m_rl_swap_i_9" cannot fire before "m_rl_swap_i_8":
      calls to m_xs_9.write vs. m_xs_9.read
Warning: "Testbench.bsv", line 31, column 8: (G0010)
  Rule "m_rl_swap_i_9" was treated as more urgent than
  "m_rl_swap_i_10". Conflicts:
    "m_rl_swap_i_9" cannot fire before "m_rl_swap_i_10":
      calls to m_xs_10.write vs. m_xs_10.read
    "m_rl_swap_i_10" cannot fire before "m_rl_swap_i_9":
      calls to m_xs_10.write vs. m_xs_10.read
Warning: "Testbench.bsv", line 31, column 8: (G0010)
  Rule "m_rl_swap_i_10" was treated as more urgent than
  "m_rl_swap_i_11". Conflicts:
    "m_rl_swap_i_10" cannot fire before "m_rl_swap_i_11":
      calls to m_xs_11.write vs. m_xs_11.read
    "m_rl_swap_i_11" cannot fire before "m_rl_swap_i_10":
      calls to m_xs_11.write vs. m_xs_11.read
Warning: "Testbench.bsv", line 31, column 8: (G0010)
  Rule "m_rl_swap_i_11" was treated as more urgent than
  "m_rl_swap_i_12". Conflicts:
    "m_rl_swap_i_11" cannot fire before "m_rl_swap_i_12":
      calls to m_xs_12.write vs. m_xs_12.read
    "m_rl_swap_i_12" cannot fire before "m_rl_swap_i_11":
      calls to m_xs_12.write vs. m_xs_12.read
Warning: "Testbench.bsv", line 31, column 8: (G0010)
  Rule "m_rl_swap_i_12" was treated as more urgent than
  "m_rl_swap_i_13". Conflicts:
    "m_rl_swap_i_12" cannot fire before "m_rl_swap_i_13":
      calls to m_xs_13.write vs. m_xs_13.read
    "m_rl_swap_i_13" cannot fire before "m_rl_swap_i_12":
      calls to m_xs_13.write vs. m_xs_13.read
Warning: "Testbench.bsv", line 31, column 8: (G0010)
  Rule "m_rl_swap_i_13" was treated as more urgent than
  "m_rl_swap_i_14". Conflicts:
    "m_rl_swap_i_13" cannot fire before "m_rl_swap_i_14":
      calls to m_xs_14.write vs. m_xs_14.read
    "m_rl_swap_i_14" cannot fire before "m_rl_swap_i_13":
      calls to m_xs_14.write vs. m_xs_14.read
Warning: "Testbench.bsv", line 31, column 8: (G0010)
  Rule "m_rl_swap_i_14" was treated as more urgent than
  "m_rl_swap_i_15". Conflicts:
    "m_rl_swap_i_14" cannot fire before "m_rl_swap_i_15":
      calls to m_xs_15.write vs. m_xs_15.read
    "m_rl_swap_i_15" cannot fire before "m_rl_swap_i_14":
      calls to m_xs_15.write vs. m_xs_15.read
Warning: "Testbench.bsv", line 31, column 8: (G0010)
  Rule "m_rl_swap_i_15" was treated as more urgent than
  "m_rl_swap_i_16". Conflicts:
    "m_rl_swap_i_15" cannot fire before "m_rl_swap_i_16":
      calls to m_xs_16.write vs. m_xs_16.read
    "m_rl_swap_i_16" cannot fire before "m_rl_swap_i_15":
      calls to m_xs_16.write vs. m_xs_16.read
Warning: "Testbench.bsv", line 31, column 8: (G0010)
  Rule "m_rl_swap_i_16" was treated as more urgent than
  "m_rl_swap_i_17". Conflicts:
    "m_rl_swap_i_16" cannot fire before "m_rl_swap_i_17":
      calls to m_xs_17.write vs. m_xs_17.read
    "m_rl_swap_i_17" cannot fire before "m_rl_swap_i_16":
      calls to m_xs_17.write vs. m_xs_17.read
Warning: "Testbench.bsv", line 31, column 8: (G0010)
  Rule "m_rl_swap_i_17" was treated as more urgent than
  "m_rl_swap_i_18". Conflicts:
    "m_rl_swap_i_17" cannot fire before "m_rl_swap_i_18":
      calls to m_xs_18.write vs. m_xs_18.read
    "m_rl_swap_i_18" cannot fire before "m_rl_swap_i_17":
      calls to m_xs_18.write vs. m_xs_18.read
Elaborated module file created: mkBubblesort_nt.ba
code generation for mkTestbench starts
Elaborated module file created: mkTestbench.ba
All packages are up to date.
bsc -sim -e mkTestbench -o sim.out 
Bluesim object created: mkTestbench.{h,o}
Bluesim object created: mkBubblesort_nt.{h,o}
Bluesim object created: model_mkTestbench.{h,o}
Simulation shared library created: sim.out.so
Simulation executable created: sim.out

./sim.out 
1: x_0 = 1
3: x_1 = 142
5: x_2 = 71
7: x_3 = 173
9: x_4 = 216
11: x_5 = 108
13: x_6 = 54
15: x_7 = 27
17: x_8 = 131
19: x_9 = 207
21: x_10 = 233
23: x_11 = 250
25: x_12 = 125
27: x_13 = 176
29: x_14 = 88
31: x_15 = 44
33: x_16 = 22
35: x_17 = 11
37: x_18 = 139
39: x_19 = 203
                                54: y_0 = 1
                                55: y_1 = 11
                                56: y_2 = 22
                                57: y_3 = 27
                                58: y_4 = 44
                                59: y_5 = 54
                                60: y_6 = 71
                                61: y_7 = 88
                                62: y_8 = 108
                                63: y_9 = 125
                                64: y_10 = 131
                                65: y_11 = 139
                                66: y_12 = 142
                                67: y_13 = 173
                                68: y_14 = 176
                                69: y_15 = 203
                                70: y_16 = 207
                                71: y_17 = 216
                                72: y_18 = 233
                                73: y_19 = 250

Bubblesort.bsv

// Copyright (c) 2013-2016 Bluespec, Inc.  All Rights Reserved.

package Bubblesort;

// ================================================================
// A parallel bubble-sorter

// Previous versions:
//     Eg01a_Bubblesort: Sorts exactly 5 'Int#(32)' values.
//
// This version:
//     Eg01b_Bubblesort: Generalizes from '5' to 'n'.

// Later versions:
//     Eg01c_Bubblesort: Generalizes 'Int#(32)' to 't', i.e., makes it polymorphic

// ================================================================
// BSV lib imports

import Vector :: *;

// ================================================================
// Project imports

import Utils :: *;

// ================================================================
// Interface definition for the parallel sorter
// Accepts a stream of n_t unsorted inputs via the put method
// Returns a stream of n_t sorted outputs via the get method

interface Sort_IFC #(numeric type n_t);
   method Action  put (Int #(32) x);
   method ActionValue #(Int #(32))  get;
endinterface

// ================================================================
// Module def for the parallel sorter

module mkBubblesort (Sort_IFC #(n_t));

   // Constant values derived from the type n_t
   Integer n    = valueOf (n_t);
   Integer jMax = n-1;

   // Count incoming values (up to n)
   Reg #(UInt #(16))  rg_inj  <- mkReg (0);

   // A vector of registers to hold the values being sorted
   // Note: 'maxBound' is largest 'Int#(32)'; we assume none of the
   // actual values to be sorted have this value.
   Vector #(n_t, Reg #(Int #(32))) xs <- replicateM (mkReg (maxBound));

   // Generate n-1 rules (concurrent) to swap xs[i] and xs[i+1] if unordered
   for (Integer i = 0; i < n-1; i = i+1)
      rule rl_swap_i (xs [i] > xs [i+1]);
         xs [i]   <= xs [i+1];
         xs [i+1] <= xs [i];
      endrule

   // Test if array is sorted
   function Bool done ();
      Bool b = (rg_inj == fromInteger (n));
      for (Integer i = 0; i < n-1; i = i+1)
	 b = b && (xs[i] <= xs[i+1]);
      return b;
   endfunction

   // ----------------
   // INTERFACE

   // Inputs: feed input values into xs[jMax]
   method Action put (Int #(32) x) if ((rg_inj < fromInteger(n)) && xs[jMax] == maxBound);
      xs[jMax] <= x;
      rg_inj <= rg_inj + 1;
   endmethod

   // Outputs: drain by shifting them out of x0
   method ActionValue#(Int #(32)) get () if (done);
      writeVReg (xs, shiftInAtN (readVReg (xs), maxBound));
      if (xs[1] == maxBound) rg_inj <= 0;
      return xs[0];
   endmethod
endmodule: mkBubblesort

// ================================================================

endpackage: Bubblesort

Testbench.bsv

// Copyright (c) 2013-2016 Bluespec, Inc.  All Rights Reserved.

package Testbench;

// ================================================================
// Testbench to drive the sorting module.
// Feed n unsorted inputs to sorter,
// drain n sorted outputs and print
// ================================================================
// BSV lib imports

import LFSR :: *;
import Vector :: *;

// ================================================================
// Project imports

import Utils      :: *;
import Bubblesort :: *;

// ================================================================
// Size of array to be sorted

typedef 20 N_t;
Int #(32) n = fromInteger (valueOf (N_t));

// ----------------
// Instantiate and separately synthesize a Bubblesort module for size 'N_t'

(*synthesize*)
module mkBubblesort_nt (Sort_IFC #(N_t));
   Sort_IFC #(N_t) m <- mkBubblesort;
   return m;
endmodule

// ================================================================
// Testbench module

(* synthesize *)
module mkTestbench (Empty);
   Reg #(Int#(32)) rg_j1 <- mkReg (0);
   Reg #(Int#(32)) rg_j2 <- mkReg (0);

   // Instantiate an 8-bit random number generator from BSV lib
   LFSR #(Bit #(8)) lfsr <- mkLFSR_8;

   // Instantiate the parallel sorter
   Sort_IFC #(N_t) sorter <- mkBubblesort_nt;

   rule rl_feed_inputs (rg_j1 < n);
      Bit#(32) v = zeroExtend (lfsr.value ());
      lfsr.next ();
      Int#(32) x = unpack (v);
      sorter.put (x);
      rg_j1 <= rg_j1 + 1;
      $display ("%0d: x_%0d = %0d", cur_cycle, rg_j1, x);
   endrule

   rule rl_drain_outputs (rg_j2 < n);
      let y <- sorter.get ();
      rg_j2 <= rg_j2 + 1;
      $display ("                                %0d: y_%0d = %0d", cur_cycle, rg_j2, y);
      if (rg_j2 == n-1) $finish;
   endrule
endmodule

// ================================================================

endpackage

Utils.bsv

package Utils;

// ================================================================
// Copyright (c) 2013-2016 Bluespec, Inc. All Rights Reserved.

// Misc. useful definitions, not app-specific

// ================================================================
// A convenience function to return the current cycle number during Bluesim simulations

ActionValue #(Bit #(32)) cur_cycle = actionvalue
					Bit #(32) t <- $stime;
					return t / 10;
				     endactionvalue;

// ================================================================

endpackage

三个文件放在同一目录下可以运行

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions