Skip to content

Commit f616045

Browse files
committed
stress-bitops: use builtin to generate optimal log2(n)
Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
1 parent fcf5e81 commit f616045

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

stress-bitops.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,19 +707,24 @@ static int OPTIMIZE3 stress_bitops_log2(const char *name, uint32_t *count)
707707
static const int8_t bitposition[32] ALIGN64 = {
708708
0, 9, 1, 10, 13, 21, 2, 29,
709709
11, 14, 16, 18, 22, 25, 3, 30,
710-
8, 12, 20, 28, 15, 17, 24, 7,
710+
8, 12, 20, 28, 15, 17, 24, 7,
711711
19, 27, 23, 6, 26, 5, 4, 31
712712
};
713713
uint32_t ln2_1;
714714
uint32_t ln2_2;
715715
uint32_t tmp;
716716
uint32_t shift;
717717

718+
#if defined(HAVE_BUILTIN_CLZ)
719+
ln2_1 = (8 * sizeof(v)) - __builtin_clz(v) - 1;
720+
sum += ln2_1;
721+
#else
718722
tmp = v;
719723
ln2_1 = 0;
720724
while (tmp >>= 1)
721725
ln2_1++;
722726
sum += ln2_1;
727+
#endif
723728

724729
tmp = v;
725730
ln2_2 = 0;

0 commit comments

Comments
 (0)