§ 1.3. Logic Gates¶
The logic gates are the leaves every structural circuit ends in. Each one-bit gate is a leaf part: it has no children, computes its output from its inputs with the four-state rule of its kind, and publishes it one gate delay later (§ 1.2 Gates). The word gates apply a one-bit gate to every bit of a word, so a recipe that treats a word bit by bit can use one part per word.
| Component | Description | Structural | Behavioral |
|---|---|---|---|
NOTGate |
Inverts one bit | Yes | No |
ANDGate |
1 when both inputs are 1 | Yes | No |
ORGate |
1 when either input is 1 | Yes | No |
NANDGate |
0 only when both inputs are 1 | Yes | No |
NORGate |
1 only when both inputs are 0 | Yes | No |
XORGate |
1 when the inputs differ | Yes | No |
ANDGate<W> |
One gate of a kind on every bit of a W-bit word; also NANDGate<W>, ORGate<W>, NORGate<W>, XORGate<W> and NOTGate<W> |
Yes | Yes |
A one-bit gate's "structural" form is the gate itself: a leaf with no smaller parts and no separate compact form. There is no one-bit XNOR gate; circuits build it as an XOR followed by a NOT.
1.3.1. NOTGate¶
NOTGate inverts one bit.
IO pins¶
| Pin | Direction | Width | Description |
|---|---|---|---|
IN |
Input | 1 | Operand bit |
OUT |
Output | 1 | Result bit |
Behavior¶
For binary inputs,
A rising input gives a falling output one gate delay later; in the realistic profiles the inverter is the fastest gate (one FO4 delay).
C++ example¶
This binary function describes the settled output. It is not a registered implementation.
Unknown inputs¶
X and Z both give X; the output never drives Z.
IN |
Settled OUT |
|---|---|
| 0 | 1 |
| 1 | 0 |
X or Z |
X |
Implementation¶
Structural implementation¶
NOTGate is a leaf: evaluate() reads the input, applies the four-state rule above and schedules the output one gate delay later. The delay is inertial: an input change that is undone before the output is published withdraws the pending output. The gate has no children, no state and no compact form; parts that need NOT on whole words use NOTGate<W>.
Examples¶
All 4 recorded rows of NOTGateTest, in checkpoint order. Outputs are test expectations verified against the simulation. Time is the absolute settled checkpoint time in simulator units, not milliseconds or CPU cycles.
Default scenario profile: fidelity-gate-v1 / structural (ed03f70afe360dba). Changing fidelity or the circuit can change these times.
| Checkpointzero-based number · timeline label | Timesimulator units | INInput · 1 bit |
OUTExpected output · 1 bit |
|---|---|---|---|
#0row-0 | 1 | 0 |
1 |
#1row-1 | 3 | 1 |
0 |
#2row-2 | 5 | X |
X |
#3row-3 | 7 | Z |
X |
Scroll within the table for all rows and pins. Buses use hexadecimal; values containing X/Z use MSB-first binary. Inputs show the declared values in effect at each checkpoint, including retained inputs. Sequential tests also replay preparation changes between checkpoints, such as lowering the clock. Use the matching checkpoint label in the simulation below.
The table covers all four input values; each row checks the settled output.
Embedded simulation¶
The not-gate scenario runs NOTGateTest.
Source and tests¶
| Test | Coverage |
|---|---|
NOTGateTest |
All four input values; the settled output of each |
SettlingAnalysisTest |
The gate settles within one gate delay |
1.3.2. ANDGate¶
ANDGate 1 when both inputs are 1.
IO pins¶
| Pin | Direction | Width | Description |
|---|---|---|---|
A |
Input | 1 | First operand bit |
B |
Input | 1 | Second operand bit |
OUT |
Output | 1 | Result bit |
Behavior¶
For binary inputs,
In the realistic profiles AND is a NAND followed by an inverter.
C++ example¶
This binary function describes the settled output. It is not a registered implementation.
Unknown inputs¶
A deciding input value fixes the output whatever the other input is; otherwise an unknown or floating input gives X. The output never drives Z.
A |
B |
Settled OUT |
|---|---|---|
| 0 | any | 0 |
| any | 0 | 0 |
| 1 | X or Z |
X |
X or Z |
1 or X or Z |
X |
Implementation¶
Structural implementation¶
ANDGate is a leaf: evaluate() reads the inputs, applies the four-state rule above and schedules the output one gate delay later. The delay is inertial: an input change that is undone before the output is published withdraws the pending output. The gate has no children, no state and no compact form; parts that need AND on whole words use ANDGate<W>.
Examples¶
All 16 recorded rows of ANDGateTest, in checkpoint order. Outputs are test expectations verified against the simulation. Time is the absolute settled checkpoint time in simulator units, not milliseconds or CPU cycles.
Default scenario profile: fidelity-gate-v1 / structural (ed03f70afe360dba). Changing fidelity or the circuit can change these times.
| Checkpointzero-based number · timeline label | Timesimulator units | AInput · 1 bit |
BInput · 1 bit |
OUTExpected output · 1 bit |
|---|---|---|---|---|
#0row-0 | 1 | 0 |
0 |
0 |
#1row-1 | 3 | 0 |
1 |
0 |
#2row-2 | 5 | 0 |
X |
0 |
#3row-3 | 7 | 0 |
Z |
0 |
#4row-4 | 9 | 1 |
0 |
0 |
#5row-5 | 11 | 1 |
1 |
1 |
#6row-6 | 13 | 1 |
X |
X |
#7row-7 | 15 | 1 |
Z |
X |
#8row-8 | 17 | X |
0 |
0 |
#9row-9 | 19 | X |
1 |
X |
#10row-10 | 21 | X |
X |
X |
#11row-11 | 23 | X |
Z |
X |
#12row-12 | 25 | Z |
0 |
0 |
#13row-13 | 27 | Z |
1 |
X |
#14row-14 | 29 | Z |
X |
X |
#15row-15 | 31 | Z |
Z |
X |
Scroll within the table for all rows and pins. Buses use hexadecimal; values containing X/Z use MSB-first binary. Inputs show the declared values in effect at each checkpoint, including retained inputs. Sequential tests also replay preparation changes between checkpoints, such as lowering the clock. Use the matching checkpoint label in the simulation below.
The table covers all 16 combinations of A and B from {0, 1, X, Z}; each row checks the settled output.
Embedded simulation¶
The and-gate scenario runs ANDGateTest.
Source and tests¶
| Test | Coverage |
|---|---|
ANDGateTest |
All 16 combinations of a and b from {0, 1, x, z}; the settled output of each |
SettlingAnalysisTest |
The gate settles within one gate delay |
1.3.3. ORGate¶
ORGate 1 when either input is 1.
IO pins¶
| Pin | Direction | Width | Description |
|---|---|---|---|
A |
Input | 1 | First operand bit |
B |
Input | 1 | Second operand bit |
OUT |
Output | 1 | Result bit |
Behavior¶
For binary inputs,
In the realistic profiles OR is a NOR followed by an inverter.
C++ example¶
This binary function describes the settled output. It is not a registered implementation.
Unknown inputs¶
A deciding input value fixes the output whatever the other input is; otherwise an unknown or floating input gives X. The output never drives Z.
A |
B |
Settled OUT |
|---|---|---|
| 1 | any | 1 |
| any | 1 | 1 |
| 0 | X or Z |
X |
X or Z |
0 or X or Z |
X |
Implementation¶
Structural implementation¶
ORGate is a leaf: evaluate() reads the inputs, applies the four-state rule above and schedules the output one gate delay later. The delay is inertial: an input change that is undone before the output is published withdraws the pending output. The gate has no children, no state and no compact form; parts that need OR on whole words use ORGate<W>.
Examples¶
All 16 recorded rows of ORGateTest, in checkpoint order. Outputs are test expectations verified against the simulation. Time is the absolute settled checkpoint time in simulator units, not milliseconds or CPU cycles.
Default scenario profile: fidelity-gate-v1 / structural (ed03f70afe360dba). Changing fidelity or the circuit can change these times.
| Checkpointzero-based number · timeline label | Timesimulator units | AInput · 1 bit |
BInput · 1 bit |
OUTExpected output · 1 bit |
|---|---|---|---|---|
#0row-0 | 1 | 0 |
0 |
0 |
#1row-1 | 3 | 0 |
1 |
1 |
#2row-2 | 5 | 0 |
X |
X |
#3row-3 | 7 | 0 |
Z |
X |
#4row-4 | 9 | 1 |
0 |
1 |
#5row-5 | 11 | 1 |
1 |
1 |
#6row-6 | 13 | 1 |
X |
1 |
#7row-7 | 15 | 1 |
Z |
1 |
#8row-8 | 17 | X |
0 |
X |
#9row-9 | 19 | X |
1 |
1 |
#10row-10 | 21 | X |
X |
X |
#11row-11 | 23 | X |
Z |
X |
#12row-12 | 25 | Z |
0 |
X |
#13row-13 | 27 | Z |
1 |
1 |
#14row-14 | 29 | Z |
X |
X |
#15row-15 | 31 | Z |
Z |
X |
Scroll within the table for all rows and pins. Buses use hexadecimal; values containing X/Z use MSB-first binary. Inputs show the declared values in effect at each checkpoint, including retained inputs. Sequential tests also replay preparation changes between checkpoints, such as lowering the clock. Use the matching checkpoint label in the simulation below.
The table covers all 16 combinations of A and B from {0, 1, X, Z}; each row checks the settled output.
Embedded simulation¶
The or-gate scenario runs ORGateTest.
Source and tests¶
| Test | Coverage |
|---|---|
ORGateTest |
All 16 combinations of a and b from {0, 1, x, z}; the settled output of each |
SettlingAnalysisTest |
The gate settles within one gate delay |
1.3.4. NANDGate¶
NANDGate 0 only when both inputs are 1.
IO pins¶
| Pin | Direction | Width | Description |
|---|---|---|---|
A |
Input | 1 | First operand bit |
B |
Input | 1 | Second operand bit |
OUT |
Output | 1 | Result bit |
Behavior¶
For binary inputs,
NAND is the basic gate of the realistic profiles (1.35 FO4).
C++ example¶
This binary function describes the settled output. It is not a registered implementation.
Unknown inputs¶
A deciding input value fixes the output whatever the other input is; otherwise an unknown or floating input gives X. The output never drives Z.
A |
B |
Settled OUT |
|---|---|---|
| 0 | any | 1 |
| any | 0 | 1 |
| 1 | X or Z |
X |
X or Z |
1 or X or Z |
X |
Implementation¶
Structural implementation¶
NANDGate is a leaf: evaluate() reads the inputs, applies the four-state rule above and schedules the output one gate delay later. The delay is inertial: an input change that is undone before the output is published withdraws the pending output. The gate has no children, no state and no compact form; parts that need NAND on whole words use NANDGate<W>.
Examples¶
All 16 recorded rows of NANDGateTest, in checkpoint order. Outputs are test expectations verified against the simulation. Time is the absolute settled checkpoint time in simulator units, not milliseconds or CPU cycles.
Default scenario profile: fidelity-gate-v1 / structural (ed03f70afe360dba). Changing fidelity or the circuit can change these times.
| Checkpointzero-based number · timeline label | Timesimulator units | AInput · 1 bit |
BInput · 1 bit |
OUTExpected output · 1 bit |
|---|---|---|---|---|
#0row-0 | 1 | 0 |
0 |
1 |
#1row-1 | 3 | 0 |
1 |
1 |
#2row-2 | 5 | 0 |
X |
1 |
#3row-3 | 7 | 0 |
Z |
1 |
#4row-4 | 9 | 1 |
0 |
1 |
#5row-5 | 11 | 1 |
1 |
0 |
#6row-6 | 13 | 1 |
X |
X |
#7row-7 | 15 | 1 |
Z |
X |
#8row-8 | 17 | X |
0 |
1 |
#9row-9 | 19 | X |
1 |
X |
#10row-10 | 21 | X |
X |
X |
#11row-11 | 23 | X |
Z |
X |
#12row-12 | 25 | Z |
0 |
1 |
#13row-13 | 27 | Z |
1 |
X |
#14row-14 | 29 | Z |
X |
X |
#15row-15 | 31 | Z |
Z |
X |
Scroll within the table for all rows and pins. Buses use hexadecimal; values containing X/Z use MSB-first binary. Inputs show the declared values in effect at each checkpoint, including retained inputs. Sequential tests also replay preparation changes between checkpoints, such as lowering the clock. Use the matching checkpoint label in the simulation below.
The table covers all 16 combinations of A and B from {0, 1, X, Z}; each row checks the settled output.
Embedded simulation¶
The nand-gate scenario runs NANDGateTest.
Open NANDGate in the simulator
Source and tests¶
| Test | Coverage |
|---|---|
NANDGateTest |
All 16 combinations of a and b from {0, 1, x, z}; the settled output of each |
SettlingAnalysisTest |
The gate settles within one gate delay |
1.3.5. NORGate¶
NORGate 1 only when both inputs are 0.
IO pins¶
| Pin | Direction | Width | Description |
|---|---|---|---|
A |
Input | 1 | First operand bit |
B |
Input | 1 | Second operand bit |
OUT |
Output | 1 | Result bit |
Behavior¶
For binary inputs,
NOR is slower than NAND in the realistic profiles (1.55 FO4).
C++ example¶
This binary function describes the settled output. It is not a registered implementation.
Unknown inputs¶
A deciding input value fixes the output whatever the other input is; otherwise an unknown or floating input gives X. The output never drives Z.
A |
B |
Settled OUT |
|---|---|---|
| 1 | any | 0 |
| any | 1 | 0 |
| 0 | X or Z |
X |
X or Z |
0 or X or Z |
X |
Implementation¶
Structural implementation¶
NORGate is a leaf: evaluate() reads the inputs, applies the four-state rule above and schedules the output one gate delay later. The delay is inertial: an input change that is undone before the output is published withdraws the pending output. The gate has no children, no state and no compact form; parts that need NOR on whole words use NORGate<W>.
Examples¶
All 16 recorded rows of NORGateTest, in checkpoint order. Outputs are test expectations verified against the simulation. Time is the absolute settled checkpoint time in simulator units, not milliseconds or CPU cycles.
Default scenario profile: fidelity-gate-v1 / structural (ed03f70afe360dba). Changing fidelity or the circuit can change these times.
| Checkpointzero-based number · timeline label | Timesimulator units | AInput · 1 bit |
BInput · 1 bit |
OUTExpected output · 1 bit |
|---|---|---|---|---|
#0row-0 | 1 | 0 |
0 |
1 |
#1row-1 | 3 | 0 |
1 |
0 |
#2row-2 | 5 | 0 |
X |
X |
#3row-3 | 7 | 0 |
Z |
X |
#4row-4 | 9 | 1 |
0 |
0 |
#5row-5 | 11 | 1 |
1 |
0 |
#6row-6 | 13 | 1 |
X |
0 |
#7row-7 | 15 | 1 |
Z |
0 |
#8row-8 | 17 | X |
0 |
X |
#9row-9 | 19 | X |
1 |
0 |
#10row-10 | 21 | X |
X |
X |
#11row-11 | 23 | X |
Z |
X |
#12row-12 | 25 | Z |
0 |
X |
#13row-13 | 27 | Z |
1 |
0 |
#14row-14 | 29 | Z |
X |
X |
#15row-15 | 31 | Z |
Z |
X |
Scroll within the table for all rows and pins. Buses use hexadecimal; values containing X/Z use MSB-first binary. Inputs show the declared values in effect at each checkpoint, including retained inputs. Sequential tests also replay preparation changes between checkpoints, such as lowering the clock. Use the matching checkpoint label in the simulation below.
The table covers all 16 combinations of A and B from {0, 1, X, Z}; each row checks the settled output.
Embedded simulation¶
The nor-gate scenario runs NORGateTest.
Source and tests¶
| Test | Coverage |
|---|---|
NORGateTest |
All 16 combinations of a and b from {0, 1, x, z}; the settled output of each |
SettlingAnalysisTest |
The gate settles within one gate delay |
1.3.6. XORGate¶
XORGate 1 when the inputs differ.
IO pins¶
| Pin | Direction | Width | Description |
|---|---|---|---|
A |
Input | 1 | First operand bit |
B |
Input | 1 | Second operand bit |
OUT |
Output | 1 | Result bit |
Behavior¶
For binary inputs,
XOR is the slowest gate in the realistic profiles (4 FO4); no input value decides it alone, so its output always waits for both inputs.
C++ example¶
This binary function describes the settled output. It is not a registered implementation.
Unknown inputs¶
Any unknown or floating input makes the output unknown; the output never drives Z.
A |
B |
Settled OUT |
|---|---|---|
| 0 or 1 | 0 or 1 | A XOR B |
X or Z |
any | X |
| any | X or Z |
X |
Implementation¶
Structural implementation¶
XORGate is a leaf: evaluate() reads the inputs, applies the four-state rule above and schedules the output one gate delay later. The delay is inertial: an input change that is undone before the output is published withdraws the pending output. The gate has no children, no state and no compact form; parts that need XOR on whole words use XORGate<W>.
Examples¶
All 16 recorded rows of XORGateTest, in checkpoint order. Outputs are test expectations verified against the simulation. Time is the absolute settled checkpoint time in simulator units, not milliseconds or CPU cycles.
Default scenario profile: fidelity-gate-v1 / structural (ed03f70afe360dba). Changing fidelity or the circuit can change these times.
| Checkpointzero-based number · timeline label | Timesimulator units | AInput · 1 bit |
BInput · 1 bit |
OUTExpected output · 1 bit |
|---|---|---|---|---|
#0row-0 | 1 | 0 |
0 |
0 |
#1row-1 | 3 | 0 |
1 |
1 |
#2row-2 | 5 | 0 |
X |
X |
#3row-3 | 7 | 0 |
Z |
X |
#4row-4 | 9 | 1 |
0 |
1 |
#5row-5 | 11 | 1 |
1 |
0 |
#6row-6 | 13 | 1 |
X |
X |
#7row-7 | 15 | 1 |
Z |
X |
#8row-8 | 17 | X |
0 |
X |
#9row-9 | 19 | X |
1 |
X |
#10row-10 | 21 | X |
X |
X |
#11row-11 | 23 | X |
Z |
X |
#12row-12 | 25 | Z |
0 |
X |
#13row-13 | 27 | Z |
1 |
X |
#14row-14 | 29 | Z |
X |
X |
#15row-15 | 31 | Z |
Z |
X |
Scroll within the table for all rows and pins. Buses use hexadecimal; values containing X/Z use MSB-first binary. Inputs show the declared values in effect at each checkpoint, including retained inputs. Sequential tests also replay preparation changes between checkpoints, such as lowering the clock. Use the matching checkpoint label in the simulation below.
The table covers all 16 combinations of A and B from {0, 1, X, Z}; each row checks the settled output.
Embedded simulation¶
The xor-gate scenario runs XORGateTest.
Source and tests¶
| Test | Coverage |
|---|---|
XORGateTest |
All 16 combinations of a and b from {0, 1, x, z}; the settled output of each |
SettlingAnalysisTest |
The gate settles within one gate delay |
1.3.7. ANDGate<W>¶
ANDGate<W> applies the one-bit AND to every bit of two W-bit words. Its
siblings NANDGate<W>, ORGate<W>, NORGate<W>, XORGate<W> and
NOTGate<W> do the same with their one-bit gate; this section describes all
six, with ANDGate<W> as the recorded example. W is any width from 2 to 32.
Each width and kind is its own contract, logic.<kind>.<W> (for example
logic.and.8, logic.not.32), returned by circuit::word::gate(GateKind, W).
IO pins¶
| Pin | Direction | Width | Description |
|---|---|---|---|
A |
Input | W | First operand word (IN for NOTGate<W>) |
B |
Input | W | Second operand word (absent for NOTGate<W>) |
OUT |
Output | W | Bit i is the gate of bit i of the inputs |
Behavior¶
For binary inputs, bit i of OUT is the one-bit gate of bit i of A and
B:
The bits are independent: nothing carries from one bit to the next. A recipe that applies the same gate to every bit of a word, or masks a word with one enable bit spread across it by wiring, uses one word gate instead of W separate gates; the gates and their timing are the same.
C++ example¶
#include <cstdint>
uint32_t and_word_ref(uint32_t a, uint32_t b, unsigned width) {
const uint32_t mask = width >= 32 ? ~0u : (1u << width) - 1;
return (a & b) & mask;
}
This binary function describes the settled output. It is not a registered implementation.
Unknown inputs¶
Each bit follows its one-bit gate's rule: for ANDGate<W>, a 0 in either
input bit gives 0, two 1s give 1, and anything else gives X. One bit's
unknown value does not affect the other bits. The output never drives Z.
Implementation¶
Structural implementation¶
W one-bit gates AND_0 … AND_<W−1> between zero-delay wiring parts: the
Rewires A_BITS and B_BITS (IN_BITS for NOTGate<W>) split the
inputs into bits, and OUT_WORD joins the gates' outputs. Each bit's path
is one gate, exactly as in a bit-by-bit circuit. In the simulator a closed
word gate is drawn as its one-bit symbol with its width (for example /8);
opening it shows the W gates.
Behavioral implementation¶
One leaf evaluates the whole word at once with the same per-bit rule on the
packed value, and publishes it on the delays proven on the W gates
(§ 1.2 Compact parts). Like every compact part it uses
transport delay, so a pulse shorter than one gate delay, which the inertial
one-bit gates swallow, can still reach OUT.
Examples¶
All 8 recorded rows of ANDGateWidth8Test, in checkpoint order. Outputs are test expectations verified against the simulation. Time is the absolute settled checkpoint time in simulator units, not milliseconds or CPU cycles.
Default scenario profile: fidelity-gate-v1 / structural (ed03f70afe360dba). Changing fidelity or the circuit can change these times.
| Checkpointzero-based number · timeline label | Timesimulator units | AInput · 8 bit |
BInput · 8 bit |
OUTExpected output · 8 bit |
|---|---|---|---|---|
#0row-0 | 1 | 0x00 |
0xFF |
0x00 |
#1row-1 | 3 | 0xFF |
0xFF |
0xFF |
#2row-2 | 5 | 0xAA |
0xFF |
0xAA |
#3row-3 | 7 | 0xAA |
0x55 |
0x00 |
#4row-4 | 9 | 0xF0 |
0x3C |
0x30 |
#5row-5 | 11 | 0xFF |
0x00 |
0x00 |
#6row-6 | 13 | 0b0ZX01ZX1 |
0x3C |
0b00X01X00 |
#7row-7 | 15 | 0x3C |
0b0ZX01ZX1 |
0b00X01X00 |
Scroll within the table for all rows and pins. Buses use hexadecimal; values containing X/Z use MSB-first binary. Inputs show the declared values in effect at each checkpoint, including retained inputs. Sequential tests also replay preparation changes between checkpoints, such as lowering the clock. Use the matching checkpoint label in the simulation below.
The table drives ANDGate<8> with boundary and alternating patterns and with
words containing X and Z bits; each row checks the settled output word.
Embedded simulation¶
The and-gate-w8 scenario runs ANDGateWidth8Test. Open the part to see
its eight one-bit AND gates.
Open ANDGate<8> in the simulator
Source and tests¶
| Test | Coverage |
|---|---|
ANDGateWidth8Test |
The recorded ANDGate<8> cases on both forms |
WordGateSweepTest |
All 186 word gates (six kinds, W = 2 to 32) on both forms against an independent one-bit rule: exhaustive binary inputs up to 4 bits, boundary and random words above, and dense four-state words; bits changing one tick apart publish at the gates' times in every timing profile |