netlist_carpentry.routines.opt.constant_folds
¶
A collection of constant folding algorithms.
Functions:
-
opt_constant–Executes several optimization routines on the given module.
-
opt_constant_mux_inputs–Optimizes multiplexers, where both inputs are constant, by replacing them with the appropriate constant signal.
-
opt_constant_propagation–Executes constant propagation to simplify the circuit.
opt_constant
¶
Executes several optimization routines on the given module.
These routines currently include constant propagation and constant multiplexer replacement. More passes may follow in the future
Parameters:
Returns:
-
bool(bool) –True if any optimizations were executed, False otherwise.
opt_constant_mux_inputs
¶
Optimizes multiplexers, where both inputs are constant, by replacing them with the appropriate constant signal.
If both inputs are constant and equal, the output is equal to the constant input.
If both inputs are constant and unequal (i.e. one is 0 and one is 1), the output is either
equal to S or !S, depending on which input is 0 and which is 1.
If S is constant, the instance can be removed, since the output follows the corresponding input signal.
Parameters:
Returns:
-
bool(bool) –True if any optimizations were executed. False if this module is already optimized in regards to constant multiplexers.
opt_constant_propagation
¶
Executes constant propagation to simplify the circuit.
Constant propagation replaces expressions with known constant values.
By substituting constants it simplifies expressions, exposes dead instances and other optimization opportunities, and can reduce circuit size.
For example, if the framework knows A = 0 and later sees B = A && 1, it can replace B with 0 and eliminate the original assignment,
since this expression can never be 1, as A is known to be 0, and 0 && x is always 0.
Parameters:
Returns:
-
bool(bool) –True if any optimizations were executed. False if this module is already optimized in regards to constant propagation.