You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
In SpinalHDL `ROUNDTOINF` is the default RoundType (``round = roundToInf``)
593
610
594
611
.. code-block:: scala
595
612
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) // ---+
611
628
// |--> equal
612
-
val B1 = A.roundToInf(6 bits, align = false).sat(1) // ---+
629
+
val b1 = a.roundToInf(6 bits, align = false).sat(1) // ---+
613
630
614
631
.. note::
615
632
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``.
651
668
652
669
.. code-block:: scala
653
670
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)
661
678
662
679
fixTo function
663
680
^^^^^^^^^^^^^^
@@ -678,13 +695,13 @@ Factory Fix function with Auto Saturation:
678
695
679
696
.. code-block:: scala
680
697
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
Copy file name to clipboardExpand all lines: source/SpinalHDL/Examples/Advanced ones/slots.rst
+14-9Lines changed: 14 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -6,31 +6,36 @@ Slots
6
6
Introduction
7
7
------------
8
8
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``.
10
12
11
13
12
14
Implementation
13
15
^^^^^^^^^^^^^^
14
16
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.
16
19
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
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) :
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).
0 commit comments