forked from russdill/bch_verilog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtb_inverter.v
75 lines (68 loc) · 1.11 KB
/
tb_inverter.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
`timescale 1ns / 1ps
module tb_inverter();
`include "bch.vh"
localparam M = 8;
reg clk = 0;
reg start = 1;
reg in = 0;
wire [M-1:0] out;
reg [M-1:0] out2 = 0;
wire [M-1:0] out_dual;
reg [M-1:0] v = 0;
integer i;
reg [M-1:0] a;
reg [M-1:0] b;
berlekamp_inverter #(M) inv(
.clk(clk),
.start(start),
.standard_in(in),
.standard_out(out)
);
fermat_inverter #(M) inv2(
.clk(clk),
.start(start),
.standard_in(a),
.dual_out(out_dual)
);
initial begin
$dumpfile("test.vcd");
$dumpvars(0);
a = lpow(M, 0);
#1;
for (i = 0; i < `BCH_M2N(M); i = i + 1) begin
b = brute_inverse(M, a);
v = a << 1;
in = a[M-1];
start = 1;
#4;
clk = 1;
#1;
repeat (M) begin
in = v[M-1];
v = v << 1;
start = 0;
#4;
clk = 0;
#5;
clk = 1;
#1;
end
out2 = dual_to_standard(M, out_dual);
repeat (M - 2) begin
in = 0;
#4;
clk = 0;
#5;
clk = 1;
#1;
end
#4;
clk = 0;
#1;
$display("%d 1/%b = %b, %b%s %b%s", i, a, b,
out, b == out ? "" : "*",
out2, b == out2 ? "" : "*");
a = `BCH_MUL1(M, a);
end
end
endmodule