index a5cc1f8b83b4eb9eeb36a4d50178e799f7f0975e..351fed8186fb2d7ce331f0244df43e142a08327d 100644 (file)
#include <math.h>
#include "lib/hyperloglog.h"
+#include "port/pg_bitutils.h"
#define POW_2_32 (4294967296.0)
#define NEG_POW_2_32 (-4294967296.0)
{
uint8 j = 1;
- while (j <= b && !(x & 0x80000000))
- {
- j++;
- x <<= 1;
- }
+ if (x == 0)
+ return b + 1;
+
+ j = 32 - pg_leftmost_one_pos32(x);
+
+ if (j > b)
+ return b + 1;
return j;
}