Trying to verify Verilog/VHDL designs with formal methods and tools
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.9 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. `define WIDTH 8
  2. module alu_t (
  3. input Reset_n_i,
  4. input Clk_i,
  5. input [1:0] Opc_i,
  6. input [`WIDTH-1:0] DinA_i,
  7. input [`WIDTH-1:0] DinB_i,
  8. output [`WIDTH-1:0] Dout_o,
  9. output OverFlow_o
  10. );
  11. `define OPC_ADD 0
  12. `define OPC_SUB 1
  13. `define OPC_AND 2
  14. `define OPC_OR 3
  15. alu #(.Width(`WIDTH)) alu_i (
  16. .Reset_n_i(Reset_n_i),
  17. .Clk_i(Clk_i),
  18. .Opc_i(Opc_i),
  19. .DinA_i(DinA_i[`WIDTH-1:0]),
  20. .DinB_i(DinB_i[`WIDTH-1:0]),
  21. .Dout_o(Dout_o[`WIDTH-1:0]),
  22. .OverFlow_o(OverFlow_o)
  23. );
  24. reg init_state = 1;
  25. // Initial reset
  26. always @(*) begin
  27. if (init_state) assume (!Reset_n_i);
  28. if (!init_state) assume (Reset_n_i);
  29. end
  30. always @(posedge Clk_i)
  31. init_state = 0;
  32. bit unsigned [`WIDTH:0] dina, dinb;
  33. assign dina = DinA_i;
  34. assign dinb = DinB_i;
  35. assert property (@(posedge Clk_i) disable iff (!Reset_n_i) Opc_i == `OPC_ADD |=> Dout_o == ($past(DinA_i) + $past(DinB_i)));
  36. assert property (@(posedge Clk_i) disable iff (!Reset_n_i) Opc_i == `OPC_ADD && (dina + dinb) > 2**`WIDTH-1 |=> OverFlow_o);
  37. assert property (@(posedge Clk_i) disable iff (!Reset_n_i) Opc_i == `OPC_SUB |=> Dout_o == ($past(DinA_i) - $past(DinB_i)));
  38. assert property (@(posedge Clk_i) disable iff (!Reset_n_i) Opc_i == `OPC_SUB && (dina - dinb) > 2**`WIDTH-1 |=> OverFlow_o);
  39. assert property (@(posedge Clk_i) disable iff (!Reset_n_i) Opc_i == `OPC_AND |=> Dout_o == ($past(DinA_i) & $past(DinB_i)));
  40. assert property (@(posedge Clk_i) disable iff (!Reset_n_i) Opc_i == `OPC_OR |=> Dout_o == ($past(DinA_i) | $past(DinB_i)));
  41. property cover_opc (opc);
  42. @(posedge Clk_i)
  43. disable iff (!Reset_n_i) Opc_i == opc;
  44. endproperty
  45. cover property (cover_opc(`OPC_ADD));
  46. cover property (cover_opc(`OPC_SUB));
  47. cover property (cover_opc(`OPC_AND));
  48. cover property (cover_opc(`OPC_OR));
  49. endmodule