(no commit message)
[libreriscv.git] / simple_v_extension / abridged_spec.mdwn
1 # Simple-V (Parallelism Extension Proposal) Specification (Abridged)
2
3 * Copyright (C) 2017, 2018, 2019 Luke Kenneth Casson Leighton
4 * Status: DRAFTv0.6
5 * Last edited: 27 jun 2019
6 * See: main [[specification]] and [[appendix]]
7
8 [[!toc ]]
9
10 # Introduction
11
12 Simple-V is a uniform parallelism API for RISC-V hardware that allows
13 the Program Counter to enter "sub-contexts" in which, ultimately, standard
14 RISC-V scalar opcodes are executed.
15
16 The sub-context execution is "nested" in "re-entrant" form, in the
17 following order:
18
19 * Main standard RISC-V Program Counter (PC)
20 * VBLOCK sub-execution context (PCVBLK increments whilst PC is paused).
21 * VL element loops (STATE srcoffs and destoffs increment, PC and PCVBLK pause).
22 Predication bits may be individually applied per element.
23 * SUBVL element loops (STATE svsrcoffs/svdestoffs increment, VL pauses).
24 Individual predicate bits from VL loops apply to the *group* of SUBVL
25 elements.
26
27 An ancillary "SVPrefix" Format (P48/P64) [[sv_prefix_proposal]] may
28 run its own VL/SUBVL "loops" and specifies its own Register and Predication
29 format on the 32-bit RV scalar opcode embedded within it.
30
31 The [[vblock_format]] specifies how VBLOCK sub-execution contexts
32 operate.
33
34 SV is never actually switched "off". VL or SUBVL may be equal to 1, and
35 Register or Predicate over-ride tables may be empty: under such circumstances
36 the behaviour becomes effectively identical to standard RV execution, however
37 SV is never truly actually "off".
38
39 Note: **there are *no* new opcodes**. The scheme works *entirely*
40 on hidden context that augments (nests) *scalar* RISC-V instructions.
41 Thus it may cover existing, future and custom scalar extensions, turning
42 all existing, all future and all custom scalar operations parallel,
43 without requiring any special (identical, parallel variant) opcodes to do so.
44
45 # CSRs <a name="csrs"></a>
46
47 There are five CSRs, available in any privilege level:
48
49 * MVL (the Maximum Vector Length)
50 * VL (which has different characteristics from standard CSRs)
51 * SUBVL (effectively a kind of SIMD)
52 * STATE (containing copies of MVL, VL and SUBVL as well as context information)
53 * PCVBLK (the current operation being executed within a VBLOCK Group)
54
55 For Privilege Levels (trap handling) there are the following CSRs,
56 where x may be u, m, s or h for User, Machine, Supervisor or Hypervisor
57 Modes respectively:
58
59 * (x)ePCVBLK (a copy of the sub-execution Program Counter, that is relative
60 to the start of the current VBLOCK Group, set on a trap).
61 * (x)eSTATE (useful for saving and restoring during context switch,
62 and for providing fast transitions)
63
64 The u/m/s CSRs are treated and handled exactly like their (x)epc
65 equivalents. On entry to or exit from a privilege level, the contents
66 of its (x)eSTATE are swapped with STATE.
67
68 (x)EPCVBLK CSRs must be treated exactly like their corresponding (x)epc
69 equivalents. See VBLOCK section for details.
70
71 ## MAXVECTORLENGTH (MVL) <a name="mvl" />
72
73 MAXVECTORLENGTH is the same concept as MVL in RVV, except that it
74 is variable length and may be dynamically set. MVL is
75 however limited to the regfile bitwidth XLEN (1-32 for RV32,
76 1-64 for RV64 and so on).
77
78 ## Vector Length (VL) <a name="vl" />
79
80 VSETVL is slightly different from RVV. Similar to RVV, VL is set to be within
81 the range 1 <= VL <= MVL (where MVL in turn is limited to 1 <= MVL <= XLEN)
82
83 VL = rd = MIN(vlen, MVL)
84
85 where 1 <= MVL <= XLEN
86
87 ## SUBVL - Sub Vector Length
88
89 This is a "group by quantity" that effectivrly asks each iteration
90 of the hardware loop to load SUBVL elements of width elwidth at a
91 time. Effectively, SUBVL is like a SIMD multiplier: instead of just 1
92 operation issued, SUBVL operations are issued.
93
94 The main effect of SUBVL is that predication bits are applied per
95 **group**, rather than by individual element. Legal values are 1 to 4.
96 Illegal values raise an exception.
97
98 ## STATE
99
100 This is a standard CSR that contains sufficient information for a
101 full context save/restore. It contains (and permits setting of):
102
103 * MVL
104 * VL
105 * destoffs - the destination element offset of the current parallel
106 instruction being executed
107 * srcoffs - for twin-predication, the source element offset as well.
108 * SUBVL
109 * svdestoffs - the subvector destination element offset of the current
110 parallel instruction being executed
111 * svsrcoffs - for twin-predication, the subvector source element offset
112 as well.
113
114 The format of the STATE CSR is as follows:
115
116 | (29..28 | (27..26) | (25..24) | (23..18) | (17..12) | (11..6) | (5...0) |
117 | ------- | -------- | -------- | -------- | -------- | ------- | ------- |
118 | dsvoffs | ssvoffs | subvl | destoffs | srcoffs | vl | maxvl |
119
120 The relationship between SUBVL and the subvl field is:
121
122 | SUBVL | (25..24) |
123 | ----- | -------- |
124 | 1 | 0b00 |
125 | 2 | 0b01 |
126 | 3 | 0b10 |
127 | 4 | 0b11 |
128
129 Notes:
130
131 * The entries are truncated to be within range. Attempts to set VL to
132 greater than MAXVL will truncate VL.
133 * Both VL and MAXVL are stored offset by one. 0b000000 represents VL=1,
134 0b000001 represents VL=2. This allows the full range 1 to XLEN instead
135 of 0 to only 63.
136
137 ## VL, MVL and SUBVL instruction aliases
138
139 This table contains pseudo-assembly instruction aliases. Note the
140 subtraction of 1 from the CSRRWI pseudo variants, to compensate for the
141 reduced range of the 5 bit immediate.
142
143 | alias | CSR |
144 | - | - |
145 | SETVL rd, rs | CSRRW VL, rd, rs |
146 | SETVLi rd, #n | CSRRWI VL, rd, #n-1 |
147 | GETVL rd | CSRRW VL, rd, x0 |
148 | SETMVL rd, rs | CSRRW MVL, rd, rs |
149 | SETMVLi rd, #n | CSRRWI MVL,rd, #n-1 |
150 | GETMVL rd | CSRRW MVL, rd, x0 |
151
152 Note: CSRRC and other bitsetting may still be used, they are however not particularly useful (very obscure).
153
154 ## Register key-value (CAM) table <a name="regcsrtable" />
155
156 The purpose of the Register table is to mark which registers change behaviour
157 if used in a "Standard" (normally scalar) opcode.
158
159 [[!inline raw="yes" pages="simple_v_extension/reg_table_format" ]]
160
161 Fields:
162
163 * i/f is set to "1" to indicate that the redirection/tag entry is to
164 be applied to integer registers; 0 indicates that it is relevant to
165 floating-point registers.
166 * isvec indicates that the register (whether a src or dest) is to progress
167 incrementally forward on each loop iteration. this gives the "effect"
168 of vectorisation. isvec is zero indicates "do not progress", giving
169 the "effect" of that register being scalar.
170 * vew overrides the operation's default width. See table below
171 * regkey is the register which, if encountered in an op (as src or dest)
172 is to be "redirected"
173 * in the 16-bit format, regidx is the *actual* register to be used
174 for the operation (note that it is 7 bits wide)
175
176 | vew | bitwidth |
177 | --- | ------------------- |
178 | 00 | default (XLEN/FLEN) |
179 | 01 | 8 bit |
180 | 10 | 16 bit |
181 | 11 | 32 bit |
182
183 As the above table is a CAM (key-value store) it may be appropriate
184 (faster, less gates, implementation-wise) to expand it as follows:
185
186 [[!inline raw="yes" pages="simple_v_extension/reg_table" ]]
187
188 ## Predication Table <a name="predication_csr_table"></a>
189
190 The Predication Table is a key-value store indicating whether, if a
191 given destination register (integer or floating-point) is referred to
192 in an instruction, it is to be predicated. Like the Register table, it
193 is an indirect lookup that allows the RV opcodes to not need modification.
194
195 * regidx is the register that in combination with the
196 i/f flag, if that integer or floating-point register is referred to in a
197 (standard RV) instruction results in the lookup table being referenced
198 to find the predication mask to use for this operation.
199 * predidx is the *actual* (full, 7 bit) register to be used for the
200 predication mask.
201 * inv indicates that the predication mask bits are to be inverted
202 prior to use *without* actually modifying the contents of the
203 register from which those bits originated.
204 * zeroing is either 1 or 0, and if set to 1, the operation must
205 place zeros in any element position where the predication mask is
206 set to zero. If zeroing is set to 0, unpredicated elements *must*
207 be left alone (unaltered), even when elwidth != default.
208 * ffirst is a special mode that stops sequential element processing when
209 a data-dependent condition occurs, whether a trap or a conditional test.
210 The handling of each (trap or conditional test) is slightly different:
211 see Instruction sections for further details
212
213 [[!inline raw="yes" pages="simple_v_extension/pred_table_format" ]]
214
215 Pseudocode for predication:
216
217 [[!inline raw="yes" pages="simple_v_extension/pred_table" ]]
218 [[!inline raw="yes" pages="simple_v_extension/get_pred_value" ]]
219
220 ## Fail-on-First Mode <a name="ffirst-mode"></a>
221
222 ffirst is a special data-dependent predicate mode. There are two
223 variants: one is for faults: typically for LOAD/STORE operations,
224 which may encounter end of page faults during a series of operations.
225 The other variant is comparisons, and anything that returns "zero" or "fail". Note: no instruction may operate in both fault mode and "condition fail" mode.
226
227 Fail on first critically relies on the program order being sequential, even for elements. Out of order designs must *commit* in-order, and are required to cancel elements at and beyond the fail point.
228
229 See [[appendix]] for more details on fail-on-first modes.
230
231 # Simplified Pseudo-code example
232
233 A greatly simplified example illustrating (just) the VL hardware for-loop
234 is as follows:
235
236 [[!inline raw="yes" pages="simple_v_extension/simple_add_example" ]]
237
238 Note that zeroing, elwidth handling, SUBVL and PCVLIW have all been
239 left out, for clarity. For examples on how to handle each, see
240 [[appendix]].
241
242 # Vector Block Format <a name="vliw-format"></a>
243
244 The Vector Block format uses the RISC-V 80-192 bit format from Section 1.5
245 of the RISC-V Spec. It permits an optional VL/MVL/SUBVL block, up to 4
246 16-bit (or 8 8-bit) Register Table entries, the same for Predicate Entries,
247 and the rest of the instruction may be either standard RV opcodes or the
248 SVPrefix opcodes ([[sv_prefix_proposal]])
249
250 [[!inline raw="yes" pages="simple_v_extension/vblock_format_table" ]]
251
252 For full details see ancillary resource: [[vblock_format]]
253
254 # Exceptions
255
256 Exception handling **MUST** be precise, in-order, and exactly
257 like Standard RISC-V as far as the instruction execution order is
258 concerned, regardless of whether it is PC, PCVBLK, VL or SUBVL that
259 is currently being incremented.
260
261 This.is extremely important. Exceptions
262 **MUST** be raised one at a time and in
263 strict sequential program order.
264
265 No instructions are permitted to be out of
266 sequence, therefore no exceptions are permitted to be, either.
267
268 # Hints
269
270 With Simple-V being capable of issuing *parallel* instructions where
271 rd=x0, the space for possible HINTs is expanded considerably. VL
272 could be used to indicate different hints. In addition, if predication
273 is set, the predication register itself could hypothetically be passed
274 in as a *parameter* to the HINT operation.
275
276 No specific hints are yet defined in Simple-V
277
278 # Subsets of RV functionality
279
280 It is permitted to only implement SVprefix and not the VBLOCK instruction
281 format option, and vice-versa. UNIX Platforms **MUST** raise illegal
282 instruction on seeing an unsupported VBLOCK or SVprefix opcode, so that
283 traps may emulate the format.
284
285 It is permitted in SVprefix to either not implement VL or not implement
286 SUBVL (see [[sv_prefix_proposal]] for full details. Again, UNIX Platforms
287 *MUST* raise illegal instruction on implementations that do not support
288 VL or SUBVL.
289
290 It is permitted to limit the size of either (or both) the register files
291 down to the original size of the standard RV architecture. However, below
292 the mandatory limits set in the RV standard will result in non-compliance
293 with the SV Specification.
294