1
0
mirror of https://github.com/pConst/basic_verilog.git synced 2025-01-14 06:42:54 +08:00

SImplified reverse_vector.sv code

This commit is contained in:
Konstantin Pavlov 2021-09-13 11:17:58 +03:00
parent 0e19b10433
commit bcc548f914

View File

@ -22,32 +22,18 @@ reverse_vector #(
module reverse_vector #( parameter
WIDTH = 8 // WIDTH must be >=2
WIDTH = 8
)(
input [(WIDTH-1):0] in,
output logic [(WIDTH-1):0] out
);
genvar i;
generate
for (i = 0; i < (WIDTH/2) ; i++) begin : gen1
always_comb begin
out[i] = in[WIDTH-1-i];
out[WIDTH-1-i] = in[i];
end // always_comb
end // for
endgenerate
// additional assign needed when WIDTH is odd
generate
if ( WIDTH%2 ) begin : gen2
always_comb begin
out[WIDTH/2] = in[WIDTH/2];
end // always_comb
end // for
endgenerate
integer i;
always_comb begin
for (i = 0; i < WIDTH ; i++) begin : gen_reverse
out[i] = in[(WIDTH-1)-i];
end // for
end // always_comb
endmodule