MUX2.cc revision 10447
1#include "model/std_cells/MUX2.h" 2 3#include <cmath> 4 5#include "model/PortInfo.h" 6#include "model/TransitionInfo.h" 7#include "model/EventInfo.h" 8#include "model/std_cells/StdCellLib.h" 9#include "model/std_cells/CellMacros.h" 10#include "model/timing_graph/ElectricalNet.h" 11#include "model/timing_graph/ElectricalDriver.h" 12#include "model/timing_graph/ElectricalLoad.h" 13#include "model/timing_graph/ElectricalDelay.h" 14 15namespace DSENT 16{ 17 using std::ceil; 18 using std::max; 19 20 MUX2::MUX2(const String& instance_name_, const TechModel* tech_model_) 21 : StdCell(instance_name_, tech_model_) 22 { 23 initProperties(); 24 } 25 26 MUX2::~MUX2() 27 {} 28 29 void MUX2::initProperties() 30 { 31 return; 32 } 33 34 void MUX2::constructModel() 35 { 36 // All constructModel should do is create Area/NDDPower/Energy Results as 37 // well as instantiate any sub-instances using only the hard parameters 38 39 createInputPort("A"); 40 createInputPort("B"); 41 createInputPort("S0"); 42 createOutputPort("Y"); 43 44 createLoad("A_Cap"); 45 createLoad("B_Cap"); 46 createLoad("S0_Cap"); 47 createDelay("A_to_Y_delay"); 48 createDelay("B_to_Y_delay"); 49 createDelay("S0_to_Y_delay"); 50 createDriver("Y_Ron", true); 51 52 ElectricalLoad* a_cap = getLoad("A_Cap"); 53 ElectricalLoad* b_cap = getLoad("B_Cap"); 54 ElectricalLoad* s0_cap = getLoad("S0_Cap"); 55 ElectricalDelay* a_to_y_delay = getDelay("A_to_Y_delay"); 56 ElectricalDelay* b_to_y_delay = getDelay("B_to_Y_delay"); 57 ElectricalDelay* s0_to_y_delay = getDelay("S0_to_Y_delay"); 58 ElectricalDriver* y_ron = getDriver("Y_Ron"); 59 60 getNet("A")->addDownstreamNode(a_cap); 61 getNet("B")->addDownstreamNode(b_cap); 62 getNet("S0")->addDownstreamNode(s0_cap); 63 a_cap->addDownstreamNode(a_to_y_delay); 64 b_cap->addDownstreamNode(b_to_y_delay); 65 s0_cap->addDownstreamNode(s0_to_y_delay); 66 a_to_y_delay->addDownstreamNode(y_ron); 67 b_to_y_delay->addDownstreamNode(y_ron); 68 s0_to_y_delay->addDownstreamNode(y_ron); 69 y_ron->addDownstreamNode(getNet("Y")); 70 71 // Create Area result 72 createElectricalAtomicResults(); 73 getEventInfo("Idle")->setStaticTransitionInfos(); 74 // Create MUX2 Event Energy Result 75 createElectricalEventAtomicResult("MUX2"); 76 77 78 return; 79 } 80 81 void MUX2::updateModel() 82 { 83 // Get parameters 84 double drive_strength = getDrivingStrength(); 85 Map<double>* cache = getTechModel()->getStdCellLib()->getStdCellCache(); 86 87 // Standard cell cache string 88 String cell_name = "MUX2_X" + (String) drive_strength; 89 90 // Get timing parameters 91 getLoad("A_Cap")->setLoadCap(cache->get(cell_name + "->Cap->A")); 92 getLoad("B_Cap")->setLoadCap(cache->get(cell_name + "->Cap->B")); 93 getLoad("S0_Cap")->setLoadCap(cache->get(cell_name + "->Cap->S0")); 94 95 getDelay("A_to_Y_delay")->setDelay(cache->get(cell_name + "->Delay->A_to_Y")); 96 getDelay("B_to_Y_delay")->setDelay(cache->get(cell_name + "->Delay->B_to_Y")); 97 getDelay("S0_to_Y_delay")->setDelay(cache->get(cell_name + "->Delay->S0_to_Y")); 98 99 getDriver("Y_Ron")->setOutputRes(cache->get(cell_name + "->DriveRes->Y")); 100 101 // Set the cell area 102 getAreaResult("Active")->setValue(cache->get(cell_name + "->ActiveArea")); 103 getAreaResult("Metal1Wire")->setValue(cache->get(cell_name + "->ActiveArea")); 104 105 return; 106 } 107 108 void MUX2::evaluateModel() 109 { 110 return; 111 } 112 113 void MUX2::useModel() 114 { 115 // Get parameters 116 double drive_strength = getDrivingStrength(); 117 Map<double>* cache = getTechModel()->getStdCellLib()->getStdCellCache(); 118 119 // Standard cell cache string 120 String cell_name = "MUX2_X" + (String) drive_strength; 121 122 // Propagate the transition and get the 0->1 transition count 123 propagateTransitionInfo(); 124 double P_A = getInputPort("A")->getTransitionInfo().getProbability1(); 125 double P_B = getInputPort("B")->getTransitionInfo().getProbability1(); 126 double P_S0 = getInputPort("S0")->getTransitionInfo().getProbability1(); 127 double S0_num_trans_01 = getInputPort("S0")->getTransitionInfo().getNumberTransitions01(); 128 double Y_num_trans_01 = getOutputPort("Y")->getTransitionInfo().getNumberTransitions01(); 129 130 // Calculate leakage 131 double leakage = 0; 132 leakage += cache->get(cell_name + "->Leakage->!A!B!S0") * (1 - P_A) * (1 - P_B) * (1 - P_S0); 133 leakage += cache->get(cell_name + "->Leakage->!A!BS0") * (1 - P_A) * (1 - P_B) * P_S0; 134 leakage += cache->get(cell_name + "->Leakage->!AB!S0") * (1 - P_A) * P_B * (1 - P_S0); 135 leakage += cache->get(cell_name + "->Leakage->!ABS0") * (1 - P_A) * P_B * P_S0; 136 leakage += cache->get(cell_name + "->Leakage->A!B!S0") * P_A * (1 - P_B) * (1 - P_S0); 137 leakage += cache->get(cell_name + "->Leakage->A!BS0") * P_A * (1 - P_B) * P_S0; 138 leakage += cache->get(cell_name + "->Leakage->AB!S0") * P_A * P_B * (1 - P_S0); 139 leakage += cache->get(cell_name + "->Leakage->ABS0") * P_A * P_B * P_S0; 140 getNddPowerResult("Leakage")->setValue(leakage); 141 142 // Get VDD 143 double vdd = getTechModel()->get("Vdd"); 144 145 // Get capacitances 146 double s0_b_cap = cache->get(cell_name + "->Cap->S0_b"); 147 double y_bar_cap = cache->get(cell_name + "->Cap->Y_b"); 148 double y_cap = cache->get(cell_name + "->Cap->Y"); 149 double y_load_cap = getNet("Y")->getTotalDownstreamCap(); 150 // Create mux2 event energy 151 double mux2_event_energy = 0.0; 152 mux2_event_energy += (s0_b_cap) * S0_num_trans_01; 153 mux2_event_energy += (y_bar_cap + y_cap + y_load_cap) * Y_num_trans_01; 154 mux2_event_energy *= vdd * vdd; 155 getEventResult("MUX2")->setValue(mux2_event_energy); 156 157 return; 158 } 159 160 void MUX2::propagateTransitionInfo() 161 { 162 // Get input signal transition info 163 const TransitionInfo& trans_A = getInputPort("A")->getTransitionInfo(); 164 const TransitionInfo& trans_B = getInputPort("B")->getTransitionInfo(); 165 const TransitionInfo& trans_S0 = getInputPort("S0")->getTransitionInfo(); 166 167 // Scale all transition information to the highest freq multiplier 168 double max_freq_mult = max(max(trans_A.getFrequencyMultiplier(), trans_B.getFrequencyMultiplier()), trans_S0.getFrequencyMultiplier()); 169 const TransitionInfo& scaled_trans_A = trans_A.scaleFrequencyMultiplier(max_freq_mult); 170 const TransitionInfo& scaled_trans_B = trans_B.scaleFrequencyMultiplier(max_freq_mult); 171 const TransitionInfo& scaled_trans_S0 = trans_S0.scaleFrequencyMultiplier(max_freq_mult); 172 173 // Compute the probability of each transition on a given cycle 174 double A_prob_00 = scaled_trans_A.getNumberTransitions00() / max_freq_mult; 175 double A_prob_01 = scaled_trans_A.getNumberTransitions01() / max_freq_mult; 176 double A_prob_10 = A_prob_01; 177 double A_prob_11 = scaled_trans_A.getNumberTransitions11() / max_freq_mult; 178 double B_prob_00 = scaled_trans_B.getNumberTransitions00() / max_freq_mult; 179 double B_prob_01 = scaled_trans_B.getNumberTransitions01() / max_freq_mult; 180 double B_prob_10 = B_prob_01; 181 double B_prob_11 = scaled_trans_B.getNumberTransitions11() / max_freq_mult; 182 double S0_prob_00 = scaled_trans_S0.getNumberTransitions00() / max_freq_mult; 183 double S0_prob_01 = scaled_trans_S0.getNumberTransitions01() / max_freq_mult; 184 double S0_prob_10 = S0_prob_01; 185 double S0_prob_11 = scaled_trans_S0.getNumberTransitions11() / max_freq_mult; 186 187 // Compute output probabilities 188 double Y_prob_00 = S0_prob_00 * A_prob_00 + 189 S0_prob_01 * (A_prob_00 + A_prob_01) * (B_prob_00 + B_prob_10) + 190 S0_prob_10 * (A_prob_00 + A_prob_10) * (B_prob_00 + B_prob_01) + 191 S0_prob_11 * B_prob_00; 192 double Y_prob_01 = S0_prob_00 * A_prob_01 + 193 S0_prob_01 * (A_prob_00 + A_prob_01) * (B_prob_01 + B_prob_11) + 194 S0_prob_10 * (A_prob_01 + A_prob_11) * (B_prob_00 + B_prob_01) + 195 S0_prob_11 * B_prob_01; 196 double Y_prob_11 = S0_prob_00 * A_prob_11 + 197 S0_prob_01 * (A_prob_10 + A_prob_11) * (B_prob_01 + B_prob_11) + 198 S0_prob_10 * (A_prob_01 + A_prob_11) * (B_prob_10 + B_prob_11) + 199 S0_prob_11 * B_prob_11; 200 201 // Check that probabilities add up to 1.0 with some finite tolerance 202 ASSERT(LibUtil::Math::isEqual((Y_prob_00 + Y_prob_01 + Y_prob_01 + Y_prob_11), 1.0), 203 "[Error] " + getInstanceName() + "Output transition probabilities must add up to 1 (" + 204 (String) Y_prob_00 + ", " + (String) Y_prob_01 + ", " + (String) Y_prob_11 + ")!"); 205 206 // Turn probability of transitions per cycle into number of transitions per time unit 207 TransitionInfo trans_Y(Y_prob_00 * max_freq_mult, Y_prob_01 * max_freq_mult, Y_prob_11 * max_freq_mult); 208 getOutputPort("Y")->setTransitionInfo(trans_Y); 209 210 return; 211 } 212 213 // Creates the standard cell, characterizes and abstracts away the details 214 void MUX2::cacheStdCell(StdCellLib* cell_lib_, double drive_strength_) 215 { 216 // Get parameters 217 double gate_pitch = cell_lib_->getTechModel()->get("Gate->PitchContacted"); 218 Map<double>* cache = cell_lib_->getStdCellCache(); 219 220 // Standard cell cache string 221 String cell_name = "MUX2_X" + (String) drive_strength_; 222 223 Log::printLine("=== " + cell_name + " ==="); 224 225 // Now actually build the full standard cell model 226 createInputPort("A"); 227 createInputPort("B"); 228 createInputPort("S0"); 229 createOutputPort("Y"); 230 231 createNet("S0_b"); 232 createNet("Y_b"); 233 234 // Adds macros 235 CellMacros::addInverter(this, "INV1", false, true, "S0", "S0_b"); 236 CellMacros::addInverter(this, "INV2", false, true, "Y_b", "Y"); 237 CellMacros::addTristate(this, "INVZ1", true, true, true, true, "A", "S0_b", "S0", "Y_b"); 238 CellMacros::addTristate(this, "INVZ2", true, true, true, true, "B", "S0", "S0_b", "Y_b"); 239 240 // I have no idea how to size each of the parts haha 241 CellMacros::updateInverter(this, "INV1", drive_strength_ * 0.250); 242 CellMacros::updateInverter(this, "INV2", drive_strength_ * 1.000); 243 CellMacros::updateTristate(this, "INVZ1", drive_strength_ * 0.500); 244 CellMacros::updateTristate(this, "INVZ2", drive_strength_ * 0.500); 245 246 // Cache area result 247 double area = 0.0; 248 area += gate_pitch * getTotalHeight() * 1; 249 area += gate_pitch * getTotalHeight() * getGenProperties()->get("INV1_GatePitches").toDouble(); 250 area += gate_pitch * getTotalHeight() * getGenProperties()->get("INV2_GatePitches").toDouble(); 251 area += gate_pitch * getTotalHeight() * getGenProperties()->get("INVZ1_GatePitches").toDouble(); 252 area += gate_pitch * getTotalHeight() * getGenProperties()->get("INVZ2_GatePitches").toDouble(); 253 cache->set(cell_name + "->ActiveArea", area); 254 Log::printLine(cell_name + "->ActiveArea=" + (String) area); 255 256 // -------------------------------------------------------------------- 257 // Cache Leakage Power (for every single signal combination) 258 // -------------------------------------------------------------------- 259 double leakage_000 = 0; //!A, !B, !S0 260 double leakage_001 = 0; //!A, !B, S0 261 double leakage_010 = 0; //!A, B, !S0 262 double leakage_011 = 0; //!A, B, S0 263 double leakage_100 = 0; //A, !B, !S0 264 double leakage_101 = 0; //A, !B, S0 265 double leakage_110 = 0; //A, B, !S0 266 double leakage_111 = 0; //A, B, S0 267 268 //This is so painful... 269 leakage_000 += getGenProperties()->get("INV1_LeakagePower_0").toDouble(); 270 leakage_000 += getGenProperties()->get("INV2_LeakagePower_1").toDouble(); 271 leakage_000 += getGenProperties()->get("INVZ1_LeakagePower_100_1").toDouble(); 272 leakage_000 += getGenProperties()->get("INVZ2_LeakagePower_010_1").toDouble(); 273 274 leakage_001 += getGenProperties()->get("INV1_LeakagePower_1").toDouble(); 275 leakage_001 += getGenProperties()->get("INV2_LeakagePower_1").toDouble(); 276 leakage_001 += getGenProperties()->get("INVZ1_LeakagePower_010_1").toDouble(); 277 leakage_001 += getGenProperties()->get("INVZ2_LeakagePower_100_1").toDouble(); 278 279 leakage_010 += getGenProperties()->get("INV1_LeakagePower_0").toDouble(); 280 leakage_010 += getGenProperties()->get("INV2_LeakagePower_1").toDouble(); 281 leakage_010 += getGenProperties()->get("INVZ1_LeakagePower_100_1").toDouble(); 282 leakage_010 += getGenProperties()->get("INVZ2_LeakagePower_011_1").toDouble(); 283 284 leakage_011 += getGenProperties()->get("INV1_LeakagePower_1").toDouble(); 285 leakage_011 += getGenProperties()->get("INV2_LeakagePower_0").toDouble(); 286 leakage_011 += getGenProperties()->get("INVZ1_LeakagePower_010_0").toDouble(); 287 leakage_011 += getGenProperties()->get("INVZ2_LeakagePower_101_0").toDouble(); 288 289 leakage_100 += getGenProperties()->get("INV1_LeakagePower_0").toDouble(); 290 leakage_100 += getGenProperties()->get("INV2_LeakagePower_0").toDouble(); 291 leakage_100 += getGenProperties()->get("INVZ1_LeakagePower_101_0").toDouble(); 292 leakage_100 += getGenProperties()->get("INVZ2_LeakagePower_010_0").toDouble(); 293 294 leakage_101 += getGenProperties()->get("INV1_LeakagePower_1").toDouble(); 295 leakage_101 += getGenProperties()->get("INV2_LeakagePower_0").toDouble(); 296 leakage_101 += getGenProperties()->get("INVZ1_LeakagePower_011_1").toDouble(); 297 leakage_101 += getGenProperties()->get("INVZ2_LeakagePower_100_1").toDouble(); 298 299 leakage_110 += getGenProperties()->get("INV1_LeakagePower_1").toDouble(); 300 leakage_110 += getGenProperties()->get("INV2_LeakagePower_1").toDouble(); 301 leakage_110 += getGenProperties()->get("INVZ1_LeakagePower_101_0").toDouble(); 302 leakage_110 += getGenProperties()->get("INVZ2_LeakagePower_011_0").toDouble(); 303 304 leakage_111 += getGenProperties()->get("INV1_LeakagePower_1").toDouble(); 305 leakage_111 += getGenProperties()->get("INV2_LeakagePower_1").toDouble(); 306 leakage_111 += getGenProperties()->get("INVZ1_LeakagePower_011_0").toDouble(); 307 leakage_111 += getGenProperties()->get("INVZ2_LeakagePower_101_0").toDouble(); 308 309 cache->set(cell_name + "->Leakage->!A!B!S0", leakage_000); 310 cache->set(cell_name + "->Leakage->!A!BS0", leakage_001); 311 cache->set(cell_name + "->Leakage->!AB!S0", leakage_010); 312 cache->set(cell_name + "->Leakage->!ABS0", leakage_011); 313 cache->set(cell_name + "->Leakage->A!B!S0", leakage_100); 314 cache->set(cell_name + "->Leakage->A!BS0", leakage_101); 315 cache->set(cell_name + "->Leakage->AB!S0", leakage_110); 316 cache->set(cell_name + "->Leakage->ABS0", leakage_111); 317 Log::printLine(cell_name + "->Leakage->!A!B!S0=" + (String) leakage_000); 318 Log::printLine(cell_name + "->Leakage->!A!BS0=" + (String) leakage_001); 319 Log::printLine(cell_name + "->Leakage->!AB!S0=" + (String) leakage_010); 320 Log::printLine(cell_name + "->Leakage->!ABS0=" + (String) leakage_011); 321 Log::printLine(cell_name + "->Leakage->A!B!S0=" + (String) leakage_100); 322 Log::printLine(cell_name + "->Leakage->A!BS0=" + (String) leakage_101); 323 Log::printLine(cell_name + "->Leakage->AB!S0=" + (String) leakage_110); 324 Log::printLine(cell_name + "->Leakage->ABS0=" + (String) leakage_111); 325 326 // Cache event energy results 327 /* 328 double event_a_flip = 0.0; 329 event_a_flip += getGenProperties()->get("INVZ1_A_Flip").toDouble(); 330 cache->set(cell_name + "->Event_A_Flip", event_a_flip); 331 Log::printLine(cell_name + "->Event_A_Flip=" + (String) event_a_flip); 332 333 double event_b_flip = 0.0; 334 event_b_flip += getGenProperties()->get("INVZ1_A_Flip").toDouble(); 335 cache->set(cell_name + "->Event_B_Flip", event_b_flip); 336 Log::printLine(cell_name + "->Event_B_Flip=" + (String) event_b_flip); 337 338 double event_s0_flip = 0.0; 339 event_s0_flip += getGenProperties()->get("INV1_A_Flip").toDouble(); 340 event_s0_flip += getGenProperties()->get("INV1_ZN_Flip").toDouble(); 341 event_s0_flip += getGenProperties()->get("INVZ1_OE_Flip").toDouble() + getGenProperties()->get("INVZ1_OEN_Flip").toDouble(); 342 event_s0_flip += getGenProperties()->get("INVZ2_OE_Flip").toDouble() + getGenProperties()->get("INVZ2_OEN_Flip").toDouble(); 343 cache->set(cell_name + "->Event_S0_Flip", event_s0_flip); 344 Log::printLine(cell_name + "->Event_S0_Flip=" + (String) event_s0_flip); 345 346 double event_y_flip = 0.0; 347 event_y_flip += getGenProperties()->get("INVZ1_ZN_Flip").toDouble(); 348 event_y_flip += getGenProperties()->get("INVZ2_ZN_Flip").toDouble(); 349 event_y_flip += getGenProperties()->get("INV2_A_Flip").toDouble(); 350 event_y_flip += getGenProperties()->get("INV2_ZN_Flip").toDouble(); 351 cache->set(cell_name + "->Event_Y_Flip", event_y_flip); 352 Log::printLine(cell_name + "->Event_Y_Flip=" + (String) event_y_flip); 353 354 double a_cap = getLoad("INVZ1_CgA")->getLoadCap(); 355 double b_cap = getLoad("INVZ2_CgA")->getLoadCap(); 356 double s0_cap = getLoad("INV1_CgA")->getLoadCap() + getLoad("INVZ1_CgOEN")->getLoadCap() + getLoad("INVZ2_CgOE")->getLoadCap(); 357 double y_ron = getDriver("INV2_RonZN")->getOutputRes(); 358 */ 359 // -------------------------------------------------------------------- 360 361 // -------------------------------------------------------------------- 362 // Get Node capacitances 363 // -------------------------------------------------------------------- 364 double a_cap = getNet("A")->getTotalDownstreamCap(); 365 double b_cap = getNet("B")->getTotalDownstreamCap(); 366 double s0_cap = getNet("S0")->getTotalDownstreamCap(); 367 double s0_b_cap = getNet("S0_b")->getTotalDownstreamCap(); 368 double y_b_cap = getNet("Y_b")->getTotalDownstreamCap(); 369 double y_cap = getNet("Y")->getTotalDownstreamCap(); 370 371 cache->set(cell_name + "->Cap->A", a_cap); 372 cache->set(cell_name + "->Cap->B", b_cap); 373 cache->set(cell_name + "->Cap->S0", s0_cap); 374 cache->set(cell_name + "->Cap->S0_b", s0_b_cap); 375 cache->set(cell_name + "->Cap->Y_b", y_b_cap); 376 cache->set(cell_name + "->Cap->Y", y_cap); 377 378 Log::printLine(cell_name + "->Cap->A=" + (String) a_cap); 379 Log::printLine(cell_name + "->Cap->B=" + (String) b_cap); 380 Log::printLine(cell_name + "->Cap->S0=" + (String) s0_cap); 381 Log::printLine(cell_name + "->Cap->S0_b=" + (String) s0_b_cap); 382 Log::printLine(cell_name + "->Cap->Y_b=" + (String) y_b_cap); 383 Log::printLine(cell_name + "->Cap->Y=" + (String) y_cap); 384 // -------------------------------------------------------------------- 385 386 // -------------------------------------------------------------------- 387 // Build Internal Delay Model 388 // -------------------------------------------------------------------- 389 // Build abstracted timing model 390 double y_ron = getDriver("INV2_RonZN")->getOutputRes(); 391 392 double a_to_y_delay = 0.0; 393 a_to_y_delay += getDriver("INVZ1_RonZN")->calculateDelay(); 394 a_to_y_delay += getDriver("INV2_RonZN")->calculateDelay(); 395 396 double b_to_y_delay = 0.0; 397 b_to_y_delay += getDriver("INVZ1_RonZN")->calculateDelay(); 398 b_to_y_delay += getDriver("INV2_RonZN")->calculateDelay(); 399 400 double s0_to_y_delay = 0.0; 401 s0_to_y_delay += getDriver("INV1_RonZN")->calculateDelay(); 402 s0_to_y_delay += max(getDriver("INVZ1_RonZN")->calculateDelay(), getDriver("INVZ1_RonZN")->calculateDelay()); 403 s0_to_y_delay += getDriver("INV2_RonZN")->calculateDelay(); 404 405 cache->set(cell_name + "->DriveRes->Y", y_ron); 406 cache->set(cell_name + "->Delay->A_to_Y", a_to_y_delay); 407 cache->set(cell_name + "->Delay->B_to_Y", b_to_y_delay); 408 cache->set(cell_name + "->Delay->S0_to_Y", s0_to_y_delay); 409 410 Log::printLine(cell_name + "->DriveRes->Y=" + (String) y_ron); 411 Log::printLine(cell_name + "->Delay->A_to_Y=" + (String) a_to_y_delay); 412 Log::printLine(cell_name + "->Delay->B_to_Y=" + (String) b_to_y_delay); 413 Log::printLine(cell_name + "->Delay->S0_to_Y=" + (String) s0_to_y_delay); 414 // -------------------------------------------------------------------- 415 416 return; 417 } 418 419} // namespace DSENT 420 421