smtbmc
[script]
-read_verilog -formal cover.v
+read -formal cover.sv
prep -top top
[files]
-cover.v
+cover.sv
--- /dev/null
+module top (
+ input clk,
+ input [7:0] din
+);
+ reg [31:0] state = 0;
+
+ always @(posedge clk) begin
+ state <= ((state << 5) + state) ^ din;
+ end
+
+`ifdef FORMAL
+ always @(posedge clk) begin
+ cover (state == 'd 12345678);
+ cover (state == 'h 12345678);
+ end
+`endif
+endmodule
+++ /dev/null
-module top (
- input clk,
- input [7:0] din
-);
- reg [31:0] state = 0;
-
- always @(posedge clk) begin
- state <= ((state << 5) + state) ^ din;
- end
-
- cover property (state == 'd 12345678);
- cover property (state == 'h 12345678);
-endmodule
smtbmc boolector
[script]
-read_verilog -formal memory.v
+read -formal memory.sv
prep -top testbench
[files]
-memory.v
+memory.sv
--- /dev/null
+module testbench (
+ input clk, wen,
+ input [9:0] addr,
+ input [7:0] wdata,
+ output [7:0] rdata
+);
+ memory uut (
+ .clk (clk ),
+ .wen (wen ),
+ .addr (addr ),
+ .wdata(wdata),
+ .rdata(rdata)
+ );
+
+ (* anyconst *) reg [9:0] test_addr;
+ reg test_data_valid = 0;
+ reg [7:0] test_data;
+
+ always @(posedge clk) begin
+ if (addr == test_addr) begin
+ if (wen) begin
+ test_data <= wdata;
+ test_data_valid <= 1;
+ end
+ if (test_data_valid) begin
+ assert(test_data == rdata);
+ end
+ end
+ end
+endmodule
+
+module memory (
+ input clk, wen,
+ input [9:0] addr,
+ input [7:0] wdata,
+ output [7:0] rdata
+);
+ reg [7:0] bank0 [0:255];
+ reg [7:0] bank1 [0:255];
+ reg [7:0] bank2 [0:255];
+ reg [7:0] bank3 [0:255];
+
+ wire [1:0] mem_sel = addr[9:8];
+ wire [7:0] mem_addr = addr[7:0];
+
+ always @(posedge clk) begin
+ case (mem_sel)
+ 0: if (wen) bank0[mem_addr] <= wdata;
+ 1: if (wen) bank1[mem_addr] <= wdata;
+ 2: if (wen) bank1[mem_addr] <= wdata; // BUG: Should assign to bank2
+ 3: if (wen) bank3[mem_addr] <= wdata;
+ endcase
+ end
+
+ assign rdata =
+ mem_sel == 0 ? bank0[mem_addr] :
+ mem_sel == 1 ? bank1[mem_addr] :
+ mem_sel == 2 ? bank2[mem_addr] :
+ mem_sel == 3 ? bank3[mem_addr] : 'bx;
+endmodule
+++ /dev/null
-module testbench (
- input clk, wen,
- input [9:0] addr,
- input [7:0] wdata,
- output [7:0] rdata
-);
- memory uut (
- .clk (clk ),
- .wen (wen ),
- .addr (addr ),
- .wdata(wdata),
- .rdata(rdata)
- );
-
- wire [9:0] test_addr = $anyconst;
- reg test_data_valid = 0;
- reg [7:0] test_data;
-
- always @(posedge clk) begin
- if (addr == test_addr) begin
- if (wen) begin
- test_data <= wdata;
- test_data_valid <= 1;
- end
- if (test_data_valid) begin
- assert(test_data == rdata);
- end
- end
- end
-endmodule
-
-module memory (
- input clk, wen,
- input [9:0] addr,
- input [7:0] wdata,
- output [7:0] rdata
-);
- reg [7:0] bank0 [0:255];
- reg [7:0] bank1 [0:255];
- reg [7:0] bank2 [0:255];
- reg [7:0] bank3 [0:255];
-
- wire [1:0] mem_sel = addr[9:8];
- wire [7:0] mem_addr = addr[7:0];
-
- always @(posedge clk) begin
- case (mem_sel)
- 0: if (wen) bank0[mem_addr] <= wdata;
- 1: if (wen) bank1[mem_addr] <= wdata;
- 2: if (wen) bank1[mem_addr] <= wdata; // BUG: Should assign to bank2
- 3: if (wen) bank3[mem_addr] <= wdata;
- endcase
- end
-
- assign rdata =
- mem_sel == 0 ? bank0[mem_addr] :
- mem_sel == 1 ? bank1[mem_addr] :
- mem_sel == 2 ? bank2[mem_addr] :
- mem_sel == 3 ? bank3[mem_addr] : 'bx;
-endmodule
smtbmc
[script]
-read_verilog -formal prove.v
+read -formal prove.sv
prep -top testbench
[files]
-prove.v
+prove.sv
--- /dev/null
+module testbench (
+ input clk,
+ input reset,
+ input [7:0] din,
+ output reg [7:0] dout
+);
+ demo uut (
+ .clk (clk ),
+ .reset(reset),
+ .din (din ),
+ .dout (dout )
+ );
+
+ reg init = 1;
+ always @(posedge clk) begin
+ if (init) assume (reset);
+ if (!reset) assert (!dout[1:0]);
+ init <= 0;
+ end
+endmodule
+
+module demo (
+ input clk,
+ input reset,
+ input [7:0] din,
+ output reg [7:0] dout
+);
+ reg [7:0] buffer;
+ reg [1:0] state;
+
+ always @(posedge clk) begin
+ if (reset) begin
+ dout <= 0;
+ state <= 0;
+ end else
+ case (state)
+ 0: begin
+ buffer <= din;
+ state <= 1;
+ end
+ 1: begin
+ if (buffer[1:0])
+ buffer <= buffer + 1;
+ else
+ state <= 2;
+ end
+ 2: begin
+ dout <= dout + buffer;
+ state <= 0;
+ end
+ endcase
+ end
+endmodule
+++ /dev/null
-module testbench (
- input clk,
- input reset,
- input [7:0] din,
- output reg [7:0] dout
-);
- demo uut (
- .clk (clk ),
- .reset(reset),
- .din (din ),
- .dout (dout ),
- );
-
- initial assume (reset);
- assert property (reset || !dout[1:0]);
-endmodule
-
-module demo (
- input clk,
- input reset,
- input [7:0] din,
- output reg [7:0] dout
-);
- reg [7:0] buffer;
- reg [1:0] state;
-
- always @(posedge clk) begin
- if (reset) begin
- dout <= 0;
- state <= 0;
- end else
- case (state)
- 0: begin
- buffer <= din;
- state <= 1;
- end
- 1: begin
- if (buffer[1:0])
- buffer <= buffer + 1;
- else
- state <= 2;
- end
- 2: begin
- dout <= dout + buffer;
- state <= 0;
- end
- endcase
- end
-endmodule
Let's consider the following example:
-.. literalinclude:: ../examples/quickstart/memory.v
+.. literalinclude:: ../examples/quickstart/memory.sv
:language: systemverilog
This example is expected to fail verification (see the BUG comment).
and we need to prove that the safety properties hold forever, not just the first
*N* cycles. Let us consider the following example:
-.. literalinclude:: ../examples/quickstart/prove.v
+.. literalinclude:: ../examples/quickstart/prove.sv
:language: systemverilog
Proving this design in an unbounded manner can be achieved using the following