5 * <https://bugs.libre-soc.org/show_bug.cgi?id=734>
9 SimdScope is the user-facing "front" behind which SimdSignal
10 is entirely and transparently hidden. Aside from using it,
11 the goal and its purpose is that
12 developers should under no circumstances have to know
13 that their HDL, which was initially written as scalar
14 nmigen HDL, is behaving entirely transparently as full
15 SIMD capable HDL. There are a few caveats to that: some
16 capabilities such as LHS assignment to an ast.Part are so
17 complex in a SIMD context that SimdSignal in its first
18 version does not implement it. Array is out at the moment
19 as well. Over time this may change.
21 SimdScope is used as follows:
25 vec_el_counts = { 0b00: 1, 0b01: 2, 0b10: 4, 0b11: 8}
26 with SimdScope(m, elwid, vec_el_counts, scalar=pspec.scalar) as s:
31 m.d.comb += b.eq(a[:32])
33 Note that the scalar parameter is selected from a runtime/compiletime
34 configuration parameter which can alter the context between scalar and
37 When set to scalar, SimdScope.Signal simply re-routes directly
38 to nmigen.ast.Signal and in this way sets the mandatory expectation
39 that **under no circumstances** shall SimdScope or SimdSignal alter
40 the fundamental language behavioural characteristics of Type 1 (AST)
41 or Type 2 (dsl.Module)
43 Note that under some circumstances, particularly temporary intermediate
44 results, it may be necessary to introduce explicit SimdShape instances
45 containing elwid-specific element widths. Relevant examples here include
46 exponent and mantissa for IEEE754FP
50 vec_el_counts = { 0b00: 1, 0b01: 2, 0b10: 4, 0b11: 4}
51 with SimdScope(m, elwid, vec_el_counts, scalar=pspec.scalar) as s:
52 expshape = SimdShape(part_shape={0b00: 11, # FP64
56 exp = s.Signal(expshape)
58 Here, because SimdShape derives from Shape, things still work
59 because SimdShape works out that its maximum scalar size is
60 11, and sets Shape.width to 11 when SimdScope is set in
61 scalar mode. When scalar=False, full SIMD is activated and
62 the resultant HDL combines vec_el_counts with expshape as part
63 of an ALU with inputs that can be
64 1xFP64, 2xFP32, 4xFP16, 4xBF16, where the exponents are 1x11, 2x8, 4x5, 4x8
67 Behind the scenes, when calling SimdShape.Signal in SIMD mode,
68 the elwid and vec_el_counts parameters from the context are combined
69 with the SimdShape passed in to SimdScope.Signsl,
70 as inputs to create a layout() that is "Element-width
71 aware" (ElwidPartType). With the full information being passed in to
72 SimdSignals, the actual use of the SimdSignals need not be inside