(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: 25 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 such as FEQ (or the augmented behaviour
226 of Branch), and any operation that returns a result of zero (whether
227 integer or floating-point). In the FP case, this includes negative-zero.
228
229 Note that the execution order must "appear" to be sequential for ffirst
230 mode to work correctly. An in-order architecture must execute the element
231 operations in sequence, whilst an out-of-order architecture must *commit*
232 the element operations in sequence (giving the appearance of in-order
233 execution).
234
235 Note also, that if ffirst mode is needed without predication, a special
236 "always-on" Predicate Table Entry may be constructed by setting
237 inverse-on and using x0 as the predicate register. This
238 will have the effect of creating a mask of all ones, allowing ffirst
239 to be set.
240
241 See [[appendix]] for more details on fail-on-first modes.
242
243 # Simplified Pseudo-code example
244
245 A greatly simplified example illustrating (just) the VL hardware for-loop
246 is as follows:
247
248 [[!inline raw="yes" pages="simple_v_extension/simple_add_example" ]]
249
250 Note that zeroing, elwidth handling, SUBVL and PCVLIW have all been
251 left out, for clarity. For examples on how to handle each, see
252 [[appendix]].
253
254 # Vector Block Format <a name="vliw-format"></a>
255
256 The Vector Block format uses the RISC-V 80-192 bit format from Section 1.5
257 of the RISC-V Spec. It permits an optional VL/MVL/SUBVL block, up to 4
258 16-bit (or 8 8-bit) Register Table entries, the same for Predicate Entries,
259 and the rest of the instruction may be either standard RV opcodes or the
260 SVPrefix opcodes ([[sv_prefix_proposal]])
261
262 [[!inline raw="yes" pages="simple_v_extension/vblock_format_table" ]]
263
264 For full details see ancillary resource: [[vblock_format]]
265
266 # Exceptions
267
268 Exception handling **MUST** be precise, in-order, and exactly
269 like Standard RISC-V as far as the instruction execution order is
270 concerned, regardless of whether it is PC, PCVBLK, VL or SUBVL that
271 is currently being incremented.
272
273 # Hints
274
275 With Simple-V being capable of issuing *parallel* instructions where
276 rd=x0, the space for possible HINTs is expanded considerably. VL
277 could be used to indicate different hints. In addition, if predication
278 is set, the predication register itself could hypothetically be passed
279 in as a *parameter* to the HINT operation.
280
281 No specific hints are yet defined in Simple-V
282
283 # Subsets of RV functionality
284
285 It is permitted to only implement SVprefix and not the VBLOCK instruction
286 format option, and vice-versa. UNIX Platforms **MUST** raise illegal
287 instruction on seeing an unsupported VBLOCK or SVprefix opcode, so that
288 traps may emulate the format.
289
290 It is permitted in SVprefix to either not implement VL or not implement
291 SUBVL (see [[sv_prefix_proposal]] for full details. Again, UNIX Platforms
292 *MUST* raise illegal instruction on implementations that do not support
293 VL or SUBVL.
294
295 It is permitted to limit the size of either (or both) the register files
296 down to the original size of the standard RV architecture. However, below
297 the mandatory limits set in the RV standard will result in non-compliance
298 with the SV Specification.
299