File size: 8,348 Bytes
d1be154 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | #include <ot/timer/timer.hpp>
// TODO (twhuang)
// (1) extend taskflow's capability to enable intra-task parallelization
namespace ot {
// Function: set_time_unit
Timer& Timer::set_time_unit(second_t unit) {
std::scoped_lock lock(_mutex);
// timer task
auto task = _taskflow.emplace([this, unit=std::move(unit)] () {
_to_time_unit(unit);
});
_add_to_lineage(task);
return *this;
}
// Procedure: _to_time_unit
void Timer::_to_time_unit(const second_t& unit) {
OT_LOGI("use time unit ", unit);
float s = (_time_unit) ? (*_time_unit / unit).value() : 1.0f;
if(_time_unit = unit; std::fabs(s - 1.0f) < 1e-2f) {
return;
}
// scale po time
for(auto& kvp : _pos) {
kvp.second._scale_time(s);
}
// scale pi time
for(auto& kvp : _pis) {
kvp.second._scale_time(s);
}
// scale clock time
for(auto& kvp : _clocks) {
kvp.second._scale_time(s);
}
// library time
FOR_EACH_EL_IF(el, _celllib[el]) {
_celllib[el]->scale_time(s);
}
// enable full timing update
_enable_full_timing_update();
}
// Function: set_capacitance_unit
Timer& Timer::set_capacitance_unit(farad_t unit) {
std::scoped_lock lock(_mutex);
// task
auto task = _taskflow.emplace([this, unit=std::move(unit)] () {
_to_capacitance_unit(unit);
});
_add_to_lineage(task);
return *this;
}
// Procedure: _to_capacitance_unit
void Timer::_to_capacitance_unit(const farad_t& unit) {
OT_LOGI("use capacitance unit ", unit);
float s = (_capacitance_unit) ? (*_capacitance_unit / unit).value() : 1.0f;
if(_capacitance_unit = unit; std::fabs(s - 1.0f) < 1e-2f) {
return;
}
// scale po capacitance
for(auto& kvp : _pos) {
kvp.second._scale_capacitance(s);
}
// scale net capacitance
for(auto& kvp : _nets) {
kvp.second._scale_capacitance(s);
}
// library capacitance
FOR_EACH_EL_IF(el, _celllib[el]) {
_celllib[el]->scale_capacitance(s);
}
// TODO: other filed may need to change as well
_enable_full_timing_update();
}
// Function: set_resistance_unit
Timer& Timer::set_resistance_unit(ohm_t unit) {
std::scoped_lock lock(_mutex);
// task
auto task = _taskflow.emplace([this, unit=std::move(unit)] () {
_to_resistance_unit(unit);
});
_add_to_lineage(task);
return *this;
}
// Procedure: _to_resistance_unit
void Timer::_to_resistance_unit(const ohm_t& unit) {
OT_LOGI("use resistance unit ", unit);
float s = (_resistance_unit) ? (*_resistance_unit / unit).value() : 1.0f;
if(_resistance_unit = unit; std::fabs(s - 1.0f) < 1e-2f) {
return;
}
// scale net resistance
for(auto& kvp : _nets) {
kvp.second._scale_resistance(s);
}
// library resistance
FOR_EACH_EL_IF(el, _celllib[el]) {
_celllib[el]->scale_resistance(s);
}
// TODO:
_enable_full_timing_update();
}
// Function: set_voltage_unit
Timer& Timer::set_voltage_unit(volt_t unit) {
std::scoped_lock lock(_mutex);
// task
auto task = _taskflow.emplace([this, unit=std::move(unit)] () {
_to_voltage_unit(unit);
});
_add_to_lineage(task);
return *this;
}
// Procedure: _to_voltage_unit
void Timer::_to_voltage_unit(const volt_t& unit) {
OT_LOGI("use voltage unit ", unit);
float s = (_voltage_unit) ? (*_voltage_unit/unit).value() : 1.0f;
if(_voltage_unit = unit; std::fabs(s - 1.0f) < 1e-2f) {
return;
}
// TODO:
_enable_full_timing_update();
}
// Function: set_current_unit
Timer& Timer::set_current_unit(ampere_t unit) {
std::scoped_lock lock(_mutex);
// task
auto task = _taskflow.emplace([this, unit=std::move(unit)] () {
_to_current_unit(unit);
});
_add_to_lineage(task);
return *this;
}
// Procedure: _to_current_unit
void Timer::_to_current_unit(const ampere_t& unit) {
OT_LOGI("use current unit ", unit);
float s = (_current_unit) ? (*_current_unit / unit).value() : 1.0f;
if(_current_unit = unit; std::fabs(s - 1.0f) < 1e-2f) {
return;
}
// TODO:
_enable_full_timing_update();
}
// Function: set_power_unit
Timer& Timer::set_power_unit(watt_t unit) {
std::scoped_lock lock(_mutex);
// task
auto task = _taskflow.emplace([this, unit=std::move(unit)] () {
_to_power_unit(unit);
});
_add_to_lineage(task);
return *this;
}
// Procedure: _to_power_unit
void Timer::_to_power_unit(const watt_t& unit) {
OT_LOGI("use power unit ", unit);
float s = (_power_unit) ? (*_power_unit/unit).value() : 1.0f;
if(_power_unit = unit; std::fabs(s - 1.0f) < 1e-2f) {
return;
}
// TODO:
_enable_full_timing_update();
}
// Procedure: _rebase_unit
void Timer::_rebase_unit(Celllib& lib) {
// Convert the time unit.
if(!_time_unit) {
if(_time_unit = lib.time_unit; _time_unit) {
OT_LOGI("use celllib time unit ", *_time_unit);
}
}
else if(lib.time_unit){
float s = (*lib.time_unit / *_time_unit).value();
if(std::fabs(s - 1.0f) >= 1e-2f) {
OT_LOGI("rebase celllib ", lib.name, " time to ", *_time_unit);
lib.scale_time(s);
}
}
// Convert the capacitance unit
if(!_capacitance_unit) {
if(_capacitance_unit = lib.capacitance_unit; _capacitance_unit) {
OT_LOGI("use celllib capacitance unit ", *_capacitance_unit);
}
}
else if(lib.capacitance_unit) {
float s = (*lib.capacitance_unit / *_capacitance_unit).value();
if(std::fabs(s - 1.0f) >= 1e-2f) {
OT_LOGI("rebase celllib ", lib.name, " capacitance to ", *_capacitance_unit);
lib.scale_capacitance(s);
}
}
// Conver the current unit.
if(!_current_unit) {
if(_current_unit = lib.current_unit; _current_unit) {
OT_LOGI("use celllib current unit ", *_current_unit);
}
}
else if(lib.current_unit) {
float s = (*lib.current_unit / *_current_unit).value();
if(std::fabs(s - 1.0f) >= 1e-2f) {
OT_LOGI("rebase celllib ", lib.name, " current to ", *_current_unit);
lib.scale_current(s);
}
}
// Conver the voltage unit.
if(!_voltage_unit) {
if(_voltage_unit = lib.voltage_unit; _voltage_unit) {
OT_LOGI("use celllib voltage unit ", *_voltage_unit);
}
}
else if(lib.voltage_unit) {
float s = (*lib.voltage_unit / *_voltage_unit).value();
if(std::fabs(s - 1.0f) >= 1e-2f) {
OT_LOGI("rebase celllib ", lib.name, " voltage to ", *_voltage_unit);
lib.scale_voltage(s);
}
}
// Conver the resistance unit.
if(!_resistance_unit) {
if(_resistance_unit = lib.resistance_unit; _resistance_unit) {
OT_LOGI("use celllib resistance unit ", *_resistance_unit);
}
}
else if(lib.resistance_unit){
float s = (*lib.resistance_unit / *_resistance_unit).value();
if(std::fabs(s - 1.0f) >= 1e-2f) {
OT_LOGI("rebase celllib ", lib.name, " resistance to ", *_resistance_unit);
lib.scale_resistance(s);
}
}
// Conver the power unit.
if(!_power_unit) {
if(_power_unit = lib.power_unit; _power_unit) {
OT_LOGI("use celllib power unit ", *_power_unit);
}
}
else if(lib.power_unit) {
float s = (*lib.power_unit / *_power_unit).value();
if(std::fabs(s - 1.0f) >= 1e-2f) {
OT_LOGI("rebase celllib ", lib.name, " power to ", *_power_unit);
lib.scale_power(s);
}
}
}
// Procedure: _rebase_unit
void Timer::_rebase_unit(spef::Spef& spef) {
auto resu = make_resistance_unit(to_lower(spef.resistance_unit));
auto capu = make_capacitance_unit(to_lower(spef.capacitance_unit));
// Convert the capacitive load unit
if(!_capacitance_unit) {
if(_capacitance_unit = capu; _capacitance_unit) {
OT_LOGI("use spef capacitance unit ", *_capacitance_unit);
}
}
else if(capu) {
float s = (*capu / *_capacitance_unit).value();
if(std::fabs(s - 1.0f) >= 1e-2f) {
OT_LOGI("rebase spef capacitance to ", *capu);
spef.scale_capacitance(s);
}
}
// conver teh resistance unit
if(!_resistance_unit) {
if(_resistance_unit = resu; _resistance_unit) {
OT_LOGI("use spef resistance unit ", *_resistance_unit);
}
}
else if(resu){
float s = (*resu / *_resistance_unit).value();
if(std::fabs(s - 1.0f) >= 1e-2f) {
OT_LOGI("rebase spef resistance to ", *resu);
spef.scale_resistance(s);
}
}
}
}; // end of namespace ot -------------------------------------------------------------------------
|