Skip to content

[bitmanip] Remove redundant logic #2296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions rtl/ibex_alu.sv
Original file line number Diff line number Diff line change
Expand Up @@ -437,21 +437,16 @@ module ibex_alu #(
assign bitcnt_cz = bitcnt_ctz | bitcnt_clz;
assign bitcnt_result = bitcnt_partial[31];

// Bit-mask generation for clz and ctz:
// The bit mask is generated by spreading the lowest-order set bit in the operand to all
// higher order bits. The resulting mask is inverted to cover the lowest order zeros. In order
// to create the bit mask for leading zeros, the input operand needs to be reversed.
assign bitcnt_mask_op = bitcnt_clz ? operand_a_rev : operand_a_i;
// Bitcnt_bits generation for clz and ctz:
// The operand of ctz can be divided into 3 parts: the don't-care bits in the high-order bits,
// the lowest-order set bit, and the trailing zeros. Bitcnt_bit_mask is obtained by subtracting 1
// from bitcnt_mask_op, which clears the lowest-order set bit and sets all the trailing zeros to 1.
// Then, bitcnt_bit_mask & ~bitcnt_mask_op clears the don't-care bits.
// At this point, counting the number of 1s gives the number of trailing zeros.
// In order to create the bit mask for leading zeros, the input operand needs to be reversed.

always_comb begin
bitcnt_bit_mask = bitcnt_mask_op;
bitcnt_bit_mask |= bitcnt_bit_mask << 1;
bitcnt_bit_mask |= bitcnt_bit_mask << 2;
bitcnt_bit_mask |= bitcnt_bit_mask << 4;
bitcnt_bit_mask |= bitcnt_bit_mask << 8;
bitcnt_bit_mask |= bitcnt_bit_mask << 16;
bitcnt_bit_mask = ~bitcnt_bit_mask;
end
assign bitcnt_mask_op = bitcnt_clz ? operand_a_rev : operand_a_i;
assign bitcnt_bit_mask = bitcnt_mask_op - 32'h1;

assign zbe_op = (operator_i == ALU_BCOMPRESS) | (operator_i == ALU_BDECOMPRESS);

Expand Down