ยง 2.1. Arithmetic Components¶
This page builds word arithmetic from one-bit cells. Two word adders compute the same sum with different carry networks: RippleCarryAdder<W> passes the carry through W full adders, and ParallelPrefixAdder<W> combines carries in logโ(W) levels. Ripple versus prefix carry compares them. AddSub<W> and ArithmeticUnit<W>, and every ALU in this project, use the faster prefix adder.
Bits are numbered from 0 at the least significant position. Let \(M=2^W\) and \(S=2^{W-1}\). Results wrap modulo M; signed values range from \(-S\) to \(S-1\). Carry is unsigned carry/no-borrow and is independent of signed overflow. These are combinational components with no clock or stored flags.
| Component | Description | Structural | Behavioral |
|---|---|---|---|
HalfAdder |
One-bit sum and carry, without carry-in | Yes | Yes |
FullAdder |
One-bit addition with carry-in | Yes | Yes |
RippleCarryAdder<W> |
Word adder built from W chained full adders | Yes | Yes |
ParallelPrefixAdder<W> |
Word adder with a logarithmic-depth carry network | Yes | Yes |
AddSub<W> |
Addition or subtraction with a carry input and signed overflow | Yes | Yes |
ArithmeticUnit<W> |
Seven arithmetic operations over one shared add/subtract path | Yes | Yes |
W is 8, 16 or 32. The fidelity columns describe the recorded configuration of each section. The word units have a compact form at every width; HalfAdder and FullAdder have the gate-list compact form, chosen only explicitly. The C++ references take W as a template parameter. Construction and selection describes construction.
2.1.1. HalfAdder¶
HalfAdder adds two one-bit operands. It has no carry input, so it cannot by itself be a general cell in a multi-bit carry chain.
IO pins¶
| Pin | Direction | Width | Description |
|---|---|---|---|
A |
Input | 1 | First operand bit |
B |
Input | 1 | Second operand bit |
Sum |
Output | 1 | Low bit of the sum |
Carry |
Output | 1 | Carry into the next bit position |
The output is named Carry, not Carry_out or Cout. Pin names are case-sensitive.
Behavior¶
For binary inputs,
Interpreting the bits as unsigned integers, A + B = Sum + 2*Carry. For example, 1 + 1 gives Sum = 0, Carry = 1. The component has no clock, stored state, or flags beyond this carry.
C++ example¶
struct HalfAdderResult {
bool Sum;
bool Carry;
};
HalfAdderResult half_adder_ref(bool a, bool b) {
return {a != b, a && b};
}
This binary-only function describes the settled outputs. It is not a registered behavioral implementation.
Unknown inputs¶
The simulator's XOR produces X if either input is X or Z. The AND produces 0 if either input is definitely 0, 1 only if both are definitely 1, and X otherwise. Neither output drives Z.
A |
B |
Settled Sum |
Settled Carry |
|---|---|---|---|
| 0 | X or Z |
X |
0 |
| 1 | X or Z |
X |
X |
Implementation¶
Structural implementation¶
Both inputs fan out to two gates, which operate in parallel:
| Child | Type | Inputs โ output |
|---|---|---|
XOR1 |
XORGate |
A, B โ Sum |
AND1 |
ANDGate |
A, B โ Carry |
There is no internal carry chain or storage. HalfAdder has only this structural implementation; the two gates remain visible in the simulator.
Behavioral implementation¶
The compact form evaluates this part's own gate list, flattened once from its structural form, and publishes the settled values on the delays proven on those gates (ยง 1.1 Structural and compact forms). Its values are the gates' by construction, including unknown and floating inputs; GateListCompactEquivalenceTest checks them. It is chosen only explicitly, for example by collapsing the part in the simulator; profiles that prefer compact forms keep the gates.
Examples¶
All 16 recorded rows of HalfAdderTest, 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 |
CarryExpected output ยท 1 bit |
SumExpected output ยท 1 bit |
|---|---|---|---|---|---|
#0row-0 | 1 | 0 |
0 |
0 |
0 |
#1row-1 | 3 | 0 |
1 |
0 |
1 |
#2row-2 | 5 | 0 |
X |
0 |
X |
#3row-3 | 7 | 0 |
Z |
0 |
X |
#4row-4 | 9 | 1 |
0 |
0 |
1 |
#5row-5 | 11 | 1 |
1 |
1 |
0 |
#6row-6 | 13 | 1 |
X |
X |
X |
#7row-7 | 15 | 1 |
Z |
X |
X |
#8row-8 | 17 | X |
0 |
0 |
X |
#9row-9 | 19 | X |
1 |
X |
X |
#10row-10 | 21 | X |
X |
X |
X |
#11row-11 | 23 | X |
Z |
X |
X |
#12row-12 | 25 | Z |
0 |
0 |
X |
#13row-13 | 27 | Z |
1 |
X |
X |
#14row-14 | 29 | Z |
X |
X |
X |
#15row-15 | 31 | Z |
Z |
X |
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 contains all 16 combinations of A and B from {0, 1, X, Z}: four binary cases and twelve nonbinary cases. Each row checks both outputs. The checkpoint number and time identify the same settled observation in the simulation below.
Embedded simulation¶
The half-adder scenario runs HalfAdderTest. Inspect XOR1 and AND1 for the sum and carry paths. Compare (A, B) = (0, X) with (1, X) to see how a known zero suppresses uncertainty in the AND output without making the sum known.
Open HalfAdder in the simulator
Source and tests¶
| Test | Coverage |
|---|---|
HalfAdderTest / halfAdderRows() |
All 16 four-state input combinations; verifies settled Sum and Carry |
SettlingAnalysisTest |
Proves the gates' settling bound (one gate delay) |
DocumentationExamplesTest |
Checks the reference pattern, implementation availability, and complete example-table export; compiles the actual C++ example and checks all four binary cases |
The binary C++ check does not verify X/Z behavior. Those cases are verified by the structural scenario and retained in its table and simulation.
2.1.2. FullAdder¶
FullAdder adds two one-bit operands and a carry input. Its carry output can feed the next bit position; W such cells form RippleCarryAdder<W>.
IO pins¶
| Pin | Direction | Width | Description |
|---|---|---|---|
A |
Input | 1 | First operand bit |
B |
Input | 1 | Second operand bit |
Carry_in |
Input | 1 | Carry from the previous bit position |
Sum |
Output | 1 | Low bit of the three-input sum |
Carry_out |
Output | 1 | Carry into the next bit position |
The one-bit cells keep the names Carry_in and Carry_out; the word adders use C_IN and C_OUT.
Behavior¶
Define the first half adder's sum as P = A XOR B. For binary inputs,
Thus A + B + Carry_in = Sum + 2*Carry_out. With three input ones, the result is Sum = 1, Carry_out = 1; with exactly two ones, it is Sum = 0, Carry_out = 1. The carry is not a signed-overflow indication.
C++ example¶
struct FullAdderResult {
bool Sum;
bool Carry_out;
};
FullAdderResult full_adder_ref(bool a, bool b, bool carry_in) {
const auto first = half_adder_ref(a, b);
const auto second = half_adder_ref(first.Sum, carry_in);
return {second.Sum, first.Carry || second.Carry};
}
This example reuses half_adder_ref above and follows the actual two-half-adder composition. It describes binary settled values, not simulator events or a selectable behavioral implementation.
Unknown inputs¶
X/Z inputs propagate through the two half adders and final OR gate. Use the stated XOR/AND/OR network, not an arbitrary binary-equivalent rewrite, to determine four-state results. For example:
A |
B |
Carry_in |
Settled Sum |
Settled Carry_out |
|---|---|---|---|---|
| 0 | 0 | Z |
X |
0 |
| 1 | 1 | X |
X |
1 |
| 1 | X |
1 | X |
X |
In the last row, both the first sum and both intermediate carries are unknown. The binary-equivalent majority expression (A AND B) OR (A AND Carry_in) OR (B AND Carry_in) would instead yield carry 1 because A AND Carry_in = 1. That is not this structural circuit's four-state contract. Neither output drives Z.
Implementation¶
Structural implementation¶
| Child | Type | Inputs โ output |
|---|---|---|
HA1 |
HalfAdder |
External A, B โ intermediate sum and first carry |
HA2 |
HalfAdder |
HA1.Sum, external Carry_in โ external Sum and second carry |
OR1 |
ORGate |
HA1.Carry, HA2.Carry โ external Carry_out |
Expanding the two half adders reveals five primitive gates in total: two XORs, two ANDs, and one OR. There is no stored carry or clock. FullAdder has only this structural implementation.
In RippleCarryAdder<8>, C_IN drives FA0.Carry_in, each cell's Carry_out drives the next cell's Carry_in, and FA7.Carry_out drives C_OUT. This is a ripple-carry connection, not eight independent additions.
Timing. The carry's longest path is HA1.XOR1 โ HA2.AND1 โ OR1 (an XOR, an AND and an OR); the sum's is two XOR gates. Which is longer depends on the profile: in unit every gate is one tick, so the carry path is longer; in the realistic profiles an XOR costs about four inverter delays, so the sum path is.
Behavioral implementation¶
The compact form evaluates this part's own gate list, flattened once from its structural form, and publishes the settled values on the delays proven on those gates (ยง 1.1 Structural and compact forms). Its values are the gates' by construction, including unknown and floating inputs; GateListCompactEquivalenceTest checks them. It is chosen only explicitly, for example by collapsing the part in the simulator; profiles that prefer compact forms keep the gates.
Examples¶
All 64 recorded rows of FullAdderTest, 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 |
Carry_inInput ยท 1 bit |
Carry_outExpected output ยท 1 bit |
SumExpected output ยท 1 bit |
|---|---|---|---|---|---|---|
#0row-0 | 2 | 0 |
0 |
0 |
0 |
0 |
#1row-1 | 4 | 0 |
0 |
1 |
0 |
1 |
#2row-2 | 6 | 0 |
0 |
X |
0 |
X |
#3row-3 | 8 | 0 |
0 |
Z |
0 |
X |
#4row-4 | 11 | 0 |
1 |
0 |
0 |
1 |
#5row-5 | 14 | 0 |
1 |
1 |
1 |
0 |
#6row-6 | 17 | 0 |
1 |
X |
X |
X |
#7row-7 | 19 | 0 |
1 |
Z |
X |
X |
#8row-8 | 22 | 0 |
X |
0 |
0 |
X |
#9row-9 | 25 | 0 |
X |
1 |
X |
X |
#10row-10 | 27 | 0 |
X |
X |
X |
X |
#11row-11 | 29 | 0 |
X |
Z |
X |
X |
#12row-12 | 32 | 0 |
Z |
0 |
0 |
X |
#13row-13 | 35 | 0 |
Z |
1 |
X |
X |
#14row-14 | 37 | 0 |
Z |
X |
X |
X |
#15row-15 | 39 | 0 |
Z |
Z |
X |
X |
#16row-16 | 42 | 1 |
0 |
0 |
0 |
1 |
#17row-17 | 45 | 1 |
0 |
1 |
1 |
0 |
#18row-18 | 48 | 1 |
0 |
X |
X |
X |
#19row-19 | 50 | 1 |
0 |
Z |
X |
X |
#20row-20 | 53 | 1 |
1 |
0 |
1 |
0 |
#21row-21 | 55 | 1 |
1 |
1 |
1 |
1 |
#22row-22 | 57 | 1 |
1 |
X |
1 |
X |
#23row-23 | 59 | 1 |
1 |
Z |
1 |
X |
#24row-24 | 62 | 1 |
X |
0 |
X |
X |
#25row-25 | 65 | 1 |
X |
1 |
X |
X |
#26row-26 | 67 | 1 |
X |
X |
X |
X |
#27row-27 | 69 | 1 |
X |
Z |
X |
X |
#28row-28 | 72 | 1 |
Z |
0 |
X |
X |
#29row-29 | 75 | 1 |
Z |
1 |
X |
X |
#30row-30 | 77 | 1 |
Z |
X |
X |
X |
#31row-31 | 79 | 1 |
Z |
Z |
X |
X |
#32row-32 | 82 | X |
0 |
0 |
0 |
X |
#33row-33 | 85 | X |
0 |
1 |
X |
X |
#34row-34 | 87 | X |
0 |
X |
X |
X |
#35row-35 | 89 | X |
0 |
Z |
X |
X |
#36row-36 | 92 | X |
1 |
0 |
X |
X |
#37row-37 | 95 | X |
1 |
1 |
X |
X |
#38row-38 | 97 | X |
1 |
X |
X |
X |
#39row-39 | 99 | X |
1 |
Z |
X |
X |
#40row-40 | 102 | X |
X |
0 |
X |
X |
#41row-41 | 105 | X |
X |
1 |
X |
X |
#42row-42 | 107 | X |
X |
X |
X |
X |
#43row-43 | 109 | X |
X |
Z |
X |
X |
#44row-44 | 112 | X |
Z |
0 |
X |
X |
#45row-45 | 115 | X |
Z |
1 |
X |
X |
#46row-46 | 117 | X |
Z |
X |
X |
X |
#47row-47 | 119 | X |
Z |
Z |
X |
X |
#48row-48 | 122 | Z |
0 |
0 |
0 |
X |
#49row-49 | 125 | Z |
0 |
1 |
X |
X |
#50row-50 | 127 | Z |
0 |
X |
X |
X |
#51row-51 | 129 | Z |
0 |
Z |
X |
X |
#52row-52 | 132 | Z |
1 |
0 |
X |
X |
#53row-53 | 135 | Z |
1 |
1 |
X |
X |
#54row-54 | 137 | Z |
1 |
X |
X |
X |
#55row-55 | 139 | Z |
1 |
Z |
X |
X |
#56row-56 | 142 | Z |
X |
0 |
X |
X |
#57row-57 | 145 | Z |
X |
1 |
X |
X |
#58row-58 | 147 | Z |
X |
X |
X |
X |
#59row-59 | 149 | Z |
X |
Z |
X |
X |
#60row-60 | 152 | Z |
Z |
0 |
X |
X |
#61row-61 | 155 | Z |
Z |
1 |
X |
X |
#62row-62 | 157 | Z |
Z |
X |
X |
X |
#63row-63 | 159 | Z |
Z |
Z |
X |
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 contains all 64 combinations of A, B, and Carry_in from {0, 1, X, Z}: eight binary cases and 56 nonbinary cases. Both outputs are checked at every checkpoint. The cases are exhaustive for settled four-state input combinations, not for every possible sequence of propagation glitches.
Embedded simulation¶
The full-adder scenario runs FullAdderTest. Expand HA1 and HA2 to inspect their gates, or keep them collapsed to trace the two intermediate carries into OR1. Compare (1, 1, X) with (1, X, 1) to inspect the four-state distinction described above.
Open FullAdder in the simulator
Source and tests¶
| Test | Coverage |
|---|---|
FullAdderTest / fullAdderRows() |
All 64 four-state input combinations; verifies settled Sum and Carry_out against the two-half-adder network |
SettlingAnalysisTest |
Proves the settling bound and reports its path |
DocumentationExamplesTest |
Checks the reference pattern, implementation availability, and complete example-table export; compiles this C++ example with half_adder_ref and checks all eight binary cases |
The embedded simulation and table use the structural test's complete sequence. The C++ function checks only binary values; it does not replace the four-state structural test.
2.1.3. RippleCarryAdder<W>¶
RippleCarryAdder<W> chains W full adders. It is the direct word-level extension of ยง 2.1.2 and the reference for the faster adder below.
IO pins¶
| Pin | Direction | Width | Description |
|---|---|---|---|
A, B |
Input | W each | Unsigned operand patterns |
C_IN |
Input | 1 | Carry into bit 0 |
OUT |
Output | W | Low W bits of the sum |
C_OUT |
Output | 1 | Carry out of bit Wโ1 |
Behavior¶
For \(T=A+B+\mathrm{C\_IN}\), OUT = T mod M and C_OUT = [T >= M]. There are no signed-overflow, zero or negative outputs. To add wider words, connect one adder's C_OUT to the next adder's C_IN: 0x00FF + 0x0001 gives a low byte of 0x00 with carry 1, then an upper byte of 0x01.
C++ example¶
This binary reference is parameterized by W = 8, 16 or 32. Inputs must fit their pin widths. It omits propagation delays and X/Z values.
#include <cstdint>
// Binary word domain used by the references in this chapter.
template<unsigned W>
struct WordReference {
static_assert(W == 8 || W == 16 || W == 32);
static constexpr std::uint64_t mask = (std::uint64_t{1} << W) - 1;
static constexpr std::uint64_t sign = std::uint64_t{1} << (W - 1);
};
template<unsigned W>
struct AdderResult {
std::uint32_t OUT;
bool C_OUT;
};
template<unsigned W>
AdderResult<W> adder_ref(std::uint32_t a, std::uint32_t b, bool c_in) {
const std::uint64_t total = std::uint64_t(a) + b + c_in;
return {
static_cast<std::uint32_t>(total & WordReference<W>::mask),
total >= (WordReference<W>::mask + 1),
};
}
Unknown inputs¶
Each bit follows the full adder's XOR/AND/OR equations. A known controlling input can mask an unknown one, so an unknown bit does not automatically make the whole word unknown. The recording below drives bit 0 of A to X and to Z with B = 0 and C_IN = 0: only OUT[0] becomes X, and C_OUT stays 0.
Implementation¶
Structural implementation¶
Two BitSplitter<W> parts separate the operand bits, W FullAdder cells FA0โฆFA(Wโ1) add them, and a BitJoiner<W> assembles OUT. C_IN feeds FA0; each Carry_out feeds the next cell; the last cell drives C_OUT. The carry path therefore grows linearly with W.
Behavioral implementation¶
The compact form computes the same ripple recurrence bit by bit with four-state values, so its outputs match the gates for every input, including X and Z. It exists at W = 8, 16 and 32 and runs on delays proven on this circuit.
Timing. These paths describe the eight-bit adder in each timing profile:
Latest time each path can still change after its input (for a setup row: how long before the edge the input must be stable), proven on the gate-level form.
| Path | unitticks | embeddedps | desktopps |
|---|---|---|---|
Slowest sum A โ OUT | 16 | 954 | 665 |
Slowest carry A โ C_OUT | 17 | 936 | 652 |
Carry chain alone C_IN โ C_OUT | 16 | 816 | 568 |
Examples¶
All 14 recorded rows of RippleCarryAdderWidth8Test, 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 |
C_INInput ยท 1 bit |
C_OUTExpected output ยท 1 bit |
OUTExpected output ยท 8 bit |
|---|---|---|---|---|---|---|
#0row-0 | 4 | 0x00 |
0x00 |
0 |
0 |
0x00 |
#1row-1 | 7 | 0x01 |
0x02 |
0 |
0 |
0x03 |
#2row-2 | 17 | 0x0F |
0x01 |
0 |
0 |
0x10 |
#3row-3 | 27 | 0xFF |
0x01 |
0 |
1 |
0x00 |
#4row-4 | 45 | 0xFF |
0x00 |
1 |
1 |
0x00 |
#5row-5 | 49 | 0x7F |
0x00 |
1 |
0 |
0x80 |
#6row-6 | 54 | 0x80 |
0x80 |
0 |
1 |
0x00 |
#7row-7 | 72 | 0xAA |
0x55 |
1 |
1 |
0x00 |
#8row-8 | 77 | 0x00 |
0x00 |
1 |
0 |
0x01 |
#9row-9 | 81 | 0xFF |
0xFF |
0 |
1 |
0xFE |
#10row-10 | 99 | 0x80 |
0x7F |
1 |
1 |
0x00 |
#11row-11 | 116 | 0x55 |
0xAA |
0 |
0 |
0xFF |
#12row-12 | 119 | 0b0000000X |
0x00 |
0 |
0 |
0b0000000X |
#13row-13 | 121 | 0b0000000Z |
0x00 |
0 |
0 |
0b0000000X |
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 14 recorded cases include ordinary sums, carry propagation across the whole word, and the two unknown-input cases above. The recording uses W = 8.
Embedded simulation¶
Expand FA0โฆFA7 to follow the carry from cell to cell.
Open RippleCarryAdder<8> in the simulator
Source and tests¶
| Test | Coverage |
|---|---|
RippleCarryAdderWidth8Test |
The 14 recorded cases, on both the structural and the compact form |
WidthComponentsTest |
Four-state carry propagation at W = 8, 16 and 32 |
AdderWidthSweepTest |
W = 8, 16 and 32 on both forms: carry chains of every length, a carry span of every length at every start position, bit patterns, 1,024 seeded random vectors and a single X or Z on every input bit, against A + B + C_IN |
ALUFidelityContractTest |
Compact against structural outputs at W = 8, 16 and 32, with binary and X/Z inputs |
2.1.4. ParallelPrefixAdder<W>¶
ParallelPrefixAdder<W> computes the same sum as RippleCarryAdder<W>, but finds every carry in logโ(W) combining levels instead of W chained cells. Every ALU in this project uses it.
IO pins¶
| Pin | Direction | Width | Description |
|---|---|---|---|
A, B |
Input | W each | Operand patterns |
C_IN |
Input | 1 | Carry into bit 0 |
OUT |
Output | W | Low W bits of the sum |
C_OUT |
Output | 1 | Carry out of bit Wโ1 |
C_SIGN |
Output | 1 | Carry into bit Wโ1, the sign bit |
Behavior¶
OUT and C_OUT follow the same rule as RippleCarryAdder<W>. C_SIGN is the carry into the sign bit; signed overflow of the addition is C_SIGN XOR C_OUT, which the RV32I ALU uses.
C++ example¶
The reference reuses adder_ref<W> and WordReference<W> from ยง 2.1.3. Inputs must fit W bits.
template<unsigned W>
struct PrefixAdderResult {
std::uint32_t OUT;
bool C_OUT;
bool C_SIGN;
};
template<unsigned W>
PrefixAdderResult<W> prefix_adder_ref(std::uint32_t a, std::uint32_t b, bool c_in) {
const auto sum = adder_ref<W>(a, b, c_in);
const auto low_mask = WordReference<W>::sign - 1;
const bool carry_into_sign = ((a & low_mask) + (b & low_mask) + c_in)
>= WordReference<W>::sign;
return {sum.OUT, sum.C_OUT, carry_into_sign};
}
Unknown inputs¶
Propagate/generate cells and combining levels use four-state XOR/AND/OR gates. The combination G = G_high OR (P_high AND G_low) is the ripple carry equation regrouped, so an unknown bit spreads the same way as in RippleCarryAdder<W>. The adder comparison test finds identical outputs for the two 32-bit adders on 3,136 binary and four-state rows.
Implementation¶
Structural implementation¶
The word gates PROPAGATE (XORGate<W>) and GENERATE (ANDGate<W>) give every bit's propagate pแตข = Aแตข XOR Bแตข and generate gแตข = Aแตข AND Bแตข at once (one-bit gates, grouped as words; see word gates). A carry group is the transformation c_out = G OR (P AND c_in); CarryCombine joins two neighbouring groups as G = G_high OR (P_high AND G_low), P = P_high AND P_low. Levels PREFIX_1, PREFIX_2, PREFIX_4, โฆ combine groups at distances 1, 2, 4, โฆ, so W = 8, 16 and 32 need 3, 4 and 5 levels. The word gates CIN (AND with C_IN on every bit) and CARRY (OR) give the carry out of every bit; the wiring part CARRY_BITS shifts it up one bit, with C_IN into bit 0, and also yields C_SIGN and C_OUT; the word gate SUM (XOR with the propagates) forms OUT.
Behavioral implementation¶
The compact form evaluates the same propagate/generate levels with four-state values and matches the gates for every input. It exists at W = 8, 16 and 32 and runs on delays proven on this circuit.
Examples¶
All 8 recorded rows of ParallelPrefixAdderWidth16Test, 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 ยท 16 bit |
BInput ยท 16 bit |
C_INInput ยท 1 bit |
C_OUTExpected output ยท 1 bit |
C_SIGNExpected output ยท 1 bit |
OUTExpected output ยท 16 bit |
|---|---|---|---|---|---|---|---|
#0sum-0 | 8 | 0x0000 |
0x0000 |
0 |
0 |
not checked | 0x0000 |
#1sum-1 | 10 | 0x0000 |
0x0000 |
1 |
0 |
not checked | 0x0001 |
#2sum-2 | 21 | 0xFFFF |
0x0001 |
0 |
1 |
not checked | 0x0000 |
#3sum-3 | 23 | 0xFFFF |
0x0001 |
1 |
1 |
not checked | 0x0001 |
#4sum-4 | 31 | 0x7FFF |
0x0001 |
0 |
0 |
not checked | 0x8000 |
#5sum-5 | 33 | 0x7FFF |
0x0001 |
1 |
0 |
not checked | 0x8001 |
#6sum-6 | 42 | 0x1234 |
0x4321 |
0 |
0 |
not checked | 0x5555 |
#7sum-7 | 46 | 0x1234 |
0x4321 |
1 |
0 |
not checked | 0x5556 |
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 eight recorded cases use W = 16: zero, a carry across all bits, the signed boundary, and both carry inputs. The ripple-carry-adder-w16 recording below repeats exactly these cases on the ripple adder.
Embedded simulation¶
Select PROPAGATE or GENERATE to see their one-bit gates, and expand PREFIX_1, PREFIX_2, PREFIX_4, PREFIX_8 to follow the carry levels.
Open ParallelPrefixAdder<16> in the simulator
Source and tests¶
| Test | Coverage |
|---|---|
ParallelPrefixAdderWidth16Test |
The eight recorded cases |
ParallelPrefixAdderWidth32Test |
32-bit boundary, carry-chain and four-state cases on both forms |
AdderWidthSweepTest |
W = 8, 16 and 32 on both forms: carry chains of every length, a carry span of every length at every start position, bit patterns, 1,024 seeded random vectors and a single X or Z on every input bit, against A + B + C_IN |
ArithmeticTimingOptimizationTest |
Equal outputs to the ripple adder; shorter settling bound at every width and timing profile |
ALUFidelityContractTest |
Compact against structural outputs at W = 8, 16 and 32 |
Ripple versus prefix carry¶
Both adders compute the same function; they differ only in how long the carry takes. A ripple adder's worst path crosses all W full adders, so it grows linearly with W. A prefix adder's worst path crosses logโ(W) combining levels plus a few gates at each end, so it grows with the logarithm of W.
The rows below are the proven worst-case delays of each adder from an operand to the carry out, read from the same delay tables the compact forms use. unit counts gates (one tick each); embedded and desktop are the 65 nm and 32 nm profiles in picoseconds.
Latest time each path can still change after its input (for a setup row: how long before the edge the input must be stable), proven on the gate-level form.
| Path | unitticks | embeddedps | desktopps |
|---|---|---|---|
RippleCarryAdder<8> A โ C_OUT | 17 | 936 | 652 |
ParallelPrefixAdder<8> A โ C_OUT | 8 | 478 | 333 |
RippleCarryAdder<16> A โ C_OUT | 33 | 1,752 | 1,220 |
ParallelPrefixAdder<16> A โ C_OUT | 10 | 580 | 404 |
RippleCarryAdder<32> A โ C_OUT | 65 | 3,384 | 2,356 |
ParallelPrefixAdder<32> A โ C_OUT | 12 | 682 | 475 |
Each doubling of W doubles the ripple adder's carry delay (17, 33 and 65 gate delays in unit) but adds only one combining level to the prefix adder (8, 10 and 12). The prefix adder is already faster at 8 bits; at 32 bits it is about 5.4 times faster in unit and about 5 times faster in the realistic profiles. The price is area: the prefix network adds a combining cell for most bits at every level. Because carry delay dominates word arithmetic, AddSub<W>, both ALUs and the RV32I branch-target adders use the prefix adder.
The same comparison runs as a test: ArithmeticTimingOptimizationTest builds both adders at W = 8, 16 and 32 in all three timing profiles and requires the prefix adder to settle sooner and to contain carry levels. It also drives both 32-bit adders with 3,136 binary and four-state rows and requires identical outputs. The ripple-carry-adder-w16 recording repeats the prefix adder's eight 16-bit cases, so the two circuits can be compared side by side in the simulator.
2.1.5. AddSub<W>¶
IO pins¶
| Pin | Direction | Width | Description |
|---|---|---|---|
A, B |
Input | W each | Operand patterns |
SUB |
Input | 1 | Invert every B bit when high |
C_IN |
Input | 1 | Carry into the adder |
OUT |
Output | W | Wrapped result |
C_OUT |
Output | 1 | Addition carry, or no-borrow for subtraction |
OVERFLOW |
Output | 1 | Signed result outside โSโฆSโ1 |
Behavior¶
Let \(B'=B\) when SUB=0 and \(B'=M-1-B\) when SUB=1. The adder computes \(T=A+B'+\mathrm{C\_IN}\); OUT is T modulo M and C_OUT is [T >= M].
| SUB | C_IN | Result before wrapping |
|---|---|---|
| 0 | 0 | A + B |
| 0 | 1 | A + B + 1 |
| 1 | 1 | A โ B |
| 1 | 0 | A โ B โ 1 |
SUB only inverts B; C_IN stays a separate input, so ordinary subtraction needs C_IN = 1. For subtraction, C_OUT is [A >= B + (1 โ C_IN)], so 1 means no borrow. Signed overflow uses the operand and result signs: NOT(A_sign XOR B'_sign) AND (A_sign XOR OUT_sign).
To subtract wider words, start the lowest word with SUB = 1, C_IN = 1 and connect each C_OUT to the next word's C_IN. For 0x0100 โ 0x0001 in bytes, the low byte gives 0xFF with C_OUT = 0 (a borrow); the upper byte then gives 0x00 with C_OUT = 1.
C++ example¶
This binary reference reuses adder_ref<W> from ยง 2.1.3. It omits propagation delays and X/Z values.
template<unsigned W>
struct AddSubResult {
std::uint32_t OUT;
bool C_OUT;
bool OVERFLOW;
};
template<unsigned W>
AddSubResult<W> addsub_ref(
std::uint32_t a, std::uint32_t b, bool sub, bool c_in) {
const auto effective_b = static_cast<std::uint32_t>(
b ^ (sub ? WordReference<W>::mask : 0x00u));
const auto sum = adder_ref<W>(a, effective_b, c_in);
const bool same_sign = ((a ^ effective_b) & WordReference<W>::sign) == 0;
const bool result_changed_sign = ((a ^ sum.OUT) & WordReference<W>::sign) != 0;
return {sum.OUT, sum.C_OUT, same_sign && result_changed_sign};
}
Unknown inputs¶
Conditional inversion, carry propagation and the sign logic use four-state gates. An unknown SUB or C_IN follows those gates rather than an assumed Boolean value.
Implementation¶
Structural implementation¶
The word gate B_XOR_SUB (XORGate<W>, one XOR per bit) forms Bโฒ from B and SUB, spread across the word by the wiring part SUB_WORD. One ParallelPrefixAdder<W>, named ADD, computes A + Bโฒ + C_IN. Splitters expose the sign bits, and XOR/NOT/AND gates produce OVERFLOW from them.
Behavioral implementation¶
The compact form, available at W = 8, 16 and 32, computes the settled outputs of these gates in one step. It keeps the gates' Boolean factoring, so X and Z inputs give the same outputs as the structural circuit, and it runs on delays proven on that circuit.
Examples¶
All 80 recorded rows of AddSubWidth8Test, 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 |
C_INInput ยท 1 bit |
SUBInput ยท 1 bit |
C_OUTExpected output ยท 1 bit |
OUTExpected output ยท 8 bit |
OVERFLOWExpected output ยท 1 bit |
|---|---|---|---|---|---|---|---|---|
#0row-0 | 10 | 0x00 |
0x00 |
0 |
0 |
0 |
0x00 |
0 |
#1row-1 | 12 | 0x00 |
0x00 |
1 |
0 |
0 |
0x01 |
0 |
#2row-2 | 19 | 0x00 |
0x00 |
0 |
1 |
0 |
0xFF |
0 |
#3row-3 | 25 | 0x00 |
0x00 |
1 |
1 |
1 |
0x00 |
0 |
#4row-4 | 32 | 0x00 |
0x01 |
0 |
0 |
0 |
0x01 |
0 |
#5row-5 | 36 | 0x00 |
0x01 |
1 |
0 |
0 |
0x02 |
0 |
#6row-6 | 42 | 0x00 |
0x01 |
0 |
1 |
0 |
0xFE |
0 |
#7row-7 | 44 | 0x00 |
0x01 |
1 |
1 |
0 |
0xFF |
0 |
#8row-8 | 50 | 0x00 |
0x80 |
0 |
0 |
0 |
0x80 |
0 |
#9row-9 | 52 | 0x00 |
0x80 |
1 |
0 |
0 |
0x81 |
0 |
#10row-10 | 59 | 0x00 |
0x80 |
0 |
1 |
0 |
0x7F |
0 |
#11row-11 | 65 | 0x00 |
0x80 |
1 |
1 |
0 |
0x80 |
1 |
#12row-12 | 72 | 0x00 |
0xFF |
0 |
0 |
0 |
0xFF |
0 |
#13row-13 | 78 | 0x00 |
0xFF |
1 |
0 |
1 |
0x00 |
0 |
#14row-14 | 85 | 0x00 |
0xFF |
0 |
1 |
0 |
0x00 |
0 |
#15row-15 | 87 | 0x00 |
0xFF |
1 |
1 |
0 |
0x01 |
0 |
#16row-16 | 90 | 0x01 |
0x00 |
0 |
0 |
0 |
0x01 |
0 |
#17row-17 | 94 | 0x01 |
0x00 |
1 |
0 |
0 |
0x02 |
0 |
#18row-18 | 106 | 0x01 |
0x00 |
0 |
1 |
1 |
0x00 |
0 |
#19row-19 | 108 | 0x01 |
0x00 |
1 |
1 |
1 |
0x01 |
0 |
#20row-20 | 119 | 0x01 |
0x01 |
0 |
0 |
0 |
0x02 |
0 |
#21row-21 | 121 | 0x01 |
0x01 |
1 |
0 |
0 |
0x03 |
0 |
#22row-22 | 128 | 0x01 |
0x01 |
0 |
1 |
0 |
0xFF |
0 |
#23row-23 | 134 | 0x01 |
0x01 |
1 |
1 |
1 |
0x00 |
0 |
#24row-24 | 141 | 0x01 |
0x80 |
0 |
0 |
0 |
0x81 |
0 |
#25row-25 | 145 | 0x01 |
0x80 |
1 |
0 |
0 |
0x82 |
0 |
#26row-26 | 157 | 0x01 |
0x80 |
0 |
1 |
0 |
0x80 |
1 |
#27row-27 | 159 | 0x01 |
0x80 |
1 |
1 |
0 |
0x81 |
1 |
#28row-28 | 167 | 0x01 |
0xFF |
0 |
0 |
1 |
0x00 |
0 |
#29row-29 | 169 | 0x01 |
0xFF |
1 |
0 |
1 |
0x01 |
0 |
#30row-30 | 180 | 0x01 |
0xFF |
0 |
1 |
0 |
0x01 |
0 |
#31row-31 | 184 | 0x01 |
0xFF |
1 |
1 |
0 |
0x02 |
0 |
#32row-32 | 190 | 0x7F |
0x00 |
0 |
0 |
0 |
0x7F |
0 |
#33row-33 | 196 | 0x7F |
0x00 |
1 |
0 |
0 |
0x80 |
1 |
#34row-34 | 206 | 0x7F |
0x00 |
0 |
1 |
1 |
0x7E |
0 |
#35row-35 | 208 | 0x7F |
0x00 |
1 |
1 |
1 |
0x7F |
0 |
#36row-36 | 220 | 0x7F |
0x01 |
0 |
0 |
0 |
0x80 |
1 |
#37row-37 | 222 | 0x7F |
0x01 |
1 |
0 |
0 |
0x81 |
1 |
#38row-38 | 230 | 0x7F |
0x01 |
0 |
1 |
1 |
0x7D |
0 |
#39row-39 | 234 | 0x7F |
0x01 |
1 |
1 |
1 |
0x7E |
0 |
#40row-40 | 244 | 0x7F |
0x80 |
0 |
0 |
0 |
0xFF |
0 |
#41row-41 | 250 | 0x7F |
0x80 |
1 |
0 |
1 |
0x00 |
0 |
#42row-42 | 260 | 0x7F |
0x80 |
0 |
1 |
0 |
0xFE |
1 |
#43row-43 | 262 | 0x7F |
0x80 |
1 |
1 |
0 |
0xFF |
1 |
#44row-44 | 270 | 0x7F |
0xFF |
0 |
0 |
1 |
0x7E |
0 |
#45row-45 | 272 | 0x7F |
0xFF |
1 |
0 |
1 |
0x7F |
0 |
#46row-46 | 282 | 0x7F |
0xFF |
0 |
1 |
0 |
0x7F |
0 |
#47row-47 | 288 | 0x7F |
0xFF |
1 |
1 |
0 |
0x80 |
1 |
#48row-48 | 294 | 0x80 |
0x00 |
0 |
0 |
0 |
0x80 |
0 |
#49row-49 | 296 | 0x80 |
0x00 |
1 |
0 |
0 |
0x81 |
0 |
#50row-50 | 303 | 0x80 |
0x00 |
0 |
1 |
1 |
0x7F |
1 |
#51row-51 | 309 | 0x80 |
0x00 |
1 |
1 |
1 |
0x80 |
0 |
#52row-52 | 316 | 0x80 |
0x01 |
0 |
0 |
0 |
0x81 |
0 |
#53row-53 | 320 | 0x80 |
0x01 |
1 |
0 |
0 |
0x82 |
0 |
#54row-54 | 327 | 0x80 |
0x01 |
0 |
1 |
1 |
0x7E |
1 |
#55row-55 | 329 | 0x80 |
0x01 |
1 |
1 |
1 |
0x7F |
1 |
#56row-56 | 335 | 0x80 |
0x80 |
0 |
0 |
1 |
0x00 |
1 |
#57row-57 | 337 | 0x80 |
0x80 |
1 |
0 |
1 |
0x01 |
1 |
#58row-58 | 344 | 0x80 |
0x80 |
0 |
1 |
0 |
0xFF |
0 |
#59row-59 | 350 | 0x80 |
0x80 |
1 |
1 |
1 |
0x00 |
0 |
#60row-60 | 357 | 0x80 |
0xFF |
0 |
0 |
1 |
0x7F |
1 |
#61row-61 | 363 | 0x80 |
0xFF |
1 |
0 |
1 |
0x80 |
0 |
#62row-62 | 370 | 0x80 |
0xFF |
0 |
1 |
0 |
0x80 |
0 |
#63row-63 | 372 | 0x80 |
0xFF |
1 |
1 |
0 |
0x81 |
0 |
#64row-64 | 378 | 0xFF |
0x00 |
0 |
0 |
0 |
0xFF |
0 |
#65row-65 | 384 | 0xFF |
0x00 |
1 |
0 |
1 |
0x00 |
0 |
#66row-66 | 394 | 0xFF |
0x00 |
0 |
1 |
1 |
0xFE |
0 |
#67row-67 | 396 | 0xFF |
0x00 |
1 |
1 |
1 |
0xFF |
0 |
#68row-68 | 408 | 0xFF |
0x01 |
0 |
0 |
1 |
0x00 |
0 |
#69row-69 | 410 | 0xFF |
0x01 |
1 |
0 |
1 |
0x01 |
0 |
#70row-70 | 418 | 0xFF |
0x01 |
0 |
1 |
1 |
0xFD |
0 |
#71row-71 | 422 | 0xFF |
0x01 |
1 |
1 |
1 |
0xFE |
0 |
#72row-72 | 432 | 0xFF |
0x80 |
0 |
0 |
1 |
0x7F |
1 |
#73row-73 | 438 | 0xFF |
0x80 |
1 |
0 |
1 |
0x80 |
0 |
#74row-74 | 448 | 0xFF |
0x80 |
0 |
1 |
1 |
0x7E |
0 |
#75row-75 | 450 | 0xFF |
0x80 |
1 |
1 |
1 |
0x7F |
0 |
#76row-76 | 456 | 0xFF |
0xFF |
0 |
0 |
1 |
0xFE |
0 |
#77row-77 | 458 | 0xFF |
0xFF |
1 |
0 |
1 |
0xFF |
0 |
#78row-78 | 468 | 0xFF |
0xFF |
0 |
1 |
0 |
0xFF |
0 |
#79row-79 | 474 | 0xFF |
0xFF |
1 |
1 |
1 |
0x00 |
0 |
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 80 recorded cases cover five A values, four B values, both SUB values and both carry inputs at W = 8. For A = B = 0xFF, SUB = 1 and C_IN = 0, the result is 255 โ 255 โ 1 = โ1: it borrows, so C_OUT = 0, and as a signed operation โ1 โ (โ1) โ 1 = โ1 does not overflow.
Embedded simulation¶
Open AddSub<8> in the simulator
Source and tests¶
| Test | Coverage |
|---|---|
AddSubWidth8Test |
The 80 recorded cases on both forms |
ALUContractTest |
All 262,144 binary inputs of AddSub<8> on both forms |
2.1.6. ArithmeticUnit<W>¶
IO pins¶
| Pin | Direction | Width | Description |
|---|---|---|---|
A, B |
Input | W each | Primary and secondary operands |
OP |
Input | 3 | Local arithmetic selector |
C_IN |
Input | 1 | Carry/no-borrow input for ADC/SBC |
OUT |
Output | W | Selected arithmetic result |
CARRY |
Output | 1 | Carry or no-borrow |
OVERFLOW |
Output | 1 | Signed overflow |
INVALID_OP |
Output | 1 | Local opcode 7 |
Behavior¶
One shared AddSub<W> performs the selected operation. Results wrap modulo M.
| Local OP | Operation | Result before wrapping | Carry input used? |
|---|---|---|---|
| 0 | ADD | A + B | No |
| 1 | ADC | A + B + C_IN | Yes |
| 2 | SUB | A โ B | No |
| 3 | SBC | A โ B โ (1 โ C_IN) | Yes |
| 4 | INC | A + 1 | No |
| 5 | DEC | A โ 1 | No |
| 6 | NEG | 0 โ A | No |
| 7 | Reserved | OUT=0, CARRY=0, OVERFLOW=0, INVALID_OP=1 | No |
For INC, carry means A=Mโ1 and overflow means A=Sโ1. For DEC, no-borrow means Aโ 0 and overflow means A=S. For NEG, no-borrow means A=0 and overflow means A=S. The other overflow cases follow the range of the signed result. INVALID_OP reports an encoding, not uncertainty in the operands. The complete ALU's arithmetic codes 0โ6 equal these local codes.
C++ example¶
This binary reference reuses addsub_ref<W> from ยง 2.1.5. It omits propagation delays and X/Z values.
template<unsigned W>
struct ArithmeticResult {
std::uint32_t OUT;
bool CARRY;
bool OVERFLOW;
bool INVALID_OP;
};
template<unsigned W>
ArithmeticResult<W> arithmetic_ref(
std::uint32_t a, std::uint32_t b, std::uint32_t op, bool c_in) {
std::uint32_t x = a;
std::uint32_t y = b;
bool sub = false;
bool carry_in = false;
switch (op) {
case 0x00: break; // ADD
case 0x01: carry_in = c_in; break; // ADC
case 0x02: sub = true; carry_in = true; break; // SUB
case 0x03: sub = true; carry_in = c_in; break; // SBC
case 0x04: y = 0; carry_in = true; break; // INC
case 0x05: y = 1; sub = true; carry_in = true; break; // DEC
case 0x06: x = 0; y = a; sub = true;
carry_in = true; break; // NEG
default: return {0, false, false, true};
}
const auto result = addsub_ref<W>(x, y, sub, carry_in);
return {result.OUT, result.C_OUT, result.OVERFLOW, false};
}
Unknown inputs¶
Operand multiplexers isolate ignored inputs: NEG ignores B and C_IN, and INC/DEC ignore B. The reserved code masks result, carry and overflow to zero. Unknown selector bits follow the gate-built multiplexers.
Implementation¶
Structural implementation¶
Opcode-controlled operand and carry multiplexers, constants, one AddSub<W> and reserved-operation masks form the circuit; the result mask is the word gate RESULT_MASK (ANDGate<W>, the valid bit spread across the word). SUB uses carry-in 1; SBC uses C_IN. INC selects B = 0 and carry 1; DEC selects B = 1, SUB = 1 and carry 1; NEG selects A = 0, B = the original A, SUB = 1 and carry 1.
Behavioral implementation¶
The compact form, available at W = 8, 16 and 32, computes the settled outputs of these gates in one step. It keeps the gates' Boolean factoring, so X and Z inputs give the same outputs as the structural circuit, and it runs on delays proven on that circuit.
Examples¶
All 80 recorded rows of ArithmeticUnitWidth8Test, 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 |
C_INInput ยท 1 bit |
OPInput ยท 3 bit |
CARRYExpected output ยท 1 bit |
INVALID_OPExpected output ยท 1 bit |
OUTExpected output ยท 8 bit |
OVERFLOWExpected output ยท 1 bit |
|---|---|---|---|---|---|---|---|---|---|
#0row-0 | 17 | 0x00 |
0x01 |
0 |
0x0 |
0 |
0 |
0x01 |
0 |
#1row-1 | 19 | 0x00 |
0x01 |
1 |
0x0 |
0 |
0 |
0x01 |
0 |
#2row-2 | 30 | 0x01 |
0x01 |
0 |
0x0 |
0 |
0 |
0x02 |
0 |
#3row-3 | 32 | 0x01 |
0x01 |
1 |
0x0 |
0 |
0 |
0x02 |
0 |
#4row-4 | 50 | 0x7F |
0x01 |
0 |
0x0 |
0 |
0 |
0x80 |
1 |
#5row-5 | 52 | 0x7F |
0x01 |
1 |
0x0 |
0 |
0 |
0x80 |
1 |
#6row-6 | 68 | 0x80 |
0x01 |
0 |
0x0 |
0 |
0 |
0x81 |
0 |
#7row-7 | 70 | 0x80 |
0x01 |
1 |
0x0 |
0 |
0 |
0x81 |
0 |
#8row-8 | 87 | 0xFF |
0x01 |
0 |
0x0 |
1 |
0 |
0x00 |
0 |
#9row-9 | 89 | 0xFF |
0x01 |
1 |
0x0 |
1 |
0 |
0x00 |
0 |
#10row-10 | 106 | 0x00 |
0x01 |
0 |
0x1 |
0 |
0 |
0x01 |
0 |
#11row-11 | 117 | 0x00 |
0x01 |
1 |
0x1 |
0 |
0 |
0x02 |
0 |
#12row-12 | 127 | 0x01 |
0x01 |
0 |
0x1 |
0 |
0 |
0x02 |
0 |
#13row-13 | 136 | 0x01 |
0x01 |
1 |
0x1 |
0 |
0 |
0x03 |
0 |
#14row-14 | 154 | 0x7F |
0x01 |
0 |
0x1 |
0 |
0 |
0x80 |
1 |
#15row-15 | 163 | 0x7F |
0x01 |
1 |
0x1 |
0 |
0 |
0x81 |
1 |
#16row-16 | 179 | 0x80 |
0x01 |
0 |
0x1 |
0 |
0 |
0x81 |
0 |
#17row-17 | 190 | 0x80 |
0x01 |
1 |
0x1 |
0 |
0 |
0x82 |
0 |
#18row-18 | 207 | 0xFF |
0x01 |
0 |
0x1 |
1 |
0 |
0x00 |
0 |
#19row-19 | 216 | 0xFF |
0x01 |
1 |
0x1 |
1 |
0 |
0x01 |
0 |
#20row-20 | 231 | 0x00 |
0x01 |
0 |
0x2 |
0 |
0 |
0xFF |
0 |
#21row-21 | 233 | 0x00 |
0x01 |
1 |
0x2 |
0 |
0 |
0xFF |
0 |
#22row-22 | 248 | 0x01 |
0x01 |
0 |
0x2 |
1 |
0 |
0x00 |
0 |
#23row-23 | 250 | 0x01 |
0x01 |
1 |
0x2 |
1 |
0 |
0x00 |
0 |
#24row-24 | 263 | 0x7F |
0x01 |
0 |
0x2 |
1 |
0 |
0x7E |
0 |
#25row-25 | 265 | 0x7F |
0x01 |
1 |
0x2 |
1 |
0 |
0x7E |
0 |
#26row-26 | 281 | 0x80 |
0x01 |
0 |
0x2 |
1 |
0 |
0x7F |
1 |
#27row-27 | 283 | 0x80 |
0x01 |
1 |
0x2 |
1 |
0 |
0x7F |
1 |
#28row-28 | 299 | 0xFF |
0x01 |
0 |
0x2 |
1 |
0 |
0xFE |
0 |
#29row-29 | 301 | 0xFF |
0x01 |
1 |
0x2 |
1 |
0 |
0xFE |
0 |
#30row-30 | 316 | 0x00 |
0x01 |
0 |
0x3 |
0 |
0 |
0xFE |
0 |
#31row-31 | 325 | 0x00 |
0x01 |
1 |
0x3 |
0 |
0 |
0xFF |
0 |
#32row-32 | 337 | 0x01 |
0x01 |
0 |
0x3 |
0 |
0 |
0xFF |
0 |
#33row-33 | 349 | 0x01 |
0x01 |
1 |
0x3 |
1 |
0 |
0x00 |
0 |
#34row-34 | 364 | 0x7F |
0x01 |
0 |
0x3 |
1 |
0 |
0x7D |
0 |
#35row-35 | 375 | 0x7F |
0x01 |
1 |
0x3 |
1 |
0 |
0x7E |
0 |
#36row-36 | 391 | 0x80 |
0x01 |
0 |
0x3 |
1 |
0 |
0x7E |
1 |
#37row-37 | 400 | 0x80 |
0x01 |
1 |
0x3 |
1 |
0 |
0x7F |
1 |
#38row-38 | 416 | 0xFF |
0x01 |
0 |
0x3 |
1 |
0 |
0xFD |
0 |
#39row-39 | 427 | 0xFF |
0x01 |
1 |
0x3 |
1 |
0 |
0xFE |
0 |
#40row-40 | 441 | 0x00 |
0x01 |
0 |
0x4 |
0 |
0 |
0x01 |
0 |
#41row-41 | 443 | 0x00 |
0x01 |
1 |
0x4 |
0 |
0 |
0x01 |
0 |
#42row-42 | 455 | 0x01 |
0x01 |
0 |
0x4 |
0 |
0 |
0x02 |
0 |
#43row-43 | 457 | 0x01 |
0x01 |
1 |
0x4 |
0 |
0 |
0x02 |
0 |
#44row-44 | 474 | 0x7F |
0x01 |
0 |
0x4 |
0 |
0 |
0x80 |
1 |
#45row-45 | 476 | 0x7F |
0x01 |
1 |
0x4 |
0 |
0 |
0x80 |
1 |
#46row-46 | 491 | 0x80 |
0x01 |
0 |
0x4 |
0 |
0 |
0x81 |
0 |
#47row-47 | 493 | 0x80 |
0x01 |
1 |
0x4 |
0 |
0 |
0x81 |
0 |
#48row-48 | 509 | 0xFF |
0x01 |
0 |
0x4 |
1 |
0 |
0x00 |
0 |
#49row-49 | 511 | 0xFF |
0x01 |
1 |
0x4 |
1 |
0 |
0x00 |
0 |
#50row-50 | 526 | 0x00 |
0x01 |
0 |
0x5 |
0 |
0 |
0xFF |
0 |
#51row-51 | 532 | 0x00 |
0x01 |
1 |
0x5 |
0 |
0 |
0xFF |
0 |
#52row-52 | 547 | 0x01 |
0x01 |
0 |
0x5 |
1 |
0 |
0x00 |
0 |
#53row-53 | 553 | 0x01 |
0x01 |
1 |
0x5 |
1 |
0 |
0x00 |
0 |
#54row-54 | 566 | 0x7F |
0x01 |
0 |
0x5 |
1 |
0 |
0x7E |
0 |
#55row-55 | 572 | 0x7F |
0x01 |
1 |
0x5 |
1 |
0 |
0x7E |
0 |
#56row-56 | 588 | 0x80 |
0x01 |
0 |
0x5 |
1 |
0 |
0x7F |
1 |
#57row-57 | 594 | 0x80 |
0x01 |
1 |
0x5 |
1 |
0 |
0x7F |
1 |
#58row-58 | 610 | 0xFF |
0x01 |
0 |
0x5 |
1 |
0 |
0xFE |
0 |
#59row-59 | 616 | 0xFF |
0x01 |
1 |
0x5 |
1 |
0 |
0xFE |
0 |
#60row-60 | 634 | 0x00 |
0x01 |
0 |
0x6 |
1 |
0 |
0x00 |
0 |
#61row-61 | 636 | 0x00 |
0x01 |
1 |
0x6 |
1 |
0 |
0x00 |
0 |
#62row-62 | 652 | 0x01 |
0x01 |
0 |
0x6 |
0 |
0 |
0xFF |
0 |
#63row-63 | 654 | 0x01 |
0x01 |
1 |
0x6 |
0 |
0 |
0xFF |
0 |
#64row-64 | 666 | 0x7F |
0x01 |
0 |
0x6 |
0 |
0 |
0x81 |
0 |
#65row-65 | 668 | 0x7F |
0x01 |
1 |
0x6 |
0 |
0 |
0x81 |
0 |
#66row-66 | 686 | 0x80 |
0x01 |
0 |
0x6 |
0 |
0 |
0x80 |
1 |
#67row-67 | 688 | 0x80 |
0x01 |
1 |
0x6 |
0 |
0 |
0x80 |
1 |
#68row-68 | 705 | 0xFF |
0x01 |
0 |
0x6 |
0 |
0 |
0x01 |
0 |
#69row-69 | 707 | 0xFF |
0x01 |
1 |
0x6 |
0 |
0 |
0x01 |
0 |
#70row-70 | 721 | 0x00 |
0x01 |
0 |
0x7 |
0 |
1 |
0x00 |
0 |
#71row-71 | 727 | 0x00 |
0x01 |
1 |
0x7 |
0 |
1 |
0x00 |
0 |
#72row-72 | 733 | 0x01 |
0x01 |
0 |
0x7 |
0 |
1 |
0x00 |
0 |
#73row-73 | 739 | 0x01 |
0x01 |
1 |
0x7 |
0 |
1 |
0x00 |
0 |
#74row-74 | 745 | 0x7F |
0x01 |
0 |
0x7 |
0 |
1 |
0x00 |
0 |
#75row-75 | 751 | 0x7F |
0x01 |
1 |
0x7 |
0 |
1 |
0x00 |
0 |
#76row-76 | 757 | 0x80 |
0x01 |
0 |
0x7 |
0 |
1 |
0x00 |
0 |
#77row-77 | 763 | 0x80 |
0x01 |
1 |
0x7 |
0 |
1 |
0x00 |
0 |
#78row-78 | 769 | 0xFF |
0x01 |
0 |
0x7 |
0 |
1 |
0x00 |
0 |
#79row-79 | 775 | 0xFF |
0x01 |
1 |
0x7 |
0 |
1 |
0x00 |
0 |
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 80 recorded cases cover all eight local opcodes, five A values and both carry inputs, with B = 1, at W = 8.
Embedded simulation¶
Open ArithmeticUnit<8> in the simulator
Source and tests¶
| Test | Coverage |
|---|---|
ArithmeticUnitWidth8Test |
The 80 recorded cases on both forms |
ALUContractTest |
Arithmetic through the complete ALU<8>: boundary, random and four-state cases |