Browse Source

improve substitute, update notebook output

devel
Stefan Holst 1 year ago
parent
commit
47ee8d5878
  1. 74
      examples/Introduction.ipynb
  2. 36
      src/kyupy/circuit.py

74
examples/Introduction.ipynb

@ -248,9 +248,9 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"{'a': 0:__fork__\"a\" >3 >9,\n", "{'a': 0:__fork__\"a\" >3 >9,\n",
" 'b': 1:__fork__\"b\" >4 >10,\n", " 'b': 1:__fork__\"b\" >4 >10,\n",
" 's': 2:__fork__\"s\" <5 ,\n", " 's': 2:__fork__\"s\" <5,\n",
" 'cout': 3:__fork__\"cout\" <14 >1,\n", " 'cout': 3:__fork__\"cout\" <14 >1,\n",
" 'cin': 5:__fork__\"cin\" <0 >7 >13,\n", " 'cin': 5:__fork__\"cin\" <0 >7 >13,\n",
" 'axb': 7:__fork__\"axb\" <2 >6 >12,\n", " 'axb': 7:__fork__\"axb\" <2 >6 >12,\n",
@ -398,9 +398,9 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"[0:__fork__\"a\" >3 >9,\n", "[0:__fork__\"a\" >3 >9,\n",
" 1:__fork__\"b\" >4 >10,\n", " 1:__fork__\"b\" >4 >10,\n",
" 2:__fork__\"s\" <5 ,\n", " 2:__fork__\"s\" <5,\n",
" 3:__fork__\"cout\" <14 >1,\n", " 3:__fork__\"cout\" <14 >1,\n",
" 4:DFF\"cin\" <1 >0,\n", " 4:DFF\"cin\" <1 >0,\n",
" 5:__fork__\"cin\" <0 >7 >13,\n", " 5:__fork__\"cin\" <0 >7 >13,\n",
@ -636,7 +636,7 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"[0:__fork__\"a\" >3 >9, 1:__fork__\"b\" >4 >10, 2:__fork__\"s\" <5 ]" "[0:__fork__\"a\" >3 >9, 1:__fork__\"b\" >4 >10, 2:__fork__\"s\" <5]"
] ]
}, },
"execution_count": 22, "execution_count": 22,
@ -667,10 +667,7 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"[0:__fork__\"a\" >3 >9,\n", "[0:__fork__\"a\" >3 >9, 1:__fork__\"b\" >4 >10, 2:__fork__\"s\" <5, 4:DFF\"cin\" <1 >0]"
" 1:__fork__\"b\" >4 >10,\n",
" 2:__fork__\"s\" <5 ,\n",
" 4:DFF\"cin\" <1 >0]"
] ]
}, },
"execution_count": 23, "execution_count": 23,
@ -766,26 +763,26 @@
"data": { "data": {
"text/plain": [ "text/plain": [
"({name: \"b15\", cells: 10789, forks: 10749, lines: 32032, io_nodes: 111},\n", "({name: \"b15\", cells: 10789, forks: 10749, lines: 32032, io_nodes: 111},\n",
" [21386:output\"BE_n[3]\" <31961 ,\n", " [21386:output\"BE_n[3]\" <31961,\n",
" 21387:output\"BE_n[2]\" <31962 ,\n", " 21387:output\"BE_n[2]\" <31962,\n",
" 21388:output\"BE_n[1]\" <31963 ,\n", " 21388:output\"BE_n[1]\" <31963,\n",
" 21389:output\"BE_n[0]\" <31964 ,\n", " 21389:output\"BE_n[0]\" <31964,\n",
" 21390:output\"Address[29]\" <31965 ,\n", " 21390:output\"Address[29]\" <31965,\n",
" 21391:output\"Address[28]\" <31966 ,\n", " 21391:output\"Address[28]\" <31966,\n",
" 21392:output\"Address[27]\" <31967 ,\n", " 21392:output\"Address[27]\" <31967,\n",
" 21393:output\"Address[26]\" <31968 ,\n", " 21393:output\"Address[26]\" <31968,\n",
" 21394:output\"Address[25]\" <31969 ,\n", " 21394:output\"Address[25]\" <31969,\n",
" 21395:output\"Address[24]\" <31970 ,\n", " 21395:output\"Address[24]\" <31970,\n",
" 21396:output\"Address[23]\" <31971 ,\n", " 21396:output\"Address[23]\" <31971,\n",
" 21397:output\"Address[22]\" <31972 ,\n", " 21397:output\"Address[22]\" <31972,\n",
" 21398:output\"Address[21]\" <31973 ,\n", " 21398:output\"Address[21]\" <31973,\n",
" 21399:output\"Address[20]\" <31974 ,\n", " 21399:output\"Address[20]\" <31974,\n",
" 21400:output\"Address[19]\" <31975 ,\n", " 21400:output\"Address[19]\" <31975,\n",
" 21401:output\"Address[18]\" <31976 ,\n", " 21401:output\"Address[18]\" <31976,\n",
" 21402:output\"Address[17]\" <31977 ,\n", " 21402:output\"Address[17]\" <31977,\n",
" 21403:output\"Address[16]\" <31978 ,\n", " 21403:output\"Address[16]\" <31978,\n",
" 21404:output\"Address[15]\" <31979 ,\n", " 21404:output\"Address[15]\" <31979,\n",
" 21405:output\"Address[14]\" <31980 ])" " 21405:output\"Address[14]\" <31980])"
] ]
}, },
"execution_count": 27, "execution_count": 27,
@ -1167,8 +1164,8 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"0:__fork__\"a\" >3 >9\n", "0:__fork__\"a\" >3 >9\n",
"1:__fork__\"b\" >4 >10\n", "1:__fork__\"b\" >4 >10\n",
"4:DFF\"cin\" <1 >0\n", "4:DFF\"cin\" <1 >0\n",
"6:XOR\"axb\" <3 <4 >2\n", "6:XOR\"axb\" <3 <4 >2\n",
"9:AND\"aab\" <9 <10 >8\n", "9:AND\"aab\" <9 <10 >8\n",
@ -1177,7 +1174,7 @@
"10:__fork__\"aab\" <8 >15\n", "10:__fork__\"aab\" <8 >15\n",
"8:XOR\"s\" <6 <7 >5\n", "8:XOR\"s\" <6 <7 >5\n",
"11:AND\"axbacin\" <12 <13 >11\n", "11:AND\"axbacin\" <12 <13 >11\n",
"2:__fork__\"s\" <5 \n", "2:__fork__\"s\" <5\n",
"12:__fork__\"axbacin\" <11 >16\n", "12:__fork__\"axbacin\" <11 >16\n",
"13:OR\"cout\" <15 <16 >14\n", "13:OR\"cout\" <15 <16 >14\n",
"3:__fork__\"cout\" <14 >1\n" "3:__fork__\"cout\" <14 >1\n"
@ -1312,10 +1309,7 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"[0:__fork__\"a\" >3 >9,\n", "[0:__fork__\"a\" >3 >9, 1:__fork__\"b\" >4 >10, 2:__fork__\"s\" <5, 4:DFF\"cin\" <1 >0]"
" 1:__fork__\"b\" >4 >10,\n",
" 2:__fork__\"s\" <5 ,\n",
" 4:DFF\"cin\" <1 >0]"
] ]
}, },
"execution_count": 37, "execution_count": 37,
@ -2045,10 +2039,10 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"Waveforms : 64293.5 kiB\n", "Waveforms : 64294.0 kiB\n",
"State Allocation Table : 129.3 kiB\n", "State Allocation Table : 129.3 kiB\n",
"Circuit Timing : 1034.1 kiB\n", "Circuit Timing : 1034.1 kiB\n",
"Circuit Netlist : 750.8 kiB\n", "Circuit Netlist : 1126.1 kiB\n",
"Sequential State : 726.0 kiB\n" "Sequential State : 726.0 kiB\n"
] ]
} }

36
src/kyupy/circuit.py

@ -343,7 +343,7 @@ class Circuit:
the signal lines are connected appropriately. The number and arrangement the signal lines are connected appropriately. The number and arrangement
of the input and output ports must match the pins of the replaced node. of the input and output ports must match the pins of the replaced node.
""" """
impl_in_lines = [n.outs[0] for n in impl.io_nodes if len(n.outs) > 0] impl_in_lines = [n.outs[0] for n in impl.io_nodes if len(n.ins) == 0]
impl_out_lines = [n.ins[0] for n in impl.io_nodes if len(n.ins) > 0] impl_out_lines = [n.ins[0] for n in impl.io_nodes if len(n.ins) > 0]
node_in_lines = list(node.ins) + [None] * (len(impl_in_lines)-len(node.ins)) node_in_lines = list(node.ins) + [None] * (len(impl_in_lines)-len(node.ins))
node_out_lines = list(node.outs) + [None] * (len(impl_out_lines)-len(node.outs)) node_out_lines = list(node.outs) + [None] * (len(impl_out_lines)-len(node.outs))
@ -354,24 +354,28 @@ class Circuit:
node.remove() node.remove()
node_map = dict() node_map = dict()
ios = set(impl.io_nodes) ios = set(impl.io_nodes)
for n in impl.nodes: for n in impl.nodes: # add all nodes to main circuit
if n not in ios: if n not in ios:
node_map[n] = Node(self, node.name + '~' + n.name, n.kind) node_map[n] = Node(self, node.name + '~' + n.name, n.kind)
for l in impl.lines: elif len(n.outs) > 0 and len(n.ins) > 0: # output is also read by impl. circuit, need to add a fork.
if l in in_lines_map: node_map[n] = Node(self, node.name + '~' + n.name)
ll = in_lines_map[l] for l in impl.lines: # add all internal lines to main circuit
if ll is not None: if l.reader in node_map and l.driver in node_map:
ll.reader = node_map[l.reader]
ll.reader_pin = l.reader_pin
ll.reader.ins[ll.reader_pin] = ll
elif l in out_lines_map:
ll = out_lines_map[l]
if ll is not None:
ll.driver = node_map[l.driver]
ll.driver_pin = l.driver_pin
ll.driver.outs[ll.driver_pin] = ll
else:
Line(self, (node_map[l.driver], l.driver_pin), (node_map[l.reader], l.reader_pin)) Line(self, (node_map[l.driver], l.driver_pin), (node_map[l.reader], l.reader_pin))
for l, ll in in_lines_map.items(): # connect inputs
if ll is None: continue
ll.reader = node_map[l.reader]
ll.reader_pin = l.reader_pin
ll.reader.ins[ll.reader_pin] = ll
for l, ll in out_lines_map.items(): # connect outputs
if ll is None: continue
if len(l.reader.outs) > 0: # output is also read by impl. circuit, connect to fork.
ll.driver = node_map[l.reader]
ll.driver_pin = len(l.reader.outs)
else:
ll.driver = node_map[l.driver]
ll.driver_pin = l.driver_pin
ll.driver.outs[ll.driver_pin] = ll
def copy(self): def copy(self):
"""Returns a deep copy of the circuit. """Returns a deep copy of the circuit.

Loading…
Cancel
Save