-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
669df0e
commit 58c047d
Showing
7 changed files
with
138 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Common | ||
======== | ||
|
||
.. currentmodule:: rtlsim | ||
|
||
.. autoclass:: FxpProps | ||
:members: | ||
:undoc-members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ API Documentation | |
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
common | ||
Quantize |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,6 @@ | |
|
||
__author__ = "Teddy van Jerry (Wuqiong Zhao)" | ||
|
||
from .common import FxpProps | ||
from .Quantize import Quantize | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
"""Common definitions for the RTL Sim | ||
""" | ||
|
||
class FxpProps: | ||
"""Fixed-point properties. | ||
""" | ||
class Overflow: | ||
"""Overflow behavior | ||
""" | ||
WRAP = 0 | ||
"""Wrap around (default behavior)""" | ||
SATURATE = 1 | ||
|
||
class Rounding: | ||
"""Rounding behavior | ||
""" | ||
TRUNCATE = 0 | ||
"""Truncate the fractional part (default behavior)""" | ||
AROUND = 1 | ||
FLOOR = 2 | ||
CEIL = 3 | ||
FIX = 4 | ||
|
||
overflow_dict = { | ||
'wrap': Overflow.WRAP, | ||
'saturate': Overflow.SATURATE, | ||
} | ||
rounding_dict = { | ||
'truncate': Rounding.TRUNCATE, | ||
'around': Rounding.AROUND, | ||
'floor': Rounding.FLOOR, | ||
'ceil': Rounding.CEIL, | ||
'fix': Rounding.FIX, | ||
} | ||
|
||
def __init__(self) -> None: | ||
pass | ||
|
||
def __repr__(self) -> str: | ||
return f'FxpProps()' | ||
|
||
def vMinInt(self, S, W): | ||
"""Minimum value of the integer number (disregarding :code:`F`). | ||
:param S: Sign bit (:code:`True` for signed, :code:`False` for unsigned) | ||
:type S: boolean | ||
:param W: Word bit width | ||
:type W: positive integer | ||
""" | ||
return -(1 << (W - 1)) if S else 0 | ||
|
||
def vMin(self, S, W, F): | ||
"""Minimum value of the fixed-point number. | ||
:param S: Sign bit (:code:`True` for signed, :code:`False` for unsigned) | ||
:type S: boolean | ||
:param W: Word bit width | ||
:type W: positive integer | ||
:param F: Fractional bit width | ||
:type F: integer | ||
""" | ||
return FxpProps.v_min_int(S, W) / (2 ** F) | ||
|
||
def vMaxInt(self, S, W): | ||
"""Maximum value of the integer number (disregarding :code:`F`). | ||
:param S: Sign bit (:code:`True` for signed, :code:`False` for unsigned) | ||
:type S: boolean | ||
:param W: Word bit width | ||
:type W: positive integer | ||
""" | ||
return (1 << (W - 1)) - 1 if S else (1 << W) - 1 | ||
|
||
def vMax(self, S, W, F): | ||
"""Maximum value of the fixed-point number. | ||
:param S: Sign bit (:code:`True` for signed, :code:`False` for unsigned) | ||
:type S: boolean | ||
:param W: Word bit width | ||
:type W: positive integer | ||
:param F: Fractional bit width | ||
:type F: integer | ||
""" | ||
return FxpProps.v_max_int(S, W) / (2 ** F) | ||
|
||
def vRangeInt(self, S, W): | ||
"""Range of the integer number (disregarding :code:`F`). | ||
:param S: Sign bit (:code:`True` for signed, :code:`False` for unsigned) | ||
:type S: boolean | ||
:param W: Word bit width | ||
:type W: positive integer | ||
""" | ||
return FxpProps.v_max_int(S, W) - FxpProps.v_min_int(S, W) | ||
|
||
def vRange(self, S, W, F): | ||
"""Range of the fixed-point number. | ||
:param S: Sign bit (:code:`True` for signed, :code:`False` for unsigned) | ||
:type S: boolean | ||
:param W: Word bit width | ||
:type W: positive integer | ||
:param F: Fractional bit width | ||
:type F: integer | ||
""" | ||
return FxpProps.v_max(S, W, F) - FxpProps.v_min(S, W, F) | ||
|
||
def vPrevision(self, F): | ||
"""Prevision of the fixed-point number (:math:`2^{-F}`). | ||
:param F: Fractional bit width | ||
:type F: integer | ||
""" | ||
return 1 / (2 ** F) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
|
||
python3 test_rtlsim.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
import rtlsim | ||
|
||
quantize_u_8_4 = rtlsim.Quantize(False, 8, 4) |