diff --git a/src/libdramsys/DRAMSys/simulation/AddressDecoder.cpp b/src/libdramsys/DRAMSys/simulation/AddressDecoder.cpp index 0025138e..b8d342af 100644 --- a/src/libdramsys/DRAMSys/simulation/AddressDecoder.cpp +++ b/src/libdramsys/DRAMSys/simulation/AddressDecoder.cpp @@ -66,12 +66,12 @@ uint64_t createBitmask(unsigned numBits, unsigned startIndex) { return ((UINT64_C(1) << numBits) - 1) << startIndex; } -std::vector> AddressDecoder::transposeMatrix(const std::vector>& matrix) { +std::vector> AddressDecoder::transposeMatrix(const std::vector>& matrix) { size_t size = matrix.size(); - std::vector> transposedMatrix(size); + std::vector> transposedMatrix(size); for (size_t i = 0; i < size; ++i) { - for (size_t j = 0; j < 64; ++j) { + for (size_t j = 0; j < ADDRESS_WIDTH; ++j) { if (matrix[i].test(j)) transposedMatrix[j].set(i); } @@ -79,7 +79,7 @@ std::vector> AddressDecoder::transposeMatrix(const std::vector>& matrix) const +uint64_t AddressDecoder::gf2Multiplication(const uint64_t& inputVec, const std::vector>& matrix) const { #if defined(__clang__) || defined(__GNUC__) uint64_t result = 0; @@ -91,8 +91,8 @@ uint64_t AddressDecoder::gf2Multiplication(const uint64_t& inputVec, const std:: } return result; #else - std::bitset<64> resultBits; - std::bitset<64> inputBits(inputVec); + std::bitset resultBits; + std::bitset inputBits(inputVec); for (size_t i = 0; i < matrix.size(); ++i) { resultBits[i] = (inputBits & matrix[i]).count() % 2; @@ -101,7 +101,7 @@ uint64_t AddressDecoder::gf2Multiplication(const uint64_t& inputVec, const std:: #endif // Print input, mapping matrix and output in a readable way (useful for debugging) - // std::cout << "Vec " << ":\t" << std::bitset<64>(vector[0]) << std::endl << std::endl; + // std::cout << "Vec " << ":\t" << std::bitset(vector[0]) << std::endl << std::endl; // for (size_t i = 0; i < mappingMatrix.size(); ++i) { // std::cout << "Row " << i << ":\t" << mappingMatrix[i] << " | " << resultBits[i] << std::endl; // } @@ -115,7 +115,7 @@ uint64_t AddressDecoder::gf2Multiplication(const uint64_t& inputVec, const std:: AddressDecoder::AddressDecoder(const DRAMSys::Config::AddressMapping& addressMapping) : highestBitValue(addressMapping.getHighestBit()) { - mappingMatrix = std::vector>(highestBitValue + 1); + mappingMatrix = std::vector>(highestBitValue + 1); upperBoundAddress = std::pow(2, highestBitValue + 1) - 1; auto addBitsToMatrix = [&](const std::optional> bits, int *rowIndex, std::string_view name) @@ -145,8 +145,8 @@ AddressDecoder::AddressDecoder(const DRAMSys::Config::AddressMapping& addressMap stackBits = addBitsToMatrix(addressMapping.STACK_BIT, &rowIndex, "St"); transposedMappingMatrix = transposeMatrix(mappingMatrix); - bankgroupsPerRank = std::lround(std::pow(2.0, bankGroupBits.length)); - banksPerGroup = std::lround(std::pow(2.0, bankBits.length)); + bankgroupsPerRank = std::lround(std::pow(2, bankGroupBits.length)); + banksPerGroup = std::lround(std::pow(2, bankBits.length)); } @@ -157,13 +157,13 @@ void AddressDecoder::plausibilityCheck(const MemSpec& memSpec) // Check if all address bits are used // TODO: Check if every bit occurs ~exactly~ once or just at least once? - std::bitset<64> orBitset(0); + std::bitset orBitset(0); for (auto bitset: mappingMatrix) { orBitset |= bitset; } - std::bitset<64> mask((1ULL << (highestBitValue + 1)) - 1); + std::bitset mask((1ULL << (highestBitValue + 1)) - 1); if (orBitset != mask) { SC_REPORT_FATAL("AddressDecoder", "Not all address bits are used"); } @@ -204,11 +204,11 @@ void AddressDecoder::checkMemorySize(const MemSpec& memSpec) { } void AddressDecoder::checkMemSpecCompatibility(const MemSpec& memSpec) { - unsigned channels = std::lround(std::pow(2.0, channelBits.length)); - unsigned ranks = std::lround(std::pow(2.0, rankBits.length)); - unsigned rows = std::lround(std::pow(2.0, rowBits.length)); - unsigned columns = std::lround(std::pow(2.0, columnBits.length)); - unsigned pseudochannels = std::lround(std::pow(2.0, pseudochannelBits.length)); + unsigned channels = std::lround(std::pow(2, channelBits.length)); + unsigned ranks = std::lround(std::pow(2, rankBits.length)); + unsigned rows = std::lround(std::pow(2, rowBits.length)); + unsigned columns = std::lround(std::pow(2, columnBits.length)); + unsigned pseudochannels = std::lround(std::pow(2, pseudochannelBits.length)); unsigned absoluteBankGroups = bankgroupsPerRank * (ranks * pseudochannels); unsigned absoluteBanks = banksPerGroup * absoluteBankGroups; @@ -242,7 +242,7 @@ void AddressDecoder::checkAddressableLimits(const MemSpec& memSpec) { } unsigned AddressDecoder::calculateAddressableElements(unsigned bitSize) const { - return std::lround(std::pow(2.0, bitSize)); + return std::lround(std::pow(2, bitSize)); } void AddressDecoder::validateAddressableLimit(unsigned memSpecValue, unsigned addressableValue, const std::string& name) { @@ -289,8 +289,8 @@ void AddressDecoder::checkBurstLengthBits(const MemSpec& memSpec) { " reserved burst bits.").c_str()); } - std::bitset<64> burstBitset(((1 << numOfMaxBurstLengthBits) - 1) << columnBits.idx); - std::bitset<64> columnBitset; + std::bitset burstBitset(((1 << numOfMaxBurstLengthBits) - 1) << columnBits.idx); + std::bitset columnBitset; for (size_t i = 0; i < columnBits.length; i++) { columnBitset |= mappingMatrix[columnBits.idx + i]; } diff --git a/src/libdramsys/DRAMSys/simulation/AddressDecoder.h b/src/libdramsys/DRAMSys/simulation/AddressDecoder.h index a73ca7a7..3ccb6aad 100644 --- a/src/libdramsys/DRAMSys/simulation/AddressDecoder.h +++ b/src/libdramsys/DRAMSys/simulation/AddressDecoder.h @@ -130,8 +130,10 @@ public: void print() const; private: - std::vector> mappingMatrix; - std::vector> transposedMappingMatrix; + static constexpr unsigned ADDRESS_WIDTH = 64; + + std::vector> mappingMatrix; + std::vector> transposedMappingMatrix; uint64_t highestBitValue; const MemSpec* memSpec; uint64_t burstBitMask; @@ -159,7 +161,7 @@ private: * @param matrix The matrix to transpose. * @return The transposed matrix. */ - [[nodiscard]] std::vector> transposeMatrix(const std::vector>& matrix); + [[nodiscard]] std::vector> transposeMatrix(const std::vector>& matrix); /** * @brief Multiplies a 64-bit vector with a matrix over GF(2). @@ -168,7 +170,7 @@ private: * @param matrix The GF(2) matrix. * @return The result of the multiplication as a 64-bit unsinged integer. */ - [[nodiscard]] uint64_t gf2Multiplication(const uint64_t& inputVec, const std::vector>& matrix) const; + [[nodiscard]] uint64_t gf2Multiplication(const uint64_t& inputVec, const std::vector>& matrix) const; /**