AND2.cc revision 10447
1#include "model/std_cells/AND2.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::max; 18 19 AND2::AND2(const String& instance_name_, const TechModel* tech_model_) 20 : StdCell(instance_name_, tech_model_) 21 { 22 initProperties(); 23 } 24 25 AND2::~AND2() 26 {} 27 28 void AND2::initProperties() 29 { 30 return; 31 } 32 33 void AND2::constructModel() 34 { 35 // All constructModel should do is create Area/NDDPower/Energy Results as 36 // well as instantiate any sub-instances using only the hard parameters 37 38 createInputPort("A"); 39 createInputPort("B"); 40 createOutputPort("Y"); 41 42 createLoad("A_Cap"); 43 createLoad("B_Cap"); 44 createDelay("A_to_Y_delay"); 45 createDelay("B_to_Y_delay"); 46 createDriver("Y_Ron", true); 47 48 ElectricalLoad* a_cap = getLoad("A_Cap"); 49 ElectricalLoad* b_cap = getLoad("B_Cap"); 50 ElectricalDelay* a_to_y_delay = getDelay("A_to_Y_delay"); 51 ElectricalDelay* b_to_y_delay = getDelay("B_to_Y_delay"); 52 ElectricalDriver* y_ron = getDriver("Y_Ron"); 53 54 getNet("A")->addDownstreamNode(a_cap); 55 getNet("B")->addDownstreamNode(b_cap); 56 a_cap->addDownstreamNode(a_to_y_delay); 57 b_cap->addDownstreamNode(b_to_y_delay); 58 a_to_y_delay->addDownstreamNode(y_ron); 59 b_to_y_delay->addDownstreamNode(y_ron); 60 y_ron->addDownstreamNode(getNet("Y")); 61 62 // Create Area result 63 // Create NDD Power result 64 createElectricalAtomicResults(); 65 getEventInfo("Idle")->setStaticTransitionInfos(); 66 // Create AND Event Energy Result 67 createElectricalEventAtomicResult("AND2"); 68 69 return; 70 } 71 72 void AND2::updateModel() 73 { 74 // All updateModel should do is calculate numbers for the Area/NDDPower/Energy 75 // Results as anything else that needs to be done using either soft or hard parameters 76 77 // Get parameters 78 double drive_strength = getDrivingStrength(); 79 Map<double>* cache = getTechModel()->getStdCellLib()->getStdCellCache(); 80 81 // Standard cell cache string 82 String cell_name = "AND2_X" + (String) drive_strength; 83 84 // Get timing parameters 85 getLoad("A_Cap")->setLoadCap(cache->get(cell_name + "->Cap->A")); 86 getLoad("B_Cap")->setLoadCap(cache->get(cell_name + "->Cap->B")); 87 getDelay("A_to_Y_delay")->setDelay(cache->get(cell_name + "->Delay->A_to_Y")); 88 getDelay("B_to_Y_delay")->setDelay(cache->get(cell_name + "->Delay->B_to_Y")); 89 getDriver("Y_Ron")->setOutputRes(cache->get(cell_name + "->DriveRes->Y")); 90 91 // Set the cell area 92 getAreaResult("Active")->setValue(cache->get(cell_name + "->ActiveArea")); 93 getAreaResult("Metal1Wire")->setValue(cache->get(cell_name + "->ActiveArea")); 94 95 return; 96 } 97 98 void AND2::evaluateModel() 99 { 100 return; 101 } 102 103 void AND2::useModel() 104 { 105 // Get parameters 106 double drive_strength = getDrivingStrength(); 107 Map<double>* cache = getTechModel()->getStdCellLib()->getStdCellCache(); 108 109 // Standard cell cache string 110 String cell_name = "AND2_X" + (String) drive_strength; 111 112 // Propagate the transition info and get the 0->1 transtion count 113 propagateTransitionInfo(); 114 double P_A = getInputPort("A")->getTransitionInfo().getProbability1(); 115 double P_B = getInputPort("B")->getTransitionInfo().getProbability1(); 116 double Y_num_trans_01 = getOutputPort("Y")->getTransitionInfo().getNumberTransitions01(); 117 118 // Calculate leakage 119 double leakage = 0; 120 leakage += cache->get(cell_name + "->Leakage->!A!B") * (1 - P_A) * (1 - P_B); 121 leakage += cache->get(cell_name + "->Leakage->!AB") * (1 - P_A) * P_B; 122 leakage += cache->get(cell_name + "->Leakage->A!B") * P_A * (1 - P_B); 123 leakage += cache->get(cell_name + "->Leakage->AB") * P_A * P_B; 124 getNddPowerResult("Leakage")->setValue(leakage); 125 126 // Get VDD 127 double vdd = getTechModel()->get("Vdd"); 128 129 // Get capacitances 130 double y_b_cap = cache->get(cell_name + "->Cap->Y_b"); 131 double y_cap = cache->get(cell_name + "->Cap->Y"); 132 double y_load_cap = getNet("Y")->getTotalDownstreamCap(); 133 134 // Calculate AND2Event energy 135 double energy_per_trans_01 = (y_b_cap + y_cap + y_load_cap) * vdd * vdd; 136 getEventResult("AND2")->setValue(energy_per_trans_01 * Y_num_trans_01); 137 138 return; 139 } 140 141 void AND2::propagateTransitionInfo() 142 { 143 // Get input signal transition info 144 const TransitionInfo& trans_A = getInputPort("A")->getTransitionInfo(); 145 const TransitionInfo& trans_B = getInputPort("B")->getTransitionInfo(); 146 147 double max_freq_mult = max(trans_A.getFrequencyMultiplier(), trans_B.getFrequencyMultiplier()); 148 const TransitionInfo& scaled_trans_A = trans_A.scaleFrequencyMultiplier(max_freq_mult); 149 const TransitionInfo& scaled_trans_B = trans_B.scaleFrequencyMultiplier(max_freq_mult); 150 151 double A_prob_00 = scaled_trans_A.getNumberTransitions00() / max_freq_mult; 152 double A_prob_01 = scaled_trans_A.getNumberTransitions01() / max_freq_mult; 153 double A_prob_10 = A_prob_01; 154 double A_prob_11 = scaled_trans_A.getNumberTransitions11() / max_freq_mult; 155 double B_prob_00 = scaled_trans_B.getNumberTransitions00() / max_freq_mult; 156 double B_prob_01 = scaled_trans_B.getNumberTransitions01() / max_freq_mult; 157 double B_prob_10 = B_prob_01; 158 double B_prob_11 = scaled_trans_B.getNumberTransitions11() / max_freq_mult; 159 160 // Set output transition info 161 double Y_prob_00 = A_prob_00 + 162 A_prob_01 * (B_prob_00 + B_prob_10) + 163 A_prob_10 * (B_prob_00 + B_prob_01) + 164 A_prob_11 * B_prob_00; 165 double Y_prob_01 = A_prob_01 * (B_prob_01 + B_prob_11) + 166 A_prob_11 * B_prob_01; 167 double Y_prob_11 = A_prob_11 * B_prob_11; 168 169 // Check that probabilities add up to 1.0 with some finite tolerance 170 ASSERT(LibUtil::Math::isEqual(Y_prob_00 + Y_prob_01 + Y_prob_01 + Y_prob_11, 1.0), "[Error] " + getInstanceName() + 171 "Output transition probabilities must add up to 1 (" + (String) Y_prob_00 + ", " + 172 (String) Y_prob_01 + ", " + (String) Y_prob_11 + ")!"); 173 174 // Turn probability of transitions per cycle into number of transitions per time unit 175 TransitionInfo trans_Y(Y_prob_00 * max_freq_mult, Y_prob_01 * max_freq_mult, Y_prob_11 * max_freq_mult); 176 getOutputPort("Y")->setTransitionInfo(trans_Y); 177 return; 178 } 179 180 void AND2::cacheStdCell(StdCellLib* cell_lib_, double drive_strength_) 181 { 182 // Standard cell cache string 183 String cell_name = "AND2_X" + (String) drive_strength_; 184 185 Log::printLine("=== " + cell_name + " ==="); 186 187 // Get parameters 188 double gate_pitch = cell_lib_->getTechModel()->get("Gate->PitchContacted"); 189 Map<double>* cache = cell_lib_->getStdCellCache(); 190 191 // Now actually build the full standard cell model 192 // Create the two input ports 193 createInputPort("A"); 194 createInputPort("B"); 195 createOutputPort("Y"); 196 197 createNet("Y_b"); 198 199 // Adds macros 200 CellMacros::addNand2(this, "NAND2", false, true, true, "A", "B", "Y_b"); 201 CellMacros::addInverter(this, "INV", false, true, "Y_b", "Y"); 202 CellMacros::updateNand2(this, "NAND2", drive_strength_ * 0.5); 203 CellMacros::updateInverter(this, "INV", drive_strength_ * 1.0); 204 205 // Cache area result 206 double area = 0.0; 207 area += gate_pitch * getTotalHeight() * 1; 208 area += gate_pitch * getTotalHeight() * getGenProperties()->get("NAND2_GatePitches").toDouble(); 209 area += gate_pitch * getTotalHeight() * getGenProperties()->get("INV_GatePitches").toDouble(); 210 cache->set(cell_name + "->ActiveArea", area); 211 Log::printLine(cell_name + "->ActiveArea=" + (String) area); 212 213 // -------------------------------------------------------------------- 214 // Leakage Model Calculation 215 // -------------------------------------------------------------------- 216 double leakage_00 = getGenProperties()->get("NAND2_LeakagePower_00").toDouble() + 217 getGenProperties()->get("INV_LeakagePower_0").toDouble(); 218 double leakage_01 = getGenProperties()->get("NAND2_LeakagePower_01").toDouble() + 219 getGenProperties()->get("INV_LeakagePower_0").toDouble(); 220 double leakage_10 = getGenProperties()->get("NAND2_LeakagePower_10").toDouble() + 221 getGenProperties()->get("INV_LeakagePower_0").toDouble(); 222 double leakage_11 = getGenProperties()->get("NAND2_LeakagePower_11").toDouble() + 223 getGenProperties()->get("INV_LeakagePower_1").toDouble(); 224 cache->set(cell_name + "->Leakage->!A!B", leakage_00); 225 cache->set(cell_name + "->Leakage->!AB", leakage_01); 226 cache->set(cell_name + "->Leakage->A!B", leakage_10); 227 cache->set(cell_name + "->Leakage->AB", leakage_11); 228 Log::printLine(cell_name + "->Leakage->!A!B=" + (String) leakage_00); 229 Log::printLine(cell_name + "->Leakage->!AB=" + (String) leakage_01); 230 Log::printLine(cell_name + "->Leakage->A!B=" + (String) leakage_10); 231 Log::printLine(cell_name + "->Leakage->AB=" + (String) leakage_11); 232 // -------------------------------------------------------------------- 233 234 // -------------------------------------------------------------------- 235 // Get Node Capacitances 236 // -------------------------------------------------------------------- 237 double a_cap = getNet("A")->getTotalDownstreamCap(); 238 double b_cap = getNet("B")->getTotalDownstreamCap(); 239 double y_b_cap = getNet("Y_b")->getTotalDownstreamCap(); 240 double y_cap = getNet("Y")->getTotalDownstreamCap(); 241 242 cache->set(cell_name + "->Cap->A", a_cap); 243 cache->set(cell_name + "->Cap->B", b_cap); 244 cache->set(cell_name + "->Cap->Y_b", y_b_cap); 245 cache->set(cell_name + "->Cap->Y", y_cap); 246 Log::printLine(cell_name + "->Cap->A=" + (String) a_cap); 247 Log::printLine(cell_name + "->Cap->B=" + (String) b_cap); 248 Log::printLine(cell_name + "->Cap->Y=" + (String) y_b_cap); 249 Log::printLine(cell_name + "->Cap->Y=" + (String) y_cap); 250 // -------------------------------------------------------------------- 251 252 // -------------------------------------------------------------------- 253 // Build Internal Delay Model 254 // -------------------------------------------------------------------- 255 double y_ron = getDriver("INV_RonZN")->getOutputRes(); 256 double a_to_y_delay = getDriver("NAND2_RonZN")->calculateDelay() + 257 getDriver("INV_RonZN")->calculateDelay(); 258 double b_to_y_delay = getDriver("NAND2_RonZN")->calculateDelay() + 259 getDriver("INV_RonZN")->calculateDelay(); 260 261 cache->set(cell_name + "->DriveRes->Y", y_ron); 262 cache->set(cell_name + "->Delay->A_to_Y", a_to_y_delay); 263 cache->set(cell_name + "->Delay->B_to_Y", b_to_y_delay); 264 Log::printLine(cell_name + "->DriveRes->Y=" + (String) y_ron); 265 Log::printLine(cell_name + "->Delay->A_to_Y=" + (String) a_to_y_delay); 266 Log::printLine(cell_name + "->Delay->B_to_Y=" + (String) b_to_y_delay); 267 // -------------------------------------------------------------------- 268 269 return; 270 271 } 272} // namespace DSENT 273