21 NAND Docs 中文

Netlist format

A TapeOut circuit's netlist is a list of two-input NAND gates: pairs says which two wires each gate connects to, taps says which wires the outputs come from.

Fields

FieldTypeMeaning
pairs[[a, b], …]NAND gates in order. pairs[i] = [a, b] means this gate's output = NAND(wire a, wire b). Required
taps[int, …]Which wire output o comes from. Required
nInintNumber of inputs
nOutintNumber of outputs, equal to len(taps)
gintNumber of gates, equal to len(pairs)
dintDepth: the largest depth among all output wires
CintCost g · d³
srcId or idintProblem number. Different files use different key names for the same thing
last_outsboolWhether the outputs are exactly the last nOut gates

The on-chain format adds:

FieldMeaning
enc"chain"
n_base2 + nIn: the constants ZERO and ONE plus the inputs
nl_hexThe on-chain netlist bytes in hexadecimal, starting with 0x
nl_lenNumber of bytes nl_hex decodes to

Wire numbers

There are two numberings; they differ in the constants.

Inputs from 0 (common in design tool output):

WireWhat it isDepth
0 … nIn−1Inputs in0 … in{nIn−1}0
nIn + iGate i1 + max(depth a, depth b)

On-chain format (constants take 0 and 1):

WireWhat it isDepth
0Constant ZERO, not a gate0
1Constant ONE, not a gate0
2 … nIn+1Inputs0
n_base + iGate i, counted in g1 + max(depth a, depth b)

Gates

val[w] = 1 − (val[a] & val[b])

Depth and cost

Outputs must be the last gates

The on-chain format requires taps to be exactly the last nOut gates:

base = nIn (inputs from 0) or n_base (on-chain format)
taps == [base + g − nOut, …, base + g − 1], and 0 < nOut ≤ g

If not, convert first: copy the output gates to the end, then delete gates nobody uses. Conversion may add gates or depth, so the cost is computed from g and d after conversion.

On-chain netlist bytes (nl_hex)

A pure NAND netlist uses 7 bytes per gate:

OffsetLengthContent
01opcode, 0 = NAND2
13Wire number of input a, big-endian
43Wire number of input b, big-endian

Total length = g × 7. Wire numbers are in the on-chain format.

Truth table bit order

Example

One circuit with 6 inputs and 3 outputs, in both formats:

ItemInputs from 0On-chain format
nIn, nOut6, 36, 3
g, d47, 847, 8
C24,064 = 47 × 8³Same as left
n_base—8
First three gates[0,0], [2,2], [6,7][2,2], [4,4], [8,9]
taps[50, 51, 52] = starting at 6 + 47 − 3[52, 53, 54] = starting at 8 + 47 − 3
nl_len—329 = 47 × 7
Start of nl_hex—0x00 000002 000002 … (the first gate, NAND(2, 2))

Invalid netlists

Not decided yet