-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmix_vg.sv
139 lines (118 loc) · 3.7 KB
/
mix_vg.sv
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
module mix_vg(
input clk,
input [63:0] a_i,
input [63:0] b_i,
input [63:0] c_i,
input [63:0] d_i,
input [63:0] m0,
input [63:0] m1,
output [63:0] a_o,
output [63:0] b_o,
output [63:0] c_o,
output [63:0] d_o
);
logic [63:0] b_i_p1;
logic [63:0] c_i_p1;
logic [63:0] m1_p1, m1_p2, m1_p3, m1_p4;
logic [63:0] a0_p0, a0_p1, a0_p2, a1_p2, a1_p3, a1_p4, a1_p5;
logic [63:0] b0_p1, b0_p2, b0_p3, b1_p3, b1_p4, b1_p5;
logic [63:0] c0_p1, c0_p2, c0_p3, c1_p3, c1_p4, c1_p5;
logic [63:0] d0_p0, d0_p1, d0_p2, d1_p2, d1_p3, d1_p4, d2_p3, d2_p4, d2_p5;
always_comb begin
// v[a] = v[a] + v[b] + (x ^ c1);
a0_p0 = a_i + b_i + m0;
// v[d] ^= v[a];
d0_p0 = d_i ^ a0_p0;
// v[d] = ROTR64(v[d], 60);
d0_p0 = {d0_p0[59:0], d0_p0[63:60]};
end
// 1
always_ff @ (posedge clk) begin
a0_p1 <= a0_p0;
d0_p1 <= d0_p0;
b_i_p1 <= b_i;
c_i_p1 <= c_i;
end
always_comb begin
// v[c] = v[c] + v[d];
c0_p1 = c_i_p1 + d0_p1;
// v[b] = ROTR64(v[b] ^ v[c], 43);
b0_p1 = b_i_p1 ^ c0_p1;
// v[b] = ROTR64(v[b] ^ v[c], 43);
b0_p1 = {b0_p1[42:0], b0_p1[63:43]};
end
// 2
always_ff @ (posedge clk) begin
m1_p1 <= m1;
m1_p2 <= m1_p1;
a0_p2 <= a0_p1;
b0_p2 <= b0_p1;
c0_p2 <= c0_p1;
d0_p2 <= d0_p1;
end
always_comb begin
// v[a] = v[a] + v[b] + (y ^ c2);
a1_p2 = a0_p2 + b0_p2 + m1_p2;
// v[d] = ROTR64(v[d] ^ v[a], 5);
d1_p2 = d0_p2 ^ a1_p2;
d1_p2 = {d1_p2[4:0], d1_p2[63:5]};
end
// 3
always_ff @ (posedge clk) begin
a1_p3 <= a1_p2;
b0_p3 <= b0_p2;
c0_p3 <= c0_p2;
d1_p3 <= d1_p2;
end
always_comb begin
// v[c] = v[c] + v[d];
c1_p3 = c0_p3 + d1_p3;
// v[b] = ROTR64(v[b] ^ v[c], 18);
b1_p3 = b0_p3 ^ c1_p3;
b1_p3 = {b1_p3[17:0], b1_p3[63:18]};
// d2_p3 = d1_p3 ^ ((~a1_p3 & ~b1_p3 & ~c1_p3) | (~a1_p3 & b1_p3 & c1_p3) |
// (a1_p3 & ~b1_p3 & c1_p3) | (a1_p3 & b1_p3 & ~c1_p3));
end
// 4
always_ff @ (posedge clk) begin
a1_p4 <= a1_p3;
b1_p4 <= b1_p3;
c1_p4 <= c1_p3;
d1_p4 <= d1_p3;
end
always_comb begin
// X'Y'Z' + X'YZ + XY'Z + XYZ' LUT: 10010110
// v[d] ^= (~v[a] & ~v[b] & ~v[c]) | (~v[a] & v[b] & v[c]) |
// (v[a] & ~v[b] & v[c]) | (v[a] & v[b] & ~v[c]);
d2_p4 = d1_p4 ^ ((~a1_p4 & ~b1_p4 & ~c1_p4) | (~a1_p4 & b1_p4 & c1_p4) |
(a1_p4 & ~b1_p4 & c1_p4) | (a1_p4 & b1_p4 & ~c1_p4));
end
// 5
always_ff @ (posedge clk) begin
a1_p5 <= a1_p4;
b1_p5 <= b1_p4;
c1_p5 <= c1_p4;
d2_p5 <= d2_p4;
end
// X'Y'Z + X'YZ' + XY'Z' + XYZ LUT: 01101001
// v[d] ^= (~v[a] & ~v[b] & v[c]) | (~v[a] & v[b] & ~v[c]) |
// (v[a] & ~v[b] & ~v[c]) | (v[a] & v[b] & v[c]);
assign d_o = d2_p5 ^ ((~a1_p5 & ~b1_p5 & c1_p5) | (~a1_p5 & b1_p5 & ~c1_p5) |
(a1_p5 & ~b1_p5 & ~c1_p5) | (a1_p5 & b1_p5 & c1_p5));
//assign d_o = d2_p4 ^ ((~a1_p4 & ~b1_p4 & c1_p4) | (~a1_p4 & b1_p4 & ~c1_p4) |
// (a1_p4 & ~b1_p4 & ~c1_p4) | (a1_p4 & b1_p4 & c1_p4));
//assign d_o = d2_p3 ^ ((~a1_p3 & ~b1_p3 & c1_p3) | (~a1_p3 & b1_p3 & ~c1_p3) |
// (a1_p3 & ~b1_p3 & ~c1_p3) | (a1_p3 & b1_p3 & c1_p3));
// (XYZ' + X' YZ + Z XY' + X' Y' Z') ^ (X'Y'Z + X'YZ' + XY'Z' + XYZ) ;
// X XY + XYZ' X Z + XYZ X Z' + XYZ YZ' Z XY + XYZ' YZ Z' XY + XYZ' YZ Z Y + XYZ YZ' Z' Y;
//assign d_o = (a1_p4 & a1_p4 & b1_p4) |
// (a1_p4 & b1_p4 & ~c1_p4 & a1_p4 & c1_p4) |
// (a1_p4 & b1_p4 & c1_p4 & a1_p4 & ~c1_p4) |
// (a1_p4 & b1_p4 & c1_p4 & b1_p4 & ~c1_p4 & c1_p4 & a1_p4 & b1_p4) |
// (a1_p4 & b1_p4 & ~c1_p4 & b1_p4 & c1_p4 & ~c1_p4 & a1_p4 & b1_p4) |
// (a1_p4 & b1_p4 & ~c1_p4 & b1_p4 & c1_p4 & c1_p4 & b1_p4) |
// (a1_p4 & b1_p4 & c1_p4 & b1_p4 & ~c1_p4 & ~c1_p4 & b1_p4);
assign a_o = a1_p5;
assign b_o = b1_p5;
assign c_o = c1_p5;
endmodule