Skip to content

Commit ec494c8

Browse files
committed
mux2, mux4
1 parent df9e342 commit ec494c8

File tree

3 files changed

+75
-39
lines changed

3 files changed

+75
-39
lines changed

src/mux.veryl

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/mux2.veryl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// src/mux2.veryl
2+
3+
module Mux2 #(
4+
param Width: u32 = 32,
5+
) (
6+
i_data: input logic<Width> [2],
7+
i_sel : input logic ,
8+
o_data: output logic<Width> ,
9+
) {
10+
assign o_data = i_data[i_sel];
11+
}
12+
13+
#[test(mux2)]
14+
embed (inline) sv{{{
15+
module test;
16+
logic [31:0] i_data [2];
17+
logic i_sel;
18+
logic [31:0] o_data;
19+
vips_Mux2 Mux2 (i_data, i_sel, o_data);
20+
21+
initial begin
22+
i_data = {1,2};
23+
i_sel = 0;
24+
#10;
25+
assert (o_data == 1) else $error("0->1");
26+
27+
i_sel = 1;
28+
#10;
29+
assert (o_data == 2) else $error("1->2");
30+
31+
$finish;
32+
end
33+
endmodule
34+
}}}

src/mux4.veryl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// src/mux4.veryl
2+
3+
module Mux4 #(
4+
param Width: u32 = 32,
5+
) (
6+
i_data: input logic<Width> [4],
7+
i_s : input logic<2> ,
8+
o_data: output logic<Width> ,
9+
) {
10+
assign o_data = i_data[i_s];
11+
}
12+
13+
#[test(mux4)]
14+
embed (inline) sv{{{
15+
module test;
16+
logic [31:0] i_data [4];
17+
logic [1:0] i_sel;
18+
logic [31:0] o_data;
19+
vips_Mux4 Mux4 (i_data, i_sel, o_data);
20+
21+
initial begin
22+
i_data = {1,2,3,4};
23+
i_sel = 0;
24+
#10;
25+
assert (o_data == 1) else $error("0->1");
26+
27+
i_sel = 1;
28+
#10;
29+
assert (o_data == 2) else $error("1->2");
30+
31+
i_sel = 2;
32+
#10;
33+
assert (o_data == 3) else $error("2->3");
34+
35+
i_sel = 3;
36+
#10;
37+
assert (o_data == 4) else $error("3->4");
38+
$finish;
39+
end
40+
endmodule
41+
}}}

0 commit comments

Comments
 (0)