sim: arith. fixes, optimized mem access
[calu.git] / 3b_sim / cpmem.cpp
index 31205e61f17a75e557c4ac2f730fe7871362d0b7..7972aa8f061344cf4a5f6c4cd5d4b9dd895c71ae 100644 (file)
@@ -18,7 +18,7 @@ void CPMem<T>::set(const MEMORY_ADDRESS address, const T data)
                throw out_of_range(error.str());
        }
 
-       MEMORY_ADDRESS temp = address;
+       MEMORY_ADDRESS temp = (address & (~(BYTE_COUNT-1))) / BYTE_COUNT;
        auto iter = m_memory.begin();
        while(temp > 0) {
                ++iter;
@@ -38,7 +38,8 @@ T CPMem<T>::get(const MEMORY_ADDRESS address) const
                error << "memoryaddress " << address << " out of range";
                throw out_of_range(error.str());
        }
-       return m_memory[address];
+       MEMORY_ADDRESS temp = (address & (~(BYTE_COUNT-1))) / BYTE_COUNT;
+       return m_memory[temp];
 }
 
 template <typename T>