Floating point implementation refactoring#481
Open
fdxmw wants to merge 2 commits intoUCSBarchlab:developmentfrom
Open
Floating point implementation refactoring#481fdxmw wants to merge 2 commits intoUCSBarchlab:developmentfrom
fdxmw wants to merge 2 commits intoUCSBarchlab:developmentfrom
Conversation
* The concatenated value can be set with the special `kwarg` "_value". This is useful when the `wire_struct`'s class name is not known. * Changes to make `wire_structs` documentable with Sphinx. The generated class copies documentation from the decorated class (`__doc__`), and the generated class's name now matches the decorated class's name. Previously all `wire_structs` were named `_WireStruct`. * Add a new `class_name` argument to `wire_matrix`. This lets users optionally set the name of the generated class. Previously all `wire_matrix` were named `_WireMatrix`.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## development #481 +/- ##
=============================================
- Coverage 92.0% 91.9% -0.0%
=============================================
Files 31 30 -1
Lines 7508 7437 -71
=============================================
- Hits 6901 6834 -67
+ Misses 607 603 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Member
Author
|
@gaborszita Here's the refactoring changes I had in mind for I also tried to clean up the documentation a bit, you can see what it currently looks like at https://pyrtl--481.org.readthedocs.build/en/481/rtllib.html#module-pyrtl.rtllib.float |
* Define canonical `wire_struct` `Float` types, and use them as the source of truth for the number of exponent and mantissa bits. See `Float16` for an example. All operators are generic, and accept any of these `Float` types as input, and produce the same `Float` type as output. So if you add a `Float16` with a `Float16`, you get a `Float16`. If the operand types do not match, a `PyrtlError` is raised. This lets us remove `_fp_wire_struct`, `FPTypeProperties`, `FloatingPointType`, `PyrtlFloatConfig` because operands now carry their own metadata and describe themselves. For example, we can inspect the operand's mantissa bitwidth directly with `operand.mantissa.bitwidth`, rather than passing around another data structure. * Remove the `FloatOperations` classes. They are no longer needed because the top-level `add`, `sub`, and `mul` functions are generic, and work with any matching `Float` types. The default rounding mode can be set with `set_default_rounding_mode`, and can be changed for individual operations. * Rename the package from `pyrtlfloat` to just `float`. The full package name was `pyrtl.rtllib.pyrtlfloat`, which was redundant. * Rename `mul` to `mult` for symmetry with `signed_mult`. * Rename `make_inf` and friends to `make_inf_like`. These functions now take an operand that specifies the desired output bitwidths, similar to `np.ones_like`. * Remove `make_zero`. It is clearer to directly set the exponent and mantissa to `0`. * Use `dataclass` to simplify some class definitions. * Use absolute imports (https://peps.python.org/pep-0008/#imports). * Rename some variables to improve readability. * Update `rtllib.rst` to generate Sphinx documentation for the `float` package.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This builds on the
wire_structimprovements in #480.Define canonical
wire_structFloattypes, and use them as the source oftruth for the number of exponent and mantissa bits. See
Float16for anexample. All operators are generic, and accept any of these
Floattypes asinput, and produce the same
Floattype as output. So if you add aFloat16with a
Float16, you get aFloat16. If the operand types do not match, aPyrtlErroris raised.This lets us remove
_fp_wire_struct,FPTypeProperties,FloatingPointType,PyrtlFloatConfigbecause operands now carry their ownmetadata and describe themselves. For example, we can inspect the operand's
mantissa bitwidth directly with
operand.mantissa.bitwidth, rather thanpassing around another data structure.
Remove the
FloatOperationsclasses. They are no longer needed because thetop-level
add,sub, andmulfunctions are generic, and work with anymatching
Floattypes. The default rounding mode can be set withset_default_rounding_mode, and can be changed for individual operations.Rename the package from
pyrtlfloatto justfloat. The full package namewas
pyrtl.rtllib.pyrtlfloat, which was redundant.Rename
multomultfor symmetry withsigned_mult.Rename
make_infand friends tomake_inf_like. These functions now take anoperand that specifies the desired output bitwidths, similar to
np.ones_like.Remove
make_zero. It is clearer to directly set the exponent and mantissato
0.Use
dataclassto simplify some class definitions.Use absolute imports (https://peps.python.org/pep-0008/#imports).
Rename some variables to improve readability.
Update
rtllib.rstto generate Sphinx documentation for thefloatpackage.