From 8447d22fc11eb3faa30455be0e6598c75ac9f559 Mon Sep 17 00:00:00 2001 From: Lukas Steiner Date: Wed, 8 Apr 2020 16:52:58 +0200 Subject: [PATCH] Removed old address decoders. --- .../src/common/CongenAddressDecoder.cpp | 365 ------------------ .../library/src/common/CongenAddressDecoder.h | 94 ----- .../library/src/common/XmlAddressDecoder.cpp | 188 --------- .../library/src/common/XmlAddressDecoder.h | 91 ----- 4 files changed, 738 deletions(-) delete mode 100644 DRAMSys/library/src/common/CongenAddressDecoder.cpp delete mode 100644 DRAMSys/library/src/common/CongenAddressDecoder.h delete mode 100644 DRAMSys/library/src/common/XmlAddressDecoder.cpp delete mode 100644 DRAMSys/library/src/common/XmlAddressDecoder.h diff --git a/DRAMSys/library/src/common/CongenAddressDecoder.cpp b/DRAMSys/library/src/common/CongenAddressDecoder.cpp deleted file mode 100644 index b7051527..00000000 --- a/DRAMSys/library/src/common/CongenAddressDecoder.cpp +++ /dev/null @@ -1,365 +0,0 @@ -/* - * Copyright (c) 2018, University of Kaiserslautern - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Authors: - * Johannes Feldmann - */ - -#include -#include -#include - -#include "CongenAddressDecoder.h" -#include "utils.h" -#include "../configuration/Configuration.h" - -tinyxml2::XMLElement *CongenAddressDecoder::getXMLNode(tinyxml2::XMLElement - *pRoot, std::string strName) -{ - tinyxml2::XMLElement *pNode = pRoot->FirstChildElement(strName.c_str()); - if (pNode == nullptr) { - reportFatal("ConGenAddressDecorder", - "XML File corrupted. Missing node " + strName + "."); - } - return pNode; -} - -unsigned int CongenAddressDecoder::getUnsignedTextFromXMLNode( - tinyxml2::XMLElement *pRoot) -{ - std::string str = pRoot->GetText(); - if (str.empty() || std::find_if(str.begin(), str.end(), [](char c) { - return !std::isdigit(c); - }) != str.end()) { - reportFatal("ConGenAddressDecoder", - "Node " + std::string(pRoot->Name()) + " is empty or not a number."); - return (unsigned)(-1); - } - return atol(str.c_str()); -} - -unsigned int CongenAddressDecoder::getUnsignedAttrFromXMLNode( - tinyxml2::XMLElement *pRoot, std::string strName) -{ - std::string str = pRoot->Attribute(strName.c_str()); - if (str.empty() || std::find_if(str.begin(), str.end(), [](char c) { - return !std::isdigit(c); - }) != str.end()) { - reportFatal("ConGenAddressDecoder", - "Attribute " + strName + " is empty or not a number."); - return (unsigned)(-1); - } - return atol(str.c_str()); -} - -void CongenAddressDecoder::setConfiguration(std::string url) -{ - tinyxml2::XMLDocument doc; - loadXML(url, doc); - tinyxml2::XMLElement *pRoot = doc.RootElement(); - std::string xmlNodeName(pRoot->Name()); - - if (xmlNodeName != "CONGEN") - reportFatal("ConGenAddressDecorder", - "Root node name differs from \"CONGEN\". File format not supported."); - - // Load address mapping - tinyxml2::XMLElement *pNode; - - for (pNode = pRoot->FirstChildElement("SOLUTION"); pNode != nullptr; - pNode = pNode->NextSiblingElement("SOLUTION")) - { - if (getUnsignedAttrFromXMLNode(pNode, "ID") == 0) - break; // Correct mapping was found. - } - - // If no mapping was found report error - if (pNode == nullptr) - SC_REPORT_FATAL("ConGenAddressDecoder", "No mapping with ID 0 was found."); - - // get XOR connections - // An XOR connection needs two parameters: A bank bit and a Row bit. - for (tinyxml2::XMLElement *pXor = pNode->FirstChildElement("XOR"); - pXor != nullptr; pXor = pXor->NextSiblingElement("XOR")) - { - vXor.push_back(XOR(getUnsignedAttrFromXMLNode(pXor, "BANK"), - getUnsignedAttrFromXMLNode(pXor, "ROW"))); - } - - unsigned counter = 0; - for (tinyxml2::XMLElement *pChannel = pNode->FirstChildElement("CHANNEL_BIT"); - pChannel != nullptr; pChannel = pChannel->NextSiblingElement("CHANNEL_BIT")) - { - unsigned nChannel = getUnsignedTextFromXMLNode(pChannel); - vChannelBits.push_back(std::pair(counter++, nChannel)); - } - - counter = 0; - for (tinyxml2::XMLElement *pRank = pNode->FirstChildElement("RANK_BIT"); - pRank != nullptr; pRank = pRank->NextSiblingElement("RANK_BIT")) - { - unsigned nRank = getUnsignedTextFromXMLNode(pRank); - vRankBits.push_back(std::pair(counter++, nRank)); - } - - counter = 0; - for (tinyxml2::XMLElement *pBankGroup = pNode->FirstChildElement("BANKGROUP_BIT"); - pBankGroup != nullptr; pBankGroup = pBankGroup->NextSiblingElement("BANKGROUP_BIT")) - { - unsigned nBankGroup = getUnsignedTextFromXMLNode(pBankGroup); - vBankGroupBits.push_back(std::pair(counter++, nBankGroup)); - } - - // get all bank bits - // Each bank bit of the address will be stored with a counter value which assigns the bit position DecodedAddress struct. - counter = 0; - for (tinyxml2::XMLElement *pBank = pNode->FirstChildElement("BANK_BIT"); - pBank != nullptr; pBank = pBank->NextSiblingElement("BANK_BIT")) - { - unsigned nBank = getUnsignedTextFromXMLNode(pBank); - vBankBits.push_back(std::pair(counter++, nBank)); - } - - // get all row bits bits - // Each Row bit of the address will be stored with a counter value which assigns the bit position DecodedAddress struct. - counter = 0; - for (tinyxml2::XMLElement *pRow = pNode->FirstChildElement("ROW_BIT"); - pRow != nullptr; pRow = pRow->NextSiblingElement("ROW_BIT")) { - unsigned nRow = getUnsignedTextFromXMLNode(pRow); - vRowBits.push_back(std::pair(counter++, nRow)); - } - - counter = 0; - for (tinyxml2::XMLElement *pColumn = pNode->FirstChildElement("COLUMN_BIT"); - pColumn != nullptr; pColumn = pColumn->NextSiblingElement("COLUMN_BIT")) - { - unsigned nColumn = getUnsignedTextFromXMLNode(pColumn); - vColumnBits.push_back(std::pair(counter++, nColumn)); - } - - counter = 0; - for (tinyxml2::XMLElement *pByte = pNode->FirstChildElement("BYTE_BIT"); - pByte != nullptr; pByte = pByte->NextSiblingElement("BYTE_BIT")) - { - unsigned nByte = getUnsignedTextFromXMLNode(pByte); - vByteBits.push_back(std::pair(counter++, nByte)); - } - - // Fill the amount map. This is copied from xmlAddressDecoder without further investigation - amount.channel = pow(2.0, vChannelBits.size()); - amount.rank = pow(2.0, vRankBits.size()); - amount.bankgroup = pow(2.0, vBankGroupBits.size()); - amount.bank = pow(2.0, vBankBits.size()); - amount.row = pow(2.0, vRowBits.size()); - amount.column = pow(2.0, vColumnBits.size()); - amount.bytes = pow(2.0, vByteBits.size()); - - banksPerGroup = amount.bank; - amount.bank = banksPerGroup * amount.bankgroup * amount.rank; - - bankgroupsPerRank = amount.bankgroup; - amount.bankgroup = bankgroupsPerRank * amount.rank; - - maximumAddress = amount.bytes * amount.column * amount.row * banksPerGroup * bankgroupsPerRank * amount.rank * amount.channel - 1; - - Configuration &config = Configuration::getInstance(); - MemSpec *memSpec = config.memSpec; - - if (config.numberOfMemChannels != amount.channel || memSpec->numberOfRanks != amount.rank - || memSpec->numberOfBankGroups != amount.bankgroup || memSpec->numberOfBanks != amount.bank - || memSpec->numberOfRows != amount.row || memSpec->numberOfColumns != amount.column - || config.numberOfDevicesOnDIMM * memSpec->bitWidth != amount.bytes * 8) - SC_REPORT_FATAL("CongenAddressDecoder", "Memspec and addressmapping do not match"); -} - -DecodedAddress CongenAddressDecoder::decodeAddress(uint64_t encAddr) -{ - if (encAddr > maximumAddress) - SC_REPORT_WARNING("CongenAddressDecoder", ("Address " + std::to_string(encAddr) + " out of range (maximum address is " + std::to_string(maximumAddress) + ")").c_str()); - - // Apply XOR - // For each used xor: - // Get the bank bit and row bit. Apply a bitwise xor operator and save it back to the bank bit. - for (auto it = vXor.begin(); it != vXor.end(); it++) - { - unsigned new_bank_bit; - // Bank Row - new_bank_bit = (((encAddr >> it->nBank) & 1) ^ ((encAddr >> it->nRow) & 1)); - encAddr &= ~(1 << it->nBank); - encAddr |= new_bank_bit << it->nBank; - } - - DecodedAddress decAddr; - - decAddr.channel = 0; - for (auto it = vChannelBits.begin(); it != vChannelBits.end(); it++) - decAddr.channel |= ((encAddr >> it->second) & 1) << it->first; - - decAddr.rank = 0; - for (auto it = vRankBits.begin(); it != vRankBits.end(); it++) - decAddr.rank |= ((encAddr >> it->second) & 1) << it->first; - - decAddr.bankgroup = 0; - for (auto it = vBankGroupBits.begin(); it != vBankGroupBits.end(); it++) - decAddr.bankgroup |= ((encAddr >> it->second) & 1) << it->first; - - // Bank - // it->second: position of the target bit in the address - // it->first: target position of the bit in the variable - // For each bank bit: - // shift address bit to position 0. Clear all other bits. shift it the right bank bit. Add it to the set of bank bits. - decAddr.bank = 0; - for (auto it = vBankBits.begin(); it != vBankBits.end(); it++) - decAddr.bank |= ((encAddr >> it->second) & 1) << it->first; - - // Row - // it->second: position of the target bit in the address - // it->first: target position of the bit in the variable - // For each row bit: - // shift address bit to position 0. Clear all other bits. shift it the right row bit. Add it to the set of row bits. - decAddr.row = 0; - for (auto it = vRowBits.begin(); it != vRowBits.end(); it++) - decAddr.row |= ((encAddr >> it->second) & 1) << it->first; - - // Column - // it->second: position of the target bit in the address - // it->first: target position of the bit in the variable - // For each column bit: - // shift address bit to position 0. Clear all other bits. shift it the right column bit. Add it to the set of column bits. - decAddr.column = 0; - for (auto it = vColumnBits.begin(); it != vColumnBits.end(); it++) - decAddr.column |= ((encAddr >> it->second) & 1) << it->first; - - decAddr.bankgroup = decAddr.bankgroup + decAddr.rank * bankgroupsPerRank; - decAddr.bank = decAddr.bank + decAddr.bankgroup * banksPerGroup; - - return decAddr; -} - -uint64_t CongenAddressDecoder::encodeAddress(DecodedAddress decAddr) -{ - decAddr.bankgroup = decAddr.bankgroup % bankgroupsPerRank; - decAddr.bank = decAddr.bank % banksPerGroup; - - uint64_t encAddr = 0; - - for (auto it = vChannelBits.begin(); it != vChannelBits.end(); it++) - encAddr |= ((decAddr.channel >> it->first) & 1) << it->second; - - for (auto it = vRankBits.begin(); it != vRankBits.end(); it++) - encAddr |= ((decAddr.rank >> it->first) & 1) << it->second; - - for (auto it = vBankGroupBits.begin(); it != vBankGroupBits.end(); it++) - encAddr |= ((decAddr.bankgroup >> it->first) & 1) << it->second; - - // Bank - // it->first: position of the target bit in the DecodedAddress struct field - // it->second: target position of the bit in the address - // For each bank bit: - // shift bank bit to position 0. Clear all other bits. shift it the right address bit. Add it to the set of address bits. - for (auto it = vBankBits.begin(); it != vBankBits.end(); it++) - encAddr |= ((decAddr.bank >> it->first) & 1) << it->second; - - // Row - // it->first: position of the target bit in the DecodedAddress struct field - // it->second: target position of the bit in the address - // For each row bit: - // shift row bit to position 0. Clear all other bits. shift it the right address bit. Add it to the set of address bits. - for (auto it = vRowBits.begin(); it != vRowBits.end(); it++) - encAddr |= ((decAddr.row >> it->first) & 1) << it->second; - - // Column - // it->first: position of the target bit in the DecodedAddress struct field - // it->second: target position of the bit in the address - // For each column bit: - // shift column bit to position 0. Clear all other bits. shift it the right address bit. Add it to the set of address bits. - for (auto it = vColumnBits.begin(); it != vColumnBits.end(); it++) - encAddr |= ((decAddr.column >> it->first) & 1) << it->second; - - for (auto it = vByteBits.begin(); it != vByteBits.end(); it++) - encAddr |= ((decAddr.bytes >> it->first) & 1) << it->second; - - // Apply XOR - // For each used xor: - // Get the bank bit and row bit. Apply a bitwise xor operator and save it back to the bank bit. - for (auto it = vXor.begin(); it != vXor.end(); it++) - { - unsigned new_bank_bit; - new_bank_bit = (((encAddr >> it->nBank) & 1) ^ ((encAddr >> it->nRow) & 1)); - encAddr &= ~(1 << it->nBank); - encAddr |= new_bank_bit << it->nBank; - } - - return encAddr; -} - -bool CongenAddressDecoder::testConfigFile(std::string url) -{ - // Simple test if the root node has the correct name. - // This is suitable for now, but can be extended in future. - - tinyxml2::XMLDocument doc; - loadXML(url, doc); - tinyxml2::XMLElement *pRoot = doc.RootElement(); - - return (strcmp(pRoot->Name(), "CONGEN") == 0); -} - -void CongenAddressDecoder::print() -{ - std::map> output; - - for (auto it = vBankBits.begin(); it != vBankBits.end(); it++) { - output[it->second] = std::pair(it->first, 'B'); - } - for (auto it = vRowBits.begin(); it != vRowBits.end(); it++) { - output[it->second] = std::pair(it->first, 'R'); - } - for (auto it = vColumnBits.begin(); it != vColumnBits.end(); it++) { - output[it->second] = std::pair(it->first, 'C'); - } - - // add byte bits - output[0] = std::pair(0, 'b'); - output[1] = std::pair(1, 'b'); - output[2] = std::pair(2, 'b'); - - std::cout << "Used addressmapping:" << std::endl; - std::cout << headline << std::endl; - for (unsigned i = 0; i < 32; i++) { - std::cout << " " << i << " "; - } - std::cout << std::endl; - for (unsigned i = 0; i < 32; i++) { - std::cout << " " << output[i].second << "(" << output[i].first << ") "; - } - std::cout << std::endl; -} diff --git a/DRAMSys/library/src/common/CongenAddressDecoder.h b/DRAMSys/library/src/common/CongenAddressDecoder.h deleted file mode 100644 index 100ae350..00000000 --- a/DRAMSys/library/src/common/CongenAddressDecoder.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2018, University of Kaiserslautern - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Authors: - * Johannes Feldmann - */ - -#ifndef CONGENADDRESSDECODER_H -#define CONGENADDRESSDECODER_H - -#include "AddressDecoder.h" - -#include "third_party/tinyxml2/tinyxml2.h" - -#include -#include - -class CongenAddressDecoder : private AddressDecoder -{ - // Friendship needed so that the AddressDecoder can access the - // constructor of this class to create the object in CreateInstance. - friend class AddressDecoder; - -public: - struct XOR - { - unsigned nBank; - unsigned nRow; - XOR() {} - XOR(unsigned bank, unsigned row) : nBank(bank), nRow(row) {} - }; - -// Member variables -private: - // This container stores for each used xor gate a pair which consists of "First/Number of an address bit which corresponds to a bank" and "Second/Number of an address bit which corresponds to a row" - std::vector vXor; - std::vector> vChannelBits; - std::vector> vRankBits; - std::vector> vBankGroupBits; - // This container stores for each bank bit a pair which consists of "First/Number of the bank bit" and "Second/Number of the address bit" - std::vector> vBankBits; - // This container stores for each row bit a pair which consists of "First/Number of the row bit" and "Second/Number of the address bit" - std::vector> vRowBits; - // This container stores for each column bit a pair which consists of "First/Number of the column bit" and "Second/Number of the address bit" - std::vector> vColumnBits; - std::vector> vByteBits; - -//Methods -private: - tinyxml2::XMLElement *getXMLNode(tinyxml2::XMLElement *pRoot, - std::string strName); - unsigned int getUnsignedTextFromXMLNode(tinyxml2::XMLElement *pRoot); - unsigned int getUnsignedAttrFromXMLNode(tinyxml2::XMLElement *pRoot, - std::string strName); -public: - virtual void setConfiguration(std::string url); - - virtual DecodedAddress decodeAddress(uint64_t addr); - virtual uint64_t encodeAddress(DecodedAddress n); - - static bool testConfigFile(std::string url); - - virtual void print(); -}; - -#endif // CONGENADDRESSDECODER_H diff --git a/DRAMSys/library/src/common/XmlAddressDecoder.cpp b/DRAMSys/library/src/common/XmlAddressDecoder.cpp deleted file mode 100644 index 168f8899..00000000 --- a/DRAMSys/library/src/common/XmlAddressDecoder.cpp +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright (c) 2015, University of Kaiserslautern - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Authors: - * Janik Schlemminger - * Robert Gernhardt - * Matthias Jung - */ - -#include "XmlAddressDecoder.h" -#include -#include "utils.h" -#include "bitset" -#include "../configuration/Configuration.h" - -using namespace tinyxml2; - -XmlAddressDecoder::XmlAddressDecoder() -{ - addressmapping = NULL; -} - -void XmlAddressDecoder::setConfiguration(std::string addressConfigURI) -{ - tinyxml2::XMLDocument doc; - loadXML(addressConfigURI, doc); - tinyxml2::XMLElement *addressMap = doc.RootElement(); - std::string xmlNodeName(addressMap->Name()); - - if (xmlNodeName != "addressmapping") - reportFatal("AddressDecorder", "addressmap node expected"); - - for (XMLElement *child = addressMap->FirstChildElement(); - child != NULL; child = child->NextSiblingElement()) - { - unsigned from; - unsigned to; - - child->QueryAttribute("from", &from); - child->QueryAttribute("to", &to); - - if (std::strcmp(child->Name(), "channel") == 0) - { - shifts.channel = from; - masks.channel = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); - amount.channel = pow(2.0, to - from + 1.0); - } - else if (std::strcmp(child->Name(), "rank") == 0) - { - shifts.rank = from; - masks.rank = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); - amount.rank = pow(2.0, to - from + 1.0); - } - else if (std::strcmp(child->Name(), "bankgroup") == 0) - { - shifts.bankgroup = from; - masks.bankgroup = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); - amount.bankgroup = pow(2.0, to - from + 1.0); - } - else if (std::strcmp(child->Name(), "bank") == 0) - { - shifts.bank = from; - masks.bank = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); - amount.bank = pow(2.0, to - from + 1.0); - } - else if (std::strcmp(child->Name(), "row") == 0) - { - shifts.row = from; - masks.row = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); - amount.row = pow(2.0, to - from + 1.0); - } - else if (std::strcmp(child->Name(), "column") == 0) - { - shifts.column = from; - masks.column = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); - amount.column = pow(2.0, to - from + 1.0); - } - else if (std::strcmp(child->Name(), "bytes") == 0) - { - shifts.bytes = from; - masks.bytes = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); - amount.bytes = pow(2.0, to - from + 1.0); - } - else - SC_REPORT_FATAL("XmlAddressDecoder", ("Unknown field " + std::string(child->Name())).c_str()); - } - - banksPerGroup = amount.bank; - amount.bank = banksPerGroup * amount.bankgroup * amount.rank; - - bankgroupsPerRank = amount.bankgroup; - amount.bankgroup = bankgroupsPerRank * amount.rank; - - maximumAddress = amount.bytes * amount.column * amount.row * banksPerGroup * bankgroupsPerRank * amount.rank * amount.channel - 1; - - Configuration &config = Configuration::getInstance(); - MemSpec *memSpec = config.memSpec; - - if (config.numberOfMemChannels != amount.channel || memSpec->numberOfRanks != amount.rank - || memSpec->numberOfBankGroups != amount.bankgroup || memSpec->numberOfBanks != amount.bank - || memSpec->numberOfRows != amount.row || memSpec->numberOfColumns != amount.column - || config.numberOfDevicesOnDIMM * memSpec->bitWidth != amount.bytes * 8) - SC_REPORT_FATAL("XmlAddressDecoder", "Memspec and addressmapping do not match"); -} - - -DecodedAddress XmlAddressDecoder::decodeAddress(uint64_t encAddr) -{ - if (encAddr > maximumAddress) - SC_REPORT_WARNING("XmlAddressDecoder", ("Address " + std::to_string(encAddr) + " out of range (maximum address is " + std::to_string(maximumAddress) + ")").c_str()); - - DecodedAddress result; - result.channel = (encAddr & masks.channel) >> shifts.channel; - result.rank = (encAddr & masks.rank) >> shifts.rank; - result.bankgroup = ((encAddr & masks.bankgroup) >> shifts.bankgroup) - + result.rank * bankgroupsPerRank; - result.bank = ((encAddr & masks.bank) >> shifts.bank) - + result.bankgroup * banksPerGroup; - result.row = (encAddr & masks.row) >> shifts.row; - result.column = (encAddr & masks.column) >> shifts.column; - result.bytes = (encAddr & masks.bytes) >> shifts.bytes; - return result; -} - -uint64_t XmlAddressDecoder::encodeAddress(DecodedAddress decAddr) -{ - return (decAddr.channel << shifts.channel) | - (decAddr.rank << shifts.rank) | - ((decAddr.bankgroup % bankgroupsPerRank) << shifts.bankgroup) | - ((decAddr.bank % banksPerGroup) << shifts.bank) | - (decAddr.row << shifts.row) | - (decAddr.column << shifts.column) | - (decAddr.bytes << shifts.bytes); -} - -bool XmlAddressDecoder::testConfigFile(std::string url) -{ - // Simple test if the root node has the correct name. - // This is suitable for now, but can be extended in future. - - tinyxml2::XMLDocument doc; - loadXML(url, doc); - tinyxml2::XMLElement *addressMap = doc.RootElement(); - - return (strcmp(addressMap->Name(), "addressmapping") == 0); -} - -void XmlAddressDecoder::print() -{ - std::cout << headline << std::endl; - std::cout << "Address Mapping:" << std::endl << std::endl; - std::cout << " channel: " << std::bitset<64>(masks.channel) << std::endl; - std::cout << " rank: " << std::bitset<64>(masks.rank) << std::endl; - std::cout << " bankgroup: " << std::bitset<64>(masks.bankgroup) << std::endl; - std::cout << " bank: " << std::bitset<64>(masks.bank) << std::endl; - std::cout << " row: " << std::bitset<64>(masks.row) << std::endl; - std::cout << " column: " << std::bitset<64>(masks.column) << std::endl; - std::cout << " bytes: " << std::bitset<64>(masks.bytes) << std::endl; - std::cout << std::endl; -} diff --git a/DRAMSys/library/src/common/XmlAddressDecoder.h b/DRAMSys/library/src/common/XmlAddressDecoder.h deleted file mode 100644 index a733ca05..00000000 --- a/DRAMSys/library/src/common/XmlAddressDecoder.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2015, University of Kaiserslautern - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER - * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * Authors: - * Janik Schlemminger - * Robert Gernhardt - * Matthias Jung - */ - -#ifndef XMLADDRESSDECODER_H -#define XMLADDRESSDECODER_H - -#include - -#include "utils.h" -#include "third_party/tinyxml2/tinyxml2.h" -#include "AddressDecoder.h" - -class XmlAddressDecoder : private AddressDecoder -{ - // Friendship needed so that the AddressDecoder can access the - // constructor of this class to create the object in CreateInstance. - friend class AddressDecoder; - -private: - tinyxml2::XMLElement *addressmapping; - - struct Masks - { - uint64_t channel = 0; - uint64_t rank = 0; - uint64_t bankgroup = 0; - uint64_t bank = 0; - uint64_t row = 0; - uint64_t column = 0; - uint64_t bytes = 0; - } masks; - - struct Shifts - { - unsigned channel = 0; - unsigned rank = 0; - unsigned bankgroup = 0; - unsigned bank = 0; - unsigned row = 0; - unsigned column = 0; - unsigned bytes = 0; - } shifts; - -public: - XmlAddressDecoder(); - - virtual void setConfiguration(std::string url); - - virtual DecodedAddress decodeAddress(uint64_t addr); - virtual uint64_t encodeAddress(DecodedAddress n); - - static bool testConfigFile(std::string url); - - virtual void print(); -}; - -#endif // XMLADDRESSDECODER_H