forked from rmanohar/layout
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgeom.h
412 lines (323 loc) · 11.3 KB
/
geom.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
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
/*************************************************************************
*
* Copyright (c) 2019 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_GEOM_H__
#define __ACT_GEOM_H__
#include <act/act.h>
#include <act/tech.h>
#include <act/passes/netlist.h>
#include <common/path.h>
#include "tile.h"
#include "attrib.h"
/*
* Geometry transformation matrix
*/
class TransformMat {
long _dx, _dy;
unsigned int _flipx:1;
unsigned int _flipy:1;
unsigned int _swap:1;
public:
TransformMat ();
void mkI();
void translate (long dx, long dy);
void mirrorLR ();
void mirrorTB ();
void mirror45 ();
void apply (long inx, long iny, long *outx, long *outy) const;
Rectangle applyBox (const Rectangle &r) const;
void applyMat (const TransformMat &t);
void Print (FILE *fp) const;
};
/*
* One abstract layer
*/
class Layer {
protected:
Material *mat; /* technology-specific
information. routing material for
the layer. */
Tile *hint; /* tile containing 0,0 / last lookup */
Tile *vhint; // tile layer containing vias to the
// next (upper) layer
Layer *up, *down; /* layer above and below */
Material **other; // for the base layer, fet + diff
int nother;
netlist_t *N;
unsigned int bbox:1; // 1 if bbox below is valid
long _llx, _lly, _urx, _ury;
long _bllx, _blly, _burx, _bury; // bloated bbox
/* BBox with spacing on all sides
This bloats the bounding box by ceil(minimum spacing/2) on all sides.
*/
public:
Layer (Material *, netlist_t *);
~Layer ();
void allocOther (int sz);
void setOther (int idx, Material *m);
void setDownLink (Layer *x);
int Draw (long llx, long lly, unsigned long wx, unsigned long wy, void *net, int type = 0);
int Draw (long llx, long lly, unsigned long wx, unsigned long wy, int type = 0);
int DrawVirt (int flavor, int type, long llx, long lly, unsigned long wx, unsigned long wy);
int drawVia (long llx, long lly, unsigned long wx, unsigned long wy, void *net, int type = 0);
int drawVia (long llx, long lly, unsigned long wx, unsigned long wy, int type = 0);
int isMetal (); // 1 if it is a metal layer or a via
// layer
void markPins (void *net, int isinput); // mark pin tiles
list_t *searchMat (void *net);
list_t *searchMat (int attr);
list_t *searchVia (void *net);
list_t *searchVia (int attr);
list_t *allNonSpaceMat ();
list_t *allNonSpaceVia (); // looks at "up" vias only
void getBBox (long *llx, long *lly, long *urx, long *ury);
void getBloatBBox (long *llx, long *lly, long *urx, long *ury);
void PrintRect (FILE *fp, TransformMat *t = NULL);
const char *getRouteName() {
RoutingMat *rmat = dynamic_cast<RoutingMat *> (mat);
if (rmat) {
return rmat->getLEFName();
}
else {
return mat->getName();
}
}
const char *getViaName() { return ((RoutingMat *)mat)->getUpC()->getName(); }
Tile *find (long x, long y);
friend class Layout;
};
class Layout {
public:
static bool _initdone;
static void Init();
static double getLeakAdjust () { return _leak_adjust; }
/*
The base layer is special as this is where the transistors are
drawn. It includes poly, fets, diffusion, and virtual diffusion.
*/
Layout (netlist_t *);
~Layout();
int DrawPoly (long llx, long lly, unsigned long wx, unsigned long wy, void *net);
int DrawDiff (int flavor, int type, long llx, long lly, unsigned long wx, unsigned long wy, void *net);
int DrawWellDiff (int flavor, int type, long llx, long lly, unsigned long wx, unsigned long wy, void *net);
int DrawFet (int flavor, int type, long llx, long lly, unsigned long wx, unsigned long wy, void *net);
int DrawDiffBBox (int flavor, int type, long llx, long lly, unsigned long wx, unsigned long wy);
/* 0 = metal1, etc. */
int DrawMetal (int num, long llx, long lly, unsigned long wx, unsigned long wy, void *net);
int DrawMetalPin (int num, long llx, long lly,
unsigned long wx, unsigned long wy,
void *net, int dir); /* dir 0 = input, 1 = output */
/* 0 = base to metal1, 1 = metal1 to metal2, etc. */
int DrawVia (int num, long llx, long lly, unsigned long wx, unsigned long wy);
Layer *getLayerPoly () { return base; }
Layer *getLayerDiff () { return base; }
Layer *getLayerWell () { return base; }
Layer *getLayerFet () { return base; }
Layer *getLayerMetal (int n) { return metals[n]; }
void markPins ();
PolyMat *getPoly ();
FetMat *getFet (int type, int flavor = 0); // type == EDGE_NFET or EDGE_PFET
DiffMat *getDiff (int type, int flavor = 0);
WellMat *getWell (int type, int flavor = 0);
// NOTE: WELL TYPE is NOT THE TYPE OF THE WELL MATERIAL, BUT THE TYPE OF
// THE FET THAT NEEDS THE WELL.
void getBBox (long *llx, long *lly, long *urx, long *ury);
void getBloatBBox (long *llx, long *lly, long *urx, long *ury);
void PrintRect (FILE *fp, TransformMat *t = NULL);
void ReadRect (const char *file, int raw_mode = 0);
void ReadRect (Process *p, int raw_mode = 0);
list_t *search (void *net);
list_t *search (int attr);
list_t *searchAllMetal ();
void propagateAllNets();
bool readRectangles() { return _readrect; }
void flushBBox() { _rbox.clear(); }
Rectangle &getAbutBox() { return _abutbox; }
LayoutEdgeAttrib *getEdgeAttrib() { return _le; }
double leak_adjust() {
if (!N->leak_correct) { return 0.0; }
else { return _leak_adjust; }
}
node_t *getVdd() { return N->Vdd; }
node_t *getGND() { return N->GND; }
private:
bool _readrect;
Rectangle _rbox; // this is from the .rect file, and
// overrides any ocmputed box and
// bounding box. If set, it is used as
// both the box and bbox for the
// layout
Rectangle _abutbox; // abutment information
LayoutEdgeAttrib *_le; // alignment information
Layer *base;
Layer **metals;
int nflavors;
int nmetals;
netlist_t *N;
struct Hashtable *lmap; // map from layer string to base layer
// name
path_info_t *_rect_inpath; // input path for rectangles, if any
static double _leak_adjust;
};
class LayoutBlob;
class SubcellInst;
enum blob_type { BLOB_BASE, /* some layout */
BLOB_CELL, /* subcell */
BLOB_MACRO, /* macro */
BLOB_LIST /* list of blobs */
};
enum blob_compose {
BLOB_HORIZ, // horizontal compositioo
BLOB_VERT, // vertical composition
BLOB_MERGE // merge paint
};
struct blob_list {
LayoutBlob *b;
TransformMat T; // transformation matrix to bring this
// blob into the coordinate system of
// the first blob and the bounding
// box/etc.
struct blob_list *next;
};
struct tile_listentry {
TransformMat m; /**< the coordinate transformation matrix */
list_t *tiles; /**< a list alternating between Layer pointer and a
list of tiles */
};
class LayoutBlob {
private:
union {
struct {
blob_list *hd, *tl;
} l; // a blob list
struct {
Layout *l; // ... layout block
// ... if this is a NULL pointer and
// it is a BLOB_BASE type, this is a
// special layout blob that is a pure
// bounding box.
} base;
SubcellInst *subcell; // subcell
ExternMacro *macro; // external macro
};
blob_type t; // type field: 0 = base, 1 = horiz,
// 2 = vert, etc.
Rectangle _bbox; // the bounding box of all paint
Rectangle _bloatbbox; // the bloated bounding box of all paint
Rectangle _abutbox; // the abut bounding box of all paint
LayoutEdgeAttrib *_le;
unsigned long count; // for statistics tracking
bool readRect;
void _printRect (FILE *fp, TransformMat *t);
public:
LayoutBlob (blob_type type, Layout *l = NULL);
LayoutBlob (SubcellInst *cell);
LayoutBlob (ExternMacro *m);
~LayoutBlob ();
bool isSubcell() { return t == BLOB_CELL ? true : false; }
/* macros */
bool isMacro() { return t == BLOB_MACRO ? true : false; }
const char *getMacroName() { return macro->getName(); }
const char *getLEFFile() { return macro->getLEFFile(); }
void appendBlob (LayoutBlob *b, blob_compose c, long gap = 0);
void markRead () { readRect = true; }
bool getRead() { return readRect; }
void PrintRect (FILE *fp, TransformMat *t = NULL);
/**
* Computes the actual bounding box of the layout blob
*
* @param llxp, llyp, urxp, uryp are used to return the boundary.
*/
Rectangle getBBox () const { return _bbox; }
Rectangle getBloatBBox () const { return _bloatbbox; }
/**
* Set bounding box: only applies to BLOB_BASE with no layout
*/
void setBBox (long _llx, long _lly, long _urx, long _ury);
/**
* Remove any bounding box blobs. Returns updated blob.
* If it is called on base bbox blob, then it returns NULL after
* deleting it.
*/
static LayoutBlob *delBBox (LayoutBlob *b);
/**
* Returns a list of tiles in the layout that match the net
* @param net is the net pointer (a node_t)
* @param m should not be used at the top-level, but provides the
* current transformatiom matrix used by the recursive call to the
* search function.
* @return a list_t of tile_listentry tiles.
*/
list_t *search (void *net, TransformMat *m = NULL);
list_t *search (int type, TransformMat *m = NULL); // this is for
// base layers
list_t *searchAllMetal (TransformMat *m = NULL);
/*
* Uses the return value from the search function and returns its
* bounding box
*/
static void searchBBox (list_t *slist, long *bllx, long *blly, long *burx,
long *bury);
static void searchFree (list_t *tiles);
/**
* Get abutment box
*/
Rectangle getAbutBox ();
/**
* Get edge attributes!
*/
LayoutEdgeAttrib *getLayoutEdgeAttrib() { return _le; }
/**
* Stats
*/
void incCount () { count++; }
unsigned long getCount () { return count; }
/**
* Alignment markers
*/
LayoutEdgeAttrib::attrib_list *getLeftAlign() {
return _le->left();
}
LayoutEdgeAttrib::attrib_list *getRightAlign() {
return _le->right();
}
LayoutEdgeAttrib::attrib_list *getTopAlign() {
return _le->top();
}
LayoutEdgeAttrib::attrib_list *getBotAlign() {
return _le->bot();
}
/**
* Print alignment markers
*/
void printAlign (FILE *fp) {
fprintf (fp, "l: ");
LayoutEdgeAttrib::print (fp, _le->left());
fprintf (fp, "; r: ");
LayoutEdgeAttrib::print (fp, _le->right());
fprintf (fp, "; t: ");
LayoutEdgeAttrib::print (fp, _le->top());
fprintf (fp, "; b: ");
LayoutEdgeAttrib::print (fp, _le->bot());
}
friend class SubcellInst;
};
#endif /* __ACT_GEOM_H__ */