ucb-bar / dsptools

A Library of Chisel3 Tools for Digital Signal Processing
Apache License 2.0
224 stars 38 forks source link

Add saturating addition/subtraction. #189

Closed grebe closed 4 years ago

grebe commented 4 years ago

This implements saturating addition/subtraction with inferred widths.

The problem is that you need to know the width of a number to be able to implement saturating add/sub. If the width is inferred, the frontend can't know what the max and min are.

To deal with this, we implement a pass that inserts a dummy operation with the right width inference behavior. This dummy operation is used in by FIRRTL for width inference, and then a later pass comes in and removes the dummy operation, replacing it with a saturating add/sub implementation.

FixedPoint and Interval support depend on this FIRRTL PR. This is because width inference and FixedPoint/Interval lowering both occur in the High->Mid stage of the compiler. This PR also depends somewhat on resolving this chisel issue because the dummy op would ideally be a +% b for FixedPoint, which is broken.