diff --git a/riscv/devices.cc b/riscv/devices.cc index cde5b756..2d902a92 100644 --- a/riscv/devices.cc +++ b/riscv/devices.cc @@ -92,7 +92,7 @@ bool mmio_plugin_device_t::store(reg_t addr, size_t len, const uint8_t* bytes) } mem_t::mem_t(reg_t size) - : sparse_memory_map(log2(size) + (size & (size-1) ? 1 : 0)), sz(size) + : sz(size) { if (size == 0 || size % PGSIZE != 0) throw std::runtime_error("memory size must be a positive multiple of 4 KiB"); diff --git a/riscv/int_map.h b/riscv/int_map.h index ed1e7a4b..10da6160 100644 --- a/riscv/int_map.h +++ b/riscv/int_map.h @@ -1,16 +1,15 @@ #ifndef _RISCV_INT_MAP_H #define _RISCV_INT_MAP_H +#include "common.h" #include #include -#include // Like std::map, but keys are integers -template +template class int_map { public: - int_map(int lg_n = sizeof(K) * CHAR_BIT) - : lg_n(lg_n) + int_map() { memset(array, 0, sizeof(array)); } @@ -24,15 +23,14 @@ class int_map { return reinterpret_cast(&array[idx]); } - if (array[idx] == nullptr) - array[idx] = new int_map(lg_n - lg_radix); + if (unlikely(array[idx] == nullptr)) + array[idx] = new int_map; return array[idx]->lookup(k >> lg_radix); } private: - int lg_n; - int_map* array[size_t(1) << lg_radix]; + int_map* array[size_t(1) << lg_radix]; }; #endif