Netlist Utils

HAL Netlist Utility functions.

hal_py.NetlistUtils.copy_netlist(nl: hal_py.Netlist) hal_py.Netlist

Get a deep copy of an entire netlist including all of its gates, nets, modules, and groupings.

Parameters

nl (hal_py.Netlist) – The netlist to copy.

Returns

The deep copy of the netlist.

Return type

hal_py.Netlist

hal_py.NetlistUtils.get_common_inputs(gates: List[hal::Gate], threshold: int = 0) List[hal::Net]

Returns all nets that are considered to be common inputs to the provided gates. A threshold value can be provided to specify the number of gates a net must be connected to in order to be classified as a common input. If the theshold value is set to 0, a net must be input to all gates to be considered a common input.

Parameters
  • gates (list[hal_py.Gate]) – The gates.

  • threshold (int) – The threshold value, defaults to 0.

Returns

The common input nets.

Return type

list[hal_py.Net]

hal_py.NetlistUtils.get_complex_gate_chain(start_gate: hal::Gate, chain_types: List[hal_py.GateType], input_pins: Dict[hal_py.GateType, List[hal::GatePin]], output_pins: Dict[hal_py.GateType, List[hal::GatePin]], filter: Callable[[hal::Gate], bool] = None) List[hal::Gate]

Find a sequence of gates (of the specified sequence of gate types) that are connected via the specified input and output pins. The start gate may be any gate within a such a sequence, it is not required to be the first or the last gate. However, the start gate must be of the first gate type within the repeating sequence. If input and/or output pins are specified for a gate type, the gates must be connected through one of the input pins and/or one of the output pins. The optional filter is evaluated on every gate such that the result only contains gates matching the specified condition.

Parameters
  • start_gate (hal_py.Gate) – The gate at which to start the chain detection.

  • chain_types (list[hal_py.GateType]) – The sequence of gate types that is expected to make up the gate chain.

  • input_pins (dict[hal_py.GateType,set[str]]) – The input pins through which the gates are allowed to be connected.

  • output_pins (dict[hal_py.GateType,set[str]]) – The output pins through which the gates are allowed to be connected.

  • filter (lambda) – A filter that is evaluated on all candidates.

Returns

A list of gates that form a chain.

Return type

list[hal_py.Gate]

hal_py.NetlistUtils.get_ff_dependency_matrix(nl: hal_py.Netlist) Tuple[Dict[int, hal::Gate], List[List[int]]]

Get the FF dependency matrix of a netlist.

Parameters

nl (hal_py.Netlist) – The netlist to extract the dependency matrix from.

Returns

A pair consisting of std::map<u32, Gate*>, which includes the mapping from the original gate

Return type

pair(dict(int, hal_py.Gate), list[list[int]])

hal_py.NetlistUtils.get_gate_chain(start_gate: hal::Gate, input_pins: List[hal::GatePin] = [], output_pins: List[hal::GatePin] = [], filter: Callable[[hal::Gate], bool] = None) List[hal::Gate]

Find a sequence of identical gates that are connected via the specified input and output pins. The start gate may be any gate within a such a sequence, it is not required to be the first or the last gate. If input and/or output pins are specified, the gates must be connected through one of the input pins and/or one of the output pins. The optional filter is evaluated on every gate such that the result only contains gates matching the specified condition.

Parameters
  • start_gate (hal_py.Gate) – The gate at which to start the chain detection.

  • input_pins (list[hal_py.GatePin]) – The input pins through which the gates must be connected. Defaults to an empty list.

  • output_pins (set[hal_py.GatePin]) – The output pins through which the gates must be connected. Defaults to an empty list.

  • filter (lambda) – An optional filter function to be evaluated on each gate.

Returns

A list of gates that form a chain on success, an empty list on error.

Return type

list[hal_py.Gate]

hal_py.NetlistUtils.get_nets_at_pins(gate: hal::Gate, pins: List[hal::GatePin]) List[hal::Net]

Get the nets that are connected to a subset of pins of the specified gate.

Parameters
Returns

The list of nets connected to the pins.

Return type

list[hal_py.Net]

hal_py.NetlistUtils.get_next_gates(*args, **kwargs)

Overloaded function.

  1. get_next_gates(gate: hal::Gate, get_successors: bool, depth: int = 0, filter: Callable[[hal::Gate], bool] = None) -> List[hal::Gate]

    Find predecessors or successors of a gate. If depth is set to 1 only direct predecessors/successors will be returned. Higher number of depth causes as many steps of recursive calls. If depth is set to 0 there is no limitation and the loop continues until no more predecessors/succesors are found. If a filter function is given, the recursion stops whenever the filter function evaluates to False. Only gates matching the filter will be added to the result vector. The result will not include the provided gate itself.

    param hal_py.Gate gate

    The initial gate.

    param bool get_successors

    True to return successors, False for Predecessors.

    param int depth

    Depth of recursion.

    param lambda filter

    User-defined filter function.

    returns

    List of predecessor/successor gates.

    rtype

    list[hal_py.Gate]

  2. get_next_gates(net: hal::Net, get_successors: bool, depth: int = 0, filter: Callable[[hal::Gate], bool] = None) -> List[hal::Gate]

    Find predecessors or successors of a net. If depth is set to 1 only direct predecessors/successors will be returned. Higher number of depth causes as many steps of recursive calls. If depth is set to 0 there is no limitation and the loop continues until no more predecessors/succesors are found. If a filter function is given, the recursion stops whenever the filter function evaluates to False. Only gates matching the filter will be added to the result vector.

    param hal_py.Net net

    The initial net.

    param bool get_successors

    True to return successors, False for Predecessors.

    param int depth

    Depth of recursion.

    param lambda filter

    User-defined filter function.

    returns

    List of predecessor/successor gates.

    rtype

    list[hal_py.Gate]

hal_py.NetlistUtils.get_next_sequential_gates(*args, **kwargs)

Overloaded function.

  1. get_next_sequential_gates(gate: hal::Gate, get_successors: bool, cache: Dict[int, List[hal::Gate]]) -> List[hal::Gate]

    Find all sequential predecessors or successors of a gate. Traverses combinational logic of all input or output nets until sequential gates are found. The result may include the provided gate itself. The use of the this cached version is recommended in case of extensive usage to improve performance. The cache will be filled by this function and should initially be provided empty. Different caches for different values of get_successors shall be used.

    param hal_py.Gate gate

    The initial gate.

    param bool get_successors

    If true, sequential successors are returned, otherwise sequential predecessors are returned.

    param dict[int, list[hal_py.Gate]] cache

    The cache.

    returns

    All sequential successors or predecessors of the gate.

    rtype

    list[hal_py.Gate]

  2. get_next_sequential_gates(gate: hal::Gate, get_successors: bool) -> List[hal::Gate]

    Find all sequential predecessors or successors of a gate. Traverses combinational logic of all input or output nets until sequential gates are found. The result may include the provided gate itself.

    param hal_py.Gate gate

    The initial gate.

    param bool get_successors

    If true, sequential successors are returned, otherwise sequential predecessors are returned.

    returns

    All sequential successors or predecessors of the gate.

    rtype

    list[hal_py.Gate]

  3. get_next_sequential_gates(net: hal::Net, get_successors: bool, cache: Dict[int, List[hal::Gate]]) -> List[hal::Gate]

    Find all sequential predecessors or successors of a net. Traverses combinational logic of all input or output nets until sequential gates are found. The use of the cache is recommended in case of extensive usage of this function. The cache will be filled by this function and should initially be provided empty. Different caches for different values of get_successors shall be used.

    param hal_py.Net net

    The initial net.

    param bool get_successors

    If true, sequential successors are returned, otherwise sequential predecessors are returned.

    param dict[int, list[hal_py.Gate]] cache

    The cache.

    returns

    All sequential successors or predecessors of the net.

    rtype

    list[hal_py.Net]

  4. get_next_sequential_gates(net: hal::Net, get_successors: bool) -> List[hal::Gate]

    Find all sequential predecessors or successors of a net. Traverses combinational logic of all input or output nets until sequential gates are found.

    param hal_py.Net net

    The initial net.

    param bool get_successors

    If true, sequential successors are returned, otherwise sequential predecessors are returned.

    returns

    All sequential successors or predecessors of the net.

    rtype

    list[hal_py.Net]

hal_py.NetlistUtils.get_path(*args, **kwargs)

Overloaded function.

  1. get_path(gate: hal::Gate, get_successors: bool, stop_properties: Set[hal_py.GateTypeProperty], cache: Dict[int, List[hal::Gate]]) -> List[hal::Gate]

    Find all gates on the predecessor or successor path of a gate. Traverses all input or output nets until gates of the specified base types are found. The result may include the provided gate itself. The use of the this cached version is recommended in case of extensive usage to improve performance. The cache will be filled by this function and should initially be provided empty. Different caches for different values of get_successors shall be used.

    param hal_py.Gate gate

    The initial gate.

    param bool get_successors

    If true, the successor path is returned, otherwise the predecessor path is returned.

    param set[hal_py.GateTypeProperty] stop_properties

    Stop recursion when reaching a gate of a type with one of the specified properties.

    param dict[int, list[hal_py.Gate]] cache

    The cache.

    returns

    All gates on the predecessor or successor path of the gate.

    rtype

    list[hal_py.Gate]

  2. get_path(gate: hal::Gate, get_successors: bool, stop_properties: Set[hal_py.GateTypeProperty]) -> List[hal::Gate]

    Find all gates on the predeccessor or successor path of a gate. Traverses all input or output nets until gates of the specified base types are found. The result may include the provided gate itself.

    param hal_py.Gate gate

    The initial gate.

    param bool get_successors

    If true, the successor path is returned, otherwise the predecessor path is returned.

    param set[hal_py.GateTypeProperty] stop_properties

    Stop recursion when reaching a gate of a type with one of the specified properties.

    returns

    All gates on the predecessor or successor path of the gate.

    rtype

    list[hal_py.Gate]

  3. get_path(net: hal::Net, get_successors: bool, stop_properties: Set[hal_py.GateTypeProperty], cache: Dict[int, List[hal::Gate]]) -> List[hal::Gate]

    Find all gates on the predecessor or successor path of a net. Traverses all input or output nets until gates of the specified base types are found. The use of the this cached version is recommended in case of extensive usage to improve performance. The cache will be filled by this function and should initially be provided empty. Different caches for different values of get_successors shall be used.

    param hal_py.Net net

    The initial net.

    param bool get_successors

    If true, the successor path is returned, otherwise the predecessor path is returned.

    param set[hal_py.GateTypeProperty] stop_properties

    Stop recursion when reaching a gate of a type with one of the specified properties.

    param dict[int, list[hal_py.Gate]] cache

    The cache.

    returns

    All gates on the predecessor or successor path of the net.

    rtype

    list[hal_py.Net]

  4. get_path(net: hal::Net, get_successors: bool, stop_properties: Set[hal_py.GateTypeProperty]) -> List[hal::Gate]

    Find all gates on the predecessor or successor path of a net. Traverses all input or output nets until gates of the specified base types are found.

    param hal_py.Net net

    The initial net.

    param bool get_successors

    If true, the successor path is returned, otherwise the predecessor path is returned.

    param set[hal_py.GateTypeProperty] stop_properties

    Stop recursion when reaching a gate of a type with one of the specified properties.

    returns

    All gates on the predecessor or successor path of the net.

    rtype

    list[hal_py.Net]

hal_py.NetlistUtils.get_shortest_path(start_gate: hal::Gate, end_gate: hal::Gate, search_both_directions: bool = False) List[hal::Gate]

Find the shortest path (i.e., theresult set with the lowest number of gates) that connects the start gate with the end gate. The gate where the search started from will be the first in the result vector, the end gate will be the last. If there is no such path an empty vector is returned. If there is more than one path with the same length only the first one is returned.

Parameters
  • input_pins (dict[hal_py.GateType,list[hal_py.GatePin]]) – The input pins (of every gate type of the sequence) through which the gates must be connected.

  • output_pins (dict[hal_py.GateType,list[hal_py.GatePin]]) – The output pins (of every gate type of the sequence) through which the gates must be connected.

  • filter (lambda) – An optional filter function to be evaluated on each gate.

Returns

A list of gates that form a chain on success, an empty list on error.

Return type

list[hal_py.Gate]

hal_py.NetlistUtils.get_subgraph_function(net: hal::Net, subgraph_gates: List[hal::Gate]) hal::BooleanFunction

Get the combined Boolean function of a subgraph of combinational gates starting at the source of the given net. The variables of the resulting Boolean function are made up of the IDs of the nets that influence the output (‘net_[ID]’).

Parameters
  • net (hal_py.Net) – The output net for which to generate the Boolean function.

  • subgraph_gates (list[hal_py.Gate]) – The gates making up the subgraph.

Returns

The combined Boolean function of the subgraph on success, an empty Boolean function otherwise.

Return type

hal_py.BooleanFunction

hal_py.NetlistUtils.remove_buffers(netlist: hal_py.Netlist, analyze_inputs: bool = False) int

Remove all buffer gates from the netlist and connect their fan-in to their fan-out nets. If enabled, analyzes every gate’s inputs and removes fixed ‘0’ or ‘1’ inputs from the Boolean function.

Parameters
  • netlist (hal_py.Netlist) – The target netlist.

  • analyze_inputs (bool) – Set True to dynamically analyze the inputs, False otherwise.

Returns

The number of removed buffers on success, -1 otherwise.

Return type

int

hal_py.NetlistUtils.remove_unused_lut_endpoints(netlist: hal_py.Netlist) int

Remove all LUT fan-in endpoints that are not present within the Boolean function of the output of a gate.

Parameters

netlist (hal_py.Netlist) – The target netlist.

Returns

The number of removed endpionts on success, -1 otherwise.

Return type

int

hal_py.NetlistUtils.replace_gate(gate: hal::Gate, target_type: hal_py.GateType, pin_map: Dict[hal::GatePin, hal::GatePin]) int

Replace the given gate with a gate of the specified gate type. A dict from old to new pins must be provided in order to correctly connect the gates inputs and outputs. A pin can be omitted if no connection at that pin is desired.

Parameters
Returns

True on success, False otherwise.

Return type

bool