Floating point implementation refactoring#481
Floating point implementation refactoring#481fdxmw wants to merge 2 commits intoUCSBarchlab:developmentfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## development #481 +/- ##
=============================================
- Coverage 91.9% 91.9% -0.0%
=============================================
Files 31 30 -1
Lines 7506 7440 -66
=============================================
- Hits 6898 6836 -62
+ Misses 608 604 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@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 |
ab66820 to
f1aeaa1
Compare
* 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.
|
Than you for your suggestions, I'll take a look at them this week! |
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.