Improve (hopefully) `Module` submodule facility.
[soclayout.git] / experiments7 / doAlu16.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 from __future__ import print_function
4 import sys
5
6 import CRL
7 import Cfg
8 from Hurricane import Box
9 from coriolis2.settings import af
10 from utils import Module, SessionManager, Config
11
12 import symbolic.cmos # do not remove
13
14 BIT_WIDTH = 16
15
16
17 def coriolis_setup():
18 with Config(Cfg.Parameter.Priority.UserFile) as cfg:
19 cfg.misc_catchCore = False
20 cfg.misc_info = False
21 cfg.misc_paranoid = False
22 cfg.misc_bug = False
23 cfg.misc_logMode = True
24 cfg.misc_verboseLevel1 = True
25 cfg.misc_verboseLevel2 = True
26 cfg.etesian_effort = 2
27 cfg.etesian_spaceMargin = "20.0%"
28 cfg.etesian_aspectRatio = "100.0%"
29 cfg.etesian_uniformDensity = True
30 cfg.anabatic_edgeLenght = 24
31 cfg.anabatic_edgeWidth = 8
32 cfg.anabatic_topRoutingLayer = 'METAL5'
33 cfg.katana_searchHalo = 30
34 cfg.katana_eventsLimit = 1000000
35 cfg.katana_hTracksReservedLocal = 7
36 cfg.katana_vTracksReservedLocal = 6
37
38 env = af.getEnvironment()
39 env.setCLOCK('^clk$|m_clock')
40 env.setPOWER('vdd')
41 env.setGROUND('vss')
42
43
44 class AddSub(Module):
45
46 def build(self):
47 """ Main routine. """
48
49 with SessionManager():
50 self.compute_ab()
51 self.create_pins()
52
53 if self.editor:
54 self.editor.setCell(self.cell)
55
56 result = self.place_and_route()
57
58 with SessionManager():
59 self.create_pads()
60
61 self.save()
62 return result
63
64
65 class ALU16(Module):
66
67 def save(self):
68 self.name = self.name + '_r'
69 self.af.saveCell(self.cell, CRL.Catalog.State.Views)
70 super(ALU16, self).save()
71
72 def build(self):
73
74 if not self.build_submodules():
75 return False
76
77 # at this point we have the (auto-calculated) submodules' dimensions
78 # in their `ab` properties.
79
80 with SessionManager():
81 self.init_ab()
82 self.place_submodules()
83
84 # TODO: replace with some form of lazy evaluation?
85 y_north = self.from_dbu(self.cell.getAbutmentBox().getYMax())
86 for pin_conf in self.north_pins:
87 pin_conf['y'] = y_north
88
89 self.create_pins()
90
91 if self.editor:
92 self.editor.setCell(self.cell)
93
94 # place first (in middle, between two)
95 # this puts all the remaining cells (little ones)
96 # into this (small) space so that they do not go
97 # "all over the place" around the add and sub
98 self.ab = Box(self.to_dbu(400.0), self.to_dbu(50.0),
99 self.to_dbu(700.0), self.to_dbu(500.0))
100 self.place()
101
102 # then route (globally)
103 # this connects up not just in the remaining (little) cells,
104 # it connects *to add and sub and the outside world as well*
105 self.init_ab()
106 result = self.place_and_route()
107
108 self.save()
109 return result
110
111
112 def ScriptMain(editor=None, **kwargs):
113 coriolis_setup()
114
115 add = AddSub(
116 'add', editor,
117 north_pins=[
118 {'net': 'a({})', 'x': 10.0, 'delta': 20.0, 'repeat': BIT_WIDTH},
119 {'net': 'b({})', 'x': 20.0, 'delta': 20.0, 'repeat': BIT_WIDTH},
120 ],
121 south_pins=[
122 {'net': 'o({})', 'x': 100.0, 'delta': 10.0, 'repeat': BIT_WIDTH},
123 ],
124 pads={
125 'b({})'.format(BIT_WIDTH-1): (
126 'BLOCKAGE2', 'BLOCKAGE3', 'BLOCKAGE4',
127 ),
128 },
129 )
130 sub = AddSub(
131 'sub', editor,
132 north_pins=[
133 {'net': 'a({})', 'x': 10.0, 'delta': 20.0, 'repeat': BIT_WIDTH},
134 {'net': 'b({})', 'x': 20.0, 'delta': 20.0, 'repeat': BIT_WIDTH},
135 ],
136 south_pins=[
137 {'net': 'o({})', 'x': 100.0, 'delta': 10.0, 'repeat': BIT_WIDTH},
138 ],
139 pads={
140 'b({})'.format(BIT_WIDTH-1): (
141 'BLOCKAGE2', 'BLOCKAGE3', 'BLOCKAGE4',
142 ),
143 },
144 )
145
146 alu16 = ALU16(
147 'alu16', editor, width=1100.0, height=570.0,
148 submodules=[(add, 25.0, 75.0), (sub, 725.0, 75.0)],
149 north_pins=[
150 {'net': 'o({})', 'x': 50.0, 'delta': 60.0, 'repeat': BIT_WIDTH},
151 {'net': 'op'},
152 ],
153 south_pins=[
154 {'net': 'a({})', 'x': 50.0, 'delta': 60.0, 'repeat': BIT_WIDTH},
155 {'net': 'b({})', 'x': 80.0, 'delta': 60.0, 'repeat': BIT_WIDTH},
156 ],
157 west_pins=[
158 {'net': 'rst', 'y': 140.0, 'layer': 'METAL2'},
159 ],
160 )
161 return alu16.build()
162
163
164 if __name__ == '__main__':
165 kwargs = {}
166 success = ScriptMain(**kwargs)
167 shellSuccess = 0
168 if not success:
169 shellSuccess = 1
170
171 sys.exit(shellSuccess)