Rotate
The rotate module is a combinatorial block that implements a bit-wise left rotation of the
given input data, i_data, by the amount, i_amt. For example, an i_data of
0b10010 with an i_amt of 0b001 would result in an o_data of 0b00101.
Parameters
DATA_WIDTH: data width in bits
Ports
i_datainput datai_amtamount to rotateo_dataoutput data (rotated version of input)
Source Code
rotate.sv
1`ifndef LIBSV_BIT_OPS_ROTATE
2`define LIBSV_BIT_OPS_ROTATE
3
4module rotate #(
5 parameter int DATA_WIDTH /* verilator public_flat_rd */ = 8
6) (
7 input logic [ DATA_WIDTH-1:0] i_data,
8 input logic [$clog2(DATA_WIDTH)-1:0] i_amt,
9 output logic [ DATA_WIDTH-1:0] o_data
10);
11
12 always_comb begin : rotate
13 o_data = '0;
14 for (int i = 0; i < DATA_WIDTH; ++i) begin
15 int rotate_amt = (int'(i_amt) + i) % DATA_WIDTH;
16 o_data[$bits(i_amt)'(rotate_amt)] = i_data[i];
17 end
18 end : rotate
19
20endmodule : rotate
21
22`endif /* LIBSV_BIT_OPS_ROTATE */