-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubRow.cpp
320 lines (269 loc) · 10.1 KB
/
SubRow.cpp
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
#include "utilities.h"
#include "SubRow.h"
#include "design_info.h"
#include <algorithm>
extern time_t tSubrowUpdate;
/* ************************************************** */
inline bool compareCell_lx(size_t p_pos_1, size_t p_pos_2);
inline bool compareCell_center_x(size_t p_pos_1, size_t p_pos_2);
/* ************************************************** */
using namespace std;
pair<int, int> getCellRowSubrowIndex(int cell_index)
{
Cell &curr_cell(design.cell_lib.at(cell_index));
size_t row_pos = getRow(curr_cell.ll.y);
size_t subrow_pos(0);
for(int subrow_iter = 0; subrow_iter < (int)design.Row_Info.at(row_pos).getSubRowNum(); subrow_iter++)
{
if(curr_cell.getCenter().x >= design.Row_Info.at(row_pos).getSubRow(subrow_iter).get_lx() &&
curr_cell.getCenter().x <= design.Row_Info.at(row_pos).getSubRow(subrow_iter).get_rx())
{
subrow_pos = subrow_iter;
break;
} // if
} // for
return make_pair(row_pos, subrow_pos);
}
SubRow& getCellSubrow(int cell_index)
{
pair<int, int> row_subrow = getCellRowSubrowIndex(cell_index);
return design.Row_Info.at(row_subrow.first).getSubRow(row_subrow.second);
}
pair<int, int> getCoorRowSubrowIndex(Coor coor)
{
size_t row_pos = getRow(coor.y);
size_t subrow_pos(0);
for(int subrow_iter = 0; subrow_iter < (int)design.Row_Info.at(row_pos).getSubRowNum(); subrow_iter++)
{
if(coor.x >= design.Row_Info.at(row_pos).getSubRow(subrow_iter).get_lx() &&
coor.x <= design.Row_Info.at(row_pos).getSubRow(subrow_iter).get_rx())
{
subrow_pos = subrow_iter;
} // if
} // for
return make_pair(row_pos, subrow_pos);
}
SubRow& getCoorSubrow(Coor coor)
{
size_t row_pos = getRow(coor.y);
size_t subrow_pos(0);
for(int subrow_iter = 0; subrow_iter < (int)design.Row_Info.at(row_pos).getSubRowNum(); subrow_iter++)
{
if(coor.x >= design.Row_Info.at(row_pos).getSubRow(subrow_iter).get_lx() &&
coor.x <= design.Row_Info.at(row_pos).getSubRow(subrow_iter).get_rx())
{
subrow_pos = subrow_iter;
} // if
} // for
return design.Row_Info.at(row_pos).getSubRow(subrow_pos);
}
bool testIfAlreadyCongested(size_t p_cell_pos, Coor p_pos) {
//return false;
Cell &c(design.cell_lib[p_cell_pos]);
size_t row_pos = getRow(c.getCenter().y);
size_t subrow_pos(-1);
for(int subrow_iter = 0; subrow_iter < (int)design.Row_Info.at(row_pos).getSubRowNum(); subrow_iter++)
{
if(c.getCenter().x >= design.Row_Info.at(row_pos).getSubRow(subrow_iter).get_lx() &&
c.getCenter().x <= design.Row_Info.at(row_pos).getSubRow(subrow_iter).get_rx())
{
subrow_pos = subrow_iter;
} // if
} // for
size_t row_pos2 = getRow(p_pos.y);
size_t subrow_pos2(-1);
for(int subrow_iter = 0; subrow_iter < (int)design.Row_Info.at(row_pos2).getSubRowNum(); subrow_iter++)
{
if(p_pos.x >= design.Row_Info.at(row_pos2).getSubRow(subrow_iter).get_lx() &&
p_pos.x <= design.Row_Info.at(row_pos2).getSubRow(subrow_iter).get_rx())
{
subrow_pos2 = subrow_iter;
} // if
} // for
if(subrow_pos2 == -1)
cout << "error2\n";
bool ans = design.cell_lib[p_cell_pos].getWidth() > design.Row_Info.at(row_pos2).getSubRow(subrow_pos2).getUnusedWidth();
ans = ans || (row_pos == row_pos2 && subrow_pos == subrow_pos2);
return ans;
}
bool canBeSwaped(size_t cell_index, SwapTarget target) {
bool a1, a2;
if(target.is_whitespace) {
a1 = !testIfAlreadyCongested(cell_index, target.center);
a2 = a1;
}
else{
size_t row_pos = getRow(design.cell_lib[cell_index].getCenter().y);
size_t subrow_pos(-1);
for(int subrow_iter = 0; subrow_iter < (int)design.Row_Info.at(row_pos).getSubRowNum(); subrow_iter++)
{
if(design.cell_lib[cell_index].getCenter().x >= design.Row_Info.at(row_pos).getSubRow(subrow_iter).get_lx() &&
design.cell_lib[cell_index].getCenter().x <= design.Row_Info.at(row_pos).getSubRow(subrow_iter).get_rx())
{
subrow_pos = subrow_iter;
} // if
} // for
size_t row_pos2 = getRow(design.cell_lib[target.cell_index].getCenter().y);
size_t subrow_pos2(-1);
for(int subrow_iter = 0; subrow_iter < (int)design.Row_Info.at(row_pos2).getSubRowNum(); subrow_iter++)
{
if(design.cell_lib[target.cell_index].getCenter().x >= design.Row_Info.at(row_pos2).getSubRow(subrow_iter).get_lx() &&
design.cell_lib[target.cell_index].getCenter().x <= design.Row_Info.at(row_pos2).getSubRow(subrow_iter).get_rx())
{
subrow_pos2 = subrow_iter;
} // if
} // for
if (row_pos == row_pos2 && subrow_pos == subrow_pos2){
a1 = true;
a2 = true;
}
else{
a1 = design.cell_lib[cell_index].getWidth() <= (design.Row_Info.at(row_pos2).getSubRow(subrow_pos2).getUnusedWidth() + design.cell_lib[target.cell_index].getWidth());
a2 = design.cell_lib[target.cell_index].getWidth() <= (design.Row_Info.at(row_pos).getSubRow(subrow_pos).getUnusedWidth() + design.cell_lib[cell_index].getWidth());
}
}
return a1 && a2;
}
void moveSubrowCellLL(size_t p_cell_pos, Coor p_pos)
{
// delete cell in original subrow
size_t row_pos = getRow(design.cell_lib.at(p_cell_pos).ll.y);
size_t subrow_pos(-1);
subrow_pos = findSubRow(design.cell_lib.at(p_cell_pos).getCenter());
Cell c = design.cell_lib.at(p_cell_pos);
if (subrow_pos == -1){
cout << "error 1" << endl;
}
for(int cell_iter = 0; cell_iter < (int)design.Row_Info.at(row_pos).getSubRow(subrow_pos).getCellNum(); cell_iter++)
{
if(p_cell_pos == design.Row_Info.at(row_pos).getSubRow(subrow_pos).getCell(cell_iter)){
design.Row_Info.at(row_pos).getSubRow(subrow_pos).deleteCell(cell_iter);
}
} // for
// find target subrow
row_pos = getRow(p_pos.y);
subrow_pos = -1;
p_pos.x += c.getWidth() / 2;
/*for(int subrow_iter = 0; subrow_iter < (int)design.Row_Info.at(row_pos).getSubRowNum(); subrow_iter++)
{
//if(p_pos.x >= design.Row_Info.at(row_pos).getSubRow(subrow_iter).get_lx() &&
// p_pos.x <= design.Row_Info.at(row_pos).getSubRow(subrow_iter).get_rx())
if(p_pos.x + c.getWidth() / 2 >= design.Row_Info.at(row_pos).getSubRow(subrow_iter).get_lx() &&
p_pos.x + c.getWidth() / 2 <= design.Row_Info.at(row_pos).getSubRow(subrow_iter).get_rx())
{
subrow_pos = subrow_iter;
} // if
} // for
*/
subrow_pos = findSubRow(p_pos);
if (subrow_pos == -1){
cout << "error3\n";
}
//update cell pos
//design.cell_lib.at(p_cell_pos).ll = p_pos;
// move into subrow
design.Row_Info.at(row_pos).getSubRow(subrow_pos).addCell(p_cell_pos);
// update subrow
//design.Row_Info.at(row_pos).getSubRow(subrow_pos).updateCell();
return;
}
int findSubRow(Coor p_pos)
{
int row_pos = getRow(p_pos.y);
int subrow_pos = -1;
int cur_subrow_pos = (design.Row_Info.at(row_pos).getSubRowNum() - 1) / 2;
int left_limit = 0;
int right_limit = design.Row_Info.at(row_pos).getSubRowNum() - 1;
while(left_limit <= right_limit)
{
if(p_pos.x >= design.Row_Info.at(row_pos).getSubRow(cur_subrow_pos).get_lx() &&
p_pos.x <= design.Row_Info.at(row_pos).getSubRow(cur_subrow_pos).get_rx())
{
// in subrow
return cur_subrow_pos;
}
else if(p_pos.x < design.Row_Info.at(row_pos).getSubRow(cur_subrow_pos).get_lx())
{
// left of subrow
right_limit = cur_subrow_pos - 1;
cur_subrow_pos = (left_limit + right_limit) / 2;
}
else if(p_pos.x > design.Row_Info.at(row_pos).getSubRow(cur_subrow_pos).get_rx())
{
// right of subrow
left_limit = cur_subrow_pos + 1;
cur_subrow_pos = (left_limit + right_limit) / 2;
}
}
//if(cur_subrow_pos == -1)
cout << "errrrrrrrrrrror" << endl;
} // findSubRow
/* ************************************************** */
extern DesignInfo design;
void SubRow::addCell(size_t p_cell)
{
cell.push_back(p_cell);
used_width += design.cell_lib[p_cell].getWidth();
}
void SubRow::deleteCell(size_t p_cell_pos)
{
used_width -= design.cell_lib[getCell(p_cell_pos)].getWidth();
cell.erase(cell.begin() + p_cell_pos);
}
void SubRow::updateCell()
{
sort(cell.begin(), cell.end(), compareCell_center_x);
return;
} // SubRow::updateCell
/* ************************************************** */
coor_type SubRow::getUsedArea(coor_type p_left, coor_type p_right)
{
// assume cells in subrow is sorted
// return total cell area in the boundary
double used_area(0.0);
double left_bound(0.0);
double right_bound(0.0);
for(int cell_iter = 0; cell_iter < cell.size(); cell_iter++)
{
/*
if(design.cell_lib.at(cell.at(cell_iter)).ll.x + design.cell_lib.at(cell.at(cell_iter)).getWidth() < p_left)
continue;
else if(design.cell_lib.at(cell.at(cell_iter)).ll.x > p_right)
break;
*/
if(design.cell_lib.at(cell.at(cell_iter)).ll.x + design.cell_lib.at(cell.at(cell_iter)).getWidth() > p_left &&
design.cell_lib.at(cell.at(cell_iter)).ll.x < p_right)
{
if(design.cell_lib.at(cell.at(cell_iter)).ll.x < p_left)
left_bound = p_left;
else
left_bound = design.cell_lib.at(cell.at(cell_iter)).ll.x;
if(design.cell_lib.at(cell.at(cell_iter)).ll.x + design.cell_lib.at(cell.at(cell_iter)).getWidth() > p_right )
right_bound = p_right;
else
right_bound = design.cell_lib.at(cell.at(cell_iter)).ll.x + design.cell_lib.at(cell.at(cell_iter)).getWidth();
used_area += right_bound - left_bound;
} // else
} // for
return used_area * design.getStandardCellHeight();
} // SubRow::getUsedArea
/* ************************************************** */
void Cluster::copy(Cluster& p_cluster, int p_begin, int p_end)
{
for(int cell_iter = p_begin; cell_iter < p_end; cell_iter++)
{
cell[cell_iter] = p_cluster.getCell(cell_iter);
} // for
return;
} // Cluster::copy
/* ************************************************** */
inline bool compareCell_lx(size_t p_pos_1, size_t p_pos_2)
{
return design.cell_lib.at(p_pos_1).ll.x < design.cell_lib.at(p_pos_2).ll.x;
} // CompareCell_lx
/* ************************************************** */
inline bool compareCell_center_x(size_t p_pos_1, size_t p_pos_2)
{
return design.cell_lib.at(p_pos_1).getCenter().x < design.cell_lib.at(p_pos_2).getCenter().x;
} // CompareCell_lx
/* ************************************************** */