Skip to content
SJulianS edited this page Oct 19, 2022 · 17 revisions

A (logical) gate is an electronic component comprising multiple in- and outputs that implements one or more Boolean function(s). A gate may implement either combinational or sequential logic and is commonly connected to a number of nets via its input and output pins. It can thus be used in larger circuits to implement complex logic operations. Such a circuit is usually referred to as a gate-level netlist.

Gate Information and Management

Similar to all other netlist components in HAL, a gate comprises basic information such as an ID, a name, and a gate type that can be read and sometimes written using dedicated commands such as get_id, get_name, set_name, and get_type. A gate can be created by using create_gate on the netlist while specifying its gate type and name. Furthermore, a gate can return the module and the grouping it is assigned to using get_module and get_grouping.

g = netlist.create_gate(some_gt, "example_gate")   # create a new gate
id = g.get_id()                                    # get the gate's ID
name = g.get_name()                                # get the gate's name
grouping = g.get_grouping()                        # get the gate's grouping

Additionally, a gate can be retrieved from the netlist by ID using get_gate_by_id and may be deleted using delete_gate. Note that deleting a gate may result in dangling wires.

g = netlist.get_gate_by_id(3)   # get the gate with ID 3 from the netlist
netlist.delete_gate(g)          # delete the gate

Gate Connections

Each gate has multiple input, output, inout or internal pins that are potentially connected to a variety of nets. The user can retrieve the pins via its gate type. The net connected to a pin can be retrieved using get_fan_in_net and get_fan_out_net by providing either the pin itself or just its name. If required, the endpoint of a pin is accessible via get_fan_in_endpoint and get_fan_out_endpoint. A list of all connected nets or endpoints of the gate is also available via get_fan_in_nets, get_fan_out_nets, get_fan_in_endpoints and get_fan_out_endpoints.

out_net = g.get_fan_out_net(out_pins[0])       # get net connected to first output pin
out_ep = g.get_fan_out_endpoint(out_pins[0])   # get endpoint of first output pin
in_eps = g.get_fan_in_endpoints()              # get all endpoints at input pins

Easy access to the predecessors and successors of a gate is provided by the functions get_predecessors and get_successors. Both functions return a list of endpoints. Each of the endpoints describes the successor/predecessor gate, the destination/source pin (i.e., the pin at the successor/predecessor gate), and the net through which the successor/predecessor is connected to the current gate. The functions get_unique_predecessors and get_unique_successors return a list of gates with each gate being included in the list at most once, no matter whether the gate is predecessor or successor to multiple pins or just a single one.

pred = g.get_predecessors()               # get all predecessor endpoints
unique_succ = g.get_unique_successors()   # get all unique successor gates

Boolean Functions

The function(s) implemented by a gate are defined by their Boolean function(s). Usually, these Boolean functions are specified by the gate type and not the gate itself. However, for FPGA netlists containing LUTs it is not sufficient to store the Boolean function solely with the gate type since different gates of the same LUT gate type may implement different functions. Therefore, the functions get_boolean_function and get_boolean_functions may be used to retrieve Boolean functions associated with a gate and its gate type. Hence we recommend always retrieving Boolean functions from individual gates and not gate types. For the LUT gate type, Boolean functions are automatically created from their initialization string and cached until this string changes. Additional Boolean functions may be added to a gate using add_boolean_function.

func = gate.get_boolean_function("O")      # get Boolean function with name "O"
all_funcs = gate.get_boolean_functions()   # get all Boolean functions associated with gate and its type

Special Gates

Each gate library is required to provide dedicated gate types for Vcc and GND. Instances of these gate type are connected to constant 1 or 0 signals and need to be marked as such by using mark_vcc_gate and mark_gnd_gate. This process can be reversed using unmark_vcc_gate and unmark_gnd_gate. Whether a gate is a Vcc or GND gate can be determined using is_vcc_gate and is_gnd_gate. Marking gates as Vcc or GND gates is usually taken care of by the netlist parser and should not be done by the user.

gate.mark_vcc_gate()        # mark a gate as a Vcc gate
print(gate.is_vcc_gate())   # prints True
gate.unmark_vcc_gate()      # unmark the Vcc gate

By providing the gate as input, all these functions can also be executed on the netlist itself. In addition, calling get_vcc_gates or get_gnd_gates on the netlist returns a list of all Vcc or GND gates respectively.

gate = netlist.get_gate_by_id(3)   # get gate with ID 3
netlist.mark_vcc_gate(gate)        # mark gate as Vcc gate
netlist.is_vcc_gate(gate)          # returns True
netlist.unmark_vcc_gate(gate)      # unmark gate
netlist.get_gnd_gates()            # return all GND gates
Clone this wiki locally