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

54 lines
1.3 KiB
Systemverilog
Raw Normal View History

//------------------------------------------------------------------------------
// reverse_vector.sv
// Konstantin Pavlov, pavlovconst@gmail.com
//------------------------------------------------------------------------------
// INFO ------------------------------------------------------------------------
// "Physically" reverses signal order within multi-bit bus
// Thus in[7] signal becomes out[0], in[6] becomes out[1] and vise-versa
2018-09-16 17:26:39 +03:00
// Module is no doubt synthesizable, but its instance does NOT occupy any FPGA resources!
/* --- INSTANTIATION TEMPLATE BEGIN ---
reverse_vector #(
.WIDTH( 8 ) // WIDTH must be >=2
) RV1 (
.in( smth[7:0] ),
.out( htms[7:0] ) // reversed bit order
);
--- INSTANTIATION TEMPLATE END ---*/
2019-02-23 00:20:06 +03:00
module reverse_vector #( parameter
WIDTH = 8 // WIDTH must be >=2
)(
input [(WIDTH-1):0] in,
output logic [(WIDTH-1):0] out
);
genvar i;
generate
2018-09-16 17:26:39 +03:00
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
2018-09-16 17:26:39 +03:00
if ( WIDTH%2 ) begin : gen2
always_comb begin
out[WIDTH/2] = in[WIDTH/2];
end // always_comb
end // for
endgenerate
endmodule