2 # SPDX-License-Identifier: LGPL-3-or-later
3 # See Notices.txt for copyright information
5 Links: https://bugs.libre-soc.org/show_bug.cgi?id=713#c20
8 from nmigen
import Signal
, Module
, Elaboratable
, Mux
, Cat
, Shape
, Repl
9 from nmigen
.back
.pysim
import Simulator
, Delay
, Settle
10 from nmigen
.cli
import rtlil
12 from collections
.abc
import Mapping
13 from pprint
import pprint
15 from ieee754
.part_mul_add
.partpoints
import PartitionPoints
19 def layout(elwid
, signed
, part_counts
, lane_shapes
):
20 # identify if the lane_shapes is a mapping (dict, etc.)
21 if not isinstance(lane_shapes
, Mapping
):
22 lane_shapes
= {i
: lane_shapes
for i
in part_counts
}
23 part_wid
= -min(-lane_shapes
[i
] // c
for i
, c
in part_counts
.items())
24 part_count
= max(part_counts
.values())
25 width
= part_wid
* part_count
27 for i
, c
in part_counts
.items():
29 points
[p
] = points
.get(p
, False) |
(elwid
== i
)
30 for start
in range(0, part_count
, c
):
31 add_p(start
* part_wid
) # start of lane
32 add_p(start
* part_wid
+ lane_shapes
[i
]) # start of padding
34 points
.pop(width
, None)
35 return (PartitionPoints(points
), width
, lane_shapes
,
38 if __name__
== '__main__':
47 pprint((i
, layout(i
, True, part_counts
, 3)))
49 l
= {0: 5, 1: 6, 2: 12, 3: 24}
51 pprint((i
, layout(i
, False, part_counts
, l
)))
53 # https://bugs.libre-soc.org/show_bug.cgi?id=713#c30
55 pp
,b
,c
,d
,e
= layout(elwid
, False, part_counts
, l
)
64 for pval
in list(pp
.values()):
65 val
= yield pval
# get nmigen to evaluate pp
67 pprint((i
, (ppt
,b
,c
,d
,e
)))
69 sim
.add_process(process
)