Commit 245d3c0
committed
Floating point implementation refactoring:
* 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.1 parent 69781de commit 245d3c0
11 files changed
Lines changed: 580 additions & 728 deletions
File tree
- docs
- pyrtl/rtllib
- float
- pyrtlfloat
- tests/rtllib
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
26 | 32 | | |
27 | 33 | | |
28 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
0 commit comments