Skip to content

Commit 181a130

Browse files
authored
Merge pull request #298 from SpinalHDL/move-logic-to-utils
Move logic to utils
2 parents 4ef3494 + e33308d commit 181a130

3 files changed

Lines changed: 65 additions & 63 deletions

File tree

source/SpinalHDL/Libraries/logic.rst

Lines changed: 0 additions & 60 deletions
This file was deleted.

source/SpinalHDL/Libraries/regIf.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ Automatic field allocation
5353

5454
conflict detection
5555

56-
.. code:: scala
56+
.. code:: scala
5757
5858
val M_REG1 = busif.newReg(doc="REG1")
5959
val r1fd0 = M_REG1.field(Bits(16 bits), RW, doc="fields 1")
6060
val r1fd2 = M_REG1.field(Bits(18 bits), RW, doc="fields 1")
61-
...
61+
...
6262
cause Exception
6363
val M_REG1 = busif.newReg(doc="REG1")
6464
val r1fd0 = M_REG1.field(Bits(16 bits), RW, doc="fields 1")
6565
val r1fd2 = M_REG1.fieldAt(pos=10, Bits(2 bits), RW, doc="fields 1")
66-
...
66+
...
6767
cause Exception
6868
6969
28 Access Types

source/SpinalHDL/Libraries/utils.rst

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,68 @@ You can filter an asynchronous reset by using an asynchronously asserted synchro
223223

224224
There is also an ``ResetCtrl.asyncAssertSyncDeassertDrive`` version of tool which directly assign the ``clockDomain`` reset with the filtered value.
225225

226+
Logic simplification utilities
227+
------------------------------
228+
229+
`DecodingSpec` with `Masked` provide a minimal Boolean simplification and decode-table
230+
utility using the `Quine–McCluskey algorithm <https://en.wikipedia.org/wiki/Quine%E2%80%93McCluskey_algorithm>`_.
231+
232+
Provides masked pattern matching, Quine–McCluskey style logic reduction,
233+
and a high-level decode-table builder.
234+
235+
`Masked`
236+
^^^^^^^^
237+
238+
Represents a bit pattern with care (significant) and don't-care bits.
239+
- `value` = bit values
240+
- `care` = which bits must match (1 = match, 0 = don't care)
241+
242+
Example:
243+
244+
.. code-block:: scala
245+
246+
Masked(0010),
247+
Masked(11-1),
248+
Masked(1--0)
249+
250+
e.g RISC-V instructions:
251+
252+
.. code-block:: scala
253+
254+
val ADD = M"0000000----------000-----0110011"
255+
val ADDI = M"-----------------000-----0010011"
256+
257+
Used to define instruction encodings for decode tables.
258+
259+
`DecodingSpec`
260+
^^^^^^^^^^^^^^
261+
262+
High-level builder for decode tables using `Masked` patterns.
263+
264+
Methods:
265+
* `addNeeds(key : Masked, value : Masked)`
266+
* `addNeeds(keys : Seq[Masked], value : Masked)`
267+
* `build(sel, coverAll)`
268+
* `setDefault(value : Masked)`
269+
270+
This generate simplified decode logic.
271+
272+
Example:
273+
274+
.. code-block:: scala
275+
276+
val spec = new DecodingSpec(UInt(4 bits))
277+
spec.setDefault(Masked(U"0011"))
278+
spec.addNeeds(Masked(B"000"), Masked(U"1000"))
279+
result := spec.build(sel, allPatterns)
280+
281+
Generates minimized combinational decode logic.
282+
283+
The practical use is to define bit patterns as `Masked` and feed them into
284+
`DecodingSpec` to build compact decode logic (e.g., RISC-V). The output hardware
285+
is then minimized (fewer LUTs / simpler gates).
286+
287+
226288
Special utilities
227289
-----------------
228290

0 commit comments

Comments
 (0)