XOR2.cc revision 10448
12381SN/A/* Copyright (c) 2012 Massachusetts Institute of Technology 28922Swilliam.wang@arm.com * 38922Swilliam.wang@arm.com * Permission is hereby granted, free of charge, to any person obtaining a copy 48922Swilliam.wang@arm.com * of this software and associated documentation files (the "Software"), to deal 58922Swilliam.wang@arm.com * in the Software without restriction, including without limitation the rights 68922Swilliam.wang@arm.com * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 78922Swilliam.wang@arm.com * copies of the Software, and to permit persons to whom the Software is 88922Swilliam.wang@arm.com * furnished to do so, subject to the following conditions: 98922Swilliam.wang@arm.com * 108922Swilliam.wang@arm.com * The above copyright notice and this permission notice shall be included in 118922Swilliam.wang@arm.com * all copies or substantial portions of the Software. 128922Swilliam.wang@arm.com * 138922Swilliam.wang@arm.com * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 142381SN/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 152381SN/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 162381SN/A * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 172381SN/A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 182381SN/A * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 192381SN/A * THE SOFTWARE. 202381SN/A */ 212381SN/A 222381SN/A#include "model/std_cells/XOR2.h" 232381SN/A 242381SN/A#include <cmath> 252381SN/A 262381SN/A#include "model/PortInfo.h" 272381SN/A#include "model/EventInfo.h" 282381SN/A#include "model/TransitionInfo.h" 292381SN/A#include "model/std_cells/StdCellLib.h" 302381SN/A#include "model/std_cells/CellMacros.h" 312381SN/A#include "model/timing_graph/ElectricalNet.h" 322381SN/A#include "model/timing_graph/ElectricalDriver.h" 332381SN/A#include "model/timing_graph/ElectricalLoad.h" 342381SN/A#include "model/timing_graph/ElectricalDelay.h" 352381SN/A 362381SN/Anamespace DSENT 372381SN/A{ 382381SN/A using std::ceil; 392665Ssaidi@eecs.umich.edu using std::max; 402665Ssaidi@eecs.umich.edu 418922Swilliam.wang@arm.com XOR2::XOR2(const String& instance_name_, const TechModel* tech_model_) 422381SN/A : StdCell(instance_name_, tech_model_) 432381SN/A { 442381SN/A initProperties(); 452381SN/A } 468922Swilliam.wang@arm.com 472381SN/A XOR2::~XOR2() 482381SN/A {} 492381SN/A 502381SN/A void XOR2::initProperties() 512381SN/A { 524762Snate@binkert.org return; 534762Snate@binkert.org } 549157Sandreas.hansson@arm.com 552381SN/A void XOR2::constructModel() 562381SN/A { 579157Sandreas.hansson@arm.com // All constructModel should do is create Area/NDDPower/Energy Results as 588922Swilliam.wang@arm.com // well as instantiate any sub-instances using only the hard parameters 592381SN/A 609157Sandreas.hansson@arm.com createInputPort("A"); 612381SN/A createInputPort("B"); 622381SN/A createOutputPort("Y"); 634762Snate@binkert.org 645530Snate@binkert.org createLoad("A_Cap"); 655530Snate@binkert.org createLoad("B_Cap"); 665530Snate@binkert.org createDelay("A_to_Y_delay"); 674762Snate@binkert.org createDelay("B_to_Y_delay"); 682394SN/A createDriver("Y_Ron", true); 698922Swilliam.wang@arm.com 708922Swilliam.wang@arm.com ElectricalLoad* a_cap = getLoad("A_Cap"); 718922Swilliam.wang@arm.com ElectricalLoad* b_cap = getLoad("B_Cap"); 728922Swilliam.wang@arm.com ElectricalDelay* a_to_y_delay = getDelay("A_to_Y_delay"); 738922Swilliam.wang@arm.com ElectricalDelay* b_to_y_delay = getDelay("B_to_Y_delay"); 748922Swilliam.wang@arm.com ElectricalDriver* y_ron = getDriver("Y_Ron"); 758922Swilliam.wang@arm.com 768922Swilliam.wang@arm.com getNet("A")->addDownstreamNode(a_cap); 778922Swilliam.wang@arm.com getNet("B")->addDownstreamNode(b_cap); 788922Swilliam.wang@arm.com a_cap->addDownstreamNode(a_to_y_delay); 798922Swilliam.wang@arm.com b_cap->addDownstreamNode(b_to_y_delay); 808922Swilliam.wang@arm.com a_to_y_delay->addDownstreamNode(y_ron); 818922Swilliam.wang@arm.com b_to_y_delay->addDownstreamNode(y_ron); 828922Swilliam.wang@arm.com y_ron->addDownstreamNode(getNet("Y")); 838922Swilliam.wang@arm.com 848922Swilliam.wang@arm.com // Create Area result 858922Swilliam.wang@arm.com // Create NDD Power result 868922Swilliam.wang@arm.com createElectricalAtomicResults(); 878922Swilliam.wang@arm.com // Create XOR2 Event Energy Result 888922Swilliam.wang@arm.com createElectricalEventAtomicResult("XOR2"); 898922Swilliam.wang@arm.com 902381SN/A getEventInfo("Idle")->setStaticTransitionInfos(); 912381SN/A 922381SN/A return; 93 } 94 95 void XOR2::updateModel() 96 { 97 // Get parameters 98 double drive_strength = getDrivingStrength(); 99 Map<double>* cache = getTechModel()->getStdCellLib()->getStdCellCache(); 100 101 // Standard cell cache string 102 String cell_name = "XOR2_X" + (String) drive_strength; 103 104 // Get timing parameters 105 getLoad("A_Cap")->setLoadCap(cache->get(cell_name + "->Cap->A")); 106 getLoad("B_Cap")->setLoadCap(cache->get(cell_name + "->Cap->B")); 107 108 getDelay("A_to_Y_delay")->setDelay(cache->get(cell_name + "->Delay->A_to_Y")); 109 getDelay("B_to_Y_delay")->setDelay(cache->get(cell_name + "->Delay->B_to_Y")); 110 111 getDriver("Y_Ron")->setOutputRes(cache->get(cell_name + "->DriveRes->Y")); 112 113 // Set the cell area 114 getAreaResult("Active")->setValue(cache->get(cell_name + "->ActiveArea")); 115 getAreaResult("Metal1Wire")->setValue(cache->get(cell_name + "->ActiveArea")); 116 117 return; 118 } 119 120 void XOR2::evaluateModel() 121 { 122 return; 123 } 124 125 void XOR2::useModel() 126 { 127 // Get parameters 128 double drive_strength = getDrivingStrength(); 129 Map<double>* cache = getTechModel()->getStdCellLib()->getStdCellCache(); 130 131 // Standard cell cache string 132 String cell_name = "XOR2_X" + (String) drive_strength; 133 134 // Propagate the transition info and get the 0->1 transtion count 135 propagateTransitionInfo(); 136 double P_A = getInputPort("A")->getTransitionInfo().getProbability1(); 137 double P_B = getInputPort("B")->getTransitionInfo().getProbability1(); 138 double A_num_trans_01 = getInputPort("A")->getTransitionInfo().getNumberTransitions01(); 139 double B_num_trans_01 = getInputPort("B")->getTransitionInfo().getNumberTransitions01(); 140 double Y_num_trans_01 = getOutputPort("Y")->getTransitionInfo().getNumberTransitions01(); 141 142 // Calculate leakage 143 double leakage = 0; 144 leakage += cache->get(cell_name + "->Leakage->!A!B") * (1 - P_A) * (1 - P_B); 145 leakage += cache->get(cell_name + "->Leakage->!AB") * (1 - P_A) * P_B; 146 leakage += cache->get(cell_name + "->Leakage->A!B") * P_A * (1 - P_B); 147 leakage += cache->get(cell_name + "->Leakage->AB") * P_A * P_B; 148 getNddPowerResult("Leakage")->setValue(leakage); 149 150 // Get VDD 151 double vdd = getTechModel()->get("Vdd"); 152 153 // Get capacitances 154 double a_b_cap = cache->get(cell_name + "->Cap->A_b"); 155 double b_b_cap = cache->get(cell_name + "->Cap->B_b"); 156 double y_cap = cache->get(cell_name + "->Cap->Y"); 157 double y_load_cap = getNet("Y")->getTotalDownstreamCap(); 158 159 // Calculate XOR Event energy 160 double xor2_event_result = 0.0; 161 xor2_event_result += a_b_cap * A_num_trans_01; 162 xor2_event_result += b_b_cap * B_num_trans_01; 163 xor2_event_result += (y_cap + y_load_cap) * Y_num_trans_01; 164 xor2_event_result *= vdd * vdd; 165 getEventResult("XOR2")->setValue(xor2_event_result); 166 167 return; 168 } 169 170 void XOR2::propagateTransitionInfo() 171 { 172 // Get input signal transition info 173 const TransitionInfo& trans_A = getInputPort("A")->getTransitionInfo(); 174 const TransitionInfo& trans_B = getInputPort("B")->getTransitionInfo(); 175 176 double max_freq_mult = max(trans_A.getFrequencyMultiplier(), trans_B.getFrequencyMultiplier()); 177 const TransitionInfo& scaled_trans_A = trans_A.scaleFrequencyMultiplier(max_freq_mult); 178 const TransitionInfo& scaled_trans_B = trans_B.scaleFrequencyMultiplier(max_freq_mult); 179 180 181 double A_prob_00 = scaled_trans_A.getNumberTransitions00() / max_freq_mult; 182 double A_prob_01 = scaled_trans_A.getNumberTransitions01() / max_freq_mult; 183 double A_prob_10 = A_prob_01; 184 double A_prob_11 = scaled_trans_A.getNumberTransitions11() / max_freq_mult; 185 double B_prob_00 = scaled_trans_B.getNumberTransitions00() / max_freq_mult; 186 double B_prob_01 = scaled_trans_B.getNumberTransitions01() / max_freq_mult; 187 double B_prob_10 = B_prob_01; 188 double B_prob_11 = scaled_trans_B.getNumberTransitions11() / max_freq_mult; 189 190 // Set output transition info 191 double Y_prob_00 = A_prob_00 * B_prob_00 + 192 A_prob_01 * B_prob_01 + 193 A_prob_10 * B_prob_10 + 194 A_prob_11 * B_prob_11; 195 double Y_prob_01 = A_prob_00 * B_prob_01 + 196 A_prob_01 * B_prob_00 + 197 A_prob_10 * B_prob_11 + 198 A_prob_11 * B_prob_10; 199 double Y_prob_11 = A_prob_00 * B_prob_11 + 200 A_prob_01 * B_prob_10 + 201 A_prob_10 * B_prob_01 + 202 A_prob_11 * B_prob_00; 203 204 // Check that probabilities add up to 1.0 with some finite tolerance 205 ASSERT(LibUtil::Math::isEqual((Y_prob_00 + Y_prob_01 + Y_prob_01 + Y_prob_11), 1.0), 206 "[Error] " + getInstanceName() + "Output transition probabilities must add up to 1 (" + 207 (String) Y_prob_00 + ", " + (String) Y_prob_01 + ", " + (String) Y_prob_11 + ")!"); 208 209 // Turn probability of transitions per cycle into number of transitions per time unit 210 TransitionInfo trans_Y(Y_prob_00 * max_freq_mult, Y_prob_01 * max_freq_mult, Y_prob_11 * max_freq_mult); 211 getOutputPort("Y")->setTransitionInfo(trans_Y); 212 return; 213 } 214 215 // Creates the standard cell, characterizes and abstracts away the details 216 void XOR2::cacheStdCell(StdCellLib* cell_lib_, double drive_strength_) 217 { 218 // Get parameters 219 double gate_pitch = cell_lib_->getTechModel()->get("Gate->PitchContacted"); 220 Map<double>* cache = cell_lib_->getStdCellCache(); 221 222 // Standard cell cache string 223 String cell_name = "XOR2_X" + (String) drive_strength_; 224 225 Log::printLine("=== " + cell_name + " ==="); 226 227 // Now actually build the full standard cell model 228 createInputPort("A"); 229 createInputPort("B"); 230 createOutputPort("Y"); 231 232 createNet("A_b"); 233 createNet("B_b"); 234 235 // Adds macros 236 CellMacros::addInverter(this, "INV1", false, true, "A", "A_b"); 237 CellMacros::addInverter(this, "INV2", false, true, "B", "B_b"); 238 CellMacros::addTristate(this, "INVZ1", true, true, true, true, "B", "A", "A_b", "Y"); 239 CellMacros::addTristate(this, "INVZ2", true, true, true, true, "B_b", "A_b", "A", "Y"); 240 241 // I have no idea how to size each of the parts haha 242 CellMacros::updateInverter(this, "INV1", drive_strength_ * 0.500); 243 CellMacros::updateInverter(this, "INV2", drive_strength_ * 0.500); 244 CellMacros::updateTristate(this, "INVZ1", drive_strength_ * 1.000); 245 CellMacros::updateTristate(this, "INVZ2", drive_strength_ * 1.000); 246 247 // Cache area result 248 double area = 0.0; 249 area += gate_pitch * getTotalHeight() * 1; 250 area += gate_pitch * getTotalHeight() * getGenProperties()->get("INV1_GatePitches").toDouble(); 251 area += gate_pitch * getTotalHeight() * getGenProperties()->get("INV2_GatePitches").toDouble(); 252 area += gate_pitch * getTotalHeight() * getGenProperties()->get("INVZ1_GatePitches").toDouble(); 253 area += gate_pitch * getTotalHeight() * getGenProperties()->get("INVZ2_GatePitches").toDouble(); 254 cache->set(cell_name + "->ActiveArea", area); 255 Log::printLine(cell_name + "->ActiveArea=" + (String) area); 256 257 // -------------------------------------------------------------------- 258 // Leakage Model Calculation 259 // -------------------------------------------------------------------- 260 // Cache leakage power results (for every single signal combination) 261 double leakage_00 = 0; //!A, !B 262 double leakage_01 = 0; //!A, B 263 double leakage_10 = 0; //A, !B 264 double leakage_11 = 0; //A, B 265 266 //This is so painful... 267 leakage_00 += getGenProperties()->get("INV1_LeakagePower_0").toDouble(); 268 leakage_00 += getGenProperties()->get("INV2_LeakagePower_0").toDouble(); 269 leakage_00 += getGenProperties()->get("INVZ1_LeakagePower_010_0").toDouble(); 270 leakage_00 += getGenProperties()->get("INVZ2_LeakagePower_101_0").toDouble(); 271 272 leakage_01 += getGenProperties()->get("INV1_LeakagePower_0").toDouble(); 273 leakage_01 += getGenProperties()->get("INV2_LeakagePower_1").toDouble(); 274 leakage_01 += getGenProperties()->get("INVZ1_LeakagePower_011_1").toDouble(); 275 leakage_01 += getGenProperties()->get("INVZ2_LeakagePower_100_1").toDouble(); 276 277 leakage_10 += getGenProperties()->get("INV1_LeakagePower_1").toDouble(); 278 leakage_10 += getGenProperties()->get("INV2_LeakagePower_0").toDouble(); 279 leakage_10 += getGenProperties()->get("INVZ1_LeakagePower_100_1").toDouble(); 280 leakage_10 += getGenProperties()->get("INVZ2_LeakagePower_011_1").toDouble(); 281 282 leakage_11 += getGenProperties()->get("INV1_LeakagePower_1").toDouble(); 283 leakage_11 += getGenProperties()->get("INV2_LeakagePower_1").toDouble(); 284 leakage_11 += getGenProperties()->get("INVZ1_LeakagePower_101_0").toDouble(); 285 leakage_11 += getGenProperties()->get("INVZ2_LeakagePower_010_0").toDouble(); 286 287 cache->set(cell_name + "->Leakage->!A!B", leakage_00); 288 cache->set(cell_name + "->Leakage->!AB", leakage_01); 289 cache->set(cell_name + "->Leakage->A!B", leakage_10); 290 cache->set(cell_name + "->Leakage->AB", leakage_11); 291 Log::printLine(cell_name + "->Leakage->!A!B=" + (String) leakage_00); 292 Log::printLine(cell_name + "->Leakage->!AB=" + (String) leakage_01); 293 Log::printLine(cell_name + "->Leakage->A!B=" + (String) leakage_10); 294 Log::printLine(cell_name + "->Leakage->AB=" + (String) leakage_11); 295 // -------------------------------------------------------------------- 296 297 // Cache event energy results 298 /* 299 double event_a_flip = 0.0; 300 event_a_flip += getGenProperties()->get("INV1_A_Flip").toDouble() + getGenProperties()->get("INV1_ZN_Flip").toDouble(); 301 event_a_flip += getGenProperties()->get("INVZ1_OE_Flip").toDouble() + getGenProperties()->get("INVZ1_OEN_Flip").toDouble(); 302 event_a_flip += getGenProperties()->get("INVZ2_OE_Flip").toDouble() + getGenProperties()->get("INVZ2_OEN_Flip").toDouble(); 303 cache->set(cell_name + "->Event_A_Flip", event_a_flip); 304 Log::printLine(cell_name + "->Event_A_Flip=" + (String) event_a_flip); 305 306 double event_b_flip = 0.0; 307 event_b_flip += getGenProperties()->get("INV2_A_Flip").toDouble() + getGenProperties()->get("INV2_ZN_Flip").toDouble(); 308 event_b_flip += getGenProperties()->get("INVZ1_A_Flip").toDouble(); 309 event_b_flip += getGenProperties()->get("INVZ2_A_Flip").toDouble(); 310 cache->set(cell_name + "->Event_B_Flip", event_b_flip); 311 Log::printLine(cell_name + "->Event_B_Flip=" + (String) event_b_flip); 312 313 double event_y_flip = 0.0; 314 event_y_flip += getGenProperties()->get("INVZ1_ZN_Flip").toDouble(); 315 event_y_flip += getGenProperties()->get("INVZ2_ZN_Flip").toDouble(); 316 cache->set(cell_name + "->Event_Y_Flip", event_y_flip); 317 Log::printLine(cell_name + "->Event_Y_Flip=" + (String) event_y_flip); 318 */ 319 320 // -------------------------------------------------------------------- 321 // Get Node Capacitances 322 // -------------------------------------------------------------------- 323 // Build abstracted timing model 324 double a_cap = getNet("A")->getTotalDownstreamCap(); 325 double b_cap = getNet("B")->getTotalDownstreamCap(); 326 double a_b_cap = getNet("A_b")->getTotalDownstreamCap(); 327 double b_b_cap = getNet("B_b")->getTotalDownstreamCap(); 328 double y_cap = getNet("Y")->getTotalDownstreamCap(); 329 330 cache->set(cell_name + "->Cap->A", a_cap); 331 cache->set(cell_name + "->Cap->B", b_cap); 332 cache->set(cell_name + "->Cap->A_b", a_b_cap); 333 cache->set(cell_name + "->Cap->B_b", b_b_cap); 334 cache->set(cell_name + "->Cap->Y", y_cap); 335 Log::printLine(cell_name + "->Cap->A=" + (String) a_cap); 336 Log::printLine(cell_name + "->Cap->B=" + (String) b_cap); 337 Log::printLine(cell_name + "->Cap->A=" + (String) a_b_cap); 338 Log::printLine(cell_name + "->Cap->B=" + (String) b_b_cap); 339 Log::printLine(cell_name + "->Cap->Y=" + (String) y_cap); 340 // -------------------------------------------------------------------- 341 342 // -------------------------------------------------------------------- 343 // Build Internal Delay Model 344 // -------------------------------------------------------------------- 345 double y_ron = (getDriver("INVZ1_RonZN")->getOutputRes() + getDriver("INVZ2_RonZN")->getOutputRes()) / 2; 346 347 double a_to_y_delay = 0.0; 348 a_to_y_delay += getDriver("INV1_RonZN")->calculateDelay(); 349 a_to_y_delay += max(getDriver("INVZ1_RonZN")->calculateDelay(), getDriver("INVZ2_RonZN")->calculateDelay()); 350 351 double b_to_y_delay = 0.0; 352 b_to_y_delay += max(getDriver("INVZ1_RonZN")->calculateDelay(), getDriver("INV2_RonZN")->calculateDelay() + getDriver("INVZ2_RonZN")->calculateDelay()); 353 354 cache->set(cell_name + "->DriveRes->Y", y_ron); 355 cache->set(cell_name + "->Delay->A_to_Y", a_to_y_delay); 356 cache->set(cell_name + "->Delay->B_to_Y", b_to_y_delay); 357 Log::printLine(cell_name + "->DriveRes->Y=" + (String) y_ron); 358 Log::printLine(cell_name + "->Delay->A_to_Y=" + (String) a_to_y_delay); 359 Log::printLine(cell_name + "->Delay->B_to_Y=" + (String) b_to_y_delay); 360 // -------------------------------------------------------------------- 361 362 return; 363 } 364 365} // namespace DSENT 366 367