aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--riscv/devices.cc2
-rw-r--r--riscv/int_map.h14
2 files changed, 7 insertions, 9 deletions
diff --git a/riscv/devices.cc b/riscv/devices.cc
index cde5b75..2d902a9 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 ed1e7a4..10da616 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 <cstdint>
#include <climits>
-#include <cassert>
// Like std::map, but keys are integers
-template<typename K, typename V, int lg_radix = 11>
+template<typename K, typename V, int lg_n = sizeof(K) * CHAR_BIT, int lg_radix = 11>
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<V*>(&array[idx]);
}
- if (array[idx] == nullptr)
- array[idx] = new int_map<K, V, lg_radix>(lg_n - lg_radix);
+ if (unlikely(array[idx] == nullptr))
+ array[idx] = new int_map<K, V, lg_n < 0 ? 0 : lg_n - lg_radix, lg_radix>;
return array[idx]->lookup(k >> lg_radix);
}
private:
- int lg_n;
- int_map<K, V, lg_radix>* array[size_t(1) << lg_radix];
+ int_map<K, V, lg_n < 0 ? 0 : lg_n - lg_radix, lg_radix>* array[size_t(1) << lg_radix];
};
#endif