Skip to content

Commit 68d199f

Browse files
committed
Merge upstream/v1.1.0 into VHDL port
2 parents ae13db3 + 9a0f677 commit 68d199f

33 files changed

+897
-71
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Compile SystemRDL into a VHDL control/status register (CSR) block.
99
For the command line tool, see the [PeakRDL project](https://peakrdl.readthedocs.io).
1010

1111
## Documentation
12-
See the [PeakRDL-regblock-vhdl Documentation](http://peakrdl-regblock-vhdl.readthedocs.io) for more details
12+
See the [PeakRDL-regblock-vhdl Documentation](https://peakrdl-regblock-vhdl.readthedocs.io) for more details
1313

1414
## Relationship with PeakRDL-regblock
1515
This is a direct VHDL translation of the SystemVerilog regblock generator [PeakRDL-regblock](https://github.com/SystemRDL/PeakRDL-regblock). Updates from the upstream regblock implementation are converted to VHDL and merged into this repository.

docs/index.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,20 @@ The easiest way to use PeakRDL-regblock-vhdl is via the `PeakRDL command line t
2727
Depending on the chosen CPU interface, the generated RTL may rely on VHDL packages
2828
available in the `hdl-src folder in the repository <https://github.com/SystemRDL/PeakRDL-regblock-vhdl/tree/main/hdl-src>`_.
2929

30+
Looking for SystemVerilog?
31+
--------------------------
32+
This project generates VHDL RTL. If you prefer using SystemVerilog, check out
33+
the upstream project from which this exporter was forked:
34+
`PeakRDL-regblock <https://peakrdl-regblock.readthedocs.io>`_
35+
36+
3037
Links
3138
-----
3239

3340
- `Source repository <https://github.com/SystemRDL/PeakRDL-regblock-vhdl>`_
3441
- `Release Notes <https://github.com/SystemRDL/PeakRDL-regblock-vhdl/releases>`_
3542
- `Issue tracker <https://github.com/SystemRDL/PeakRDL-regblock-vhdl/issues>`_
3643
- `PyPi <https://pypi.org/project/peakrdl-regblock-vhdl>`_
37-
- `SystemVerilog Exporter <https://github.com/SystemRDL/PeakRDL-regblock>`_
3844
- `SystemRDL Specification <http://accellera.org/downloads/standards/systemrdl>`_
3945

4046

@@ -86,3 +92,5 @@ Links
8692
udps/read_buffering
8793
udps/write_buffering
8894
udps/extended_swacc
95+
udps/signed
96+
udps/fixedpoint

docs/udps/fixedpoint.rst

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
.. _fixedpoint:
2+
3+
Fixed-Point Fields
4+
==================
5+
6+
`Fixed-point <https://en.wikipedia.org/wiki/Fixed-point_arithmetic>`_ numbers
7+
can be used to efficiently represent real numbers using integers. Fixed-point
8+
numbers consist of some combination of integer bits and fractional bits. The
9+
number of integer/fractional bits is usually implicitly tracked (not stored)
10+
for each number, unlike for floating-point numbers.
11+
12+
For this VHDL exporter, these properties only affect the signal type in
13+
the the ``hwif`` structs. There is no special handling in the internals of
14+
the regblock.
15+
16+
Properties
17+
----------
18+
Fields can be declared as fixed-point numbers using the following two properties:
19+
20+
.. literalinclude:: ../../hdl-src/regblock_udps.rdl
21+
:lines: 46-54
22+
23+
The :ref:`is_signed<signed>` property can be used in conjunction with these
24+
properties to declare signed fixed-point fields.
25+
26+
These UDP definitions, along with others supported by PeakRDL-regblock, can be
27+
enabled by compiling the following file along with your design:
28+
:download:`regblock_udps.rdl <../../hdl-src/regblock_udps.rdl>`.
29+
30+
.. describe:: intwidth
31+
32+
* The ``intwidth`` property defines the number of integer bits in the
33+
fixed-point representation (including the sign bit, if present).
34+
35+
.. describe:: fracwidth
36+
37+
* The ``fracwidth`` property defines the number of fractional bits in the
38+
fixed-point representation.
39+
40+
Representable Numbers
41+
^^^^^^^^^^^^^^^^^^^^^
42+
43+
The range of representable real numbers is summarized in the table below.
44+
45+
.. list-table:: Representable Numbers
46+
:header-rows: 1
47+
48+
* - Signedness
49+
- Minimum Value
50+
- Maximum Value
51+
- Step Size
52+
53+
* - Unsigned
54+
- :math:`0`
55+
- :math:`2^{\mathrm{intwidth}} - 2^{-\mathrm{fracwidth}}`
56+
- :math:`2^{-\mathrm{fracwidth}}`
57+
58+
* - Signed
59+
- :math:`-2^{\mathrm{intwidth}-1}`
60+
- :math:`2^{\mathrm{intwidth}-1} - 2^{-\mathrm{fracwidth}}`
61+
- :math:`2^{-\mathrm{fracwidth}}`
62+
63+
VHDL Types
64+
^^^^^^^^^^
65+
66+
The standard VHDL-2008 types defined in ``ieee.fixed_pkg`` are used for
67+
fixed-point numbers.
68+
69+
When either ``intwidth`` or ``fracwidth`` are defined for a field, that field's
70+
type in the generated VHDL ``hwif`` record is ``ufixed(intwidth-1 downto -fracwidth)``,
71+
or ``sfixed(intwidth-1 downto -fracwidth)`` if ``is_signed`` is true. The bit at
72+
index :math:`i` contributes a weight of :math:`2^i` to the real number represented.
73+
74+
Other Rules
75+
^^^^^^^^^^^
76+
* Only one of ``intwidth`` or ``fracwidth`` need be defined. The other is
77+
inferred from the field bit width.
78+
* The bit width of the field shall be equal to ``intwidth`` + ``fracwidth``.
79+
* If both ``intwidth`` and ``fracwidth`` are defined for a field, it is an
80+
error if their sum does not equal the bit width of the field.
81+
* Either ``fracwidth`` or ``intwidth`` can be a negative integer. Because
82+
SystemRDL does not have a signed integer type, the only way to achieve
83+
this is to define one of the widths as larger than the bit width of the
84+
component so that the other width is inferred as a negative number.
85+
* The properties defined above are mutually exclusive with the ``counter``
86+
property.
87+
* The properties defined above are mutually exclusive with the ``encode``
88+
property.
89+
90+
Examples
91+
--------
92+
93+
A 12-bit signed fixed-point field with 4 integer bits and 8 fractional bits
94+
can be declared with
95+
96+
.. code-block:: systemrdl
97+
:emphasize-lines: 3, 4
98+
99+
field {
100+
sw=rw; hw=r;
101+
intwidth = 4;
102+
is_signed;
103+
} fixedpoint_num[11:0] = 0;
104+
105+
This field can represent values from -8.0 to 7.99609375
106+
in steps of 0.00390625.

docs/udps/intro.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,26 @@ To enable these UDPs, compile this RDL file prior to the rest of your design:
6060
- Enables an output strobe that is asserted on sw writes.
6161

6262
See: :ref:`extended_swacc`.
63+
64+
* - is_signed
65+
- field
66+
- boolean
67+
- Defines the signedness of a field.
68+
69+
See: :ref:`signed`.
70+
71+
* - intwidth
72+
- field
73+
- unsigned integer
74+
- Defines the number of integer bits in the fixed-point representation
75+
of a field.
76+
77+
See: :ref:`fixedpoint`.
78+
79+
* - fracwidth
80+
- field
81+
- unsigned integer
82+
- Defines the number of fractional bits in the fixed-point representation
83+
of a field.
84+
85+
See: :ref:`fixedpoint`.

docs/udps/signed.rst

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
.. _signed:
2+
3+
Signed Fields
4+
=============
5+
6+
SystemRDL does not natively provide a way to mark fields as signed or unsigned.
7+
The ``is_signed`` user-defined property fills this need.
8+
9+
For this VHDL exporter, marking a field as signed only affects the
10+
signal type in the ``hwif`` structs. There is no special handling in the internals
11+
of the regblock.
12+
13+
Properties
14+
----------
15+
A field can be marked as signed using the following user-defined property:
16+
17+
.. literalinclude:: ../../hdl-src/regblock_udps.rdl
18+
:lines: 40-44
19+
20+
This UDP definition, along with others supported by PeakRDL-regblock, can be
21+
enabled by compiling the following file along with your design:
22+
:download:`regblock_udps.rdl <../../hdl-src/regblock_udps.rdl>`.
23+
24+
.. describe:: is_signed
25+
26+
* Assigned value is a boolean.
27+
* If true, the hardware interface field will have the type
28+
``signed(width-1 downto 0)``.
29+
* If false, the hardware interface field will have the type
30+
``unsigned(width-1 downto 0)``.
31+
* If not assigned, the field will have the regular ``std_logic`` or
32+
``std_logic_vector`` type.
33+
34+
Other Rules
35+
^^^^^^^^^^^
36+
37+
* ``is_signed=true`` is mutually exclusive with the ``counter`` property.
38+
* ``is_signed=true`` is mutually exclusive with the ``encode`` property.
39+
40+
Examples
41+
--------
42+
Below are some examples of fields with different signedness.
43+
44+
Signed Fields
45+
^^^^^^^^^^^^^
46+
.. code-block:: systemrdl
47+
:emphasize-lines: 3, 8
48+
49+
field {
50+
sw=rw; hw=r;
51+
is_signed;
52+
} signed_num[63:0] = 0;
53+
54+
field {
55+
sw=r; hw=w;
56+
is_signed = true;
57+
} another_signed_num[19:0] = 20'hFFFFF; // -1
58+
59+
SystemRDL's own integer type is always unsigned. In order to specify a negative
60+
reset value, the two's complement value must be used as shown in the second
61+
example above.
62+
63+
Unsigned Fields
64+
^^^^^^^^^^^^^^^
65+
.. code-block:: systemrdl
66+
:emphasize-lines: 3
67+
68+
field {
69+
sw=rw; hw=r;
70+
is_signed = false;
71+
} unsigned_num[63:0] = 0;

0 commit comments

Comments
 (0)