python2verilog.optimizer package

Submodules

python2verilog.optimizer.helpers module

Optimizer helper functions

backwards_replace(expr: Expression, mapping: dict[Var, Expression]) Expression[source]

If the expression matches a key in the mapping, it is replaced with the corresponding value in the mapping.

Note: ignores exclusive vars in replacement process

Returns:

a copy of the updated expression.

python2verilog.optimizer.increase_work module

IncreaseWorkPerClockCycle

class IncreaseWorkPerClockCycle(root: Node, threshold: int = 0)[source]

Bases: object

A closure for the increase work per clock cycle optimizer

threshold (an integer >= 0) tunes how much the code can be unrolled (and duplicated)

A larger threshold will result in a reduction in clock cycles, but an increase in hardware usage

If a python generator function generates all of its outputs in O(n) time:

  1. hardware optimized with threshold=0 completes in O(n) cycles

  2. hardware optimized with threshold=x for x > 0 completes in O(n/(x+1)) cycles

apply(root: Node) None[source]

Optimizes a node, by increasing amount of work done in a cycle. Creates an optimal path that maximizes nonclocked edges.

apply_recursive(edge: Edge, new_mapping: dict[Var, Expression], old_mapping: dict[Var, Expression], visited_path: dict[str, int]) Edge[source]

Recursively visits the children, conditionally adding them to an optimal path

The concept of mapping is as follows:

If a = 1 b = a then b == 1, if no clock cycle occurs in-between, at the end of this block, mapping would be {a: 1, b: 1}

Parameters:
  • mapping – values of variables, given the previous logic

  • visited – visited unique_ids and exclusive vars for this nonclocked sequence

static chain_generators(iterable: Iterator[Any], *functions: Callable[[Iterator[Any]], Iterator[Any]]) Iterator[Any][source]

Applies transformations to iterators

static exclusive_vars(variables) Iterator[ExclusiveVar][source]

Filters for exclusive variables

static map_to_ver_name(variables) Iterator[str][source]

Maps a variable to its ver_name

Module contents

Optimizer Functions