forked from rmanohar/layout
-
Notifications
You must be signed in to change notification settings - Fork 1
/
subcell.h
296 lines (256 loc) · 6.22 KB
/
subcell.h
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
/*************************************************************************
*
* Copyright (c) 2024 Rajit Manohar
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
**************************************************************************
*/
#ifndef __ACT_LAYOUT_SUBCELL_H__
#define __ACT_LAYOUT_SUBCELL_H__
#include "geom.h"
class SubcellInst {
private:
LayoutBlob *_b; //< the actual layout (subcell)
TransformMat _m; //< geometric transformations to get
// the tiles into global coordinates
const char *_uid; //< unique identifier for the subcell
int _nx, _ny; //< array size
public:
SubcellInst (LayoutBlob *b, const char *id, TransformMat *m = NULL) {
_nx = 1;
_ny = 1;
_b = b;
_uid = id;
if (m) {
_m = *m;
}
}
void mkArray (int nx, int ny) {
_nx = nx;
_ny = ny;
}
LayoutEdgeAttrib *getLayoutEdgeAttrib () {
LayoutEdgeAttrib *le;
le = _b->getLayoutEdgeAttrib();
if (le) {
// clone, and apply transformation matrix
le = le->Clone (&_m);
}
return le;
}
Rectangle getBBox() {
Rectangle r;
if (!_b) {
return r;
}
r = _b->getBBox ();
Rectangle a = _b->getAbutBox ();
if (a.empty()) {
a = r;
}
long fringex = (a.llx() - r.llx()) + (r.urx() - a.urx());
long fringey = (a.lly() - r.lly()) + (r.ury() - a.ury());
r.setRectCoords (r.llx(), r.lly(), r.llx() + a.wx()*_nx + fringex,
r.lly() + a.wy()*_ny + fringey);
return r;
}
Rectangle getBloatBBox() {
Rectangle r;
if (!_b) {
return r;
}
r = _b->getBBox ();
Rectangle a = _b->getAbutBox ();
if (a.empty()) {
a = r;
}
r = _b->getBloatBBox ();
long fringex = (a.llx() - r.llx()) + (r.urx() - a.urx());
long fringey = (a.lly() - r.lly()) + (r.ury() - a.ury());
r.setRectCoords (r.llx(), r.lly(), r.llx() + a.wx()*_nx + fringex,
r.lly() + a.wy()*_ny + fringey);
return r;
}
Rectangle getAbutBox () {
Rectangle r;
if (!_b) {
return r;
}
r = _b->getAbutBox ();
if (r.empty()) {
return getBBox();
}
r.setRect (r.llx(), r.lly(), r.wx()*_nx, r.wy()*_ny);
return r;
}
void PrintRect (FILE *fp, TransformMat *mat) {
TransformMat m;
if (mat) {
m = *mat;
}
_b->_printRect (fp, mat);
}
};
class SubcellList {
private:
SubcellList *_next; /* linked-list of subcells */
SubcellInst *_cell; /* actual subcell */
public:
SubcellList (SubcellInst *c) {
_cell = c;
_next = NULL;
}
~SubcellList () {
if (_next) {
delete _next;
}
}
void append (SubcellInst *c, bool sort_x) {
SubcellList *tmp = new SubcellList (c);
SubcellList *prev, *cur;
prev = NULL;
cur = this;
while (cur) {
bool gonext;
if (sort_x) {
if (cur->_cell->getBBox().urx() < c->getBBox().llx()) {
gonext = true;
}
else {
gonext = false;
}
}
else {
if (cur->_cell->getBBox().ury() < c->getBBox().lly()) {
gonext = true;
}
else {
gonext = false;
}
}
if (gonext) {
prev = cur;
cur = cur->_next;
}
else {
if (!prev) {
SubcellInst *x;
tmp->_next = _next;
_next = tmp;
tmp->_cell = _cell;
_cell = c;
return;
}
else {
prev->_next = tmp;
tmp->_next = cur;
return;
}
}
}
prev->_next = tmp;
}
SubcellList *del (SubcellInst *c) {
SubcellList *prev, *cur;
prev = NULL;
cur = this;
while (cur) {
if (cur->_cell == c) {
break;
}
else {
prev = cur;
cur = cur->_next;
}
}
if (cur) {
if (prev) {
prev->_next = cur->_next;
delete cur;
return this;
}
else {
cur = cur->_next;
delete this;
return cur;
}
}
return this;
}
SubcellList *getNext() { return _next; }
SubcellInst *getCell() { return _cell; }
void clearCell() { _cell = NULL; }
SubcellList *flushClear();
};
/*
* Recursively partition space
*/
class LayerSubcell {
private:
unsigned int _splitx:1; /* 1 if my split was in the x-direction */
long _splitval:62; /* location of split. the split
coordinate is in the "_leq" box. */
Rectangle _region; /* owned region */
Rectangle _bbox; /* actual bounding box */
Rectangle _bloatbbox; /* bloated bbox */
Rectangle _abutbox; /* abutment box */
LayerSubcell *_leq, *_gt; /* split tile */
SubcellList *_lst; /* list of subcells here */
int _levelcount; /* list length */
void _computeBBox();
public:
static int subcell_level_threshold; // if you exceed this threshold,
// then add sub-trees
static int subcell_recompute_threshold; // if you exceed this
// threshold, then
// re-compute the entire subtree!
LayerSubcell(bool sort_x = true) {
Assert (subcell_recompute_threshold > subcell_level_threshold, "What?");
_splitx = sort_x ? 1 : 0;
_splitval = 0;
_leq = NULL;
_gt = NULL;
_lst = NULL;
_levelcount = 0;
}
~LayerSubcell() {
if (_leq) {
delete _leq;
}
if (_gt) {
delete _gt;
}
if (_lst) {
delete _lst;
}
}
void initGlobal() {
if (_leq || _gt || _lst) {
fatal_error ("LayerSubcell:: initGlobal() called after subcells were added!");
}
_region.setRect (MIN_VALUE, MIN_VALUE, MAX_VALUE, MAX_VALUE);
}
void setRegion (Rectangle &r) {
_region = r;
}
void addSubcell (SubcellInst *s);
void delSubcell (SubcellInst *s);
Rectangle getBBox ();
Rectangle getBloatBBox ();
Rectangle getAbutBox();
};
#endif /* __ACT_LAYOUT_SUBCELL_H__ */