MemCommand.h revision 10428:0caf62b57dfd
1/* 2 * Copyright (c) 2012-2014, TU Delft 3 * Copyright (c) 2012-2014, TU Eindhoven 4 * Copyright (c) 2012-2014, TU Kaiserslautern 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions are 9 * met: 10 * 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * 3. Neither the name of the copyright holder nor the names of its 19 * contributors may be used to endorse or promote products derived from 20 * this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 23 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 28 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * 34 * Authors: Karthik Chandrasekar 35 * 36 */ 37 38#ifndef MEMCOMMAND_H 39#define MEMCOMMAND_H 40 41#include <stdint.h> 42#include <cassert> 43#include <string> 44 45#include "MemorySpecification.h" 46 47namespace Data { 48class MemCommand { 49 public: 50 /* 51 * 1. ACT - Activate 52 * 2. RD - Read 53 * 3. WR - Write 54 * 4. PRE - Explicit Precharge per bank 55 * 5. REF - Refresh all banks 56 * 6. END - To indicate end of trace 57 * 7. RDA - Read with auto-precharge 58 * 8. WRA - Write with auto-precharge 59 * 9. PREA - Precharge all banks 60 * 10. PDN_F_PRE - Precharge Power-down Entry command (Fast-Exit) 61 * 11. PDN_S_PRE - Precharge Power-down Entry command (Slow-Exit) 62 * 12. PDN_F_ACT - Active Power-down Entry command (Fast-Exit) 63 * 13. PDN_S_ACT - Active Power-down Entry command (Slow-Exit) 64 * 14. PUP_PRE - Precharge Power-down Exit 65 * 15. PUP_ACT - Active Power-down Exit 66 * 16. SREN - Self-Refresh Entry command 67 * 17. SREX - Self-refresh Exit 68 * 18. NOP - To indicate end of trace 69 */ 70 71 enum cmds { 72 ACT = 0, 73 RD = 1, 74 WR = 2, 75 PRE = 3, 76 REF = 4, 77 END = 5, 78 RDA = 6, 79 WRA = 7, 80 PREA = 8, 81 PDN_F_PRE = 9, 82 PDN_S_PRE = 10, 83 PDN_F_ACT = 11, 84 PDN_S_ACT = 12, 85 PUP_PRE = 13, 86 PUP_ACT = 14, 87 SREN = 15, 88 SREX = 16, 89 NOP = 17 90 }; 91 92 MemCommand(); 93 MemCommand( 94 // Command Type 95 MemCommand::cmds type, 96 // Target Bank 97 unsigned bank = 0, 98 // Command Issue Timestamp (in cc) 99 double timestamp = 0); 100 101 // Get command type 102 cmds getType() const; 103 104 // Set command type 105 void setType(MemCommand::cmds type); 106 107 // Set target Bank 108 void setBank(unsigned bank); 109 110 // Get target Bank 111 unsigned getBank() const; 112 113 // Set timestamp 114 void setTime(double _timestamp); 115 116 // Get timestamp 117 double getTime() const; 118 int64_t getTimeInt64() const; 119 120 cmds typeWithoutAutoPrechargeFlag() const; 121 122 // To calculate precharge offset after read or write with auto-precharge 123 int getPrechargeOffset(const MemorySpecification& memSpec, 124 MemCommand::cmds type) const; 125 126 // To check for equivalence 127 128 bool operator==(const MemCommand& other) const 129 { 130 if ((getType() == other.getType()) && 131 (getBank() == other.getBank()) 132 ) { 133 return true; 134 } else { 135 return false; 136 } 137 } 138 139 static const unsigned int nCommands = 18; 140 141 static std::string* getCommandTypeStrings() 142 { 143 static std::string type_map[nCommands] = { "ACT", "RD", "WR", "PRE", "REF", 144 "END", "RDA", "WRA", "PREA", "PDN_F_PRE","PDN_S_PRE", "PDN_F_ACT", 145 "PDN_S_ACT", "PUP_PRE", "PUP_ACT", "SREN", "SREX", "NOP" }; 146 147 return type_map; 148 } 149 150 // To identify command type from name 151 static cmds getTypeFromName(const std::string name) 152 { 153 std::string* typeStrings = getCommandTypeStrings(); 154 155 for (size_t typeId = 0; typeId < nCommands; typeId++) { 156 if (typeStrings[typeId] == name) { 157 cmds commandType = static_cast<cmds>(typeId); 158 return commandType; 159 } 160 } 161 assert(false); // Unknown name. 162 } 163 164 private: 165 MemCommand::cmds type; 166 unsigned bank; 167 double timestamp; 168}; 169} 170#endif // ifndef MEMCOMMAND_H 171