Skip to content

Commit 562d651

Browse files
committed
deploy: 7fff9a1
1 parent 3094270 commit 562d651

File tree

3 files changed

+45
-33
lines changed

3 files changed

+45
-33
lines changed

pr-10/compiler-user-guide/developing-hardware/limitations.html

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ <h1 id="limitations-of-the-compiler"><a class="header" href="#limitations-of-the
189189
[0,1,1,2,3,5,8,13,21,34]
190190
</code></pre>
191191
<p>The <code>fibR</code> function is not synthesizable by the Clash compiler, because, when we take a <em>structural</em> view, <code>fibR</code> describes an infinitely deep structure.</p>
192-
<p>In principal, descriptions like the above could be synthesized to a circuit, but it would have to be a <em>sequential</em> circuit.
192+
<p>In principle, descriptions like the above could be synthesized to a circuit, but it would have to be a <em>sequential</em> circuit.
193193
Where the most general synthesis would then require a stack.
194194
Such a synthesis approach is also known as <em>behavioral</em> synthesis, something which the Clash compiler simply does not do.
195195
One reason that Clash does not do this is because it does not fit the paradigm that only functions working on values of type <code>Signal</code> result in sequential circuits, and all other (non higher-order) functions result in combinational circuits.
@@ -210,13 +210,16 @@ <h1 id="limitations-of-the-compiler"><a class="header" href="#limitations-of-the
210210
Where the recursively defined (non-function) value <em>r</em> is synthesized to a feedback loop containing three registers and one adder.</p>
211211
<p>Note that not all recursively defined values result in a feedback loop.
212212
An example that uses recursively defined values which does not result in a feedback loop is the following function that performs one iteration of bubble sort:</p>
213-
<pre><code class="language-haskell">sortVL xs = map fst sorted :&lt; (snd (last sorted))
213+
<pre><code class="language-haskell">sortV xs = map fst sorted :&lt; (snd (last sorted))
214214
where
215215
lefts = head xs :&gt; map snd (init sorted)
216216
rights = tail xs
217-
sorted = zipWith compareSwapL (lazyV lefts) rights
217+
sorted = zipWith compareAndSwap (lazyV lefts) rights
218+
219+
compareAndSwap a b = if a &lt; b then (a,b) else (b,a)
218220
</code></pre>
219-
<p>Where we can clearly see that <code>lefts</code> and <code>sorted</code> are defined in terms of each other. Also the above <code>sortV</code> function <em>is</em> synthesizable.</p>
221+
<p>Where we can clearly see that <code>lefts</code> and <code>sorted</code> are defined in terms of each other.
222+
Also the above <code>sortV</code> function <em>is</em> synthesizable.</p>
220223
</li>
221224
<li>
222225
<p><strong>Static/Structure-dependent recursion</strong></p>
@@ -245,11 +248,12 @@ <h1 id="limitations-of-the-compiler"><a class="header" href="#limitations-of-the
245248
While this is trivial for values of the elementary types, sum types, and product types, putting a fixed upper bound on recursive types is not (always) feasible.
246249
This means that the ubiquitous list type is unsupported!
247250
The only recursive types that are currently supported by the Clash compiler is the <code>Vec</code>tor and <code>RTree</code> types, for which the compiler has hard-coded knowledge.</p>
248-
<p>For "easy" <code>Vec</code>tor literals you should use Template Haskell splices and the <code>listToVecTH</code> <em>meta</em>-function that as we have seen earlier in this tutorial.</p>
251+
<p>For "easy" <code>Vec</code>tor literals you should use Template Haskell splices and the <code>listToVecTH</code> <em>meta</em>-function.</p>
249252
</li>
250253
<li>
251254
<p><strong>GADTs</strong></p>
252-
<p>Clash has experimental support for GADTs. Similar to recursive types, Clash can't determine bit-sizes of GADTs.
255+
<p>Clash has experimental support for GADTs.
256+
Similar to recursive types, Clash cannot determine bit-sizes of GADTs.
253257
Notable exceptions to this rule are <code>Vec</code> and <code>RTree</code>.
254258
You can still use your own GADTs, as long as they can be removed through static analysis.
255259
For example, the following case will be optimized away and is therefore fine to use:</p>
@@ -272,11 +276,11 @@ <h1 id="limitations-of-the-compiler"><a class="header" href="#limitations-of-the
272276
<pre><code class="language-haskell">plusFloat# :: Float# -&gt; Float# -&gt; Float#
273277
</code></pre>
274278
<p>which underlie <code>Float</code>'s <code>Num</code> instance, must be implemented as purely combinational circuits according to their type.
275-
Remember, sequential circuits operate on values of type "<code>Signal dom a</code>".</p>
279+
Remember, sequential circuits operate on values of type <code>Signal dom a</code>.</p>
276280
</li>
277281
</ol>
278282
<p>Although it is possible to implement purely combinational (not pipelined) arithmetic circuits for floating point data types, the circuit would be unreasonable slow.
279-
So, without synthesis possibilities for the basic arithmetic operations, there is no point in supporting the floating point data types.</p>
283+
So, without synthesis possibilities for the basic arithmetic operations, there is no point in supporting the floating point data types.</p>
280284
</li>
281285
<li>
282286
<p><strong>Haskell primitive types</strong></p>
@@ -298,33 +302,35 @@ <h1 id="limitations-of-the-compiler"><a class="header" href="#limitations-of-the
298302
<p>There are several aspects of which you should take note:</p>
299303
<ul>
300304
<li>
301-
<p>'Int' and 'Word' are represented by the same number of bits as is native for the architecture of the computer on which the Clash compiler is executed.
302-
This means that if you are working on a 64-bit machine, 'Int' and 'Word' will be 64-bit.
305+
<p><code>Int</code> and <code>Word</code> are represented by the same number of bits as is native for the architecture of the computer on which the Clash compiler is executed.
306+
This means that if you are working on a 64-bit machine, <code>Int</code> and <code>Word</code> will be 64-bit.
303307
This might be problematic when you are working in a team, and one designer has a 32-bit machine, and the other has a 64-bit machine.
304308
In general, you should be avoiding 'Int' in such cases, but as a band-aid solution, you can force the Clash compiler to use a specific bit-width for <code>Int</code> and <code>Word</code> using the <code>-fclash-intwidth=N</code> flag, where <em>N</em> must either be <em>32</em> or <em>64</em>.</p>
305309
</li>
306310
<li>
307311
<p>When you use the <code>-fclash-intwidth=32</code> flag on a <em>64-bit</em> machine, the 'Word64' and 'Int64' types <em>cannot</em> be translated. This restriction does <em>not</em> apply to the other three combinations of <code>-fclash-intwidth</code> flag and machine type.</p>
308312
</li>
309313
<li>
310-
<p>The translation of 'Integer' is not meaning-preserving. 'Integer' in Haskell is an arbitrary precision integer, something that cannot be represented in a statically known number of bits.
314+
<p>The translation of 'Integer' is not meaning-preserving.
315+
'Integer' in Haskell is an arbitrary precision integer, something that cannot be represented in a statically known number of bits.
311316
In the Clash compiler, we chose to represent 'Integer' by the same number of bits as we do for <code>Int</code> and <code>Word</code>.
312317
As you have read in a previous bullet point, this number of bits is either 32 or 64, depending on the architecture of the machine the Clash compiler is running on, or the setting of the <code>-fclash-intwidth</code> flag.</p>
313-
<p>Consequently, you should use <code>Integer</code> with due diligence; be especially careful when using <code>fromIntegral</code> as it does a conversion via 'Integer'. For example:</p>
318+
<p>Consequently, you should use <code>Integer</code> with due diligence; be especially careful when using <code>fromIntegral</code> as it does a conversion via 'Integer'.
319+
For example:</p>
314320
<pre><code class="language-haskell">signedToUnsigned :: Signed 128 -&gt; Unsigned 128
315321
signedToUnsigned = fromIntegral
316322
</code></pre>
317-
<p>can either lose the top 64 or 96 bits depending on whether 'Integer' is represented by 64 or 32 bits.
318-
Instead, when doing such conversions, you should use 'bitCoerce':</p>
323+
<p>can either lose the top 64 or 96 bits depending on whether <code>Integer</code> is represented by 64 or 32 bits.
324+
Instead, when doing such conversions, you should use <code>bitCoerce</code>:</p>
319325
<pre><code class="language-haskell">signedToUnsigned :: Signed 128 -&gt; Unsigned 128
320326
signedToUnsigned = bitCoerce
321327
</code></pre>
322328
</li>
323329
</ul>
324330
</li>
325331
<li>
326-
<p><strong>Side-effects: 'IO', 'ST', etc.</strong></p>
327-
<p>There is no support for side-effecting computations such as those in the 'IO' or 'ST' monad.
332+
<p><strong>Side-effects: <code>IO</code>, <code>ST</code>, etc.</strong></p>
333+
<p>There is no support for side-effecting computations such as those in the <code>IO</code> or <code>ST</code> monad.
328334
There is also no support for Haskell's <a href="http://www.haskell.org/haskellwiki/Foreign_Function_Interface">FFI</a>.</p>
329335
</li>
330336
</ul>

pr-10/compiler-user-guide/print.html

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ <h2 id="systemverilog-examples"><a class="header" href="#systemverilog-examples"
11791179
[0,1,1,2,3,5,8,13,21,34]
11801180
</code></pre>
11811181
<p>The <code>fibR</code> function is not synthesizable by the Clash compiler, because, when we take a <em>structural</em> view, <code>fibR</code> describes an infinitely deep structure.</p>
1182-
<p>In principal, descriptions like the above could be synthesized to a circuit, but it would have to be a <em>sequential</em> circuit.
1182+
<p>In principle, descriptions like the above could be synthesized to a circuit, but it would have to be a <em>sequential</em> circuit.
11831183
Where the most general synthesis would then require a stack.
11841184
Such a synthesis approach is also known as <em>behavioral</em> synthesis, something which the Clash compiler simply does not do.
11851185
One reason that Clash does not do this is because it does not fit the paradigm that only functions working on values of type <code>Signal</code> result in sequential circuits, and all other (non higher-order) functions result in combinational circuits.
@@ -1200,13 +1200,16 @@ <h2 id="systemverilog-examples"><a class="header" href="#systemverilog-examples"
12001200
Where the recursively defined (non-function) value <em>r</em> is synthesized to a feedback loop containing three registers and one adder.</p>
12011201
<p>Note that not all recursively defined values result in a feedback loop.
12021202
An example that uses recursively defined values which does not result in a feedback loop is the following function that performs one iteration of bubble sort:</p>
1203-
<pre><code class="language-haskell">sortVL xs = map fst sorted :&lt; (snd (last sorted))
1203+
<pre><code class="language-haskell">sortV xs = map fst sorted :&lt; (snd (last sorted))
12041204
where
12051205
lefts = head xs :&gt; map snd (init sorted)
12061206
rights = tail xs
1207-
sorted = zipWith compareSwapL (lazyV lefts) rights
1207+
sorted = zipWith compareAndSwap (lazyV lefts) rights
1208+
1209+
compareAndSwap a b = if a &lt; b then (a,b) else (b,a)
12081210
</code></pre>
1209-
<p>Where we can clearly see that <code>lefts</code> and <code>sorted</code> are defined in terms of each other. Also the above <code>sortV</code> function <em>is</em> synthesizable.</p>
1211+
<p>Where we can clearly see that <code>lefts</code> and <code>sorted</code> are defined in terms of each other.
1212+
Also the above <code>sortV</code> function <em>is</em> synthesizable.</p>
12101213
</li>
12111214
<li>
12121215
<p><strong>Static/Structure-dependent recursion</strong></p>
@@ -1235,11 +1238,12 @@ <h2 id="systemverilog-examples"><a class="header" href="#systemverilog-examples"
12351238
While this is trivial for values of the elementary types, sum types, and product types, putting a fixed upper bound on recursive types is not (always) feasible.
12361239
This means that the ubiquitous list type is unsupported!
12371240
The only recursive types that are currently supported by the Clash compiler is the <code>Vec</code>tor and <code>RTree</code> types, for which the compiler has hard-coded knowledge.</p>
1238-
<p>For "easy" <code>Vec</code>tor literals you should use Template Haskell splices and the <code>listToVecTH</code> <em>meta</em>-function that as we have seen earlier in this tutorial.</p>
1241+
<p>For "easy" <code>Vec</code>tor literals you should use Template Haskell splices and the <code>listToVecTH</code> <em>meta</em>-function.</p>
12391242
</li>
12401243
<li>
12411244
<p><strong>GADTs</strong></p>
1242-
<p>Clash has experimental support for GADTs. Similar to recursive types, Clash can't determine bit-sizes of GADTs.
1245+
<p>Clash has experimental support for GADTs.
1246+
Similar to recursive types, Clash cannot determine bit-sizes of GADTs.
12431247
Notable exceptions to this rule are <code>Vec</code> and <code>RTree</code>.
12441248
You can still use your own GADTs, as long as they can be removed through static analysis.
12451249
For example, the following case will be optimized away and is therefore fine to use:</p>
@@ -1262,11 +1266,11 @@ <h2 id="systemverilog-examples"><a class="header" href="#systemverilog-examples"
12621266
<pre><code class="language-haskell">plusFloat# :: Float# -&gt; Float# -&gt; Float#
12631267
</code></pre>
12641268
<p>which underlie <code>Float</code>'s <code>Num</code> instance, must be implemented as purely combinational circuits according to their type.
1265-
Remember, sequential circuits operate on values of type "<code>Signal dom a</code>".</p>
1269+
Remember, sequential circuits operate on values of type <code>Signal dom a</code>.</p>
12661270
</li>
12671271
</ol>
12681272
<p>Although it is possible to implement purely combinational (not pipelined) arithmetic circuits for floating point data types, the circuit would be unreasonable slow.
1269-
So, without synthesis possibilities for the basic arithmetic operations, there is no point in supporting the floating point data types.</p>
1273+
So, without synthesis possibilities for the basic arithmetic operations, there is no point in supporting the floating point data types.</p>
12701274
</li>
12711275
<li>
12721276
<p><strong>Haskell primitive types</strong></p>
@@ -1288,33 +1292,35 @@ <h2 id="systemverilog-examples"><a class="header" href="#systemverilog-examples"
12881292
<p>There are several aspects of which you should take note:</p>
12891293
<ul>
12901294
<li>
1291-
<p>'Int' and 'Word' are represented by the same number of bits as is native for the architecture of the computer on which the Clash compiler is executed.
1292-
This means that if you are working on a 64-bit machine, 'Int' and 'Word' will be 64-bit.
1295+
<p><code>Int</code> and <code>Word</code> are represented by the same number of bits as is native for the architecture of the computer on which the Clash compiler is executed.
1296+
This means that if you are working on a 64-bit machine, <code>Int</code> and <code>Word</code> will be 64-bit.
12931297
This might be problematic when you are working in a team, and one designer has a 32-bit machine, and the other has a 64-bit machine.
12941298
In general, you should be avoiding 'Int' in such cases, but as a band-aid solution, you can force the Clash compiler to use a specific bit-width for <code>Int</code> and <code>Word</code> using the <code>-fclash-intwidth=N</code> flag, where <em>N</em> must either be <em>32</em> or <em>64</em>.</p>
12951299
</li>
12961300
<li>
12971301
<p>When you use the <code>-fclash-intwidth=32</code> flag on a <em>64-bit</em> machine, the 'Word64' and 'Int64' types <em>cannot</em> be translated. This restriction does <em>not</em> apply to the other three combinations of <code>-fclash-intwidth</code> flag and machine type.</p>
12981302
</li>
12991303
<li>
1300-
<p>The translation of 'Integer' is not meaning-preserving. 'Integer' in Haskell is an arbitrary precision integer, something that cannot be represented in a statically known number of bits.
1304+
<p>The translation of 'Integer' is not meaning-preserving.
1305+
'Integer' in Haskell is an arbitrary precision integer, something that cannot be represented in a statically known number of bits.
13011306
In the Clash compiler, we chose to represent 'Integer' by the same number of bits as we do for <code>Int</code> and <code>Word</code>.
13021307
As you have read in a previous bullet point, this number of bits is either 32 or 64, depending on the architecture of the machine the Clash compiler is running on, or the setting of the <code>-fclash-intwidth</code> flag.</p>
1303-
<p>Consequently, you should use <code>Integer</code> with due diligence; be especially careful when using <code>fromIntegral</code> as it does a conversion via 'Integer'. For example:</p>
1308+
<p>Consequently, you should use <code>Integer</code> with due diligence; be especially careful when using <code>fromIntegral</code> as it does a conversion via 'Integer'.
1309+
For example:</p>
13041310
<pre><code class="language-haskell">signedToUnsigned :: Signed 128 -&gt; Unsigned 128
13051311
signedToUnsigned = fromIntegral
13061312
</code></pre>
1307-
<p>can either lose the top 64 or 96 bits depending on whether 'Integer' is represented by 64 or 32 bits.
1308-
Instead, when doing such conversions, you should use 'bitCoerce':</p>
1313+
<p>can either lose the top 64 or 96 bits depending on whether <code>Integer</code> is represented by 64 or 32 bits.
1314+
Instead, when doing such conversions, you should use <code>bitCoerce</code>:</p>
13091315
<pre><code class="language-haskell">signedToUnsigned :: Signed 128 -&gt; Unsigned 128
13101316
signedToUnsigned = bitCoerce
13111317
</code></pre>
13121318
</li>
13131319
</ul>
13141320
</li>
13151321
<li>
1316-
<p><strong>Side-effects: 'IO', 'ST', etc.</strong></p>
1317-
<p>There is no support for side-effecting computations such as those in the 'IO' or 'ST' monad.
1322+
<p><strong>Side-effects: <code>IO</code>, <code>ST</code>, etc.</strong></p>
1323+
<p>There is no support for side-effecting computations such as those in the <code>IO</code> or <code>ST</code> monad.
13181324
There is also no support for Haskell's <a href="http://www.haskell.org/haskellwiki/Foreign_Function_Interface">FFI</a>.</p>
13191325
</li>
13201326
</ul>

pr-10/compiler-user-guide/searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)