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.

76 lines
1.7 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
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. default clocking
  33. @(posedge Clk_i);
  34. endclocking
  35. default disable iff (!Reset_n_i);
  36. bit unsigned [`WIDTH:0] dina, dinb;
  37. assign dina = DinA_i;
  38. assign dinb = DinB_i;
  39. assert property (Opc_i == `OPC_ADD |=> Dout_o == ($past(DinA_i) + $past(DinB_i)));
  40. assert property (Opc_i == `OPC_ADD && (dina + dinb) > 2**`WIDTH-1 |=> OverFlow_o);
  41. assert property (Opc_i == `OPC_SUB |=> Dout_o == ($past(DinA_i) - $past(DinB_i)));
  42. assert property (Opc_i == `OPC_SUB && (dina - dinb) > 2**`WIDTH-1 |=> OverFlow_o);
  43. assert property (Opc_i == `OPC_AND |=> Dout_o == ($past(DinA_i) & $past(DinB_i)));
  44. assert property (Opc_i == `OPC_OR |=> Dout_o == ($past(DinA_i) | $past(DinB_i)));
  45. property cover_opc (opc);
  46. Opc_i == opc;
  47. endproperty
  48. cover property (cover_opc(`OPC_ADD));
  49. cover property (cover_opc(`OPC_SUB));
  50. cover property (cover_opc(`OPC_AND));
  51. cover property (cover_opc(`OPC_OR));
  52. endmodule