Small refactor of AddressDecoder
This commit is contained in:
@@ -66,12 +66,12 @@ uint64_t createBitmask(unsigned numBits, unsigned startIndex) {
|
||||
return ((UINT64_C(1) << numBits) - 1) << startIndex;
|
||||
}
|
||||
|
||||
std::vector<std::bitset<64>> AddressDecoder::transposeMatrix(const std::vector<std::bitset<64>>& matrix) {
|
||||
std::vector<std::bitset<AddressDecoder::ADDRESS_WIDTH>> AddressDecoder::transposeMatrix(const std::vector<std::bitset<ADDRESS_WIDTH>>& matrix) {
|
||||
size_t size = matrix.size();
|
||||
std::vector<std::bitset<64>> transposedMatrix(size);
|
||||
std::vector<std::bitset<ADDRESS_WIDTH>> 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<std::bitset<64>> AddressDecoder::transposeMatrix(const std::vector<s
|
||||
return transposedMatrix;
|
||||
}
|
||||
|
||||
uint64_t AddressDecoder::gf2Multiplication(const uint64_t& inputVec, const std::vector<std::bitset<64>>& matrix) const
|
||||
uint64_t AddressDecoder::gf2Multiplication(const uint64_t& inputVec, const std::vector<std::bitset<ADDRESS_WIDTH>>& 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<ADDRESS_WIDTH> resultBits;
|
||||
std::bitset<ADDRESS_WIDTH> 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<ADDRESS_WIDTH>(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<std::bitset<64>>(highestBitValue + 1);
|
||||
mappingMatrix = std::vector<std::bitset<ADDRESS_WIDTH>>(highestBitValue + 1);
|
||||
upperBoundAddress = std::pow(2, highestBitValue + 1) - 1;
|
||||
|
||||
auto addBitsToMatrix = [&](const std::optional<std::vector<Config::AddressMapping::BitEntry>> 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<ADDRESS_WIDTH> orBitset(0);
|
||||
for (auto bitset: mappingMatrix) {
|
||||
orBitset |= bitset;
|
||||
}
|
||||
|
||||
|
||||
std::bitset<64> mask((1ULL << (highestBitValue + 1)) - 1);
|
||||
std::bitset<ADDRESS_WIDTH> 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<ADDRESS_WIDTH> burstBitset(((1 << numOfMaxBurstLengthBits) - 1) << columnBits.idx);
|
||||
std::bitset<ADDRESS_WIDTH> columnBitset;
|
||||
for (size_t i = 0; i < columnBits.length; i++) {
|
||||
columnBitset |= mappingMatrix[columnBits.idx + i];
|
||||
}
|
||||
|
||||
@@ -130,8 +130,10 @@ public:
|
||||
void print() const;
|
||||
|
||||
private:
|
||||
std::vector<std::bitset<64>> mappingMatrix;
|
||||
std::vector<std::bitset<64>> transposedMappingMatrix;
|
||||
static constexpr unsigned ADDRESS_WIDTH = 64;
|
||||
|
||||
std::vector<std::bitset<ADDRESS_WIDTH>> mappingMatrix;
|
||||
std::vector<std::bitset<ADDRESS_WIDTH>> 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<std::bitset<64>> transposeMatrix(const std::vector<std::bitset<64>>& matrix);
|
||||
[[nodiscard]] std::vector<std::bitset<ADDRESS_WIDTH>> transposeMatrix(const std::vector<std::bitset<ADDRESS_WIDTH>>& 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<std::bitset<64>>& matrix) const;
|
||||
[[nodiscard]] uint64_t gf2Multiplication(const uint64_t& inputVec, const std::vector<std::bitset<ADDRESS_WIDTH>>& matrix) const;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user