Optimized (datapath) placement and direct place.
[soclayout.git] / experiments7 / doAlu16.py
index aa9dbda4b6000151bcb61212ec708cd173a3c2f3..70b6d5e584e019c86a48d65ca8d39a55504772ac 100755 (executable)
@@ -2,11 +2,14 @@
 # -*- coding: utf-8 -*-
 from __future__ import print_function
 import sys
+import re
 
 import CRL
 import Cfg
 from Hurricane import Box
 from Hurricane import Transformation
+from Hurricane import Breakpoint
+from Hurricane import Instance
 from coriolis2.settings import af
 from utils import Module, SessionManager, Config
 
@@ -48,7 +51,7 @@ class AddSub(Module):
         """ Main routine. """
 
         with SessionManager():
-            self.compute_ab()
+           #self.compute_ab()
             self.create_pins()
 
         if self.editor:
@@ -65,6 +68,69 @@ class AddSub(Module):
 
 class ALU16(Module):
 
+    @staticmethod
+    def match_instance(datapath_insts, op, plug_name, inst):
+        """
+        Guess the position of an instance from it's nets connections,
+        and put it at the right place in the datapath vector.
+
+        :param datapath_insts: vector of bit slices,
+        :param op: operator name,
+        :param inst: instance to classify,
+        :param plug_name: name of the plug to use to guess the bit index,
+        :return: boolean, True if the instance has been matched.
+        """
+        matched = False
+        re_net_index = re.compile(r'[^(]+\((?P<index>[\d]+)\)$')
+        if inst.getMasterCell().getName().startswith(op):
+            for plug in inst.getPlugs():
+                if plug.getMasterNet().getName() == plug_name:
+                    m = re_net_index.match(plug.getNet().getName())
+                    if m:
+                        bit_slice = datapath_insts[int(m.group('index'))]
+                        for column in bit_slice:
+                            if column[0] == op:
+                                column[1] = inst
+                                matched = True
+                                break
+                        break
+        return matched
+
+    def place_datapath(self, datapath_insts, x_orig, y_orig, fold):
+        channel_sff1 = self.to_dbu(60)
+        with SessionManager():
+            slice_height = self.to_dbu(50.0)
+            for i in range(len(datapath_insts)):
+                if not i%fold:
+                    x = self.to_dbu(x_orig)
+                slice = i/fold
+                if slice%2:
+                    y = self.to_dbu(y_orig) + slice_height*(slice+1)
+                    orient = Transformation.Orientation.MY
+                else:
+                    y = self.to_dbu(y_orig) + slice_height*slice
+                    orient = Transformation.Orientation.ID
+
+                for (opname, inst) in datapath_insts[i]:
+                    if opname == 'sff1':
+                        x += channel_sff1
+                    inst.setTransformation(Transformation(x, y, orient))
+                    inst.setPlacementStatus(Instance.PlacementStatus.PLACED)
+                    x += inst.getAbutmentBox().getWidth()
+
+    def place(self):
+        """ALU16.place(), manual placement overload."""
+        datapath_insts = []
+        for i in range(BIT_WIDTH):
+            datapath_insts.append([['nmx2', None], ['no2', None], ['sff1', None]])
+
+        for inst in self.cell.getInstances():
+            if ALU16.match_instance(datapath_insts, 'nmx2', 'i0', inst): continue
+            if ALU16.match_instance(datapath_insts, 'no2', 'nq', inst): continue
+            if ALU16.match_instance(datapath_insts, 'sff1', 'i', inst): continue
+
+        self.place_datapath(datapath_insts, 160.0, 50.0, 1)
+
     def save(self):
         self.name = self.name + '_r'
         self.af.saveCell(self.cell, CRL.Catalog.State.Views)
@@ -72,8 +138,8 @@ class ALU16(Module):
 
     def build(self):
 
-        h_margin = 25.0
-        v_margin = 10.0
+        h_margin = 0.0
+        v_margin = 50.0
 
         if not self.build_submodules():
             return False
@@ -91,20 +157,20 @@ class ALU16(Module):
             ) + 4*h_margin
             height = self.from_dbu(max([
                 self.ab.getHeight(), add.ab.getHeight(), sub.ab.getHeight()
-            ])) + 2*v_margin
+            ])) + v_margin
 
             # experiment, over-ride
-            width = 1310
-            height = 370
+            width = 580
+            #width = 1310
+            #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, 25, v_margin+add_wid)
-            self.place_submodule(sub, width-sub.ab_width-h_margin+sub_ht-35,
-                                      v_margin)
+            self.place_submodule(add, 0, v_margin)
+            self.place_submodule(sub, 400, v_margin)
 
             # TODO: replace with some form of lazy evaluation?
             y_north = self.from_dbu(self.ab.getYMax())
@@ -123,74 +189,72 @@ class ALU16(Module):
 
         # 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(475), self.to_dbu(10),
-                      self.to_dbu(840), self.to_dbu(360))
+        #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(475), self.to_dbu(10),
+        #              self.to_dbu(840), self.to_dbu(360))
+        self.ab = Box(0, 0, self.to_dbu(width), self.to_dbu(height))
         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.ab = Box(0, 0, self.to_dbu(width), self.to_dbu(height))
         result = self.route()
 
         self.save()
         return result
 
 
-def ScriptMain(editor=None, **kwargs):
+def scriptMain(editor=None, **kwargs):
     coriolis_setup()
 
     add = AddSub(
         'add', editor,
-        north_pins=[
-            {'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=[
+        east_pins=[
+            {'net': 'a({})', 'y': 15.0, 'delta': 50.0, 'repeat': BIT_WIDTH, 'layer': 'METAL2'},
+            {'net': 'b({})', 'y': 25.0, 'delta': 50.0, 'repeat': BIT_WIDTH, 'layer': 'METAL2'},
+            {'net': 'o({})', 'y': 35.0, 'delta': 50.0, 'repeat': BIT_WIDTH, 'layer': 'METAL2'},
         ],
         pads={
             'b({})'.format(BIT_WIDTH-1): (
                 'BLOCKAGE2', 'BLOCKAGE3', 'BLOCKAGE4',
             ),
         },
-        orientation=Transformation.Orientation.R3,
+        orientation=Transformation.Orientation.ID,
     )
+    add.set_ab(160.0, 800.0)
     sub = AddSub(
         'sub', editor,
-        north_pins=[
-            {'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=[
+        west_pins=[
+            {'net': 'a({})', 'y': 15.0, 'delta': 50.0, 'repeat': BIT_WIDTH, 'layer': 'METAL2'},
+            {'net': 'b({})', 'y': 25.0, 'delta': 50.0, 'repeat': BIT_WIDTH, 'layer': 'METAL2'},
+            {'net': 'o({})', 'y': 35.0, 'delta': 50.0, 'repeat': BIT_WIDTH, 'layer': 'METAL2'},
         ],
         pads={
             'b({})'.format(BIT_WIDTH-1): (
                 'BLOCKAGE2', 'BLOCKAGE3', 'BLOCKAGE4',
             ),
         },
-        orientation=Transformation.Orientation.R1,
+        orientation=Transformation.Orientation.ID,
     )
+    sub.set_ab(180.0, 800.0)
 
     alu16 = ALU16(
         'alu16', editor, submodules=[add, sub],
         north_pins=[
-            {'net': 'o({})', 'x': 500.0, 'delta': 20.0, 'repeat': BIT_WIDTH},
+            {'net': 'o({})', 'x': 365.0, 'delta': -5.0, 'repeat': BIT_WIDTH},
             {'net': 'op'},
         ],
         south_pins=[
-            {'net': 'a({})', 'x': 500.0, 'delta': 10.0, 'repeat': BIT_WIDTH},
-            {'net': 'b({})', 'x': 700.0, 'delta': 10.0, 'repeat': BIT_WIDTH},
+            {'net': 'a({})', 'x': 205.0, 'delta': 5.0, 'repeat': BIT_WIDTH},
+            {'net': 'b({})', 'x': 295.0, 'delta': 5.0, 'repeat': BIT_WIDTH},
         ],
         west_pins=[
-            {'net': 'rst', 'y': 140.0, 'layer': 'METAL2'},
+            {'net': 'rst', 'y': 10.0, 'layer': 'METAL2'},
         ],
     )
     return alu16.build()
@@ -198,7 +262,7 @@ def ScriptMain(editor=None, **kwargs):
 
 if __name__ == '__main__':
     kwargs = {}
-    success = ScriptMain(**kwargs)
+    success = scriptMain(**kwargs)
     shellSuccess = 0
     if not success:
         shellSuccess = 1