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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
#include <ot/liberty/timing.hpp>

namespace ot {

// Function: to_string
std::string to_string(TimingSense sense) {

  switch(sense) {

    case TimingSense::NEGATIVE_UNATE:
      return "negative_unate";
    break;

    case TimingSense::POSITIVE_UNATE:
      return "positive_unate";
    break;

    case TimingSense::NON_UNATE:
      return "non_unate";
    break;

    default:
      return "undefined";
    break;
  }
}

// Function: timing_type_name
std::string to_string(TimingType t) {

  switch (t) {

    case TimingType::COMBINATIONAL:
      return "combinational";
    break;

    case TimingType::COMBINATIONAL_RISE:
      return "combinational_rise";
    break;

    case TimingType::COMBINATIONAL_FALL:
      return "combinational_fall";
    break;

    case TimingType::THREE_STATE_DISABLE:
      return "three_state_disable";
    break;

    case TimingType::THREE_STATE_DISABLE_RISE:
      return "three_state_disable_rise";
    break;

    case TimingType::THREE_STATE_DISABLE_FALL:
      return "three_state_disable_fall";
    break;

    case TimingType::THREE_STATE_ENABLE:
      return "three_state_enable";
    break;

    case TimingType::THREE_STATE_ENABLE_RISE:
      return "three_state_enable_rise";
    break;

    case TimingType::THREE_STATE_ENABLE_FALL:
      return "three_state_enable_fall";
    break;

    case TimingType::RISING_EDGE:
      return "rising_edge";
    break;

    case TimingType::FALLING_EDGE:
      return "falling_edge";
    break;

    case TimingType::PRESET:
      return "preset";
    break;

    case TimingType::CLEAR:
      return "clear";
    break;

    case TimingType::HOLD_RISING:
      return "hold_rising";
    break;

    case TimingType::HOLD_FALLING:
      return "hold_falling"; 
    break;

    case TimingType::SETUP_RISING:
      return "setup_rising";
    break;

    case TimingType::SETUP_FALLING:
      return "setup_falling";
    break;

    case TimingType::RECOVERY_RISING:
      return "recovery_rising";
    break;

    case TimingType::RECOVERY_FALLING:
      return "recovery_falling";
    break;

    case TimingType::SKEW_RISING:
      return "skew_rising";
    break;

    case TimingType::SKEW_FALLING:
      return "skew_falling";
    break;

    case TimingType::REMOVAL_RISING:
      return "removal_rising";
    break;

    case TimingType::REMOVAL_FALLING:
      return "removal_falling";
    break;

    case TimingType::MIN_PULSE_WIDTH:
      return "min_pulse_width";
    break;
  
    case TimingType::MINIMUM_PERIOD:
      return "minimum_period";
    break;

    case TimingType::MAX_CLOCK_TREE_PATH:
      return "max_clock_tree_path";
    break;

    case TimingType::MIN_CLOCK_TREE_PATH:
      return "min_clock_tree_path";
    break;
  
    case TimingType::NON_SEQ_SETUP_RISING:
      return "non_seq_setup_rising";
    break;

    case TimingType::NON_SEQ_SETUP_FALLING:
      return "non_seq_setup_falling";
    break;

    case TimingType::NON_SEQ_HOLD_RISING:
      return "non_seq_hold_rising";
    break;

    case TimingType::NON_SEQ_HOLD_FALLING:
      return "non_seq_hold_falling";
    break;

    case TimingType::NOCHANGE_HIGH_HIGH:
      return "nochange_high_high";
    break;

    case TimingType::NOCHANGE_HIGH_LOW:
      return "nochange_high_low";
    break;

    case TimingType::NOCHANGE_LOW_HIGH:
      return "nochange_low_high";
    break;

    case TimingType::NOCHANGE_LOW_LOW:
      return "nochange_low_low";
    break;

    default:
      return "undefined";
    break;
  }
}

// ------------------------------------------------------------------------------------------------

// Function: isomorphic
bool Timing::isomorphic(const Timing& rhs) const {
  
  if(related_pin != rhs.related_pin) return false;
  if(sense != rhs.sense)             return false;
  if(type != rhs.type)               return false;
  if(cell_rise.has_value() != rhs.cell_rise.has_value()) return false;
  if(cell_fall.has_value() != rhs.cell_fall.has_value()) return false;
  if(rise_transition.has_value() != rhs.rise_transition.has_value()) return false;
  if(fall_transition.has_value() != rhs.fall_transition.has_value()) return false;
  if(rise_constraint.has_value() != rhs.rise_constraint.has_value()) return false;
  if(fall_constraint.has_value() != rhs.fall_constraint.has_value()) return false;

  return true;
}

// Function: is_transition_defined
bool Timing::is_transition_defined(Tran irf, Tran orf) const {

  if(!is_input_transition_defined(irf)) return false;
  
  if(sense) {
    switch(*sense) {
      case TimingSense::POSITIVE_UNATE:
        if(irf != orf) return false;
      break;

      case TimingSense::NEGATIVE_UNATE:
        if(irf == orf) return false;
      break;

      default:
      break;
    }
  }

  return true;
}

// Function: is_input_transition_defined
bool Timing::is_input_transition_defined(Tran irf) const {
  if(is_rising_edge_triggered() && irf != RISE) return false;
  if(is_falling_edge_triggered() && irf != FALL) return false;
  return true;
}

// Function: is_input_transition_defined
bool Timing::is_input_transition_defined() const {
  return (is_falling_edge_triggered() || is_rising_edge_triggered());
}

// Function: is_constraint
bool Timing::is_constraint() const {
  if(type) {
    switch(*type) {
      case TimingType::REMOVAL_RISING:
      case TimingType::REMOVAL_FALLING:
      case TimingType::RECOVERY_RISING:
      case TimingType::RECOVERY_FALLING:
      case TimingType::SETUP_RISING:
      case TimingType::SETUP_FALLING:
      case TimingType::HOLD_RISING:
      case TimingType::HOLD_FALLING:
      case TimingType::NON_SEQ_SETUP_RISING:
      case TimingType::NON_SEQ_SETUP_FALLING:
      case TimingType::NON_SEQ_HOLD_RISING:
      case TimingType::NON_SEQ_HOLD_FALLING:
        return true;
      break;

      default:
        return false;
      break;
    }
  }
  else {
    return false;
  }
}

// Function: is_min_constraint
bool Timing::is_min_constraint() const {
  if(type) {
    switch(*type) {
      case TimingType::HOLD_RISING:
      case TimingType::HOLD_FALLING:
      case TimingType::NON_SEQ_HOLD_RISING:
      case TimingType::NON_SEQ_HOLD_FALLING:
      case TimingType::REMOVAL_RISING:
      case TimingType::REMOVAL_FALLING:
        return true;
      break;

      default:
        return false;
      break;
    }
  }
  else {
    return false;
  }
}

// Function: is_max_constraint
bool Timing::is_max_constraint() const {
  if(type) {
    switch(*type) {
      case TimingType::SETUP_RISING:
      case TimingType::SETUP_FALLING:
      case TimingType::NON_SEQ_SETUP_RISING:
      case TimingType::NON_SEQ_SETUP_FALLING:
      case TimingType::RECOVERY_RISING:
      case TimingType::RECOVERY_FALLING:
        return true;
      break;

      default:
        return false;
      break;
    }
  }
  else {
    return false;
  }
}

// Function: is_falling_edge_triggered
bool Timing::is_falling_edge_triggered() const {
  if(type) {
    switch (*type) {
      case TimingType::SETUP_FALLING:
      case TimingType::HOLD_FALLING:
      case TimingType::REMOVAL_FALLING:
      case TimingType::RECOVERY_FALLING:
      case TimingType::FALLING_EDGE:
        return true;
      break;

      default:
        return false;
      break;
    };
  }
  else {
    return false;
  }
}

// Function: is_rising_edge_triggered
bool Timing::is_rising_edge_triggered() const {
  if(type) {
    switch (*type) {
      case TimingType::SETUP_RISING:
      case TimingType::HOLD_RISING:
      case TimingType::REMOVAL_RISING:
      case TimingType::RECOVERY_RISING:
      case TimingType::RISING_EDGE:
        return true;
      break;

      default:
        return false;
      break;
    };
  }
  else {
    return false;
  }
}

// Procedure: scale_time
void Timing::scale_time(float s) {

  if(cell_rise) {
    cell_rise->scale_time(s);
  }
  
  if(cell_fall) {
    cell_fall->scale_time(s);
  }

  if(rise_transition) {
    rise_transition->scale_time(s);
  }

  if(fall_transition) {
    fall_transition->scale_time(s);
  }

  if(rise_constraint) {
    rise_constraint->scale_time(s);
  }

  if(fall_constraint) {
    fall_constraint->scale_time(s);
  }

  internal_power.scale_time(s);
}

// Procedure: scale_capacitance
void Timing::scale_capacitance(float s) {

  if(cell_rise) {
    cell_rise->scale_capacitance(s);
  }
  
  if(cell_fall) {
    cell_fall->scale_capacitance(s);
  }

  if(rise_transition) {
    rise_transition->scale_capacitance(s);
  }

  if(fall_transition) {
    fall_transition->scale_capacitance(s);
  }

  if(rise_constraint) {
    rise_constraint->scale_capacitance(s);
  }

  if(fall_constraint) {
    fall_constraint->scale_capacitance(s);
  }

  internal_power.scale_capacitance(s);
}

// Function: delay
// Query the delay which is referenced by the output transition status, input slew, and driving 
// load. The output transition status indicates the type of lut that should be used during the
// linear interpolation or linear extrapolation.
std::optional<float> Timing::delay(Tran irf, Tran orf, float slew, float load) const {

  if(!is_transition_defined(irf, orf)) {
    return std::nullopt;
  }
  
  const Lut* lut {nullptr};

  switch(orf) {
    case RISE:
      lut = cell_rise ? &(cell_rise.value()) : nullptr;
    break;

    case FALL:
      lut = cell_fall ? &(cell_fall.value()) : nullptr;
    break;

    default:
      assert(false);
    break;
  };
  
  if(lut == nullptr) {
    return std::nullopt;
  }
  
  // Case 1: scalar.
  if(lut->lut_template == nullptr) {     
    if(lut->is_scalar()) {
      return lut->table[0];
    }
    else {
      OT_LOGF("lut without template must contain a single scalar");
    }
  }

  // Case 2: non-scalar table.
  float val1 {.0f}, val2 {.0f};
  
  // - obtain the input numerics
  assert(lut->lut_template->variable1);

  switch(*(lut->lut_template->variable1)) {

    case LutVar::TOTAL_OUTPUT_NET_CAPACITANCE:
      if(lut->lut_template->variable2) {
        assert(lut->lut_template->variable2 == LutVar::INPUT_NET_TRANSITION);
      }
      val1 = load;
      val2 = slew;
    break;

    case LutVar::INPUT_NET_TRANSITION:
      if(lut->lut_template->variable2) {
        assert(lut->lut_template->variable2 == LutVar::TOTAL_OUTPUT_NET_CAPACITANCE);
      }
      val1 = slew;
      val2 = load;
    break;

    default:
      OT_LOGF("invalid delay lut template variable");
    break;
  };
  
  // - perform the linear inter/extro-polation on indices1 and indices2
  return (*lut)(val1, val2); 
}

// Function: slew
// Query the slew which is referenced by the output transition status, input slew, and driving 
// load. The output transition status indicates the type of lut that should be used during the
// linear interpolation or linear extrapolation.
std::optional<float> Timing::slew(Tran irf, Tran orf, float slew, float load) const {
  
  if(!is_transition_defined(irf, orf)) {
    return std::nullopt;
  }
  
  const Lut* lut {nullptr};

  switch(orf) {

    case RISE:
      lut = rise_transition ? &(rise_transition.value()) : nullptr;
    break;

    case FALL:
      lut = fall_transition ? &(fall_transition.value()) : nullptr;
    break;

    default:
      assert(false);
    break;
  };
  
  // No slew lut
  if(lut == nullptr) {
    return std::nullopt;
  }
  
  // Case 1: scalar.
  if(lut->lut_template == nullptr) {     
    if(lut->is_scalar()) {
      return lut->table[0];
    }
    else {
      OT_LOGF("lut without template must contain a single scalar");
    }
  }

  // Case 2: non-scalar table.
  float val1 {0.0f}, val2 {0.0f};
  
  // - obtain the input numerics
  assert(lut->lut_template->variable1);

  switch(*(lut->lut_template->variable1)) {

    case LutVar::TOTAL_OUTPUT_NET_CAPACITANCE:
      if(lut->lut_template->variable2) {
        assert(*(lut->lut_template->variable2) == LutVar::INPUT_NET_TRANSITION);
      }
      val1 = load;
      val2 = slew;
    break;

    case LutVar::INPUT_NET_TRANSITION:
      if(lut->lut_template->variable2) {
        assert(*(lut->lut_template->variable2) == LutVar::TOTAL_OUTPUT_NET_CAPACITANCE);
      }
      val1 = slew;
      val2 = load;
    break;

    default:
      OT_LOGF("invalid slew lut template variable");
    break;
  }
  
  // - perform the linear inter/extro-polation on indices1 and indices2
  return (*lut)(val1, val2); 
}

// Function: constraint
// Query the constraint which is referenced by the output transition status, input slew, and
// output slew. The output transition status indicates the type of lut that should be used 
// during the linear interpolation or linear extrapolation.
std::optional<float> Timing::constraint(
  Tran irf, 
  Tran orf, 
  float related_slew, 
  float constrained_slew
) const {
  
  if(!is_transition_defined(irf, orf)) {
    return std::nullopt;
  }
  
  const Lut* lut {nullptr};

  switch(orf) {

    case RISE:
      lut = rise_constraint ? &(rise_constraint.value()) : nullptr;
    break;

    case FALL:
      lut = fall_constraint ? &(fall_constraint.value()) : nullptr;
    break;

    default:
      assert(false);
    break;
  };
  
  if(lut == nullptr) {
    return std::nullopt;
  }
  
  // Case 1: scalar.
  if(lut->lut_template == nullptr) {     
    if(lut->is_scalar()) {
      return lut->table[0];
    }
    else {
      OT_LOGF("lut without template must contain a single scalar");
    }
  }
  
  // Case 2: non-scalar table.
  float val1 {0.0f}, val2 {0.0f};
  
  // - obtain the input numerics
  assert(lut->lut_template->variable1);

  switch(*(lut->lut_template->variable1)) {

    case LutVar::CONSTRAINED_PIN_TRANSITION:
      if(lut->lut_template->variable2) {
        assert(lut->lut_template->variable2 == LutVar::RELATED_PIN_TRANSITION);
      }
      val1 = constrained_slew;
      val2 = related_slew;
    break;

    case LutVar::RELATED_PIN_TRANSITION:
      if(lut->lut_template->variable2) {
        assert(lut->lut_template->variable2 == LutVar::CONSTRAINED_PIN_TRANSITION);
      }
      val1 = related_slew;
      val2 = constrained_slew;
    break;

    default:
      OT_LOGF("invalid constraint lut template variable");
    break;
  };
  
  // - perform the linear inter/extro-polation on indices1 and indices2
  return (*lut)(val1, val2); 
}

// operator
std::ostream& operator << (std::ostream& os, const Timing& timing) {
  
  // Write the timing.
  os << "    timing () {\n";

  // Write the related pin (from cellpin).
  os << "      related_pin : \"" << timing.related_pin << "\";\n";

  // Write the timing sense.
  if(timing.sense) {
    os << "      timing_sense : " << to_string(*timing.sense) << ";\n";
  }

  // Write the timing type.
  if(timing.type) {
    os << "      timing_type : " << to_string(*timing.type) << ";\n";
  }

  // Write cell_rise
  if(timing.cell_rise) {
    os << "      cell_rise (\"" << timing.cell_rise->name << "\") {\n"; 
    os << *(timing.cell_rise);
    os << "      }\n";
  }

  // Write cell_fall
  if(timing.cell_fall) {
    os << "      cell_fall (\"" << timing.cell_fall->name << "\") {\n"; 
    os << *(timing.cell_fall);
    os << "      }\n";
  }

  // Write rise_transition
  if(timing.rise_transition) {
    os << "      rise_transition (\"" << timing.rise_transition->name << "\") {\n"; 
    os << *(timing.rise_transition);
    os << "      }\n";
  }
  
  // Write fall_transition
  if(timing.fall_transition) {
    os << "      fall_transition (\"" << timing.fall_transition->name << "\") {\n"; 
    os << *(timing.fall_transition);
    os << "      }\n";
  }
  
  // Write rise_constraint
  if(timing.rise_constraint) {
    os << "      rise_constraint (\"" << timing.rise_constraint->name << "\") {\n"; 
    os << *(timing.rise_constraint);
    os << "      }\n";
  }
  
  // Write fall_constraint
  if(timing.fall_constraint) {
    os << "      fall_constraint (\"" << timing.fall_constraint->name << "\") {\n"; 
    os << *(timing.fall_constraint);
    os << "      }\n";
  }
  
  // Write the ending group symbol.
  os << "    }\n";

  if (!timing.internal_power.related_pin.empty()) {
    os << timing.internal_power;
  }

  return os;
}

};  // end of namespace ot. -----------------------------------------------------------------------