invert pin-direction to make it sort-of "mirror"
[soclayout.git] / experiments7 / doAlu16.py
index ea376c7effa08f8306e685837f2a2dd691acb68e..15fbd26bffd955ceab249f85a27f5c9218b5a399 100755 (executable)
@@ -6,8 +6,9 @@ import sys
 import CRL
 import Cfg
 from Hurricane import Box
+from Hurricane import Transformation
 from coriolis2.settings import af
-from utils import Module, SessionManager
+from utils import Module, SessionManager, Config
 
 import symbolic.cmos  # do not remove
 
@@ -15,32 +16,30 @@ BIT_WIDTH = 16
 
 
 def coriolis_setup():
-    Cfg.Configuration.pushDefaultPriority(Cfg.Parameter.Priority.UserFile)
-    Cfg.getParamBool('misc.catchCore').setBool(False)
-    Cfg.getParamBool('misc.info').setBool(False)
-    Cfg.getParamBool('misc.paranoid').setBool(False)
-    Cfg.getParamBool('misc.bug').setBool(False)
-    Cfg.getParamBool('misc.logMode').setBool(True)
-    Cfg.getParamBool('misc.verboseLevel1').setBool(True)
-    Cfg.getParamBool('misc.verboseLevel2').setBool(True)
-    Cfg.getParamEnumerate('etesian.effort').setInt(2)
-    Cfg.getParamPercentage('etesian.spaceMargin').setPercentage(20.0)
-    Cfg.getParamPercentage('etesian.aspectRatio').setPercentage(100.0)
-    Cfg.getParamBool('etesian.uniformDensity').setBool(True)
-    Cfg.getParamInt('anabatic.edgeLenght').setInt(24)
-    Cfg.getParamInt('anabatic.edgeWidth').setInt(8)
-    Cfg.getParamString('anabatic.topRoutingLayer').setString('METAL5')
-    Cfg.getParamInt('katana.searchHalo').setInt(30)
-    Cfg.getParamInt('katana.eventsLimit').setInt(1000000)
-    Cfg.getParamInt('katana.hTracksReservedLocal').setInt(7)
-    Cfg.getParamInt('katana.vTracksReservedLocal').setInt(6)
-
-    env = af.getEnvironment()
-    env.setCLOCK('^clk$|m_clock')
-    env.setPOWER('vdd')
-    env.setGROUND('vss')
-
-    Cfg.Configuration.popDefaultPriority()
+    with Config(Cfg.Parameter.Priority.UserFile) as cfg:
+        cfg.misc_catchCore = False
+        cfg.misc_info = False
+        cfg.misc_paranoid = False
+        cfg.misc_bug = False
+        cfg.misc_logMode = True
+        cfg.misc_verboseLevel1 = True
+        cfg.misc_verboseLevel2 = True
+        cfg.etesian_effort = 2
+        cfg.etesian_spaceMargin = "20.0%"
+        cfg.etesian_aspectRatio = "100.0%"
+        cfg.etesian_uniformDensity = True
+        cfg.anabatic_edgeLenght = 24
+        cfg.anabatic_edgeWidth = 8
+        cfg.anabatic_topRoutingLayer = 'METAL5'
+        cfg.katana_searchHalo = 30
+        cfg.katana_eventsLimit = 1000000
+        cfg.katana_hTracksReservedLocal = 7
+        cfg.katana_vTracksReservedLocal = 6
+
+        env = af.getEnvironment()
+        env.setCLOCK('^clk$|m_clock')
+        env.setPOWER('vdd')
+        env.setGROUND('vss')
 
 
 class AddSub(Module):
@@ -49,7 +48,7 @@ class AddSub(Module):
         """ Main routine. """
 
         with SessionManager():
-            self.init_abutment_box()
+            self.compute_ab()
             self.create_pins()
 
         if self.editor:
@@ -73,15 +72,41 @@ class ALU16(Module):
 
     def build(self):
 
+        h_margin = 25.0
+        v_margin = 10.0
+
         if not self.build_submodules():
             return False
 
+        # at this point we have the (auto-calculated) submodules' dimensions
+        # in their `ab` properties.
+
+        add, sub = self.submodules
+
         with SessionManager():
-            self.init_abutment_box()
-            self.place_submodules()
+            self.compute_ab()
+
+            width = self.from_dbu(
+                self.ab.getWidth() + add.ab.getWidth() + sub.ab.getWidth()
+            ) + 4*h_margin
+            height = self.from_dbu(max([
+                self.ab.getHeight(), add.ab.getHeight(), sub.ab.getHeight()
+            ])) + 2*v_margin
+
+            # experiment, over-ride
+            width = 1300
+            height = 370
+
+            self.ab = Box(0, 0, self.to_dbu(width), self.to_dbu(height))
+
+            add_wid = self.from_dbu(add.ab.getWidth())
+            sub_ht = self.from_dbu(sub.ab.getHeight())
+            self.place_submodule(add, h_margin, v_margin+add_wid)
+            self.place_submodule(sub, width-sub.ab_width-h_margin+sub_ht-45,
+                                      v_margin)
 
             # TODO: replace with some form of lazy evaluation?
-            y_north = self.from_dbu(self.cell.getAbutmentBox().getYMax())
+            y_north = self.from_dbu(self.ab.getYMax())
             for pin_conf in self.north_pins:
                 pin_conf['y'] = y_north
 
@@ -94,15 +119,24 @@ class ALU16(Module):
         # this puts all the remaining cells (little ones)
         # into this (small) space so that they do not go
         # "all over the place" around the add and sub
-        self.ab = Box(self.to_dbu(400.0), self.to_dbu(50.0),
-                      self.to_dbu(700.0), self.to_dbu(500.0))
-        self.place()
+
+        # XXX this doesn't work: box is far too big, covers the entire
+        # area (including "under" the add and sub)
+        self.ab = Box(
+            self.to_dbu((width-self.ab_width)/2 - h_margin),
+            self.to_dbu(v_margin),
+            self.to_dbu((width+self.ab_width)/2 + h_margin),
+            self.to_dbu(height - v_margin)
+        )
+        self.ab = Box(self.to_dbu(450), self.to_dbu(15),
+                      self.to_dbu(835), self.to_dbu(370))
+        self.place() # place only
 
         # then route (globally)
         # this connects up not just in the remaining (little) cells,
         # it connects *to add and sub and the outside world as well*
-        self.init_abutment_box()
-        result = self.place_and_route()
+        self.ab = Box(0, 0, self.to_dbu(width), self.to_dbu(height))
+        result = self.route()
 
         self.save()
         return result
@@ -112,46 +146,47 @@ def ScriptMain(editor=None, **kwargs):
     coriolis_setup()
 
     add = AddSub(
-        'add', editor, width=350.0, height=400.0,
+        'add', editor,
         north_pins=[
-            {'net': 'a({})', 'x': 10.0, 'delta': 20.0, 'repeat': BIT_WIDTH},
-            {'net': 'b({})', 'x': 20.0, 'delta': 20.0, 'repeat': BIT_WIDTH},
+            {'net': 'a({})', 'x': 165.0, 'delta': -10.0, 'repeat': BIT_WIDTH},
+            {'net': 'b({})', 'x': 160.0, 'delta': -10.0, 'repeat': BIT_WIDTH},
+            {'net': 'o({})', 'x': 340.0, 'delta': -10.0, 'repeat': BIT_WIDTH},
         ],
         south_pins=[
-            {'net': 'o({})', 'x': 100.0, 'delta': 10.0, 'repeat': BIT_WIDTH},
         ],
         pads={
             'b({})'.format(BIT_WIDTH-1): (
                 'BLOCKAGE2', 'BLOCKAGE3', 'BLOCKAGE4',
             ),
         },
+        orientation=Transformation.Orientation.R3,
     )
     sub = AddSub(
-        'sub', editor, width=350.0, height=400.0,
+        'sub', editor,
         north_pins=[
-            {'net': 'a({})', 'x': 10.0, 'delta': 20.0, 'repeat': BIT_WIDTH},
-            {'net': 'b({})', 'x': 20.0, 'delta': 20.0, 'repeat': BIT_WIDTH},
+            {'net': 'a({})', 'x': 180.0, 'delta': 10.0, 'repeat': BIT_WIDTH},
+            {'net': 'b({})', 'x': 185.0, 'delta': 10.0, 'repeat': BIT_WIDTH},
+            {'net': 'o({})', 'x': 10.0, 'delta': 10.0, 'repeat': BIT_WIDTH},
         ],
         south_pins=[
-            {'net': 'o({})', 'x': 100.0, 'delta': 10.0, 'repeat': BIT_WIDTH},
         ],
         pads={
             'b({})'.format(BIT_WIDTH-1): (
                 'BLOCKAGE2', 'BLOCKAGE3', 'BLOCKAGE4',
             ),
         },
+        orientation=Transformation.Orientation.R1,
     )
 
     alu16 = ALU16(
-        'alu16', editor, width=1100.0, height=600.0,
-        submodules=[(add, 25.0, 75.0), (sub, 725.0, 75.0)],
+        'alu16', editor, submodules=[add, sub],
         north_pins=[
-            {'net': 'o({})', 'x': 50.0, 'delta': 60.0, 'repeat': BIT_WIDTH},
+            {'net': 'o({})', 'x': 500.0, 'delta': 10.0, 'repeat': BIT_WIDTH},
             {'net': 'op'},
         ],
         south_pins=[
-            {'net': 'a({})', 'x': 50.0, 'delta': 60.0, 'repeat': BIT_WIDTH},
-            {'net': 'b({})', 'x': 80.0, 'delta': 60.0, 'repeat': BIT_WIDTH},
+            {'net': 'a({})', 'x': 500.0, 'delta': 10.0, 'repeat': BIT_WIDTH},
+            {'net': 'b({})', 'x': 700.0, 'delta': 10.0, 'repeat': BIT_WIDTH},
         ],
         west_pins=[
             {'net': 'rst', 'y': 140.0, 'layer': 'METAL2'},