#define CEPH_CRUSH_LN_H
+// RH_LH_tbl[2*k] = 2^48/(1.0+k/128.0)
+// RH_LH_tbl[2*k+1] = 2^48*log2(1.0+k/128.0)
+
static int64_t __RH_LH_tbl[128*2+2] = {
0x0001000000000000ll, 0x0000000000000000ll, 0x0000fe03f80fe040ll, 0x000002dfca16dde1ll,
0x0000fc0fc0fc0fc1ll, 0x000005b9e5a170b4ll, 0x0000fa232cf25214ll, 0x0000088e68ea899all,
return bucket->h.items[high];
}
-// compute 2^12*log2(input+1)
-unsigned crush_ln(unsigned xin)
+// compute 2^44*log2(input+1)
+uint64_t crush_ln(unsigned xin)
{
- unsigned x=xin, x1, result;
+ unsigned x=xin, x1;
int iexpon, index1, index2;
- uint64_t RH, LH, LL, xl64;
+ uint64_t RH, LH, LL, xl64, result;
x++;
xl64 >>= 48;
x1 = xl64;
- result = iexpon << 12;
+ result = iexpon;
+ result <<= (12 + 32);
index2 = x1 & 0xff;
// LL ~ 2^48*log2(1.0+index2/2^15)
LH = LH + LL;
- LH >>= (48-12);
- result += (unsigned)LH;
+ LH >>= (48-12 - 32);
+ result += LH;
return result;
}
*
* the natural log lookup table maps [0,0xffff]
* (corresponding to real numbers [1/0x10000, 1] to
- * [0, 0xffff] (corresponding to real numbers
+ * [0, 0xffffffffffff] (corresponding to real numbers
* [-11.090355,0]).
*/
- ln = crush_ln(u) - 0x10000;
+ ln = crush_ln(u) - 0x1000000000000ll;
/*
* divide by 16.16 fixed-point weight
*/
- draw = (ln << 32) / bucket->item_weights[i];
+ draw = ln / bucket->item_weights[i];
if (i == 0 || draw > high_draw) {
high = i;