-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #886 from diffblue/xnor1
Verilog: implement xnor gates
- Loading branch information
Showing
8 changed files
with
186 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
CORE broken-smt-backend | ||
xnor1.sv | ||
--bound 0 | ||
^\[main\.xnor_ok\] always !\(xor\(xor\(main\.xnor_in1, main\.xnor_in2\), main\.xnor_in3\)\) == main\.xnor_out: PROVED up to bound 0$ | ||
^\[main\.xnor_fail\] always main\.xnor_in1 == main\.xnor_in2 == main\.xnor_in3 == main\.xnor_out: REFUTED$ | ||
^\[main\.xnor_is_reduction_xnor\] always ~\^\{ main\.xnor_in1, main\.xnor_in2, main\.xnor_in3 \} == main\.xnor_out: PROVED up to bound 0$ | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring | ||
-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
module main(output xnor_out, input xnor_in1, xnor_in2, xnor_in3); | ||
|
||
// An 'xnor' with three inputs. | ||
// 1800-2017 28.4 says that these "shall have a natural extension". | ||
xnor x1(xnor_out, xnor_in1, xnor_in2, xnor_in3); | ||
|
||
// should pass | ||
`ifndef __ICARUS__ | ||
xnor_ok: assert final (!(xnor_in1 ^ xnor_in2 ^ xnor_in3)==xnor_out); | ||
`endif | ||
|
||
// should fail -- not the same as using a chain of binary xnors | ||
`ifndef __ICARUS__ | ||
xnor_fail: assert final ((xnor_in1 ~^ xnor_in2 ~^ xnor_in3)==xnor_out); | ||
`endif | ||
|
||
// should pass -- xnor is the same as reduction xnor | ||
`ifndef __ICARUS__ | ||
xnor_is_reduction_xnor: assert final (~^{xnor_in1, xnor_in2, xnor_in3}==xnor_out); | ||
`endif | ||
|
||
endmodule | ||
|
||
// To check simulator behavior | ||
module xnor_tb; | ||
|
||
wire xnor_out; | ||
reg xnor_in1, xnor_in2, xnor_in3; | ||
|
||
main m(xnor_out, xnor_in1, xnor_in2, xnor_in3); | ||
|
||
task print; | ||
begin | ||
$display("input: ", xnor_in1, xnor_in2, xnor_in3); | ||
$display(" xnor gate: ", xnor_out); | ||
$display(" reduction-xnor: ", ~^{xnor_in1, xnor_in2, xnor_in3}); | ||
$display(" !reduction-xor: ", !(^{xnor_in1, xnor_in2, xnor_in3})); | ||
$display(" !xor: ", !(xnor_in1 ^ xnor_in2 ^ xnor_in3)); | ||
$display(" binary xnors: ", xnor_in1 ~^ xnor_in2 ~^ xnor_in3); | ||
end | ||
endtask | ||
|
||
initial begin | ||
{xnor_in1, xnor_in2, xnor_in3} = 'b000; | ||
#1; | ||
print(); | ||
{xnor_in1, xnor_in2, xnor_in3} = 'b100; | ||
#1; | ||
print(); | ||
{xnor_in1, xnor_in2, xnor_in3} = 'b110; | ||
#1; | ||
print(); | ||
{xnor_in1, xnor_in2, xnor_in3} = 'b111; | ||
#1; | ||
print(); | ||
{xnor_in1, xnor_in2, xnor_in3} = 'b101; | ||
#1; | ||
print(); | ||
end | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CORE broken-smt-backend | ||
xnor2.sv | ||
--bound 0 | ||
^\[main\.xnor_ok\] always !main\.xnor_in1 == main\.xnor_out: PROVED up to bound 0$ | ||
^\[main\.xnor_is_reduction_xnor\] always ~\^\{ main\.xnor_in1 \} == main\.xnor_out: PROVED up to bound 0$ | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring | ||
-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module main(output xnor_out, input xnor_in1); | ||
|
||
// An 'xnor' with just one input. These negate. | ||
xnor x1(xnor_out, xnor_in1); | ||
|
||
// should pass | ||
`ifndef __ICARUS__ | ||
xnor_ok: assert final (!xnor_in1==xnor_out); | ||
`endif | ||
|
||
// should pass -- xnor is the same as reduction xnor | ||
`ifndef __ICARUS__ | ||
xnor_is_reduction_xnor: assert final (~^{xnor_in1}==xnor_out); | ||
`endif | ||
|
||
endmodule | ||
|
||
// To check simulator behavior | ||
module xnor_tb; | ||
|
||
wire xnor_out; | ||
reg xnor_in1; | ||
|
||
main m(xnor_out, xnor_in1); | ||
|
||
task print; | ||
begin | ||
$display("input: ", xnor_in1); | ||
$display(" xnor gate: ", xnor_out); | ||
$display(" reduction-xnor: ", ~^{xnor_in1}); | ||
$display(" !reduction-xor: ", !(^{xnor_in1})); | ||
$display(" !: ", !xnor_in1); | ||
end | ||
endtask | ||
|
||
initial begin | ||
{xnor_in1} = 'b0; | ||
#1; | ||
print(); | ||
{xnor_in1} = 'b1; | ||
#1; | ||
print(); | ||
end | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CORE broken-smt-backend | ||
xnor3.sv | ||
--bound 0 | ||
^\[main\.xnor_ok\] always main\.xnor_in1 ~\^ main\.xnor_in2 == main\.xnor_out: PROVED up to bound 0$ | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring | ||
-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module main(output [31:0] xnor_out, input [31:0] xnor_in1, xnor_in2); | ||
|
||
// An 'xnor' with two inputs, 32 bits each. | ||
xnor x1[31:0](xnor_out, xnor_in1, xnor_in2); | ||
|
||
// should pass | ||
`ifndef __ICARUS__ | ||
xnor_ok: assert final (xnor_in1 ~^ xnor_in2==xnor_out); | ||
`endif | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters