Ask a question related to Ibex alu bitcounting
Nobody has claimed this yet.
- Dominant language
- SystemVerilog
- Stars
- 2.1k
- Forks
- 810
- Avg merge
- 5d 23h
- Merged PRs (30d)
- 9
Description
What is the purpose of bitcnt_bit_mask & ~bitcnt_mask_op? I find it that it still works properly without & ~bitcnt_mask_op. Here are the rawcode in ibex_alu and my C test program.
Rawcode:
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 zbe_op = (operator_i == ALU_BCOMPRESS) | (operator_i == ALU_BDECOMPRESS);
always_comb begin
unique case (1'b1)
zbe_op: bitcnt_bits = operand_b_i;
bitcnt_cz: bitcnt_bits = bitcnt_bit_mask & ~bitcnt_mask_op; // clz / ctz
default: bitcnt_bits = operand_a_i; // cpop
endcase
end
C test code:
#include <stdio.h>
#include <stdint.h>
uint64_t check_pass_num = 0;
void check(uint32_t bitcnt_mask_op)
{
uint32_t bitcnt_bit_mask;
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;
if (bitcnt_bit_mask != (bitcnt_bit_mask & ~bitcnt_mask_op))
printf("%x check fail\n", bitcnt_mask_op);
else
check_pass_num++;
}
int main()
{
for (uint32_t i = 0; i < UINT32_MAX; i++)
check(i);
check(UINT32_MAX);
printf("check_pass_num = %ld\n", check_pass_num);
return 0;
}
Result: check_pass_num = 4294967296
My Environment
EDA tool and version:
gcc version 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04)
Operating system:
Ubuntu Linux 24.04
Version of the Ibex source code:
e5b8d05fea3edd00a068d41f2160fe9076090952
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the bit-counting logic in ibex_alu, especially the construction of bitcnt_bit_mask and its use for clz/ctz operations. Compare the expression with the surrounding bit-counting behavior and the reported C test; done means documenting why the masking operation is present or identifying the remaining case that requires it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- embedded-iot
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100