Advertisement
Guest User

Untitled

a guest
Nov 5th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module test (i_clk, i_wr, i_val, i_rst, o_match);
  2. input i_clk;
  3. input i_wr;
  4. input i_val;
  5. input i_rst;
  6. output o_match;
  7.  
  8. reg r_val;
  9.  
  10. always @(posedge i_clk) begin
  11.     if (rst_i) begin
  12.         r_val <= 1'b0;
  13.     end
  14.     else if (i_wr) begin
  15.         r_val <= i_val;
  16.     end
  17. end
  18.  
  19. assign o_match = (r_val == i_val);
  20.  
  21. endmodule
  22.  
  23.  
  24.  
  25.  
  26. module test_tb();
  27.  
  28. reg clk;
  29. reg wr;
  30. reg val;
  31. reg rst;
  32. wire match1;
  33. wire match2;
  34.  
  35. initial begin
  36.     rst <= 1'b1;
  37.     wr <= 1'b1;
  38.     val <= 1'b1;
  39.     #1000 rst<= 1'b0;
  40. end
  41.  
  42. `ifdef FORMAL
  43.     reg f_last_clk;
  44.     always @($global_clock) begin
  45.         assume(clk == !f_last_clk);
  46.         f_last_clk <= clk;
  47.         clk <= (clk === 1'b0);
  48.     end
  49.  
  50.     reg f_past_valid;
  51.     initial f_past_valid = 1'b0;
  52.     always @(posedge clk_i) begin
  53.         f_past_valid <= 1'b1;
  54.     end
  55.  
  56.     always @(posedge clk) begin
  57.         if (!f_past_valid) begin
  58.             assume(rst);
  59.         end
  60.         if (!rst) begin
  61.             assert (match1 == match2);
  62.         end
  63.     end
  64.  
  65. `else
  66.     always #100 clk <= (clk === 1'b0);
  67. `endif
  68.  
  69. test test1 (
  70.     .i_clk(clk),
  71.     .i_wr(wr),
  72.     .i_val(val),
  73.     .i_rst(rst),
  74.     .o_match(match1)
  75. );
  76.  
  77. test test2 (
  78.     .i_clk(clk),
  79.     .i_wr(wr),
  80.     .i_val(val),
  81.     .i_rst(rst),
  82.     .o_match(match2)
  83. );
  84.  
  85. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement