On Wed, 31 May 2023, Shaopeng Tan (Fujitsu) wrote:
Hi Ilpo,
CAT and CMT tests depends on masks being continuous.
Replace count_bits with more appropriate variant that counts consecutive bits.
Signed-off-by: Ilpo Järvinen ilpo.jarvinen@linux.intel.com
@@ -218,6 +220,34 @@ static int get_bit_mask(char *filename, unsigned long *mask) return 0; }
+/*
- count_consecutive_bits - Returns the longest train of bits in a bit mask
- @val A bit mask
- @start The location of the least-significant bit of the longest train
- Return: The length of the consecutive bits in the longest train of bits
- */
+unsigned int count_consecutive_bits(unsigned long val, unsigned int +*start) {
- unsigned long last_val;
- int count = 0;
- while (val) {
last_val = val;
val &= (val >> 1);
count++;
- }
There may not be a case that the most-significant bit is 1 at present, but if this case exists, it cannot count correctly.
Can you please rephrase what is your concern here please?
I test 0U, 1U, ~0U, and a few more complex combinations of bits, and all returned correct count so I might not have understood what case you meant with your description.
This function does not count nor calculate the most-significant bit in any phase but the longest train of bits using the count variable (and the least-significant bit of the longest train in the code that is not included into this partial snippet).