A parameterizable SystemVerilog module for finding the maximum value and its index from chunked input data.
- Configurable input width and chunk size
- Balanced tree reduction for optimal timing
- Optional pipelining and input/output registers
- Support for signed/unsigned comparison
- Configurable tie-breaking (first vs last index wins)
- LSB-first or MSB-first chunking
max_idx_tree #(
.TOTAL_WIDTH (60),
.CHUNK_WIDTH (6),
.REQUIRE_MULTIPLE (1),
.SIGNED_COMPARE (0),
.TIE_HIGH_INDEX (0),
.PIPE_STAGES (0),
.REGISTER_INPUT (0),
.REGISTER_OUTPUT (0),
.MSB_FIRST (0)
) max_finder (
.clk(clk),
.rst_n(rst_n),
.ce_i(1'b1),
.valid_i(valid),
.din(data_in),
.valid_o(valid_out),
.idx_o(max_index),
.val_o(max_value)
);Compile and run the testbench (combinational):
bash run_max_idx_tree_tb.sh