diff --git a/src/libdramsys/DRAMSys/simulation/AddressDecoder.cpp b/src/libdramsys/DRAMSys/simulation/AddressDecoder.cpp index 12bc61bb..ac99a572 100644 --- a/src/libdramsys/DRAMSys/simulation/AddressDecoder.cpp +++ b/src/libdramsys/DRAMSys/simulation/AddressDecoder.cpp @@ -47,8 +47,7 @@ namespace DRAMSys { -AddressDecoder::AddressDecoder(const DRAMSys::Config::AddressMapping& addressMapping, - const MemSpec& memSpec) +AddressDecoder::AddressDecoder(const DRAMSys::Config::AddressMapping& addressMapping) { if (const auto& channelBits = addressMapping.CHANNEL_BIT) { @@ -108,6 +107,23 @@ AddressDecoder::AddressDecoder(const DRAMSys::Config::AddressMapping& addressMap unsigned columns = std::lround(std::pow(2.0, vColumnBits.size())); unsigned bytes = std::lround(std::pow(2.0, vByteBits.size())); + maximumAddress = + static_cast(bytes) * columns * rows * banks * bankGroups * ranks * channels - 1; + + bankgroupsPerRank = bankGroups; + banksPerGroup = banks; +} + +void AddressDecoder::plausibilityCheck(const MemSpec& memSpec) +{ + unsigned channels = std::lround(std::pow(2.0, vChannelBits.size())); + unsigned ranks = std::lround(std::pow(2.0, vRankBits.size())); + unsigned bankGroups = std::lround(std::pow(2.0, vBankGroupBits.size())); + unsigned banks = std::lround(std::pow(2.0, vBankBits.size())); + unsigned rows = std::lround(std::pow(2.0, vRowBits.size())); + unsigned columns = std::lround(std::pow(2.0, vColumnBits.size())); + unsigned bytes = std::lround(std::pow(2.0, vByteBits.size())); + maximumAddress = static_cast(bytes) * columns * rows * banks * bankGroups * ranks * channels - 1; @@ -131,7 +147,8 @@ AddressDecoder::AddressDecoder(const DRAMSys::Config::AddressMapping& addressMap { highestByteBit = static_cast(*std::max_element(vByteBits.begin(), vByteBits.end())); - for (unsigned bitPosition = 0; bitPosition <= static_cast(highestByteBit); bitPosition++) + for (unsigned bitPosition = 0; bitPosition <= static_cast(highestByteBit); + bitPosition++) { if (std::find(vByteBits.begin(), vByteBits.end(), bitPosition) == vByteBits.end()) SC_REPORT_FATAL("AddressDecoder", "Byte bits are not continuous starting from 0"); @@ -148,16 +165,13 @@ AddressDecoder::AddressDecoder(const DRAMSys::Config::AddressMapping& addressMap SC_REPORT_FATAL("AddressDecoder", "No continuous column bits for maximum burst length"); } - bankgroupsPerRank = bankGroups; - bankGroups = bankgroupsPerRank * ranks; - - banksPerGroup = banks; - banks = banksPerGroup * bankGroups; + unsigned absoluteBankGroups = bankgroupsPerRank * ranks; + unsigned absoluteBanks = banksPerGroup * absoluteBankGroups; if (memSpec.numberOfChannels != channels || memSpec.ranksPerChannel != ranks || - memSpec.bankGroupsPerChannel != bankGroups || memSpec.banksPerChannel != banks || - memSpec.rowsPerBank != rows || memSpec.columnsPerRow != columns || - memSpec.devicesPerRank * memSpec.bitWidth != bytes * 8) + memSpec.bankGroupsPerChannel != absoluteBankGroups || + memSpec.banksPerChannel != absoluteBanks || memSpec.rowsPerBank != rows || + memSpec.columnsPerRow != columns || memSpec.devicesPerRank * memSpec.bitWidth != bytes * 8) SC_REPORT_FATAL("AddressDecoder", "Memspec and address mapping do not match"); } diff --git a/src/libdramsys/DRAMSys/simulation/AddressDecoder.h b/src/libdramsys/DRAMSys/simulation/AddressDecoder.h index 4cb01668..3216d1be 100644 --- a/src/libdramsys/DRAMSys/simulation/AddressDecoder.h +++ b/src/libdramsys/DRAMSys/simulation/AddressDecoder.h @@ -81,11 +81,14 @@ struct DecodedAddress class AddressDecoder { public: - AddressDecoder(const DRAMSys::Config::AddressMapping& addressMapping, const MemSpec& memSpec); + AddressDecoder(const DRAMSys::Config::AddressMapping& addressMapping); + [[nodiscard]] DecodedAddress decodeAddress(uint64_t encAddr) const; [[nodiscard]] unsigned decodeChannel(uint64_t encAddr) const; [[nodiscard]] uint64_t encodeAddress(DecodedAddress decodedAddress) const; + void print() const; + void plausibilityCheck(const MemSpec &memSpec); private: unsigned banksPerGroup; diff --git a/src/libdramsys/DRAMSys/simulation/DRAMSys.cpp b/src/libdramsys/DRAMSys/simulation/DRAMSys.cpp index e085624a..dec0463d 100644 --- a/src/libdramsys/DRAMSys/simulation/DRAMSys.cpp +++ b/src/libdramsys/DRAMSys/simulation/DRAMSys.cpp @@ -151,7 +151,8 @@ void DRAMSys::setupDebugManager([[maybe_unused]] const std::string& traceName) c void DRAMSys::instantiateModules(const ::DRAMSys::Config::AddressMapping& addressMapping) { - addressDecoder = std::make_unique(addressMapping, *config.memSpec); + addressDecoder = std::make_unique(addressMapping); + addressDecoder->plausibilityCheck(*config.memSpec); addressDecoder->print(); // Create arbiter diff --git a/src/libdramsys/DRAMSys/simulation/DRAMSysRecordable.cpp b/src/libdramsys/DRAMSys/simulation/DRAMSysRecordable.cpp index 22f7ba29..5c4159df 100644 --- a/src/libdramsys/DRAMSys/simulation/DRAMSysRecordable.cpp +++ b/src/libdramsys/DRAMSys/simulation/DRAMSysRecordable.cpp @@ -106,7 +106,8 @@ void DRAMSysRecordable::setupTlmRecorders(const std::string& traceName, void DRAMSysRecordable::instantiateModules(const std::string& traceName, const ::DRAMSys::Config::Configuration& configLib) { - addressDecoder = std::make_unique(configLib.addressmapping, *config.memSpec); + addressDecoder = std::make_unique(configLib.addressmapping); + addressDecoder->plausibilityCheck(*config.memSpec); addressDecoder->print(); // Create and properly initialize TLM recorders. diff --git a/tests/tests_dramsys/AddressDecoderConfigs.h b/tests/tests_dramsys/AddressDecoderConfigs.h index 86f8816c..4f997e93 100644 --- a/tests/tests_dramsys/AddressDecoderConfigs.h +++ b/tests/tests_dramsys/AddressDecoderConfigs.h @@ -37,70 +37,6 @@ #include -inline constexpr std::string_view memSpecJsonString = R"( -{ - "memspec": { - "memarchitecturespec": { - "burstLength": 16, - "dataRate": 8, - "nbrOfBankGroups": 4, - "nbrOfBanks": 16, - "nbrOfColumns": 1024, - "nbrOfRows": 65536, - "nbrOfRanks": 1, - "nbrOfDevices": 1, - "nbrOfChannels": 1, - "width": 16, - "per2BankOffset": 8 - }, - "memoryId": "JEDEC_1Gbx16_BG_LPDDR5-6400", - "memoryType": "LPDDR5", - "memtimingspec": { - "RCD_L": 15, - "RCD_S": 15, - "PPD": 2, - "RPab": 17, - "RPpb": 15, - "RAS": 34, - "RCab": 51, - "RCpb": 48, - "FAW": 16, - "RRD": 4, - "RL": 17, - "WCK2CK": 0, - "WCK2DQO": 1, - "RBTP": 4, - "RPRE": 0, - "RPST": 0, - "WL": 9, - "WCK2DQI": 0, - "WPRE": 0, - "WPST": 0, - "WR": 28, - "WTR_L": 10, - "WTR_S": 5, - "CCDMW": 16, - "REFI": 3124, - "REFIpb": 390, - "RFCab": 224, - "RFCpb": 112, - "RTRS": 1, - "BL_n_min_16": 2, - "BL_n_max_16": 4, - "BL_n_L_16": 4, - "BL_n_S_16": 2, - "BL_n_min_32": 6, - "BL_n_max_32": 8, - "BL_n_L_32": 8, - "BL_n_S_32": 2, - "pbR2act": 6, - "pbR2pbR": 72, - "clkMhz": 800 - } - } -} -)"; - inline constexpr std::string_view addressMappingJsonString = R"( { "addressmapping": { diff --git a/tests/tests_dramsys/AddressDecoderTests.cpp b/tests/tests_dramsys/AddressDecoderTests.cpp index 748ae984..4abd9705 100644 --- a/tests/tests_dramsys/AddressDecoderTests.cpp +++ b/tests/tests_dramsys/AddressDecoderTests.cpp @@ -35,32 +35,23 @@ #include "AddressDecoderConfigs.h" +#include #include -#include #include class AddressDecoderFixture : public ::testing::Test { protected: AddressDecoderFixture() : - addressMappingJson(nlohmann::json::parse(addressMappingJsonString).at("addressmapping")), - memSpecJson(nlohmann::json::parse(memSpecJsonString).at("memspec")), - addressMappingConfig(addressMappingJson.get()), - memSpecConfig(memSpecJson.get()), - memSpec(memSpecConfig), - addressDecoder(addressMappingConfig, memSpec) + addressMappingConfig(nlohmann::json::parse(addressMappingJsonString) + .at("addressmapping") + .get()), + addressDecoder(addressMappingConfig) { } - nlohmann::json addressMappingJson; - nlohmann::json memSpecJson; - - // Configs DRAMSys::Config::AddressMapping addressMappingConfig; - DRAMSys::Config::MemSpec memSpecConfig; - - DRAMSys::MemSpecLPDDR5 memSpec; DRAMSys::AddressDecoder addressDecoder; }; @@ -116,4 +107,4 @@ TEST_F(AddressDecoderFixture, DeEncoding) EXPECT_EQ(encodedAddress, address); } -} \ No newline at end of file +}