1 #include "jemalloc/internal/jemalloc_preamble.h" 2 #include "jemalloc/internal/jemalloc_internal_includes.h" 3 4 /* 5 * To avoid using floating point math down core paths (still necessary because 6 * versions of the glibc dynamic loader that did not preserve xmm registers are 7 * still somewhat common, requiring us to be compilable with -mno-sse), and also 8 * to avoid generally expensive library calls, we use a precomputed table of 9 * values. We want to sample U uniformly on [0, 1], and then compute 10 * ceil(log(u)/log(1-1/nticks)). We're mostly interested in the case where 11 * nticks is reasonably big, so 1/log(1-1/nticks) is well-approximated by 12 * -nticks. 13 * 14 * To compute log(u), we sample an integer in [1, 64] and divide, then just look 15 * up results in a table. As a space-compression mechanism, we store these as 16 * uint8_t by dividing the range (255) by the highest-magnitude value the log 17 * can take on, and using that as a multiplier. We then have to divide by that 18 * multiplier at the end of the computation. 19 * 20 * The values here are computed in src/ticker.py 21 */ 22 23 const uint8_t ticker_geom_table[1 << TICKER_GEOM_NBITS] = { 24 254, 211, 187, 169, 156, 144, 135, 127, 25 120, 113, 107, 102, 97, 93, 89, 85, 26 81, 77, 74, 71, 68, 65, 62, 60, 27 57, 55, 53, 50, 48, 46, 44, 42, 28 40, 39, 37, 35, 33, 32, 30, 29, 29 27, 26, 24, 23, 21, 20, 19, 18, 30 16, 15, 14, 13, 12, 10, 9, 8, 31 7, 6, 5, 4, 3, 2, 1, 0 32 }; 33