6 #ifndef TURI_FAST_INTEGER_POWER_H_ 7 #define TURI_FAST_INTEGER_POWER_H_ 12 #include <core/util/bitops.hpp> 13 #include <core/util/code_optimization.hpp> 65 _setup_block_lookups(a);
75 static constexpr
size_t bits_per_block = 8;
76 static constexpr
size_t bit_selector = (1 << bits_per_block) - 1;
77 static constexpr
size_t first_level_size = (bitsizeof(
size_t) + bits_per_block - 1) / bits_per_block;
79 std::array<std::array<double, (1 << bits_per_block)>, first_level_size> block_lookups;
83 inline void _setup_block_lookups(
double v);
95 for (
size_t i = 0; i < bitsizeof(
size_t) / bits_per_block; ++i) {
96 v *= block_lookups[i][n & bit_selector];
107 inline void fast_integer_power::_setup_block_lookups(
double v) {
109 std::array<double, bitsizeof(size_t)> power_lookup;
113 for(
size_t i = 1; i < bitsizeof(v); ++i)
114 power_lookup[i] = power_lookup[i - 1] * power_lookup[i - 1];
117 for(
size_t main_level = 0; main_level < first_level_size; ++main_level) {
118 size_t offset = main_level * bits_per_block;
120 for(
size_t second_level = 0; second_level < (1 << bits_per_block); ++second_level) {
124 for(
size_t bit_idx = 0;
125 bit_idx < bits_per_block && offset + bit_idx < bitsizeof(
size_t);
128 if(second_level & (1 << bit_idx) )
129 vp *= power_lookup[offset + bit_idx];
132 block_lookups[main_level][second_level] = vp;
fast_integer_power(double a=1.0)
double pow(size_t b) const GL_HOT_INLINE_FLATTEN
#define GL_HOT_INLINE_FLATTEN