memory: optimize block_id size for powers of 2 block numbers
MODIFY
tools/transform.cpp
tools/transform.cpp
@@ -482,7 +482,7 @@ static void calculateAndInitConstants(Transform &t) {
num_nonlocals = num_globals + num_ptrinputs + num_max_nonlocals_inst + 1;
// ceil(log2(maxblks)) + 1 for local bit
- bits_for_bid = ilog2(max(num_locals, num_nonlocals)) + 1 + 1;
+ bits_for_bid = max(2u, ilog2_ceil(max(num_locals, num_nonlocals)) + 1);
// TODO
bits_for_offset = 64;

MODIFY
util/compiler.cpp
util/compiler.cpp
@@ -18,6 +18,11 @@ unsigned ilog2(uint64_t n) {
#endif
}
+unsigned ilog2_ceil(uint64_t n) {
+ auto log = ilog2(n);
+ return is_power2(n) ? log : log + 1;
+}
+
bool is_power2(uint64_t n, uint64_t *log) {
if (n == 0 || (n & (n - 1)) != 0)
return false;

MODIFY
util/compiler.h
util/compiler.h
@@ -43,6 +43,7 @@ struct const_strip_unique_ptr {
};
unsigned ilog2(uint64_t n);
+unsigned ilog2_ceil(uint64_t n);
bool is_power2(uint64_t n, uint64_t *log = nullptr);
unsigned num_sign_bits(uint64_t n);
unsigned num_leading_zeros(uint64_t n);

memory: optimize block_id size for powers of 2 block numbers