(no commit message)
[libreriscv.git] / 3d_gpu / architecture / dynamic_simd / slice.mdwn
1 # Dynamic Partitioned Slice (`SimdSlice`)
2
3 In order to match the semantics of nmigen's `Slice` class, `SimdSlice` has to have each element of the result have
4 exactly the same `Shape` as the result of slicing the input `SimdSignal`'s corresponding element.
5
6 ## Example code:
7
8 ```python
9 a_s = SimdSignal(...)
10 a = a_s.sig # shorthand to make table smaller
11 b_s = a_s[3:6]
12 b = b_s.sig # shorthand to make table smaller
13 ```
14
15 ## `a`'s Elements:
16
17 <table>
18 <tr class="text-right">
19 <th scope="row" class="text-left">Bit #</th>
20 <td>63&#8288;&hellip;&#8288;56</td>
21 <td>55&#8288;&hellip;&#8288;48</td>
22 <td>47&#8288;&hellip;&#8288;40</td>
23 <td>39&#8288;&hellip;&#8288;32</td>
24 <td>31&#8288;&hellip;&#8288;24</td>
25 <td>23&#8288;&hellip;&#8288;16</td>
26 <td>15&#8288;&hellip;&#8288;8</td>
27 <td>7&#8288;&hellip;&#8288;0</td>
28 </tr>
29 <tr class="text-right">
30 <th scope="row" class="text-left">ElWid: 8-bit</th>
31 <td><code>a[56:64]</code></td>
32 <td><code>a[48:56]</code></td>
33 <td><code>a[40:48]</code></td>
34 <td><code>a[32:40]</code></td>
35 <td><code>a[24:32]</code></td>
36 <td><code>a[16:24]</code></td>
37 <td><code>a[8:16]</code></td>
38 <td><code>a[0:8]</code></td>
39 </tr>
40 <tr class="text-right">
41 <th scope="row" class="text-left">ElWid: 16-bit</th>
42 <td colspan="2"><code>a[48:64]</code></td>
43 <td colspan="2"><code>a[32:48]</code></td>
44 <td colspan="2"><code>a[16:32]</code></td>
45 <td colspan="2"><code>a[0:16]</code></td>
46 </tr>
47 <tr class="text-right">
48 <th scope="row" class="text-left">ElWid: 32-bit</th>
49 <td colspan="4"><code>a[32:64]</code></td>
50 <td colspan="4"><code>a[0:32]</code></td>
51 </tr>
52 <tr class="text-right">
53 <th scope="row" class="text-left">ElWid: 64-bit</th>
54 <td colspan="8"><code>a[0:64]</code></td>
55 </tr>
56 </table>
57
58 So, slicing bits `3:6` of a 32-bit element of `a` must, because we have to match nmigen, produce a 3-bit element, which might seem like no problem, however, slicing bits `3:6` of a 16-bit element of a 64-bit `SimdSignal` must *also* produce a 3-bit element, so, in order to get a `SimdSignal` where *all* elements are 3-bit elements, as required by `SimdSlice`'s output, we have to introduce padding:
59
60 ## `b`'s Elements:
61
62 <table>
63 <tr class="text-right">
64 <th scope="row" class="text-left">Bit #</th>
65 <td>23&#8288;&hellip;&#8288;21</td>
66 <td>20&#8288;&hellip;&#8288;18</td>
67 <td>17&#8288;&hellip;&#8288;15</td>
68 <td>14&#8288;&hellip;&#8288;12</td>
69 <td>11&#8288;&hellip;&#8288;9</td>
70 <td>8&#8288;&hellip;&#8288;6</td>
71 <td>5&#8288;&hellip;&#8288;3</td>
72 <td>2&#8288;&hellip;&#8288;0</td>
73 </tr>
74 <tr class="text-right">
75 <th scope="row" class="text-left">ElWid: 8-bit</th>
76 <td><code>b[21:24]</code></td>
77 <td><code>b[18:21]</code></td>
78 <td><code>b[15:18]</code></td>
79 <td><code>b[12:15]</code></td>
80 <td><code>b[9:12]</code></td>
81 <td><code>b[6:9]</code></td>
82 <td><code>b[3:6]</code></td>
83 <td><code>b[0:3]</code></td>
84 </tr>
85 <tr class="text-right">
86 <th scope="row" class="text-left">ElWid: 16-bit</th>
87 <td class="text-center"><i>Padding</i></td>
88 <td><code>b[18:21]</code></td>
89 <td class="text-center"><i>Padding</i></td>
90 <td><code>b[12:15]</code></td>
91 <td class="text-center"><i>Padding</i></td>
92 <td><code>b[6:9]</code></td>
93 <td class="text-center"><i>Padding</i></td>
94 <td><code>b[0:3]</code></td>
95 </tr>
96 <tr class="text-right">
97 <th scope="row" class="text-left">ElWid: 32-bit</th>
98 <td colspan="3" class="text-center"><i>Padding</i></td>
99 <td><code>b[12:15]</code></td>
100 <td colspan="3" class="text-center"><i>Padding</i></td>
101 <td><code>b[0:3]</code></td>
102 </tr>
103 <tr class="text-right">
104 <th scope="row" class="text-left">ElWid: 64-bit</th>
105 <td colspan="7" class="text-center"><i>Padding</i></td>
106 <td><code>b[0:3]</code></td>
107 </tr>
108 </table>
109
110 <style>
111 /* duplicated from bootstrap so text editors can see it
112 -- ignored by ikiwiki */
113 .text-left {
114 text-align: left !important
115 }
116
117 .text-right {
118 text-align: right !important
119 }
120
121 .text-center {
122 text-align: center !important
123 }
124 </style>