1 /* 2 * EFint.h -- 3 * 4 * Internal definitions for the procedures to flatten hierarchical 5 * (.ext) circuit extraction files. 6 * 7 * ********************************************************************* 8 * * Copyright (C) 1985, 1990 Regents of the University of California. * 9 * * Permission to use, copy, modify, and distribute this * 10 * * software and its documentation for any purpose and without * 11 * * fee is hereby granted, provided that the above copyright * 12 * * notice appear in all copies. The University of California * 13 * * makes no representations about the suitability of this * 14 * * software for any purpose. It is provided "as is" without * 15 * * express or implied warranty. Export of this software outside * 16 * * of the United States of America may require an export license. * 17 * ********************************************************************* 18 * 19 * rcsid $Header: /usr/cvsroot/magic-8.0/extflat/EFint.h,v 1.6 2010/12/16 18:59:03 tim Exp $ 20 */ 21 22 #ifndef _EFINT_H 23 #define _EFINT_H 24 25 #include "utils/magic.h" 26 27 /* 28 * Add in the next character value to a hash sum. 29 * This function uses a 4-bit rotate to ensure that "ab" and "ba" 30 * hash to different values; the 4 bits of rotation are provided 31 * to allow even short strings to produce large hash values. 32 * (Small hash values don't get randomized very well). 33 * 34 *************************************************************** 35 * BE VERY CAREFUL ABOUT CHANGING THIS! IT CAN MAKE AN ENORMOUS 36 * DIFFERENCE TO THE PERFORMANCE OF THE HASHING ALGORITHM! 37 *************************************************************** 38 */ 39 #define HASHADDVAL(sum, val) \ 40 (((((unsigned) (sum)) >> 28) | (((unsigned) (sum)) << 4)) + (val)) 41 42 /* ------------------------ Distance information ---------------------- */ 43 44 /* 45 * The .ext file also allows explicit distance information to be 46 * represented. This information is stored in a hash table in each 47 * Def, keyed by this same structure. Distances are between named 48 * signals, rather than nodes, so we use HierNames instead of EFNodes 49 * for the two points between which distance is measured. 50 */ 51 typedef struct dist 52 { 53 int dist_min, dist_max; /* Min and max distance (lambda) */ 54 HierName *dist_1, *dist_2; /* Two points */ 55 } Distance; 56 57 /* ------------------------- Kill information ------------------------- */ 58 59 /* 60 * In order for resistance and distance extraction to work correctly, 61 * it's sometimes necessary to override the structure of the graph 62 * extracted at a lower level of the hierarchy. The "killnode" line 63 * in a .ext file specifies that a given node, and everything that 64 * connects to it, have been re-extracted and are represented in 65 * flat format later in the .ext file. 66 * 67 * The kill list bisects the .ext file. Fets, resistors, distance 68 * info, etc that appear before the first killnode in a .ext file 69 * are processed by the flattener before processing the kill list 70 * for a given cell, followed by processing those fets, resistors, 71 * etc that appear after the first killnode line. 72 * 73 * To allow the distinction to be made between before-kill and after-kill 74 * processing, node structures have a flag field that can have the 75 * EF_AFTERKILL bit set, indicating that the node appeared after 76 * the killnode lines. This information isn't necessary for capacitors, 77 * resistors, or fets, since they are implicitly killed whenever any 78 * of their terminals is connected to a killed node. 79 */ 80 typedef struct kill 81 { 82 struct kill *kill_next; /* Next kill in def */ 83 HierName *kill_name; /* Node to kill */ 84 } Kill; 85 86 /* --------------------------- Connections ---------------------------- */ 87 88 /* 89 * Connections are used for a multitude of purposes. They all 90 * boil down to a need to represent hierarchical names with some 91 * array range information present. 92 * 93 * Connections are used to represent that two nodes must be merged, 94 * and the resultant node's resistance and capacitance adjusted 95 * (conn_name2 non-NULL), or that the resistance and capacitance 96 * of a single node be adjusted (conn_name2 NULL). 97 * 98 * They are also used to represent internodal capacitors when 99 * they appear on the def_caps list of a Def, or explicit resistors 100 * when appearing on the def_resistors list. In these latter cases, 101 * both conn_name1 and conn_name2 are non-NULL. 102 */ 103 104 /* Max number of dimensions in an array */ 105 #define MAXSUBS 2 106 107 /* Subscripts range from r_lo to r_hi inclusive; r_lo <= r_hi */ 108 typedef struct 109 { 110 int r_lo, r_hi; 111 } Range; 112 113 /* 114 * Each node in the connection may be accompanied by subscripts. 115 * The range of values of the subscripts are stored here. 116 * When cn_nsubs is 2, cn_subs[0] is x, cn_subs[1] is y. 117 */ 118 typedef struct 119 { 120 char *cn_name; 121 int cn_nsubs; 122 Range cn_subs[MAXSUBS]; 123 } ConnName; 124 125 /* Connection itself */ 126 typedef struct conn 127 { 128 ConnName conn_1; /* First node in connection */ 129 ConnName conn_2; /* Second (optional) node in connection */ 130 union { 131 float conn_val_res; /* Value of capacitance (attofarads) or */ 132 EFCapValue conn_val_cap; /* resistance (milliohms). */ 133 } conn_value; 134 135 struct conn *conn_next; /* Next connection in list */ 136 EFPerimArea conn_pa[1]; /* Dummy; each connection actually has 137 * efNumResistClasses array elements 138 * allocated to it. 139 */ 140 } Connection; 141 142 /* Abbreviations */ 143 #define conn_name1 conn_1.cn_name 144 #define conn_name2 conn_2.cn_name 145 #define conn_res conn_value.conn_val_res 146 #define conn_cap conn_value.conn_val_cap 147 148 /* -------------------------- Defs and uses --------------------------- */ 149 150 /* A Def exists for each .ext file */ 151 typedef struct def 152 { 153 char *def_name; /* Name of this def */ 154 float def_scale; /* Multiply all dimensions by this */ 155 int def_flags; /* Flags -- see below */ 156 HashTable def_nodes; /* Map names into EFNodeNames */ 157 HashTable def_dists; /* Map pairs of names into Distances */ 158 HashTable def_uses; /* Hash children of this def by name */ 159 HashTable def_devs; /* Devices (hash by position) */ 160 EFNode def_firstn; /* Head of circular list of nodes */ 161 162 /* The following are all NULL-terminated lists */ 163 164 Connection *def_conns; /* Hierarchical connections/adjustments */ 165 Connection *def_caps; /* Two-terminal capacitors */ 166 Connection *def_resistors; /* Two-terminal resistors */ 167 Kill *def_kills; /* Used to modify hierarchical structure 168 * using information present only in the 169 * parent, e.g, to kill an old node and 170 * all its attached fets prior to replacing 171 * the node with several smaller ones, 172 * connected by explicit resistors. 173 */ 174 } Def; 175 176 #define DEF_AVAILABLE 0x01 /* This def has been read in */ 177 #define DEF_SUBCIRCUIT 0x02 /* This def defines subcircuit ports */ 178 #define DEF_PROCESSED 0x04 /* This def processed in hierarchical output */ 179 #define DEF_NODEVICES 0x08 /* This def contains no devices */ 180 #define DEF_SUBSNODES 0x10 /* This def contains implicit substrate nodes */ 181 #define DEF_ABSTRACT 0x20 /* This def is an abstract view (e.g., LEF) */ 182 183 /* 184 * Every Def has a NULL-terminated list of uses that correspond 185 * to the subcells of that Def. If the use is an array, the ArrayInfo 186 * structure describes the indices and the separation between elements 187 * (for computing transforms). 188 */ 189 #ifndef _DATABASE_H 190 typedef struct 191 { 192 int ar_xlo, ar_xhi; 193 int ar_ylo, ar_yhi; 194 int ar_xsep, ar_ysep; 195 } ArrayInfo; 196 #endif /* _DATABASE_H */ 197 198 typedef struct use 199 { 200 char *use_id; /* Use identifier (appears in hier paths) */ 201 Def *use_def; /* Sub def being used */ 202 Transform use_trans; /* Transform up to parent coords (for fets) */ 203 ArrayInfo use_array; /* Arraying information */ 204 } Use; 205 206 #define use_xlo use_array.ar_xlo 207 #define use_xhi use_array.ar_xhi 208 #define use_ylo use_array.ar_ylo 209 #define use_yhi use_array.ar_yhi 210 #define use_xsep use_array.ar_xsep 211 #define use_ysep use_array.ar_ysep 212 213 #define IsArray(u) ((u)->use_xlo!=(u)->use_xhi || (u)->use_ylo!=(u)->use_yhi) 214 215 /* -------------------------------------------------------------------- */ 216 217 /* Structure passed down during hierarchical searching */ 218 typedef struct 219 { 220 Use *hc_use; /* Use being visited */ 221 int hc_x, hc_y; /* X and Y indices if array */ 222 Transform hc_trans; /* Transform to flat coordinates (for fets) */ 223 HierName *hc_hierName; /* Ptr to trailing component of HierName list */ 224 } HierContext; 225 226 /* ------------------------------ Debugging --------------------------- */ 227 228 extern bool efHNStats; /* TRUE if we keep statistics on HierNames */ 229 230 /* -------------------------------------------------------------------- */ 231 232 /* Structure for passing procedures and cdata to client functions */ 233 typedef struct 234 { 235 int (*ca_proc)(); 236 ClientData ca_cdata; 237 } CallArg; 238 239 /* -------------------------------------------------------------------- */ 240 241 /* 242 * Structure used as key in hash table of internodal capacitors. 243 * Keys are EFNodes, since capacitors exist between a pair of electrical 244 * nodes. The keys are ordered so that the lowest-address EFNode is 245 * first. 246 */ 247 typedef struct 248 { 249 EFNode *ck_1, *ck_2; 250 } EFCoupleKey; 251 252 /* -------------------------------------------------------------------- */ 253 254 /* Max filename length */ 255 #define FNSIZE 1024 256 257 /* Resistance is in milliohms, capacitance in attofarads */ 258 extern bool efWarn; /* If TRUE, warn about unusual occurrences */ 259 extern bool efScaleChanged; /* If TRUE, multiply all dimensions by scale 260 * factor on output; otherwise, leave them 261 * alone and output a global scale factor 262 * of efScale in the .sim file. 263 */ 264 265 extern int efResists[]; /* Resistance per square for each class */ 266 extern bool efResistChanged; /* TRUE if some cells' resistclasses unequal */ 267 268 extern HashTable efFreeHashTable; 269 extern HashTable efNodeHashTable; 270 extern HashTable efDevParamTable; 271 extern HashTable efHNUseHashTable; 272 extern HashTable efCapHashTable; 273 extern HashTable efDistHashTable; 274 extern HashTable efWatchTable; 275 extern bool efWatchNodes; 276 extern EFNode efNodeList; 277 extern Def *efFlatRootDef; 278 279 /* --------------------- Internally used procedures ------------------- */ 280 281 /* Def table management */ 282 extern Def *efDefLook(); 283 extern Def *efDefNew(); 284 extern Def *EFRootDef(); 285 286 /* HierName manipulation */ 287 extern HierName *efHNFromUse(); 288 extern char *efHNToStrFunc(); 289 extern bool EFHNBest(); 290 291 /* Functions for hashing of HierNames */ 292 extern int efHNCompare(); 293 extern int efHNHash(HierName *); 294 295 /* Functions for hashing of Distances */ 296 extern bool efHNDistCompare(); 297 extern char *efHNDistCopy(); 298 extern int efHNDistHash(); 299 extern void efHNDistKill(); 300 301 /* Functions for hashing of use id HierNames */ 302 extern bool efHNUseCompare(); 303 extern int efHNUseHash(); 304 305 extern EFCapValue CapHashGetValue(); 306 extern void CapHashSetValue(); 307 308 /* efBuild procedures */ 309 /* Warning: The capacitance argument to these should be always double 310 regardless of whether you set EFCapValue to float or double 311 This should be done to avoid trouble with argument promotion 312 that some ANSI C compilers introduce */ 313 314 extern DevParam *efGetDeviceParams(); 315 extern void efBuildNode(); 316 extern void efBuildConnect(); 317 extern void efBuildResistor(); 318 extern void efBuildCap(); 319 extern HierContext *EFFlatBuildOneLevel(); 320 321 #endif /* _EFINT_H */ 322