/home/runner/work/LabNeura/LabNeura/include/labneura/eda/cell_library.h
Line | Count | Source (jump to first uncovered line) |
1 | | #ifndef LABNEURA_EDA_CELL_LIBRARY_H |
2 | | #define LABNEURA_EDA_CELL_LIBRARY_H |
3 | | |
4 | | #include "labneura/tensor.h" |
5 | | |
6 | | #include <cstddef> |
7 | | #include <optional> |
8 | | #include <string> |
9 | | #include <utility> |
10 | | #include <vector> |
11 | | |
12 | | namespace labneura::eda { |
13 | | |
14 | | class LookupTable { |
15 | | public: |
16 | | LookupTable(std::string template_name, std::vector<double> index_1, |
17 | | std::vector<double> index_2, |
18 | | std::vector<std::vector<double>> values) |
19 | 43.1k | : template_name_(std::move(template_name)), |
20 | 43.1k | index_1_(std::move(index_1)), |
21 | 43.1k | index_2_(std::move(index_2)), |
22 | 43.1k | values_(std::move(values)) {} |
23 | | |
24 | 1 | const std::string& get_template_name() const noexcept { |
25 | 1 | return template_name_; |
26 | 1 | } |
27 | 1 | const std::vector<double>& get_index_1() const noexcept { return index_1_; } |
28 | 1 | const std::vector<double>& get_index_2() const noexcept { return index_2_; } |
29 | 36 | const std::vector<std::vector<double>>& get_values() const noexcept { |
30 | 36 | return values_; |
31 | 36 | } |
32 | | |
33 | | // 2-D FP32 tensor (rows x columns) of the table values. |
34 | 1 | Tensor to_tensor() const { |
35 | 1 | std::vector<std::vector<float>> rows; |
36 | 1 | rows.reserve(values_.size()); |
37 | 2 | for (const auto& row : values_) { |
38 | 2 | rows.emplace_back(row.begin(), row.end()); |
39 | 2 | } |
40 | 1 | return Tensor(rows); |
41 | 1 | } |
42 | | |
43 | | private: |
44 | | std::string template_name_; |
45 | | std::vector<double> index_1_; |
46 | | std::vector<double> index_2_; |
47 | | std::vector<std::vector<double>> values_; |
48 | | }; |
49 | | |
50 | | class TimingArc { |
51 | | public: |
52 | | TimingArc(std::string related_pin, std::string timing_type, |
53 | | std::string timing_sense, |
54 | | std::optional<LookupTable> cell_rise, |
55 | | std::optional<LookupTable> cell_fall, |
56 | | std::optional<LookupTable> rise_transition, |
57 | | std::optional<LookupTable> fall_transition, |
58 | | std::optional<LookupTable> rise_constraint, |
59 | | std::optional<LookupTable> fall_constraint) |
60 | 12.9k | : related_pin_(std::move(related_pin)), |
61 | 12.9k | timing_type_(std::move(timing_type)), |
62 | 12.9k | timing_sense_(std::move(timing_sense)), |
63 | 12.9k | cell_rise_(std::move(cell_rise)), |
64 | 12.9k | cell_fall_(std::move(cell_fall)), |
65 | 12.9k | rise_transition_(std::move(rise_transition)), |
66 | 12.9k | fall_transition_(std::move(fall_transition)), |
67 | 12.9k | rise_constraint_(std::move(rise_constraint)), |
68 | 12.9k | fall_constraint_(std::move(fall_constraint)) {} |
69 | | |
70 | 47 | const std::string& get_related_pin() const noexcept { return related_pin_; } |
71 | 3 | const std::string& get_timing_type() const noexcept { return timing_type_; } |
72 | 1 | const std::string& get_timing_sense() const noexcept { return timing_sense_; } |
73 | 37 | const std::optional<LookupTable>& get_cell_rise() const noexcept { |
74 | 37 | return cell_rise_; |
75 | 37 | } |
76 | 1 | const std::optional<LookupTable>& get_cell_fall() const noexcept { |
77 | 1 | return cell_fall_; |
78 | 1 | } |
79 | 0 | const std::optional<LookupTable>& get_rise_transition() const noexcept { |
80 | 0 | return rise_transition_; |
81 | 0 | } |
82 | 0 | const std::optional<LookupTable>& get_fall_transition() const noexcept { |
83 | 0 | return fall_transition_; |
84 | 0 | } |
85 | 2 | const std::optional<LookupTable>& get_rise_constraint() const noexcept { |
86 | 2 | return rise_constraint_; |
87 | 2 | } |
88 | 0 | const std::optional<LookupTable>& get_fall_constraint() const noexcept { |
89 | 0 | return fall_constraint_; |
90 | 0 | } |
91 | | |
92 | | private: |
93 | | std::string related_pin_; |
94 | | std::string timing_type_; |
95 | | std::string timing_sense_; |
96 | | std::optional<LookupTable> cell_rise_; |
97 | | std::optional<LookupTable> cell_fall_; |
98 | | std::optional<LookupTable> rise_transition_; |
99 | | std::optional<LookupTable> fall_transition_; |
100 | | std::optional<LookupTable> rise_constraint_; |
101 | | std::optional<LookupTable> fall_constraint_; |
102 | | }; |
103 | | |
104 | | class CellPin { |
105 | | public: |
106 | | CellPin(std::string name, std::string direction, std::string function, |
107 | | std::optional<double> capacitance, std::vector<TimingArc> timing_arcs) |
108 | 12.5k | : name_(std::move(name)), |
109 | 12.5k | direction_(std::move(direction)), |
110 | 12.5k | function_(std::move(function)), |
111 | 12.5k | capacitance_(capacitance), |
112 | 12.5k | timing_arcs_(std::move(timing_arcs)) {} |
113 | | |
114 | 37.4k | const std::string& get_name() const noexcept { return name_; } |
115 | 211k | const std::string& get_direction() const noexcept { return direction_; } |
116 | 24.3k | const std::string& get_function() const noexcept { return function_; } |
117 | 7 | const std::optional<double>& get_capacitance() const noexcept { |
118 | 7 | return capacitance_; |
119 | 7 | } |
120 | 34 | const std::vector<TimingArc>& get_timing_arcs() const noexcept { |
121 | 34 | return timing_arcs_; |
122 | 34 | } |
123 | | |
124 | | private: |
125 | | std::string name_; |
126 | | std::string direction_; |
127 | | std::string function_; |
128 | | std::optional<double> capacitance_; |
129 | | std::vector<TimingArc> timing_arcs_; |
130 | | }; |
131 | | |
132 | | class StandardCell { |
133 | | public: |
134 | | StandardCell(std::string name, std::optional<double> area, |
135 | | std::vector<CellPin> pins) |
136 | 3.03k | : name_(std::move(name)), area_(area), pins_(std::move(pins)) {} |
137 | | |
138 | 156k | const std::string& get_name() const noexcept { return name_; } |
139 | 177 | const std::optional<double>& get_area() const noexcept { return area_; } |
140 | 63.1k | const std::vector<CellPin>& get_pins() const noexcept { return pins_; } |
141 | 802 | const CellPin* find_pin(const std::string& name) const noexcept { |
142 | 1.58k | for (const auto& pin : pins_) { |
143 | 1.58k | if (pin.get_name() == name) return &pin; |
144 | 1.58k | } |
145 | 0 | return nullptr; |
146 | 802 | } |
147 | | |
148 | | private: |
149 | | std::string name_; |
150 | | std::optional<double> area_; |
151 | | std::vector<CellPin> pins_; |
152 | | }; |
153 | | |
154 | | class StandardCellLibrary { |
155 | | public: |
156 | | StandardCellLibrary(std::string name, std::string time_unit, |
157 | | std::string capacitance_unit, |
158 | | std::vector<StandardCell> cells) |
159 | 17 | : name_(std::move(name)), |
160 | 17 | time_unit_(std::move(time_unit)), |
161 | 17 | capacitance_unit_(std::move(capacitance_unit)), |
162 | 17 | cells_(std::move(cells)) {} |
163 | | |
164 | 4 | const std::string& get_name() const noexcept { return name_; } |
165 | 1 | const std::string& get_time_unit() const noexcept { return time_unit_; } |
166 | 1 | const std::string& get_capacitance_unit() const noexcept { |
167 | 1 | return capacitance_unit_; |
168 | 1 | } |
169 | 143 | const std::vector<StandardCell>& get_cells() const noexcept { return cells_; } |
170 | 2 | std::size_t get_cell_count() const noexcept { return cells_.size(); } |
171 | 12.3k | const StandardCell* find_cell(const std::string& name) const noexcept { |
172 | 140k | for (const auto& cell : cells_) { |
173 | 140k | if (cell.get_name() == name) return &cell; |
174 | 140k | } |
175 | 303 | return nullptr; |
176 | 12.3k | } |
177 | | |
178 | | private: |
179 | | std::string name_; |
180 | | std::string time_unit_; |
181 | | std::string capacitance_unit_; |
182 | | std::vector<StandardCell> cells_; |
183 | | }; |
184 | | |
185 | | StandardCellLibrary parse_liberty(const std::string& path); |
186 | | const StandardCellLibrary& get_default_cell_library(); |
187 | | |
188 | | } // namespace labneura::eda |
189 | | |
190 | | #endif |