add purism draft update
[crowdsupply.git] / updates / 019_2019jul16_purism_donation.mdwn
1 **DRAFT STATUS. last edit 16jul2019**
2
3 We are delighted to be able to announce additional sponsorship by
4 [Purism](http://puri.sm), through [NLNet](http://nlnet.nl).
5
6 # Purism Sponsorship
7
8 As a Benefit Corporation, Purism is empowered to balance ethics, social
9 enterprise and profitable business. I am delighted that they chose to
10 fund the Libre RISC-V hybrid CPU/GPU through the NLNet Foundation. Their
11 donation provides us some extra flexibility in how we reach the goal of
12 bringing to market a hybrid CPU, VPU and GPU that is libre to the bedrock.
13
14 Purism started with a crowdsupply campaign to deliver a modern laptop
15 with full software support and a coreboot BIOS. I know that, after
16 this initial success, they worked hard to try to solve the "NSA backdoor
17 coprocessor" issue, known as the "Management Engine". Ironically, inspired
18 by Purism, Intel's internal efforts became moot, as a 3rd party reverse
19 engineered an Intel BIOS and discovered the "nsa\_me\_off\_switch" parameter,
20 designed to be used by the NSA when Intel equipment is deployed within
21 NSA premises.
22
23 Purism then moved quickly to provide a BIOS update to disable this
24 "feature", eliminating the last and most important barrier to being able
25 to declare a full privacy software stack.
26
27 It is these kinds of brave strategic decisions to kick the trend towards
28 privacy invading hardware "by default" for which Purism deserves our
29 respect and gratitude.
30
31 However, just as NLNet recognise, Purism also appreciate that we cannot
32 stop at just the software. Profit maximising Corporations just do not
33 take the brave decisions that can compromise profits, particularly when
34 faced with competition: it's too much.
35
36 So we are extremely grateful for their donation, managed through NLnet,
37 the Charitable Foundation.
38
39 # Progress
40
41 So much has happened already, since the last update, it is hard to know
42 where to begin.
43
44 * The IEEE754 FPU has a simulation-proven FADD pipeline, and FMUL,
45 FDIV, FSQRT and FCVT are on the way.
46 * A RISC-V Reciprocal Square Root FP Opcode has been proposed, which is
47 needed for 3D operations, particularly normalisation of vectors. With
48 other RISC-V implementors needing this opcode it makes sense for it
49 to be a Standard Extension.
50 * The SimpleV extension has had a major overhaul, with the addition of a
51 single-instruction prefix (P32C, P48 and P64), and a "VBLOCK" format that
52 adds Vectorisation Context to a batch of instructions.
53 * Implementation of the precise-augmented 6600 style scoreboard system has
54 begun, with ALU register hazards and shadowing already completed, and
55 memory hazards underway.
56
57 # Multi Issue
58
59 Multi Issue is absolutely critical for this CPU/VPU/GPU because the
60 [SimpleV](https://libre-riscv.org/simple_v_extension/specification)
61 engine critically relies on being able to turn one "vector"
62 operation into multiple "scalar element" instructions, in every cycle. The
63 simplest way to do this is to throw equivalent scalar opcodes into a
64 multi issue execution engine, and let the engine sort it out.
65
66 So, regarding the Dependency Matrices: thanks to Mitch Alsup's absolutely
67 invaluable input we now know how to do multi-issue. On top of a precise
68 6600 style Dependency Matrix it is almost comically trivial.
69
70 The key insight that Mitch gave us was that instruction dependencies are
71 transitive. In other words: if there are 4 instructions to be issued,
72 the second instruction may have the dependencies of the first added to it;
73 the 3rd may accumulate the dependencies of the first and second and so on.
74
75 Where this trick does not work well (or takes significant hardware to
76 implement) is when, for example with the Tomasulo Algorithm (or the
77 original 6600 Q-Table), the Register Dependency Hazards are expressed
78 in *binary* (r5 = 0b00101, r3=0b00011). If instead the registers are
79 expressed in *unary* (r5 = 0b00010000, r3= 0b00000100) then it should
80 be pretty obvious that in a multi issue design, all that is needed in
81 each clock cycle is to OR the cumulative register dependencies in a
82 cascading fashion. Aside from now also needing to increase the number of
83 register ports and other resources to cope with the increased workload,
84 amazingly that's all it takes!
85
86 To achieve the same trick with a Tomasulo Reorder Buffer (ROB) requires
87 the addition of an entire extra CAM per every extra issue to be added to
88 the architecture: four way multi issue would require four ROB CAMs! The
89 power consumption and gate count would be prohibitively expensive,
90 and resolving the commits of multiple parallel operations is also fraught.
91
92 # SimpleV
93
94 What began ironically as "simple" still bears some vestige of its
95 original name, in that the ISA needs no new opcodes: any scalar RISC-V
96 implementation may be turned parallel through the addition of SV at the
97 instruction issue phase.
98
99 However, one of the major drawbacks of the initial draft spec was that
100 the use of CSRs took a huge number of instructions just to set up and
101 then tear down the vectorisation context.
102
103 This had to be solved.
104
105 The idea which came to mind was to embed RISC-V opcodes within
106 a longer, variable-length encoding, which we've called the
107 [VBLOCK Format](https://libre-riscv.org/simple_v_extension/vblock_format/).
108 At the beginning of this new format, the vectorisation and predication
109 context could be embedded, which "changes" the standard *scalar* opcodes
110 to become "parallel" (multi-issue) operations.
111
112 The advantage of this approach is that, firstly, the context is much
113 smaller: the actual CSR opcodes are gone, leaving only the "data",
114 which is now batched together. Secondly, there is no need to "reset"
115 (tear down) the vectorisation context, because that automatically goes
116 when the long-format ends.
117
118 The other issue that needed to be fixed is that we really need a
119 [SETVL](https://libre-riscv.org/simple_v_extension/specification/sv.setvl/)
120 instruction. This is really unfortunate as it breaks the "no new opcodes"
121 paradigm. However, what we are going to do is simply to reuse the RVV
122 SETVL opcode, now that RVV has reached its last anticipated draft before
123 ratification. Secondly: it's not an *actual* instruction related to
124 elements (it doesn't perform a parallel add, for example). It's more an
125 "infrastructure support" instruction.
126
127 The reason for needing SETVL is complex. It is down to the fact that,
128 unlike in RVV, the Maximum Vector Length is **not** an architectural hard
129 design parameter, it is a runtime dynamic one. Thus, it is absolutely
130 crucial that not only VL is set on every loop (or SV Prefix instruction),
131 but that MVL is also set.
132
133 This means that SV has two additional instructions for any algorithm,
134 when compared to RVV, and this kind of penalty is just not acceptable. The
135 solution therefore was to create a special SV.SETVL opcode that always
136 takes the MVL as an *additional* extra parameter over and above those
137 provided to the RV equivalent opcode. That basically puts SV on par with
138 RV as far as instruction count is concerned.
139
140 # Fail on First
141
142 The other really nice addition, which came with a small reorganisation
143 of the Vector and Predicate Contexts, is data dependent
144 ["fail on first"](https://libre-riscv.org/simple_v_extension/appendix/#ffirst).
145
146 ARM's SVE, RVV, and the Mill Architecture all have an incredibly neat
147 feature where if data is being loaded from memory in parallel, and the
148 LD operations run off the end of a page boundary, this may be detected
149 and the *legal* parallel operations may complete, all without needing
150 to drop into "scalar" mode.
151
152 In the case of the Mill Architecture, this is achieved through the
153 extremely innovative feature of simply marking the result of the
154 operation as "invalid", and that "tag" cascades through all subsequent
155 operations. Thus, any attempts to ADD or STORE the data will result in
156 the invalid data being simply ignored.
157
158 RV instead detects the point at which the LD became invalid, "fails"
159 at the "first" such illegal memory access, and truncates all subsequent
160 vector operations to within that limit, by *changing VL*. This is an
161 extremely effective and very simple idea, it was worth adding to SV.
162
163 However, when doing so, the idea sprang to mind: why not extend the
164 "fail on first" concept to not just cover LD/ST operations, but to cover
165 actual ALU operations as well? Why not, if any of the the results from
166 a sequence of parallel operations is zero ("fail"), similarly truncate VL?
167
168 This idea was tested out on strncpy (the typical canonical function
169 used to test out data-dependent ISA concepts), and it worked! So, that
170 is going into SV as well. It does mean that after every ALU operation,
171 a comparator against zero will be optionally activated: given that it
172 is optional and under the control of the ffirst bit, it is not a power
173 penalty on every single instruction.
174
175 # Summary
176
177 There is so much to do, and so much that has already been achieved,
178 it is almost overwhelming. We still cannot lose sight of the fact that
179 there is an enormous amount that we do not yet know, yet at the same
180 time, never let that stop us from moving forward. A journey starts with
181 a first step, and continues with each step.
182
183 With help from NLNet and companies like Purism we can look forward
184 to actually paying people to contribute to solving what was formerly
185 considered an impossible task.
186
187 It is worthwhile emphasising: any individual or Corporation wishing to
188 see this project succeed (so that you can use it as the basis for one
189 of your products, for example), donations through NLNet, as a Registered
190 Charitable Foundation, are tax deductible.
191
192 Likewise, for anyone who would like to help with the project's Milestones,
193 payments from NLnet are *donations*, and, depending on jurisdiction,
194 may also be tax deductible. If you are interested to learn more, do
195 get in touch.
196