Skip to content

Commit 7d8bdc9

Browse files
committed
add vector hdl
1 parent e998445 commit 7d8bdc9

File tree

9 files changed

+151
-0
lines changed

9 files changed

+151
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
`resetall
2+
`timescale 1ns / 1ps
3+
`default_nettype none
4+
5+
module four_input_gates (
6+
input wire [3:0] i,
7+
output wire out_and,
8+
output wire out_or,
9+
output wire out_xor
10+
);
11+
12+
assign out_and = & i;
13+
assign out_or = | i;
14+
assign out_xor = ^ i;
15+
16+
endmodule
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
`resetall
2+
`timescale 1ns / 1ps
3+
`default_nettype none
4+
5+
module vector_basics (
6+
input wire [2:0] vec,
7+
output wire [2:0] outv,
8+
output wire o2,
9+
output wire o1,
10+
output wire o0
11+
);
12+
13+
assign outv = vec;
14+
assign {o2, o1, o0} = vec;
15+
16+
endmodule
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
`resetall
2+
`timescale 1ns / 1ps
3+
`default_nettype none
4+
5+
module bit_replication (
6+
input wire [7:0] i,
7+
output wire [31:0] o
8+
);
9+
10+
assign o = {{24{i[7]}}, i};
11+
12+
endmodule
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
`resetall
2+
`timescale 1ns / 1ps
3+
`default_nettype none
4+
5+
module byte_endian_swap #(
6+
parameter BYTE_COUNT = 4,
7+
parameter BYTE_SIZE = 8
8+
)(
9+
input wire [(BYTE_COUNT*BYTE_SIZE)-1:0] i,
10+
output wire [(BYTE_COUNT*BYTE_SIZE)-1:0] o
11+
);
12+
13+
genvar i;
14+
generate
15+
for (i = 0; i < BYTE_COUNT; i++) begin : OUTPUT_ASSIGNMENT
16+
assign o[(BYTE_SIZE*(BYTE_COUNT-i))-1:(BYTE_SIZE*(BYTE_COUNT-1-i))] = i[(BYTE_SIZE*(1+i))-1:BYTE_SIZE*i];
17+
end
18+
endgenerate
19+
20+
endmodule
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
`resetall
2+
`timescale 1ns / 1ps
3+
`default_nettype none
4+
5+
module concatenation (
6+
input wire [4:0] a,
7+
input wire [4:0] b,
8+
input wire [4:0] c,
9+
input wire [4:0] d,
10+
input wire [4:0] e,
11+
input wire [4:0] f,
12+
13+
output wire [7:0] w,
14+
output wire [7:0] x,
15+
output wire [7:0] y,
16+
output wire [7:0] z
17+
);
18+
19+
assign {w, x, y, z} = {a, b, c, d, e, f, 2'b11};
20+
21+
endmodule
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
`resetall
2+
`timescale 1ns / 1ps
3+
`default_nettype none
4+
5+
module vector_gates (
6+
input wire [2:0] a,
7+
input wire [2:0] b,
8+
output wire [2:0] out_or_bitwise,
9+
output wire out_or_logical,
10+
output wire [5:0] out_not
11+
);
12+
13+
assign out_or_bitwise = a | b;
14+
assign out_or_logical = a || b;
15+
assign out_not = {~b, ~a};
16+
17+
endmodule
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
`resetall
2+
`timescale 1ns / 1ps
3+
`default_nettype none
4+
5+
module vector_splitter (
6+
input wire [15:0] i,
7+
output wire [7:0] out_hi,
8+
output wire [7:0] out_lo
9+
);
10+
11+
assign out_hi = i[15:8];
12+
assign out_lo = i[7:0];
13+
14+
endmodule
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
`resetall
2+
`timescale 1ns / 1ps
3+
`default_nettype none
4+
5+
module reverse #(
6+
parameter VECTOR_SIZE = 8
7+
)(
8+
input wire [VECTOR_SIZE-1:0] i,
9+
output wire [VECTOR_SIZE-1:0] o
10+
);
11+
12+
genvar i;
13+
generate
14+
for (i = 0; i < VECTOR_SIZE; i++) begin : INPUT_REVERSE
15+
assign out[VECTOR_SIZE-1-i] = in[i];
16+
end
17+
endgenerate
18+
19+
endmodule
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
`resetall
2+
`timescale 1ns / 1ps
3+
`default_nettype none
4+
5+
module top_module (
6+
input wire a,
7+
input wire b,
8+
input wire c,
9+
input wire d,
10+
input wire e,
11+
output wire [24:0] out
12+
);
13+
14+
assign out = ~{{5{a}}, {5{b}}, {5{c}}, {5{d}}, {5{e}}} ^ {5{a, b, c, d, e}};
15+
16+
endmodule

0 commit comments

Comments
 (0)