Skip to content

Commit 385db84

Browse files
authored
Merge pull request #277 from mrcmry/extra-blackbox-typo-presentation
Add extra blackbox description and fix typo and presentation
2 parents 98064d6 + 86e2d44 commit 385db84

File tree

10 files changed

+311
-192
lines changed

10 files changed

+311
-192
lines changed

examples/src/main/scala/spinaldoc/examples/advanced/Slots.scala

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,38 @@ case class SlotsDemo(slotsCount : Int) extends Component {
88
// ...
99

1010

11-
// Create the hardware for each slot
12-
// Note each slot is an Area, not a Bundle
11+
// Create the hardware for each slot.
12+
// Note each slot is an Area, not a Bundle.
1313
val slots = for(i <- 0 until slotsCount) yield new Area {
14-
// Because the slot is an Area, we can define mix signal, registers, logic definitions
15-
// Here are the registers for each slots
14+
// Because the slot is an Area, we can define mix signals, registers,
15+
// logic definitions.
16+
// Here are the registers for each slots:
1617
val valid = RegInit(False)
1718
val address = Reg(UInt(8 bits))
1819
val age = Reg(UInt(16 bits)) // Will count since how many cycles the slot is valid
1920

20-
// Here is some hardware behavior for each slots
21-
// Implement the age logic
21+
// Here is some hardware behavior for each slots.
22+
// Implement the age logic.
2223
when(valid) {
2324
age := age + 1
2425
}
2526

26-
// removeIt will be used as a slot interface later on
27+
// removeIt will be used as a slot interface later on.
2728
val removeIt = False
2829
when(removeIt) {
2930
valid := False
3031
}
3132
}
3233

33-
// Logic to allocate a new slot
34+
// Logic to allocate a new slot.
3435
val insert = new Area {
35-
val cmd = Stream(UInt(8 bits)) // interface to issue requests
36+
val cmd = Stream(UInt(8 bits)) // Interface to issue requests.
3637
val free = slots.map(!_.valid)
37-
val freeOh = OHMasking.first(free) // Get the first free slot (on hot mask)
38-
cmd.ready := free.orR // Only allow cmd when there is a free slot
38+
val freeOh = OHMasking.first(free) // Get the first free slot (on hot mask).
39+
cmd.ready := free.orR // Only allow cmd when there is a free slot.
3940
when(cmd.fire) {
40-
// slots.onMask(freeOh)(code) will execute the code for each slot where the corresponding freeOh bit is set
41+
// slots.onMask(freeOh)(code) will execute the code for each slot where
42+
// the corresponding freeOh bit is set
4143
slots.onMask(freeOh){slot =>
4244
slot.valid := True
4345
slot.address := cmd.payload
@@ -46,17 +48,21 @@ case class SlotsDemo(slotsCount : Int) extends Component {
4648
}
4749
}
4850

49-
// Logic to remove the slots which match a given address (assuming there is not more than one match)
51+
// Logic to remove the slots which match a given address (assuming
52+
// there is not more than one match).
5053
val remove = new Area {
51-
val cmd = Flow(UInt(8 bits)) // interface to issue requests
52-
val oh = slots.map(s => s.valid && s.address === cmd.payload) // oh meaning "one hot"
54+
val cmd = Flow(UInt(8 bits)) // Interface to issue requests.
55+
// oh meaning "one hot"
56+
val oh = slots.map(s => s.valid && s.address === cmd.payload)
5357
when(cmd.fire) {
5458
slots.onMask(oh){ slot =>
5559
slot.removeIt := True
5660
}
5761
}
5862

59-
val reader = slots.reader(oh) // Create a facility to read the slots using "oh" as index
63+
// Create a facility to read the slots using "oh" as index
64+
val reader = slots.reader(oh)
65+
6066
val age = reader(_.age) // Age of the slot which is selected by "oh"
6167
}
6268

source/SpinalHDL/Data types/Int.rst

Lines changed: 83 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -343,25 +343,25 @@ To cast a ``Bool``, a ``Bits``, or an ``SInt`` into a ``UInt``, you can use ``U(
343343
val mySInt = S(myBits)
344344
345345
// UInt to SInt conversion
346-
val UInt_30 = U(30, 8 bit)
346+
val uInt_30 = U(30, 8 bit)
347347
348-
val SInt_30 = UInt_30.intoSInt
349-
assert(SInt_30 === S(30, 9 bit))
348+
val sInt_30 = uint_30.intoSInt
349+
assert(sInt_30 === S(30, 9 bit))
350350
351-
mySInt := UInt_30.twoComplement(booleanDoInvert)
351+
mySInt := uInt_30.twoComplement(booleanDoInvert)
352352
// if booleanDoInvert is True then we get S(-30, 9 bit)
353353
// otherwise we get S(30, 9 bit)
354354
355355
// absolute values
356-
val SInt_n_4 = S(-3, 3 bit)
357-
val abs_en = SInt_n_3.abs(booleanDoAbs)
356+
val sInt_n_4 = S(-3, 3 bit)
357+
val abs_en = sInt_n_3.abs(booleanDoAbs)
358358
// if booleanDoAbs is True we get U(3, 3 bit)
359359
// otherwise we get U"3'b101" or U(5, 3 bit) (raw bit pattern of -3)
360360
361-
val SInt_n_128 = S(-128, 8 bit)
362-
val abs = SInt_n_128.abs
361+
val sInt_n_128 = S(-128, 8 bit)
362+
val abs = sInt_n_128.abs
363363
assert(abs === U(128, 8 bit))
364-
val sym_abs = SInt_n_128.absWithSym
364+
val sym_abs = sInt_n_128.absWithSym
365365
assert(sym_abs === U(127, 7 bit))
366366
367367
Bit extraction
@@ -558,58 +558,75 @@ Lower bit operations
558558

559559
About Rounding: https://en.wikipedia.org/wiki/Rounding
560560

561-
================ ================= ============= ======================== ====================== ===========
562-
SpinalHDL-Name Wikipedia-Name API Mathematic Algorithm return(align=false) Supported
563-
================ ================= ============= ======================== ====================== ===========
564-
FLOOR RoundDown floor floor(x) w(x)-n bits Yes
565-
FLOORTOZERO RoundToZero floorToZero sign*floor(abs(x)) w(x)-n bits Yes
566-
CEIL RoundUp ceil ceil(x) w(x)-n+1 bits Yes
567-
CEILTOINF RoundToInf ceilToInf sign*ceil(abs(x)) w(x)-n+1 bits Yes
568-
ROUNDUP RoundHalfUp roundUp floor(x+0.5) w(x)-n+1 bits Yes
569-
ROUNDDOWN RoundHalfDown roundDown ceil(x-0.5) w(x)-n+1 bits Yes
570-
ROUNDTOZERO RoundHalfToZero roundToZero sign*ceil(abs(x)-0.5) w(x)-n+1 bits Yes
571-
ROUNDTOINF RoundHalfToInf roundToInf sign*floor(abs(x)+0.5) w(x)-n+1 bits Yes
572-
ROUNDTOEVEN RoundHalfToEven roundToEven No
573-
ROUNDTOODD RoundHalfToOdd roundToOdd No
574-
================ ================= ============= ======================== ====================== ===========
561+
+-------------+-----------------+-------------+------------------------+----------------+----------+
562+
|| Spinal HDL || Wikipedia || API || Mathematic || return || Sup- |
563+
|| name || name || || Algorithm || (align=false) || port |
564+
+=============+=================+=============+========================+================+==========+
565+
| FLOOR | RoundDown | floor | floor(x) | w(x)-n bits | Yes |
566+
+-------------+-----------------+-------------+------------------------+----------------+----------+
567+
| FLOORTOZERO | RoundToZero | floorToZero | sign*floor(abs(x)) | w(x)-n bits | Yes |
568+
+-------------+-----------------+-------------+------------------------+----------------+----------+
569+
| CEIL | RoundUp | ceil | ceil(x) | w(x)-n+1 bits | Yes |
570+
+-------------+-----------------+-------------+------------------------+----------------+----------+
571+
| CEILTOINF | RoundToInf | ceilToInf | sign*ceil(abs(x)) | w(x)-n+1 bits | Yes |
572+
+-------------+-----------------+-------------+------------------------+----------------+----------+
573+
| ROUNDUP | RoundHalfUp | roundUp | floor(x+0.5) | w(x)-n+1 bits | Yes |
574+
+-------------+-----------------+-------------+------------------------+----------------+----------+
575+
| ROUNDDOWN | RoundHalfDown | roundDown | ceil(x-0.5) | w(x)-n+1 bits | Yes |
576+
+-------------+-----------------+-------------+------------------------+----------------+----------+
577+
| ROUNDTOZERO | RoundHalfToZero | roundToZero | sign*ceil(abs(x)-0.5) | w(x)-n+1 bits | Yes |
578+
+-------------+-----------------+-------------+------------------------+----------------+----------+
579+
| ROUNDTOINF | RoundHalfToInf | roundToInf | sign*floor(abs(x)+0.5) | w(x)-n+1 bits | Yes |
580+
+-------------+-----------------+-------------+------------------------+----------------+----------+
581+
| ROUNDTOEVEN | RoundHalfToEven | roundToEven | | | No |
582+
+-------------+-----------------+-------------+------------------------+----------------+----------+
583+
| ROUNDTOODD | RoundHalfToOdd | roundToOdd | | | No |
584+
+-------------+-----------------+-------------+------------------------+----------------+----------+
575585

576586
.. note::
577-
The **RoundToEven** and **RoundToOdd** modes are very special, and are used in some big data statistical fields with high accuracy concerns, SpinalHDL doesn't support them yet.
578-
579-
You will find `ROUNDUP`, `ROUNDDOWN`, `ROUNDTOZERO`, `ROUNDTOINF`, `ROUNDTOEVEN`, `ROUNTOODD` are very close in behavior, `ROUNDTOINF` is the most common. The behavior of rounding in different programming languages may be different.
580-
581-
====================== =================== ========================================================= ====================
582-
Programming language default-RoundType Example comments
583-
====================== =================== ========================================================= ====================
584-
Matlab ROUNDTOINF round(1.5)=2,round(2.5)=3;round(-1.5)=-2,round(-2.5)=-3 round to ±Infinity
585-
python2 ROUNDTOINF round(1.5)=2,round(2.5)=3;round(-1.5)=-2,round(-2.5)=-3 round to ±Infinity
586-
python3 ROUNDTOEVEN round(1.5)=round(2.5)=2; round(-1.5)=round(-2.5)=-2 close to Even
587-
Scala.math ROUNDTOUP round(1.5)=2,round(2.5)=3;round(-1.5)=-1,round(-2.5)=-2 always to +Infinity
588-
SpinalHDL ROUNDTOINF round(1.5)=2,round(2.5)=3;round(-1.5)=-2,round(-2.5)=-3 round to ±Infinity
589-
====================== =================== ========================================================= ====================
587+
The **RoundToEven** and **RoundToOdd** modes are very special, and are used in some big data statistical fields
588+
with high accuracy concerns, SpinalHDL doesn't support them yet.
589+
590+
You will find ``ROUNDUP``, ``ROUNDDOWN``, ``ROUNDTOZERO``, ``ROUNDTOINF``, ``ROUNDTOEVEN``, ``ROUNTOODD`` are very close in behavior,
591+
``ROUNDTOINF`` is the most common. The behavior of rounding in different programming languages may be different.
592+
593+
============= =================== ================================================= ====================
594+
language default-RoundType example comments
595+
============= =================== ================================================= ====================
596+
Matlab ROUNDTOINF | ``round(1.5) == 2``, ``round(2.5) == 3`` round to ±Infinity
597+
| ``round(-1.5) == -2``, ``round(-2.5) == -3``
598+
python2 ROUNDTOINF | ``round(1.5) == 2``, ``round(2.5) == 3`` round to ±Infinity
599+
| ``round(-1.5) == -2``, ``round(-2.5) == -3``
600+
python3 ROUNDTOEVEN | ``round(1.5) == round(2.5) == 2`` close to Even
601+
| ``round(-1.5) == round(-2.5) == -2``
602+
Scala.math ROUNDTOUP | ``round(1.5) == 2``, ``round(2.5) == 3`` always to +Infinity
603+
| ``round(-1.5) == -1``, ``round(-2.5) == -2``
604+
SpinalHDL ROUNDTOINF | ``round(1.5) == 2``, ``round(2.5) == 3`` round to ±Infinity
605+
| ``round(-1.5) == -2``, ``round(-2.5) == -3``
606+
============= =================== ================================================= ====================
590607

591608
.. note::
592609
In SpinalHDL `ROUNDTOINF` is the default RoundType (``round = roundToInf``)
593610

594611
.. code-block:: scala
595612
596-
val A = SInt(16 bits)
597-
val B = A.roundToInf(6 bits) // default 'align = false' with carry, got 11 bit
598-
val B = A.roundToInf(6 bits, align = true) // sat 1 carry bit, got 10 bit
599-
val B = A.floor(6 bits) // return 10 bit
600-
val B = A.floorToZero(6 bits) // return 10 bit
601-
val B = A.ceil(6 bits) // ceil with carry so return 11 bit
602-
val B = A.ceil(6 bits, align = true) // ceil with carry then sat 1 bit return 10 bit
603-
val B = A.ceilToInf(6 bits)
604-
val B = A.roundUp(6 bits)
605-
val B = A.roundDown(6 bits)
606-
val B = A.roundToInf(6 bits)
607-
val B = A.roundToZero(6 bits)
608-
val B = A.round(6 bits) // SpinalHDL uses roundToInf as the default rounding mode
609-
610-
val B0 = A.roundToInf(6 bits, align = true) // ---+
613+
val a = SInt(16 bits)
614+
val b = a.roundToInf(6 bits) // default 'align = false' with carry, got 11 bit
615+
val b = a.roundToInf(6 bits, align = true) // sat 1 carry bit, got 10 bit
616+
val b = a.floor(6 bits) // return 10 bit
617+
val b = a.floorToZero(6 bits) // return 10 bit
618+
val b = a.ceil(6 bits) // ceil with carry so return 11 bit
619+
val b = a.ceil(6 bits, align = true) // ceil with carry then sat 1 bit return 10 bit
620+
val b = a.ceilToInf(6 bits)
621+
val b = a.roundUp(6 bits)
622+
val b = a.roundDown(6 bits)
623+
val b = a.roundToInf(6 bits)
624+
val b = a.roundToZero(6 bits)
625+
val b = a.round(6 bits) // SpinalHDL uses roundToInf as the default rounding mode
626+
627+
val b0 = a.roundToInf(6 bits, align = true) // ---+
611628
// |--> equal
612-
val B1 = A.roundToInf(6 bits, align = false).sat(1) // ---+
629+
val b1 = a.roundToInf(6 bits, align = false).sat(1) // ---+
613630
614631
.. note::
615632
Only ``floor`` and ``floorToZero`` work without the ``align`` option; they do not need a carry bit. Other rounding operations default to using a carry bit.
@@ -651,13 +668,13 @@ Symmetric is only valid for ``SInt``.
651668

652669
.. code-block:: scala
653670
654-
val A = SInt(8 bits)
655-
val B = A.sat(3 bits) // return 5 bits with saturated highest 3 bits
656-
val B = A.sat(3) // equal to sat(3 bits)
657-
val B = A.trim(3 bits) // return 5 bits with the highest 3 bits discarded
658-
val B = A.trim(3 bits) // return 5 bits with the highest 3 bits discarded
659-
val C = A.symmetry // return 8 bits and symmetry as (-128~127 to -127~127)
660-
val C = A.sat(3).symmetry // return 5 bits and symmetry as (-16~15 to -15~15)
671+
val a = SInt(8 bits)
672+
val b = a.sat(3 bits) // return 5 bits with saturated highest 3 bits
673+
val b = a.sat(3) // equal to sat(3 bits)
674+
val b = a.trim(3 bits) // return 5 bits with the highest 3 bits discarded
675+
val b = a.trim(3 bits) // return 5 bits with the highest 3 bits discarded
676+
val c = a.symmetry // return 8 bits and symmetry as (-128~127 to -127~127)
677+
val c = a.sat(3).symmetry // return 5 bits and symmetry as (-16~15 to -15~15)
661678
662679
fixTo function
663680
^^^^^^^^^^^^^^
@@ -678,13 +695,13 @@ Factory Fix function with Auto Saturation:
678695

679696
.. code-block:: scala
680697
681-
val A = SInt(16 bits)
682-
val B = A.fixTo(10 downto 3) // default RoundType.ROUNDTOINF, sym = false
683-
val B = A.fixTo( 8 downto 0, RoundType.ROUNDUP)
684-
val B = A.fixTo( 9 downto 3, RoundType.CEIL, sym = false)
685-
val B = A.fixTo(16 downto 1, RoundType.ROUNDTOINF, sym = true )
686-
val B = A.fixTo(10 downto 3, RoundType.FLOOR) // floor 3 bit, sat 5 bit @ highest
687-
val B = A.fixTo(20 downto 3, RoundType.FLOOR) // floor 3 bit, expand 2 bit @ highest
698+
val a = SInt(16 bits)
699+
val b = a.fixTo(10 downto 3) // default RoundType.ROUNDTOINF, sym = false
700+
val b = a.fixTo( 8 downto 0, RoundType.ROUNDUP)
701+
val b = a.fixTo( 9 downto 3, RoundType.CEIL, sym = false)
702+
val b = a.fixTo(16 downto 1, RoundType.ROUNDTOINF, sym = true )
703+
val b = a.fixTo(10 downto 3, RoundType.FLOOR) // floor 3 bit, sat 5 bit @ highest
704+
val b = a.fixTo(20 downto 3, RoundType.FLOOR) // floor 3 bit, expand 2 bit @ highest
688705
689706
690707
.. _saturation: https://en.wikipedia.org/wiki/Saturation_arithmetic

source/SpinalHDL/Examples/Advanced ones/slots.rst

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,36 @@ Slots
66
Introduction
77
------------
88

9-
Let's say you have some hardware which has to keep track of multiple similar ongoing activities, you may want to implement an array of "slots" to do so. This example show how to do it using Area, OHMasking.first, onMask and reader.
9+
Let's say you have some hardware which has to keep track of multiple similar ongoing activities,
10+
you may want to implement an array of "slots" to do so. This example show how to do it using
11+
``Area``, ``OHMasking.first``, ``onMask`` and ``reader``.
1012

1113

1214
Implementation
1315
^^^^^^^^^^^^^^
1416

15-
This implementation avoid the use of Vec. Instead, it use Area which allow to mix signal, registers and logic definitions in each slot.
17+
This implementation avoid the use of ``Vec``. Instead, it use Area which allow to mix signals,
18+
registers and logic definitions in each slot.
1619

17-
Note that the `reader` API is for SpinalHDL version coming after 1.9.1
20+
Note that the ``reader`` API is for SpinalHDL version coming after 1.9.1
1821

1922
.. literalinclude:: /../examples/src/main/scala/spinaldoc/examples/advanced/Slots.scala
2023
:language: scala
2124

2225

2326
In practice
24-
^^^^^^^^^^^^^^
27+
^^^^^^^^^^^
2528

26-
For instance, this kind of slot pattern is used in Tilelink coherency hub to keep track of all ongoing memory probes in flight:
29+
For instance, this kind of slot pattern is used in Tilelink coherency hub to keep track of all
30+
ongoing memory probes in flight `in SpinalHDL code <https://github.com/SpinalHDL/SpinalHDL/blob/008c73f1ce18e294f137efe7a1442bd3f8fa2ee0/lib/src/main/scala/spinal/lib/bus/tilelink/coherent/Hub.scala#L376>`_.
2731

28-
https://github.com/SpinalHDL/SpinalHDL/blob/008c73f1ce18e294f137efe7a1442bd3f8fa2ee0/lib/src/main/scala/spinal/lib/bus/tilelink/coherent/Hub.scala#L376
2932

30-
As well in the DRAM / SDR / DDR memory controller to implement the handling of multiple memory transactions at once (having multiple precharge / active / read / write running at the same time to improve performances) :
3133

32-
https://github.com/SpinalHDL/SpinalHDL/blob/1edba1890b5f629b28e5171b3c449155337d2548/lib/src/main/scala/spinal/lib/memory/sdram/xdr/Tasker.scala#L202
34+
As well in the DRAM / SDR / DDR memory controller to implement the handling of multiple memory
35+
transactions at once (having multiple precharge / active / read / write running at the same time to
36+
improve performances) `here <https://github.com/SpinalHDL/SpinalHDL/blob/1edba1890b5f629b28e5171b3c449155337d2548/lib/src/main/scala/spinal/lib/memory/sdram/xdr/Tasker.scala#L202>`_.
3337

34-
As well in the NaxRiscv (out of order CPU) load-store-unit to handle the store-queue / load-queue hardware (a bit too scary to show here in the doc XD)
38+
As well in the NaxRiscv (out of order CPU) load-store-unit to handle the store-queue / load-queue
39+
hardware (a bit too scary to show here in the doc XD).
3540

3641

source/SpinalHDL/Introduction/Projects using SpinalHDL.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Repositories
1212
* `VexRiscv CPU and SoC <https://github.com/SpinalHDL/VexRiscv>`_
1313
* `NaxRiscv CPU <https://github.com/SpinalHDL/NaxRiscv>`_
1414
* `SaxonSoc <https://github.com/SpinalHDL/SaxonSoc/tree/dev-0.3/bsp/digilent/ArtyA7SmpLinux>`_
15+
* `VexiiRiscv CPU <https://github.com/SpinalHDL/VexiiRiscv>`_
1516
* `open-rdma <https://github.com/datenlord/open-rdma>`_
1617
* `MicroRV32 SoC <https://github.com/agra-uni-bremen/microrv32>`_
1718
* \.\.\.

0 commit comments

Comments
 (0)