Skip to content

Commit b9925d9

Browse files
collucaphsauter
authored andcommitted
lzc: Create enum type for MODE parameter
1 parent 63e1b67 commit b9925d9

3 files changed

Lines changed: 26 additions & 9 deletions

File tree

Bender.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ sources:
4646
- src/lfsr_16bit.sv
4747
- src/lfsr_8bit.sv
4848
- src/lossy_valid_to_stream.sv
49+
- src/lzc_pkg.sv
4950
- src/mv_filter.sv
5051
- src/onehot_to_bin.sv
5152
- src/plru_tree.sv

src/lzc.sv

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
`include "common_cells/assertions.svh"
66

77
/// A trailing zero counter / leading zero counter.
8-
/// Set MODE to 0 for trailing zero counter => cnt_o is the number of trailing zeros (from the LSB)
9-
/// Set MODE to 1 for leading zero counter => cnt_o is the number of leading zeros (from the MSB)
8+
/// Set MODE to TRAILING_ZERO_CNT for trailing zero counter => cnt_o is the number of trailing zeros (from the LSB)
9+
/// Set MODE to LEADING_ZERO_CNT for leading zero counter => cnt_o is the number of leading zeros (from the MSB)
1010
/// If the input does not contain a one, `empty_o` is asserted. Additionally `cnt_o` contains
1111
/// the maximum number of zeros - 1. For example:
12-
/// in_i = 000_0000, empty_o = 1, cnt_o = 6 (mode = 0)
13-
/// in_i = 000_0001, empty_o = 0, cnt_o = 0 (mode = 0)
14-
/// in_i = 000_1000, empty_o = 0, cnt_o = 3 (mode = 0)
12+
/// in_i = 000_0000, empty_o = 1, cnt_o = 6 (mode = TRAILING_ZERO_CNT)
13+
/// in_i = 000_0001, empty_o = 0, cnt_o = 0 (mode = TRAILING_ZERO_CNT)
14+
/// in_i = 000_1000, empty_o = 0, cnt_o = 3 (mode = TRAILING_ZERO_CNT)
1515
/// Furthermore, this unit contains a more efficient implementation for Verilator (simulation only).
1616
/// This speeds up simulation significantly.
17-
module lzc #(
17+
module lzc import lzc_pkg::*; #(
1818
/// The width of the input vector.
1919
parameter int unsigned WIDTH = 2,
20-
/// Mode selection: 0 -> trailing zero, 1 -> leading zero
21-
parameter bit MODE = 1'b0,
20+
/// Trailing or leading zero mode selection
21+
parameter lzc_mode_e MODE = TRAILING_ZERO_CNT,
2222
/// Dependent parameter. Do **not** change!
2323
///
2424
/// Width of the output signal with the zero count.
@@ -51,7 +51,7 @@ module lzc #(
5151

5252
logic [WIDTH-1:0] in_tmp;
5353

54-
if (MODE) begin : g_flip
54+
if (MODE == LEADING_ZERO_CNT) begin : g_flip
5555
// Mode 1 (leading zero): flip input vector
5656
always_comb begin : flip_vector
5757
for (int unsigned i = 0; i < WIDTH; i++) begin

src/lzc_pkg.sv

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2025 ETH Zurich and University of Bologna.
2+
// Solderpad Hardware License, Version 0.51, see LICENSE for details.
3+
// SPDX-License-Identifier: SHL-0.51
4+
//
5+
// Author: Luca Colagrande <colluca@iis.ee.ethz.ch>
6+
//
7+
// Contains common defintions for the LZC IP.
8+
9+
package lzc_pkg;
10+
11+
typedef enum logic {
12+
TRAILING_ZERO_CNT = 1'b0,
13+
LEADING_ZERO_CNT = 1'b1
14+
} lzc_mode_e;
15+
16+
endpackage : lzc_pkg

0 commit comments

Comments
 (0)