fa37bd8ce31896ebc6e2ed75049b476594603b93
[soclayout.git] / experiments5 / doAlu16.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 import sys
5 import re
6 import traceback
7 import os.path
8 import optparse
9 import Cfg
10 import Hurricane
11 from Hurricane import DbU
12 from Hurricane import DataBase
13 from Hurricane import UpdateSession
14 from Hurricane import Breakpoint
15 from Hurricane import Box
16 from Hurricane import Transformation
17 from Hurricane import Instance
18 from Hurricane import Contact
19 from Hurricane import Vertical
20 from Hurricane import Horizontal
21 from Hurricane import Pin
22 from Hurricane import NetExternalComponents
23 import Viewer
24 import CRL
25 import Etesian
26 import Anabatic
27 import Katana
28 import Unicorn
29 from helpers import l, u, n
30 import clocktree.ClockTree
31 import plugins.RSavePlugin
32 import plugins.ClockTreePlugin
33 import symbolic.cmos
34
35 af = CRL.AllianceFramework.get()
36
37
38 def toDbU ( l ): return DbU.fromLambda(l)
39
40 def createVertical ( contacts, x, layer, width=None):
41 def yincrease ( lhs, rhs ): return int(lhs.getY() - rhs.getY())
42
43 contacts.sort( yincrease )
44
45 if width is None: width = l(2.0)
46
47 for i in range(1,len(contacts)):
48 print "create vert", contacts[i-1], contacts[i], layer, x, width
49 v = Vertical.create( contacts[i-1], contacts[i], layer, x, width )
50 print "v", v
51
52
53 def createHorizontal ( contactPaths, y, layer, width=None):
54 def xincrease ( lhs, rhs ): return int(lhs.getX() - rhs.getX())
55
56 contacts = contactPaths
57
58 if width is None: width = l(2.0)
59
60 contacts.sort( xincrease )
61
62 for i in range(1,len(contacts)):
63 Horizontal.create( contacts[i-1], contacts[i], layer, y, width )
64
65
66 def build_crosstrace(net, via, layer, x, x1, y):
67
68 contacts = \
69 [ Contact.create( net, via, l(x), l(y), l(1.0), l(1.0) )
70 , Contact.create( net, via, l(x1), l(y), l(1.0), l(1.0) )
71 ]
72
73 createHorizontal( contacts, l(y), layer )
74 print "slaves", contacts[-1].getSlaveComponents()
75 for component in contacts[-1].getSlaveComponents():
76 NetExternalComponents.setExternal(component)
77
78 def build_downtrace(net, via, layer, x, y, y1):
79
80 contacts = \
81 [ Contact.create( net, via, l(x), l(y), l(1.0), l(1.0) )
82 , Contact.create( net, via, l(x), l(y1), l(1.0), l(1.0) )
83 ]
84
85 createVertical( contacts, l(x), layer )
86 print "slaves", contacts[-1].getSlaveComponents()
87 for component in contacts[-1].getSlaveComponents():
88 NetExternalComponents.setExternal(component)
89
90 #print "af", dir(af)
91 #sys.exit(0)
92
93 Cfg.Configuration.pushDefaultPriority( Cfg.Parameter.Priority.UserFile )
94
95 cellsTop = '~/alliance-check-toolkit/cells'
96 env = af.getEnvironment()
97 env.addSYSTEM_LIBRARY( library=cellsTop+'/nsxlib', mode=CRL.Environment.Prepend )
98 env.addSYSTEM_LIBRARY( library=cellsTop+'/mpxlib', mode=CRL.Environment.Prepend )
99
100
101 Cfg.getParamBool ( 'misc.catchCore' ).setBool ( False )
102 Cfg.getParamBool ( 'misc.info' ).setBool ( False )
103 Cfg.getParamBool ( 'misc.paranoid' ).setBool ( False )
104 Cfg.getParamBool ( 'misc.bug' ).setBool ( False )
105 Cfg.getParamBool ( 'misc.logMode' ).setBool ( True )
106 Cfg.getParamBool ( 'misc.verboseLevel1' ).setBool ( True )
107 Cfg.getParamBool ( 'misc.verboseLevel2' ).setBool ( True )
108 #Cfg.getParamInt ( 'misc.minTraceLevel' ).setInt ( 159 )
109 #Cfg.getParamInt ( 'misc.maxTraceLevel' ).setInt ( 160 )
110 Cfg.getParamEnumerate ( 'etesian.effort' ).setInt ( 2 )
111 Cfg.getParamPercentage( 'etesian.spaceMargin' ).setPercentage( 20.0 )
112 Cfg.getParamPercentage( 'etesian.aspectRatio' ).setPercentage( 100.0 )
113 Cfg.getParamBool ( 'etesian.uniformDensity' ).setBool ( True )
114 Cfg.getParamInt ( 'anabatic.edgeLenght' ).setInt ( 24 )
115 Cfg.getParamInt ( 'anabatic.edgeWidth' ).setInt ( 8 )
116 Cfg.getParamString ( 'anabatic.topRoutingLayer' ).setString ( 'METAL5')
117 Cfg.getParamInt ( 'katana.eventsLimit' ).setInt ( 1000000 )
118 Cfg.getParamInt ( 'katana.hTracksReservedLocal' ).setInt ( 7 )
119 Cfg.getParamInt ( 'katana.vTracksReservedLocal' ).setInt ( 6 )
120 #Cfg.getParamInt ( 'clockTree.minimumSide' ).setInt ( l(1000) )
121
122 env = af.getEnvironment()
123 env.setCLOCK( '^clk$|m_clock' )
124 env.setPOWER( 'vdd' )
125 env.setGROUND( 'vss' )
126
127 Cfg.Configuration.popDefaultPriority()
128
129 ###################
130 # add
131
132 def add ( **kw ):
133 editor = None
134 if kw.has_key('editor') and kw['editor']:
135 editor = kw['editor']
136
137 db = DataBase.getDB()
138 print db, dir(db)
139 metal2 = DataBase.getDB().getTechnology().getLayer( 'metal2' )
140 metal3 = DataBase.getDB().getTechnology().getLayer( 'metal3' )
141 metal5 = DataBase.getDB().getTechnology().getLayer( 'metal5' )
142
143 cell = af.getCell( 'add', CRL.Catalog.State.Logical )
144 print cell.getNet('a(0)')
145
146 if not cell:
147 print '[ERROR] Unable to load cell "alu16.vst", aborting .'
148 return False
149 kw[ 'cell' ] = cell
150
151 width = 350.0
152 height = 405.0
153
154 ab = Box( l( 0.0 )
155 , l( 0.0 )
156 , l( width )
157 , l( height ) )
158
159 cellGauge = af.getCellGauge()
160 spaceMargin = (Cfg.getParamPercentage('etesian.spaceMargin').asPercentage()+5) / 100.0
161 aspectRatio = Cfg.getParamPercentage('etesian.aspectRatio').asPercentage() / 100.0
162 clocktree.ClockTree.computeAbutmentBox( cell, spaceMargin, aspectRatio, cellGauge )
163 ab2 = cell.getAbutmentBox()
164 print "box", ab, ab.getHeight(), ab.getWidth()
165 print "calc box", ab2, ab2.getHeight(), ab2.getWidth()
166
167 #height = ab.getHeight()
168 #width = ab.getWidth()
169
170 UpdateSession.open()
171 cell.setAbutmentBox( ab )
172
173 for i in range(16):
174 if True:
175 x = 20.0*i + 10.0
176 y = height
177 Pin.create( cell.getNet('a(%d)' % i)
178 , 'a(%d).0' % i
179 , Pin.Direction.NORTH
180 , Pin.PlacementStatus.FIXED
181 , metal3
182 , l( x ), l( y - 0 ) # Position.
183 , l( 2.0 ) , l( 2.0 ) # Size.
184 )
185 for i in range(16):
186 if True:
187 Pin.create( cell.getNet('o(%d)' % i)
188 , 'o(%d).0' % i
189 , Pin.Direction.SOUTH
190 , Pin.PlacementStatus.FIXED
191 , metal3
192 , l( 10.0*i + 100.0 ), l( 0) # Position.
193 , l( 2.0 ) , l( 2.0 ) # Size.
194 )
195
196 for i in range(16):
197 if True:
198 net = cell.getNet('b(%d)' % i)
199 x = 20.0*i + 10.0 + 10
200 y = height - 0
201 #build_downtrace(net, metal3, x, y+11, y)
202 #continue
203 Pin.create( net
204 , 'b(%d).0' % i
205 , Pin.Direction.NORTH
206 , Pin.PlacementStatus.FIXED
207 , metal3
208 , l( x ), l( y - 0 ) # Position.
209 , l( 2.0 ) , l( 2.0 ) # Size.
210 )
211 if False:
212 Pin.create( cell.getNet('rst')
213 , 'p_reset.0'
214 , Pin.Direction.WEST
215 , Pin.PlacementStatus.FIXED
216 , metal2
217 , l( 0.0 )
218 , l( 140.0 )
219 , l( 2.0 )
220 , l( 2.0 )
221 )
222 UpdateSession.close()
223
224 if True:
225 if editor: editor.setCell( cell )
226
227 etesian = Etesian.EtesianEngine.create(cell)
228 etesian.place()
229
230 katana = Katana.KatanaEngine.create(cell)
231 katana.digitalInit ()
232 #katana.runNegociatePreRouted()
233 print dir(katana)
234 katana.runGlobalRouter (0)
235 katana.loadGlobalRouting ( Anabatic.EngineLoadGrByNet )
236 katana.layerAssign ( Anabatic.EngineNoNetLayerAssign )
237 katana.runNegociate ( Katana.Flags.NoFlags )
238 katana.finalizeLayout ()
239 print dir(katana)
240 success = katana.getSuccessState()
241 katana.destroy()
242
243 if True:
244 VIA23 = DataBase.getDB().getTechnology().getLayer( 'VIA23' )
245 UpdateSession.open()
246 #net = cell.getNet('b(%d)' % 0)
247 net = cell.getNet('vdd')
248 build_downtrace(net, VIA23, metal2, -5, -10, -20)
249 build_downtrace(net, VIA23, metal2, -10, -10, -20)
250 build_crosstrace(net, VIA23, metal2, -5, -10, -10)
251 build_crosstrace(net, VIA23, metal2, -5, -10, -20)
252 for i in range(16):
253 if False:
254 net = cell.getNet('b(%d)' % i)
255 x = 20.0*i + 10.0 + 10
256 y = height-10
257 build_downtrace(net, metal2, x, y, y+10)
258 ab.inflate ( l(30.0) )
259 cell.setAbutmentBox( ab )
260 UpdateSession.close()
261
262 #af.saveCell( cell, CRL.Catalog.State.Views )
263 plugins.RSavePlugin.ScriptMain( **kw )
264
265 ###################
266 # sub
267
268 def sub ( **kw ):
269 editor = None
270 if kw.has_key('editor') and kw['editor']:
271 editor = kw['editor']
272
273 db = DataBase.getDB()
274 print db, dir(db)
275 metal2 = DataBase.getDB().getTechnology().getLayer( 'metal2' )
276 metal3 = DataBase.getDB().getTechnology().getLayer( 'metal3' )
277 metal5 = DataBase.getDB().getTechnology().getLayer( 'metal5' )
278
279 cell = af.getCell( 'sub', CRL.Catalog.State.Logical )
280 print cell.getNet('a(0)')
281
282 if not cell:
283 print '[ERROR] Unable to load cell "alu16.vst", aborting .'
284 return False
285 kw[ 'cell' ] = cell
286
287 width = 350.0
288 height = 405.0
289
290 ab = Box( l( 0.0 )
291 , l( 0.0 )
292 , l( width )
293 , l( height ) )
294
295 cellGauge = af.getCellGauge()
296 spaceMargin = (Cfg.getParamPercentage('etesian.spaceMargin').asPercentage()+5) / 100.0
297 aspectRatio = Cfg.getParamPercentage('etesian.aspectRatio').asPercentage() / 100.0
298 clocktree.ClockTree.computeAbutmentBox( cell, spaceMargin, aspectRatio, cellGauge )
299 ab2 = cell.getAbutmentBox()
300 print "box", ab, ab.getHeight(), ab.getWidth()
301 print "calc box", ab2, ab2.getHeight(), ab2.getWidth()
302
303 #height = ab.getHeight()
304 #width = ab.getWidth()
305
306 UpdateSession.open()
307 cell.setAbutmentBox( ab )
308
309 for i in range(16):
310 if True:
311 x = 20.0*i + 10.0
312 y = height
313 Pin.create( cell.getNet('a(%d)' % i)
314 , 'a(%d).0' % i
315 , Pin.Direction.NORTH
316 , Pin.PlacementStatus.FIXED
317 , metal3
318 , l( x ), l( y - 0 ) # Position.
319 , l( 2.0 ) , l( 2.0 ) # Size.
320 )
321 for i in range(16):
322 if True:
323 Pin.create( cell.getNet('o(%d)' % i)
324 , 'o(%d).0' % i
325 , Pin.Direction.SOUTH
326 , Pin.PlacementStatus.FIXED
327 , metal3
328 , l( 10.0*i + 100.0 ), l( 0) # Position.
329 , l( 2.0 ) , l( 2.0 ) # Size.
330 )
331
332 for i in range(16):
333 if True:
334 net = cell.getNet('b(%d)' % i)
335 x = 20.0*i + 10.0 + 10
336 y = height - 0
337 #build_downtrace(net, metal3, x, y+11, y)
338 #continue
339 Pin.create( net
340 , 'b(%d).0' % i
341 , Pin.Direction.NORTH
342 , Pin.PlacementStatus.FIXED
343 , metal3
344 , l( x ), l( y - 0 ) # Position.
345 , l( 2.0 ) , l( 2.0 ) # Size.
346 )
347 if False:
348 Pin.create( cell.getNet('rst')
349 , 'p_reset.0'
350 , Pin.Direction.WEST
351 , Pin.PlacementStatus.FIXED
352 , metal2
353 , l( 0.0 )
354 , l( 140.0 )
355 , l( 2.0 )
356 , l( 2.0 )
357 )
358 UpdateSession.close()
359
360 if True:
361 if editor: editor.setCell( cell )
362
363 etesian = Etesian.EtesianEngine.create(cell)
364 etesian.place()
365
366 katana = Katana.KatanaEngine.create(cell)
367 katana.digitalInit ()
368 #katana.runNegociatePreRouted()
369 print dir(katana)
370 katana.runGlobalRouter (0)
371 katana.loadGlobalRouting ( Anabatic.EngineLoadGrByNet )
372 katana.layerAssign ( Anabatic.EngineNoNetLayerAssign )
373 katana.runNegociate ( Katana.Flags.NoFlags )
374 katana.finalizeLayout ()
375 print dir(katana)
376 success = katana.getSuccessState()
377 katana.destroy()
378
379 if False:
380 UpdateSession.open()
381 cell.setAbutmentBox( ab )
382 for i in range(16):
383 if True:
384 net = cell.getNet('b(%d)' % i)
385 x = 20.0*i + 10.0 + 10
386 y = height-10
387 build_downtrace(net, metal2, x, y, y+10)
388 UpdateSession.close()
389
390 #af.saveCell( cell, CRL.Catalog.State.Views )
391 plugins.RSavePlugin.ScriptMain( **kw )
392
393 def connect ( instanceRef, pin, netRef ):
394 instance = instanceRef
395
396 if isinstance(netRef,str):
397 net = self.getNet( netRef )
398 else:
399 net = netRef
400
401 masterNet = instance.getMasterCell().getNet(pin)
402 if not masterNet:
403 print '[ERR] Master cell "%s" of instance "%s" no connector named "%s".' \
404 % (instance.getMasterCell().getName(), instance.getName(), pin)
405
406 instance.getPlug( instance.getMasterCell().getNet(pin) ).setNet( net )
407
408 def place ( instanceRef, x, y, orient ):
409 print "place", instanceRef, x, y, orient
410 instance = instanceRef
411 instance.setTransformation ( Transformation( x, y, orient ) )
412 instance.setPlacementStatus( Instance.PlacementStatus.PLACED )
413
414 def createInstance ( cell, instanceName, modelRef, portmap={}, transf=None ):
415 instance = cell.getInstance( instanceName )
416 if instance:
417 print "found instace", instance
418 return instance
419 if isinstance(modelRef,str):
420 model = af.getCell( modelRef, Catalog.State.Views )
421 else:
422 model = modelRef
423 instance = Instance.create( self.cell, instanceName, model )
424 for pin, net in portmap.items():
425 connect( instance, pin, net )
426
427 print "create transf", transf
428 if transf:
429 place( instance, transf[0], transf[1], transf[2] )
430 return instance
431
432 ################# SNX
433 #
434
435 def alu_hier_place(**kw):
436
437 editor = None
438 if kw.has_key('editor') and kw['editor']:
439 editor = kw['editor']
440
441 db = DataBase.getDB()
442 print db, dir(db)
443 metal2 = DataBase.getDB().getTechnology().getLayer( 'metal2' )
444 metal3 = DataBase.getDB().getTechnology().getLayer( 'metal3' )
445
446 add = af.getCell( 'add', CRL.Catalog.State.Views )
447 sub = af.getCell( 'sub', CRL.Catalog.State.Views )
448 cell = af.getCell( 'alu_hier', CRL.Catalog.State.Logical )
449 if not cell:
450 print '[ERROR] Unable to load cell "snx.vst", aborting .'
451 return False
452 kw[ 'cell' ] = cell
453
454 ab = Box( l( 0.0 )
455 , l( 0.0 )
456 , l( 1000.0 )
457 , l( 600.0 ) )
458
459 UpdateSession.open()
460 cell.setAbutmentBox( ab )
461
462 transf = (l(50.0), l(100.0), Transformation.Orientation.ID)
463 subi = createInstance(cell, "subckt_49_sub", sub)
464 place( subi, transf[0], transf[1], transf[2] )
465 print "sub place", subi
466
467 transf = (l(550.0), l(100.0), Transformation.Orientation.ID)
468 addi = createInstance(cell, "subckt_48_add", add)
469 place( addi, transf[0], transf[1], transf[2] )
470 print "add place", addi
471
472 if False:
473 for i in range(16):
474 Pin.create( cell.getNet('a(%d)' % i)
475 , 'a(%d).0' % i
476 , Pin.Direction.SOUTH
477 , Pin.PlacementStatus.FIXED
478 , metal3
479 , l( 100.0*i + 50.0 ) , l( 0.0 ) # Position.
480 , l( 2.0 ) , l( 2.0 ) # Size.
481 )
482 Pin.create( cell.getNet('b(%d)' % i)
483 , 'b(%d).0' % i
484 , Pin.Direction.SOUTH
485 , Pin.PlacementStatus.FIXED
486 , metal3
487 , l( 100.0*i + 50.0 ) , l( 0.0 ) # Position.
488 , l( 2.0 ) , l( 2.0 ) # Size.
489 )
490 Pin.create( cell.getNet('o(%d)' % i)
491 , 'o(%d).0' % i
492 , Pin.Direction.NORTH
493 , Pin.PlacementStatus.FIXED
494 , metal3
495 , l( 100.0*i + 25.0 ) , l( 0.0 ) # Position.
496 , l( 2.0 ) , l( 2.0 ) # Size.
497 )
498
499 Pin.create( cell.getNet('rst')
500 , 'p_reset.0'
501 , Pin.Direction.WEST
502 , Pin.PlacementStatus.FIXED
503 , metal2
504 , l( 0.0 )
505 , l( 140.0 )
506 , l( 2.0 )
507 , l( 2.0 )
508 )
509 UpdateSession.close()
510
511 if editor: editor.setCell( cell )
512
513 print "editor", editor, dir(editor)
514
515 #af.saveCell( cell, CRL.Catalog.State.Views )
516 plugins.RSavePlugin.ScriptMain( **kw )
517
518 return 0
519
520 ################# SNX
521 #
522
523 def alu_hier_route(**kw):
524
525 editor = None
526 if kw.has_key('editor') and kw['editor']:
527 editor = kw['editor']
528
529 db = DataBase.getDB()
530 print db, dir(db)
531 metal2 = DataBase.getDB().getTechnology().getLayer( 'metal2' )
532 metal3 = DataBase.getDB().getTechnology().getLayer( 'metal3' )
533
534 cell = af.getCell( 'alu_hier', CRL.Catalog.State.Logical )
535 if not cell:
536 print '[ERROR] Unable to load cell "snx.vst", aborting .'
537 return False
538 kw[ 'cell' ] = cell
539
540 ab = Box( l( 0.0 )
541 , l( 0.0 )
542 , l( 1000.0 )
543 , l( 600.0 ) )
544
545 cell.setAbutmentBox( ab )
546
547 if editor: editor.setCell( cell )
548
549 print "editor", editor, dir(editor)
550
551 if True:
552 etesian = Etesian.EtesianEngine.create(cell)
553 #etesian.place()
554
555 katana = Katana.KatanaEngine.create(cell)
556 katana.digitalInit ()
557 katana.runNegociatePreRouted()
558 print dir(katana)
559 katana.runGlobalRouter (0)
560 katana.loadGlobalRouting ( Anabatic.EngineLoadGrByNet )
561 katana.layerAssign ( Anabatic.EngineNoNetLayerAssign )
562 katana.runNegociate ( Katana.Flags.NoFlags )
563 katana.finalizeLayout ()
564 print dir(katana)
565 success = katana.getSuccessState()
566 katana.destroy()
567 else:
568 success = 0
569
570 #af.saveCell( cell, CRL.Catalog.State.Views )
571 plugins.RSavePlugin.ScriptMain( **kw )
572
573 print "cell", cell, dir(cell)
574 c = cell.getComponents()
575 print "components", c, dir(c)
576 for child in cell.getInstances():
577 print "child", child
578
579 return success
580
581
582 if __name__ == '__main__':
583 success = add()
584 #success = sub()
585 #success = alu_hier_place()
586 #success = alu_hier_route()
587 shellSuccess = 0
588 if not success: shellSuccess = 1
589
590 sys.exit( shellSuccess )
591
592