Skip to content

§ 4.3.3. RV32I ALU

RV32IALU is the arithmetic and logic unit of every RV32I and RV32IM core in this project: the single-cycle core, both pipelines and the RV32IM core. It performs the 13 operations that RV32I instructions need and reports the three comparisons that branches test. It is a fixed 32-bit circuit, because RV32I fixes the register width, and it always uses the parallel-prefix adder.

It differs from the Chapter 2 ALU<W> in the ways RISC-V differs from a classic flag-based processor: there is no carry input, no flag outputs and no invalid-opcode output, and comparisons are output pins rather than flags. Multiplication and division are not part of it; the RV32IM execute stage places MulDivUnit<32> beside it and selects that unit's result for M instructions.

Component Description Structural Behavioral
RV32IALUControl Turns the five-bit operation code into selector and control bits Yes Yes
RV32IALUAddSub 32-bit addition or subtraction, with SUB as the carry input Yes Yes
RV32IALULogic AND, OR and XOR of two words, all at once Yes Yes
RV32IALUShifter Logical left, logical right and arithmetic right shifts Yes Yes
RV32IALUCompare Equality and signed/unsigned less-than from a subtraction Yes Yes
RV32IALUResultSelect Picks the result word for the operation code Yes Yes
RV32IALU The complete RV32I ALU Yes Yes

The six parts are documented first, in the order the ALU uses them; § 4.3.3.7 assembles them. Execute builds the ALU with b.add(circuit::families::rv32iALU(), "ALU"), so a build profile chooses its fidelity; its contract is rv32i.alu, and the parts are rv32i.alu.control, rv32i.alu.add-sub, rv32i.alu.logic, rv32i.alu.shifter, rv32i.alu.compare and rv32i.alu.result-select. Each part is chosen by the build profile like any other family, so a structural RV32IALU may hold compact parts; each part's compact form follows its own gates bit for bit, including X and Z. Python creates the ALU with create_rv32i_alu(name, fidelity). The operation codes are named in rv32i::ALUOp in include/modules/rv32i/RV32IALU.hpp.

4.3.3.1. RV32IALUControl

IO pins

Pin Direction Width Description
OP Input 5 Operation code
LOCAL_OP Output 3 OP[2:0], the index within a result group
HIGH_HALF Output 1 OP[3], selects the upper result group
OUT_OF_RANGE Output 1 OP[4], forces the result to zero
SUB Output 1 Subtract, and enable the comparisons
SHIFT_LEFT, SHIFT_ARITHMETIC Output 1 each Shifter direction and sign fill

Behavior

SUB is 1 for SUB (1), SLT (8) and SLTU (9). The shift controls are plain functions of the opcode bits, not shift enables: they can be high while another result is selected, which is harmless because the result selector ignores the shifter then. OUT_OF_RANGE detects codes 16–31; the result selector also maps 13–15 to zero.

C++ example

These binary references share the namespace rv32i_alu_example. They omit propagation delays and X/Z values.

#include <array>
#include <cstdint>
namespace rv32i_alu_example {
constexpr uint64_t MASK = 0xffffffffu, SIGN = 0x80000000u;
struct Control {
    unsigned LOCAL_OP;
    bool HIGH_HALF, OUT_OF_RANGE, SUB, SHIFT_LEFT, SHIFT_ARITHMETIC;
};
Control control(unsigned op) { // OP is a five-bit input.
    const bool arithmetic = !(op & 16) && !(op & 4) && !(op & 2);
    return {op & 7, bool(op & 8), bool(op & 16),
            arithmetic && bool(op & 9), !(op & 2), bool(op & 1)};
}
}

Unknown inputs

LOCAL_OP, HIGH_HALF and OUT_OF_RANGE are wiring and pass X and Z through unchanged. SUB and the shift controls follow their NOT/AND/OR gates.

Implementation

Structural implementation

A splitter and a joiner expose the opcode bits. NOT gates on bits 1, 2 and 4 and two AND gates detect the arithmetic codes 0, 1, 8 and 9; an OR of bits 3 and 0 and a final AND give SUB.

Behavioral implementation

The compact form evaluates the same gates bit by bit with the gate rules (a low input forces AND low, a high input forces OR high, other X or Z inputs give X; wiring passes Z unchanged), so it gives the same outputs as the structural circuit for every four-state input, and it runs on delays proven on that circuit (delay model). CompactFormEquivalenceTest runs both forms on binary, dense four-state and single-unknown vectors.

Examples

All 32 recorded rows of RV32IALUControlTest, 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 OPInput · 5 bit HIGH_HALFExpected output · 1 bit LOCAL_OPExpected output · 3 bit OUT_OF_RANGEExpected output · 1 bit SHIFT_ARITHMETICExpected output · 1 bit SHIFT_LEFTExpected output · 1 bit SUBExpected output · 1 bit
#0row-04 0x00 0 0x0 0 0 1 0
#1row-17 0x01 0 0x1 0 1 1 1
#2row-211 0x02 0 0x2 0 0 0 0
#3row-314 0x03 0 0x3 0 1 0 0
#4row-419 0x04 0 0x4 0 0 1 0
#5row-522 0x05 0 0x5 0 1 1 0
#6row-625 0x06 0 0x6 0 0 0 0
#7row-728 0x07 0 0x7 0 1 0 0
#8row-833 0x08 1 0x0 0 0 1 1
#9row-935 0x09 1 0x1 0 1 1 1
#10row-1039 0x0A 1 0x2 0 0 0 0
#11row-1141 0x0B 1 0x3 0 1 0 0
#12row-1246 0x0C 1 0x4 0 0 1 0
#13row-1348 0x0D 1 0x5 0 1 1 0
#14row-1451 0x0E 1 0x6 0 0 0 0
#15row-1553 0x0F 1 0x7 0 1 0 0
#16row-1656 0x10 0 0x0 1 0 1 0
#17row-1759 0x11 0 0x1 1 1 1 0
#18row-1862 0x12 0 0x2 1 0 0 0
#19row-1965 0x13 0 0x3 1 1 0 0
#20row-2068 0x14 0 0x4 1 0 1 0
#21row-2171 0x15 0 0x5 1 1 1 0
#22row-2274 0x16 0 0x6 1 0 0 0
#23row-2377 0x17 0 0x7 1 1 0 0
#24row-2480 0x18 1 0x0 1 0 1 0
#25row-2582 0x19 1 0x1 1 1 1 0
#26row-2685 0x1A 1 0x2 1 0 0 0
#27row-2787 0x1B 1 0x3 1 1 0 0
#28row-2890 0x1C 1 0x4 1 0 1 0
#29row-2992 0x1D 1 0x5 1 1 1 0
#30row-3095 0x1E 1 0x6 1 0 0 0
#31row-3197 0x1F 1 0x7 1 1 0 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.

All 32 binary opcodes are recorded, each checking every output.

Embedded simulation

Open RV32IALUControl in the simulator

Tests

RV32IALUControlTest checks every binary opcode and every output. Source: RV32IALU.cpp.

4.3.3.2. RV32IALUAddSub

IO pins

Pin Direction Width Description
A, B Input 32 each Operands
SUB Input 1 0: addition; 1: subtraction
OUT Output 32 Wrapped result
C_OUT Output 1 Addition carry; for subtraction, 1 means no borrow
OVERFLOW Output 1 Signed overflow

Behavior

The adder computes A + (B XOR {32{SUB}}) + SUB. Unlike the Chapter 2 AddSub<W>, SUB is also the carry input, so subtraction needs no separate carry pin. Subtraction sets C_OUT when unsigned A >= B. Overflow is independent of the unsigned carry.

C++ example

namespace rv32i_alu_example {
struct Arithmetic { uint32_t OUT; bool C_OUT, OVERFLOW; };
Arithmetic addsub(uint32_t a, uint32_t b, bool sub) {
    const uint64_t wide = uint64_t(a) + (sub ? (uint64_t(b) ^ MASK) : b) + sub;
    const uint32_t out = uint32_t(wide & MASK);
    const bool overflow = ((sub ? (a ^ b) : ~(a ^ b)) & (a ^ out) & SIGN) != 0;
    return {out, bool(wide >> 32), overflow};
}
}

Unknown inputs

Each bit follows the adder's XOR/AND/OR logic, so a known controlling value can mask an unknown one; the whole word is not automatically discarded.

Implementation

Structural implementation

The word gate B_XOR_SUB (XORGate<32>, one XOR per bit) inverts B when SUB is high; the wiring part SUB_WORD spreads SUB across the word (word gates). SUB also drives the carry input of one ParallelPrefixAdder<32> named PREFIX_ADDER. Overflow is C_SIGN XOR C_OUT: the carry into the sign bit against the carry out of it.

The carry crosses 32 bits in five prefix levels instead of 32 ripple stages:

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.

Pathunitticksembeddedpsdesktopps
Prefix adder, operand to carry out A → C_OUT12682475
Ripple adder, operand to carry out A → C_OUT653,3842,356

Behavioral implementation

The compact form evaluates the same gates bit by bit with the gate rules (a low input forces AND low, a high input forces OR high, other X or Z inputs give X; wiring passes Z unchanged), so it gives the same outputs as the structural circuit for every four-state input, and it runs on delays proven on that circuit (delay model). CompactFormEquivalenceTest runs both forms on binary, dense four-state and single-unknown vectors.

Examples

All 80 recorded rows of RV32IALUAddSubTest, 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 · 32 bit BInput · 32 bit SUBInput · 1 bit C_OUTExpected output · 1 bit OUTExpected output · 32 bit OVERFLOWExpected output · 1 bit
#0row-010 0x00000000 0x00000000 0 0 0x00000000 0
#1row-115 0x00000001 0x00000002 0 0 0x00000003 0
#2row-230 0xFFFFFFFF 0x00000001 0 1 0x00000000 0
#3row-339 0xFFFFFFFF 0xFFFFFFFF 0 1 0xFFFFFFFE 0
#4row-454 0x55555555 0xAAAAAAAA 0 0 0xFFFFFFFF 0
#5row-565 0x55555555 0xAAAAAAAA 1 0 0xAAAAAAAB 1
#6row-679 0x7FFFFFFF 0x00000001 0 0 0x80000000 1
#7row-789 0x80000000 0x80000000 0 1 0x00000000 1
#8row-8100 0x7FFFFFFF 0xFFFFFFFF 0 1 0x7FFFFFFE 0
#9row-9113 0x00000005 0x00000003 1 1 0x00000002 0
#10row-10126 0x00000000 0x00000001 1 0 0xFFFFFFFF 0
#11row-11135 0x80000000 0x00000001 1 1 0x7FFFFFFF 1
#12row-12146 0x7FFFFFFF 0xFFFFFFFF 1 0 0x80000000 1
#13row-13156 0x80000000 0x7FFFFFFF 1 1 0x00000001 1
#14row-14167 0xFFFFFFFF 0xFFFFFFFF 1 1 0x00000000 0
#15row-15177 0x00000001 0x00000001 0 0 0x00000002 0
#16row-16191 0x00000002 0x00000001 1 1 0x00000001 0
#17row-17202 0x00000003 0x00000001 0 0 0x00000004 0
#18row-18216 0x00000004 0x00000001 1 1 0x00000003 0
#19row-19227 0x00000007 0x00000001 0 0 0x00000008 0
#20row-20241 0x00000008 0x00000001 1 1 0x00000007 0
#21row-21252 0x0000000F 0x00000001 0 0 0x00000010 0
#22row-22266 0x00000010 0x00000001 1 1 0x0000000F 0
#23row-23277 0x0000001F 0x00000001 0 0 0x00000020 0
#24row-24291 0x00000020 0x00000001 1 1 0x0000001F 0
#25row-25302 0x0000003F 0x00000001 0 0 0x00000040 0
#26row-26316 0x00000040 0x00000001 1 1 0x0000003F 0
#27row-27327 0x0000007F 0x00000001 0 0 0x00000080 0
#28row-28341 0x00000080 0x00000001 1 1 0x0000007F 0
#29row-29352 0x000000FF 0x00000001 0 0 0x00000100 0
#30row-30366 0x00000100 0x00000001 1 1 0x000000FF 0
#31row-31377 0x000001FF 0x00000001 0 0 0x00000200 0
#32row-32391 0x00000200 0x00000001 1 1 0x000001FF 0
#33row-33402 0x000003FF 0x00000001 0 0 0x00000400 0
#34row-34416 0x00000400 0x00000001 1 1 0x000003FF 0
#35row-35427 0x000007FF 0x00000001 0 0 0x00000800 0
#36row-36441 0x00000800 0x00000001 1 1 0x000007FF 0
#37row-37452 0x00000FFF 0x00000001 0 0 0x00001000 0
#38row-38466 0x00001000 0x00000001 1 1 0x00000FFF 0
#39row-39477 0x00001FFF 0x00000001 0 0 0x00002000 0
#40row-40491 0x00002000 0x00000001 1 1 0x00001FFF 0
#41row-41502 0x00003FFF 0x00000001 0 0 0x00004000 0
#42row-42516 0x00004000 0x00000001 1 1 0x00003FFF 0
#43row-43528 0x00007FFF 0x00000001 0 0 0x00008000 0
#44row-44542 0x00008000 0x00000001 1 1 0x00007FFF 0
#45row-45555 0x0000FFFF 0x00000001 0 0 0x00010000 0
#46row-46569 0x00010000 0x00000001 1 1 0x0000FFFF 0
#47row-47582 0x0001FFFF 0x00000001 0 0 0x00020000 0
#48row-48595 0x00020000 0x00000001 1 1 0x0001FFFF 0
#49row-49608 0x0003FFFF 0x00000001 0 0 0x00040000 0
#50row-50621 0x00040000 0x00000001 1 1 0x0003FFFF 0
#51row-51634 0x0007FFFF 0x00000001 0 0 0x00080000 0
#52row-52647 0x00080000 0x00000001 1 1 0x0007FFFF 0
#53row-53660 0x000FFFFF 0x00000001 0 0 0x00100000 0
#54row-54673 0x00100000 0x00000001 1 1 0x000FFFFF 0
#55row-55686 0x001FFFFF 0x00000001 0 0 0x00200000 0
#56row-56699 0x00200000 0x00000001 1 1 0x001FFFFF 0
#57row-57712 0x003FFFFF 0x00000001 0 0 0x00400000 0
#58row-58725 0x00400000 0x00000001 1 1 0x003FFFFF 0
#59row-59738 0x007FFFFF 0x00000001 0 0 0x00800000 0
#60row-60751 0x00800000 0x00000001 1 1 0x007FFFFF 0
#61row-61764 0x00FFFFFF 0x00000001 0 0 0x01000000 0
#62row-62777 0x01000000 0x00000001 1 1 0x00FFFFFF 0
#63row-63790 0x01FFFFFF 0x00000001 0 0 0x02000000 0
#64row-64802 0x02000000 0x00000001 1 1 0x01FFFFFF 0
#65row-65815 0x03FFFFFF 0x00000001 0 0 0x04000000 0
#66row-66827 0x04000000 0x00000001 1 1 0x03FFFFFF 0
#67row-67840 0x07FFFFFF 0x00000001 0 0 0x08000000 0
#68row-68852 0x08000000 0x00000001 1 1 0x07FFFFFF 0
#69row-69865 0x0FFFFFFF 0x00000001 0 0 0x10000000 0
#70row-70877 0x10000000 0x00000001 1 1 0x0FFFFFFF 0
#71row-71890 0x1FFFFFFF 0x00000001 0 0 0x20000000 0
#72row-72901 0x20000000 0x00000001 1 1 0x1FFFFFFF 0
#73row-73914 0x3FFFFFFF 0x00000001 0 0 0x40000000 0
#74row-74925 0x40000000 0x00000001 1 1 0x3FFFFFFF 0
#75row-75939 0x7FFFFFFF 0x00000001 0 0 0x80000000 1
#76row-76949 0x80000000 0x00000001 1 1 0x7FFFFFFF 1
#77row-77960 0b00000000000000000000000000X00000 0x00000000 0 0 0b00000000000000000000000000X00000 0
#78row-78962 0b00000000000000000000000000Z00000 0x00000000 0 0 0b00000000000000000000000000X00000 0
#79row-79973 0x00000000 0x00000000 X X 0bXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 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 recorded cases cover addition and subtraction at the carry, borrow and signed-overflow boundaries, and full-length carry chains.

Embedded simulation

Open RV32IALUAddSub in the simulator

Tests

RV32IALUAddSubTest checks arithmetic boundaries and all three outputs; RV32IALUSliceTest checks a representative four-bit add/subtract slice exhaustively. Source: RV32IALUAddSub.cpp.

4.3.3.3. RV32IALULogic

IO pins

Pin Direction Width Description
A, B Input 32 each Operands
AND_OUT, OR_OUT, XOR_OUT Output 32 each The three bitwise results

Behavior

All three outputs are always active; there is no opcode. The result selector picks one of them.

C++ example

namespace rv32i_alu_example {
struct Logic { uint32_t AND_OUT, OR_OUT, XOR_OUT; };
Logic logic(uint32_t a, uint32_t b) { return {a & b, a | b, a ^ b}; }
}

Unknown inputs

AND with zero gives zero and OR with one gives one; other cases with X or Z give X, including XOR. Each bit is independent.

Implementation

Structural implementation

Three word gates, AND (ANDGate<32>), OR (ORGate<32>) and XOR (XORGate<32>), take the whole operands and drive the three outputs. Each is 32 one-bit gates, grouped as a word, so the three paths are independent per bit.

Behavioral implementation

The compact form evaluates the same gates bit by bit with the gate rules (a low input forces AND low, a high input forces OR high, other X or Z inputs give X; wiring passes Z unchanged), so it gives the same outputs as the structural circuit for every four-state input, and it runs on delays proven on that circuit (delay model). CompactFormEquivalenceTest runs both forms on binary, dense four-state and single-unknown vectors.

Examples

All 69 recorded rows of RV32IALULogicTest, 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 · 32 bit BInput · 32 bit AND_OUTExpected output · 32 bit OR_OUTExpected output · 32 bit XOR_OUTExpected output · 32 bit
#0row-01 0xF0F0F0F0 0x0FF00FF0 0x00F000F0 0xFFF0FFF0 0xFF00FF00
#1row-13 0xFFFFFFFF 0x00000000 0x00000000 0xFFFFFFFF 0xFFFFFFFF
#2row-25 0xAAAAAAAA 0x55555555 0x00000000 0xFFFFFFFF 0xFFFFFFFF
#3row-37 0x80000000 0x7FFFFFFF 0x00000000 0xFFFFFFFF 0xFFFFFFFF
#4row-49 0x00000001 0x00000000 0x00000000 0x00000001 0x00000001
#5row-511 0x00000001 0x00000001 0x00000001 0x00000001 0x00000000
#6row-613 0x00000002 0x00000000 0x00000000 0x00000002 0x00000002
#7row-715 0x00000002 0x00000002 0x00000002 0x00000002 0x00000000
#8row-817 0x00000004 0x00000000 0x00000000 0x00000004 0x00000004
#9row-919 0x00000004 0x00000004 0x00000004 0x00000004 0x00000000
#10row-1021 0x00000008 0x00000000 0x00000000 0x00000008 0x00000008
#11row-1123 0x00000008 0x00000008 0x00000008 0x00000008 0x00000000
#12row-1225 0x00000010 0x00000000 0x00000000 0x00000010 0x00000010
#13row-1327 0x00000010 0x00000010 0x00000010 0x00000010 0x00000000
#14row-1429 0x00000020 0x00000000 0x00000000 0x00000020 0x00000020
#15row-1531 0x00000020 0x00000020 0x00000020 0x00000020 0x00000000
#16row-1633 0x00000040 0x00000000 0x00000000 0x00000040 0x00000040
#17row-1735 0x00000040 0x00000040 0x00000040 0x00000040 0x00000000
#18row-1837 0x00000080 0x00000000 0x00000000 0x00000080 0x00000080
#19row-1939 0x00000080 0x00000080 0x00000080 0x00000080 0x00000000
#20row-2041 0x00000100 0x00000000 0x00000000 0x00000100 0x00000100
#21row-2143 0x00000100 0x00000100 0x00000100 0x00000100 0x00000000
#22row-2245 0x00000200 0x00000000 0x00000000 0x00000200 0x00000200
#23row-2347 0x00000200 0x00000200 0x00000200 0x00000200 0x00000000
#24row-2449 0x00000400 0x00000000 0x00000000 0x00000400 0x00000400
#25row-2551 0x00000400 0x00000400 0x00000400 0x00000400 0x00000000
#26row-2653 0x00000800 0x00000000 0x00000000 0x00000800 0x00000800
#27row-2755 0x00000800 0x00000800 0x00000800 0x00000800 0x00000000
#28row-2857 0x00001000 0x00000000 0x00000000 0x00001000 0x00001000
#29row-2959 0x00001000 0x00001000 0x00001000 0x00001000 0x00000000
#30row-3061 0x00002000 0x00000000 0x00000000 0x00002000 0x00002000
#31row-3163 0x00002000 0x00002000 0x00002000 0x00002000 0x00000000
#32row-3265 0x00004000 0x00000000 0x00000000 0x00004000 0x00004000
#33row-3367 0x00004000 0x00004000 0x00004000 0x00004000 0x00000000
#34row-3469 0x00008000 0x00000000 0x00000000 0x00008000 0x00008000
#35row-3571 0x00008000 0x00008000 0x00008000 0x00008000 0x00000000
#36row-3673 0x00010000 0x00000000 0x00000000 0x00010000 0x00010000
#37row-3775 0x00010000 0x00010000 0x00010000 0x00010000 0x00000000
#38row-3877 0x00020000 0x00000000 0x00000000 0x00020000 0x00020000
#39row-3979 0x00020000 0x00020000 0x00020000 0x00020000 0x00000000
#40row-4081 0x00040000 0x00000000 0x00000000 0x00040000 0x00040000
#41row-4183 0x00040000 0x00040000 0x00040000 0x00040000 0x00000000
#42row-4285 0x00080000 0x00000000 0x00000000 0x00080000 0x00080000
#43row-4387 0x00080000 0x00080000 0x00080000 0x00080000 0x00000000
#44row-4489 0x00100000 0x00000000 0x00000000 0x00100000 0x00100000
#45row-4591 0x00100000 0x00100000 0x00100000 0x00100000 0x00000000
#46row-4693 0x00200000 0x00000000 0x00000000 0x00200000 0x00200000
#47row-4795 0x00200000 0x00200000 0x00200000 0x00200000 0x00000000
#48row-4897 0x00400000 0x00000000 0x00000000 0x00400000 0x00400000
#49row-4999 0x00400000 0x00400000 0x00400000 0x00400000 0x00000000
#50row-50101 0x00800000 0x00000000 0x00000000 0x00800000 0x00800000
#51row-51103 0x00800000 0x00800000 0x00800000 0x00800000 0x00000000
#52row-52105 0x01000000 0x00000000 0x00000000 0x01000000 0x01000000
#53row-53107 0x01000000 0x01000000 0x01000000 0x01000000 0x00000000
#54row-54109 0x02000000 0x00000000 0x00000000 0x02000000 0x02000000
#55row-55111 0x02000000 0x02000000 0x02000000 0x02000000 0x00000000
#56row-56113 0x04000000 0x00000000 0x00000000 0x04000000 0x04000000
#57row-57115 0x04000000 0x04000000 0x04000000 0x04000000 0x00000000
#58row-58117 0x08000000 0x00000000 0x00000000 0x08000000 0x08000000
#59row-59119 0x08000000 0x08000000 0x08000000 0x08000000 0x00000000
#60row-60121 0x10000000 0x00000000 0x00000000 0x10000000 0x10000000
#61row-61123 0x10000000 0x10000000 0x10000000 0x10000000 0x00000000
#62row-62125 0x20000000 0x00000000 0x00000000 0x20000000 0x20000000
#63row-63127 0x20000000 0x20000000 0x20000000 0x20000000 0x00000000
#64row-64129 0x40000000 0x00000000 0x00000000 0x40000000 0x40000000
#65row-65131 0x40000000 0x40000000 0x40000000 0x40000000 0x00000000
#66row-66133 0x80000000 0x00000000 0x00000000 0x80000000 0x80000000
#67row-67135 0x80000000 0x80000000 0x80000000 0x80000000 0x00000000
#68row-68137 0bZX10ZX10ZX10ZX10ZX10ZX10ZX10ZX10 0b10ZX10ZX10ZX10ZX10ZX10ZX10ZX10ZX 0bX0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0 0b1X1X1X1X1X1X1X1X1X1X1X1X1X1X1X1X 0bXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

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 recorded cases include complementary patterns and four-state inputs.

Embedded simulation

Open RV32IALULogic in the simulator

Tests

RV32IALULogicTest checks all three outputs, including four-state cases. Source: RV32IALULogic.cpp.

4.3.3.4. RV32IALUShifter

IO pins

Pin Direction Width Description
A Input 32 Word to shift
B Input 32 Shift amount; only B[4:0] is used
LEFT Input 1 1: left; 0: right
ARITHMETIC Input 1 Sign fill for right shifts; ignored for left shifts
OUT Output 32 Shifted word

Behavior

The distance is 0–31. Left shifts and logical right shifts fill with zero; arithmetic right shifts fill with the original sign bit. Distance zero keeps the word. There is no rotation and no shifted-out carry, unlike the Chapter 2 BarrelShifter<W>.

C++ example

namespace rv32i_alu_example {
uint32_t shift(uint32_t a, uint32_t b, bool left, bool arithmetic) {
    const unsigned n = b & 31;
    if (left) return uint32_t((uint64_t(a) << n) & MASK);
    uint32_t out = a >> n;
    if (n && arithmetic && (a & SIGN)) out |= uint32_t(MASK << (32 - n));
    return out;
}
}

Unknown inputs

B[31:5] is unused even when unknown. The distance bits drive gate-built muxes, so an unknown distance bit does not necessarily keep equal data. Left shifting disables sign fill.

Implementation

Structural implementation

One right-shift network selects distances 1, 2, 4, 8 and 16 in five stages, SHIFT_S0 … SHIFT_S4. Each stage is one 2:1 word mux (Mux<2,32>, one 2:1 mux per bit) choosing between the word and the word moved down by its distance, with the fill bit entering at the top; the moved word is wiring only (a splitter and the joiner SHIFT_Sk_MOVED). The word muxes INPUT_REVERSE and OUTPUT_REVERSE, selected by LEFT, reverse the bit order at the input and output, so the same network performs left shifts. The fill bit is A[31] AND ARITHMETIC AND NOT LEFT.

Behavioral implementation

The compact form evaluates the same gates bit by bit with the gate rules (a low input forces AND low, a high input forces OR high, other X or Z inputs give X; wiring passes Z unchanged), so it gives the same outputs as the structural circuit for every four-state input, and it runs on delays proven on that circuit (delay model). CompactFormEquivalenceTest runs both forms on binary, dense four-state and single-unknown vectors.

Examples

All 447 recorded rows of RV32IALUShifterTest, 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 · 32 bit ARITHMETICInput · 1 bit BInput · 32 bit LEFTInput · 1 bit OUTExpected output · 32 bit
#0row-014 0x80000001 0 0x00000000 1 0x80000001
#1row-130 0x80000001 0 0x00000000 0 0x80000001
#2row-234 0x80000001 1 0x00000000 0 0x80000001
#3row-350 0x7FFFFFFF 0 0x00000000 1 0x7FFFFFFF
#4row-466 0x7FFFFFFF 0 0x00000000 0 0x7FFFFFFF
#5row-568 0x7FFFFFFF 1 0x00000000 0 0x7FFFFFFF
#6row-683 0xFFFFFFFF 0 0x00000000 1 0xFFFFFFFF
#7row-799 0xFFFFFFFF 0 0x00000000 0 0xFFFFFFFF
#8row-8103 0xFFFFFFFF 1 0x00000000 0 0xFFFFFFFF
#9row-9119 0x00000001 0 0x00000000 1 0x00000001
#10row-10135 0x00000001 0 0x00000000 0 0x00000001
#11row-11137 0x00000001 1 0x00000000 0 0x00000001
#12row-12152 0x80000001 0 0x00000001 1 0x00000002
#13row-13168 0x80000001 0 0x00000001 0 0x40000000
#14row-14183 0x80000001 1 0x00000001 0 0xC0000000
#15row-15198 0x7FFFFFFF 0 0x00000001 1 0xFFFFFFFE
#16row-16214 0x7FFFFFFF 0 0x00000001 0 0x3FFFFFFF
#17row-17216 0x7FFFFFFF 1 0x00000001 0 0x3FFFFFFF
#18row-18231 0xFFFFFFFF 0 0x00000001 1 0xFFFFFFFE
#19row-19247 0xFFFFFFFF 0 0x00000001 0 0x7FFFFFFF
#20row-20262 0xFFFFFFFF 1 0x00000001 0 0xFFFFFFFF
#21row-21277 0x00000001 0 0x00000001 1 0x00000002
#22row-22292 0x00000001 0 0x00000001 0 0x00000000
#23row-23294 0x00000001 1 0x00000001 0 0x00000000
#24row-24309 0x80000001 0 0x00000002 1 0x00000004
#25row-25325 0x80000001 0 0x00000002 0 0x20000000
#26row-26338 0x80000001 1 0x00000002 0 0xE0000000
#27row-27353 0x7FFFFFFF 0 0x00000002 1 0xFFFFFFFC
#28row-28369 0x7FFFFFFF 0 0x00000002 0 0x1FFFFFFF
#29row-29371 0x7FFFFFFF 1 0x00000002 0 0x1FFFFFFF
#30row-30386 0xFFFFFFFF 0 0x00000002 1 0xFFFFFFFC
#31row-31402 0xFFFFFFFF 0 0x00000002 0 0x3FFFFFFF
#32row-32415 0xFFFFFFFF 1 0x00000002 0 0xFFFFFFFF
#33row-33430 0x00000001 0 0x00000002 1 0x00000004
#34row-34445 0x00000001 0 0x00000002 0 0x00000000
#35row-35447 0x00000001 1 0x00000002 0 0x00000000
#36row-36462 0x80000001 0 0x00000003 1 0x00000008
#37row-37478 0x80000001 0 0x00000003 0 0x10000000
#38row-38493 0x80000001 1 0x00000003 0 0xF0000000
#39row-39508 0x7FFFFFFF 0 0x00000003 1 0xFFFFFFF8
#40row-40524 0x7FFFFFFF 0 0x00000003 0 0x0FFFFFFF
#41row-41526 0x7FFFFFFF 1 0x00000003 0 0x0FFFFFFF
#42row-42541 0xFFFFFFFF 0 0x00000003 1 0xFFFFFFF8
#43row-43557 0xFFFFFFFF 0 0x00000003 0 0x1FFFFFFF
#44row-44572 0xFFFFFFFF 1 0x00000003 0 0xFFFFFFFF
#45row-45587 0x00000001 0 0x00000003 1 0x00000008
#46row-46602 0x00000001 0 0x00000003 0 0x00000000
#47row-47604 0x00000001 1 0x00000003 0 0x00000000
#48row-48619 0x80000001 0 0x00000004 1 0x00000010
#49row-49635 0x80000001 0 0x00000004 0 0x08000000
#50row-50646 0x80000001 1 0x00000004 0 0xF8000000
#51row-51661 0x7FFFFFFF 0 0x00000004 1 0xFFFFFFF0
#52row-52677 0x7FFFFFFF 0 0x00000004 0 0x07FFFFFF
#53row-53679 0x7FFFFFFF 1 0x00000004 0 0x07FFFFFF
#54row-54694 0xFFFFFFFF 0 0x00000004 1 0xFFFFFFF0
#55row-55710 0xFFFFFFFF 0 0x00000004 0 0x0FFFFFFF
#56row-56721 0xFFFFFFFF 1 0x00000004 0 0xFFFFFFFF
#57row-57736 0x00000001 0 0x00000004 1 0x00000010
#58row-58751 0x00000001 0 0x00000004 0 0x00000000
#59row-59753 0x00000001 1 0x00000004 0 0x00000000
#60row-60768 0x80000001 0 0x00000005 1 0x00000020
#61row-61784 0x80000001 0 0x00000005 0 0x04000000
#62row-62799 0x80000001 1 0x00000005 0 0xFC000000
#63row-63814 0x7FFFFFFF 0 0x00000005 1 0xFFFFFFE0
#64row-64830 0x7FFFFFFF 0 0x00000005 0 0x03FFFFFF
#65row-65832 0x7FFFFFFF 1 0x00000005 0 0x03FFFFFF
#66row-66847 0xFFFFFFFF 0 0x00000005 1 0xFFFFFFE0
#67row-67863 0xFFFFFFFF 0 0x00000005 0 0x07FFFFFF
#68row-68878 0xFFFFFFFF 1 0x00000005 0 0xFFFFFFFF
#69row-69893 0x00000001 0 0x00000005 1 0x00000020
#70row-70908 0x00000001 0 0x00000005 0 0x00000000
#71row-71910 0x00000001 1 0x00000005 0 0x00000000
#72row-72925 0x80000001 0 0x00000006 1 0x00000040
#73row-73941 0x80000001 0 0x00000006 0 0x02000000
#74row-74954 0x80000001 1 0x00000006 0 0xFE000000
#75row-75969 0x7FFFFFFF 0 0x00000006 1 0xFFFFFFC0
#76row-76985 0x7FFFFFFF 0 0x00000006 0 0x01FFFFFF
#77row-77987 0x7FFFFFFF 1 0x00000006 0 0x01FFFFFF
#78row-781002 0xFFFFFFFF 0 0x00000006 1 0xFFFFFFC0
#79row-791018 0xFFFFFFFF 0 0x00000006 0 0x03FFFFFF
#80row-801031 0xFFFFFFFF 1 0x00000006 0 0xFFFFFFFF
#81row-811046 0x00000001 0 0x00000006 1 0x00000040
#82row-821061 0x00000001 0 0x00000006 0 0x00000000
#83row-831063 0x00000001 1 0x00000006 0 0x00000000
#84row-841078 0x80000001 0 0x00000007 1 0x00000080
#85row-851094 0x80000001 0 0x00000007 0 0x01000000
#86row-861109 0x80000001 1 0x00000007 0 0xFF000000
#87row-871124 0x7FFFFFFF 0 0x00000007 1 0xFFFFFF80
#88row-881140 0x7FFFFFFF 0 0x00000007 0 0x00FFFFFF
#89row-891142 0x7FFFFFFF 1 0x00000007 0 0x00FFFFFF
#90row-901157 0xFFFFFFFF 0 0x00000007 1 0xFFFFFF80
#91row-911173 0xFFFFFFFF 0 0x00000007 0 0x01FFFFFF
#92row-921188 0xFFFFFFFF 1 0x00000007 0 0xFFFFFFFF
#93row-931203 0x00000001 0 0x00000007 1 0x00000080
#94row-941218 0x00000001 0 0x00000007 0 0x00000000
#95row-951220 0x00000001 1 0x00000007 0 0x00000000
#96row-961235 0x80000001 0 0x00000008 1 0x00000100
#97row-971251 0x80000001 0 0x00000008 0 0x00800000
#98row-981260 0x80000001 1 0x00000008 0 0xFF800000
#99row-991275 0x7FFFFFFF 0 0x00000008 1 0xFFFFFF00
#100row-1001291 0x7FFFFFFF 0 0x00000008 0 0x007FFFFF
#101row-1011293 0x7FFFFFFF 1 0x00000008 0 0x007FFFFF
#102row-1021308 0xFFFFFFFF 0 0x00000008 1 0xFFFFFF00
#103row-1031324 0xFFFFFFFF 0 0x00000008 0 0x00FFFFFF
#104row-1041333 0xFFFFFFFF 1 0x00000008 0 0xFFFFFFFF
#105row-1051348 0x00000001 0 0x00000008 1 0x00000100
#106row-1061363 0x00000001 0 0x00000008 0 0x00000000
#107row-1071365 0x00000001 1 0x00000008 0 0x00000000
#108row-1081380 0x80000001 0 0x00000009 1 0x00000200
#109row-1091396 0x80000001 0 0x00000009 0 0x00400000
#110row-1101411 0x80000001 1 0x00000009 0 0xFFC00000
#111row-1111426 0x7FFFFFFF 0 0x00000009 1 0xFFFFFE00
#112row-1121442 0x7FFFFFFF 0 0x00000009 0 0x003FFFFF
#113row-1131444 0x7FFFFFFF 1 0x00000009 0 0x003FFFFF
#114row-1141459 0xFFFFFFFF 0 0x00000009 1 0xFFFFFE00
#115row-1151475 0xFFFFFFFF 0 0x00000009 0 0x007FFFFF
#116row-1161490 0xFFFFFFFF 1 0x00000009 0 0xFFFFFFFF
#117row-1171505 0x00000001 0 0x00000009 1 0x00000200
#118row-1181520 0x00000001 0 0x00000009 0 0x00000000
#119row-1191522 0x00000001 1 0x00000009 0 0x00000000
#120row-1201537 0x80000001 0 0x0000000A 1 0x00000400
#121row-1211553 0x80000001 0 0x0000000A 0 0x00200000
#122row-1221566 0x80000001 1 0x0000000A 0 0xFFE00000
#123row-1231581 0x7FFFFFFF 0 0x0000000A 1 0xFFFFFC00
#124row-1241597 0x7FFFFFFF 0 0x0000000A 0 0x001FFFFF
#125row-1251599 0x7FFFFFFF 1 0x0000000A 0 0x001FFFFF
#126row-1261614 0xFFFFFFFF 0 0x0000000A 1 0xFFFFFC00
#127row-1271630 0xFFFFFFFF 0 0x0000000A 0 0x003FFFFF
#128row-1281643 0xFFFFFFFF 1 0x0000000A 0 0xFFFFFFFF
#129row-1291658 0x00000001 0 0x0000000A 1 0x00000400
#130row-1301673 0x00000001 0 0x0000000A 0 0x00000000
#131row-1311675 0x00000001 1 0x0000000A 0 0x00000000
#132row-1321690 0x80000001 0 0x0000000B 1 0x00000800
#133row-1331706 0x80000001 0 0x0000000B 0 0x00100000
#134row-1341721 0x80000001 1 0x0000000B 0 0xFFF00000
#135row-1351736 0x7FFFFFFF 0 0x0000000B 1 0xFFFFF800
#136row-1361752 0x7FFFFFFF 0 0x0000000B 0 0x000FFFFF
#137row-1371754 0x7FFFFFFF 1 0x0000000B 0 0x000FFFFF
#138row-1381769 0xFFFFFFFF 0 0x0000000B 1 0xFFFFF800
#139row-1391785 0xFFFFFFFF 0 0x0000000B 0 0x001FFFFF
#140row-1401800 0xFFFFFFFF 1 0x0000000B 0 0xFFFFFFFF
#141row-1411815 0x00000001 0 0x0000000B 1 0x00000800
#142row-1421830 0x00000001 0 0x0000000B 0 0x00000000
#143row-1431832 0x00000001 1 0x0000000B 0 0x00000000
#144row-1441847 0x80000001 0 0x0000000C 1 0x00001000
#145row-1451863 0x80000001 0 0x0000000C 0 0x00080000
#146row-1461874 0x80000001 1 0x0000000C 0 0xFFF80000
#147row-1471889 0x7FFFFFFF 0 0x0000000C 1 0xFFFFF000
#148row-1481905 0x7FFFFFFF 0 0x0000000C 0 0x0007FFFF
#149row-1491907 0x7FFFFFFF 1 0x0000000C 0 0x0007FFFF
#150row-1501922 0xFFFFFFFF 0 0x0000000C 1 0xFFFFF000
#151row-1511938 0xFFFFFFFF 0 0x0000000C 0 0x000FFFFF
#152row-1521949 0xFFFFFFFF 1 0x0000000C 0 0xFFFFFFFF
#153row-1531964 0x00000001 0 0x0000000C 1 0x00001000
#154row-1541979 0x00000001 0 0x0000000C 0 0x00000000
#155row-1551981 0x00000001 1 0x0000000C 0 0x00000000
#156row-1561996 0x80000001 0 0x0000000D 1 0x00002000
#157row-1572012 0x80000001 0 0x0000000D 0 0x00040000
#158row-1582027 0x80000001 1 0x0000000D 0 0xFFFC0000
#159row-1592042 0x7FFFFFFF 0 0x0000000D 1 0xFFFFE000
#160row-1602058 0x7FFFFFFF 0 0x0000000D 0 0x0003FFFF
#161row-1612060 0x7FFFFFFF 1 0x0000000D 0 0x0003FFFF
#162row-1622075 0xFFFFFFFF 0 0x0000000D 1 0xFFFFE000
#163row-1632091 0xFFFFFFFF 0 0x0000000D 0 0x0007FFFF
#164row-1642106 0xFFFFFFFF 1 0x0000000D 0 0xFFFFFFFF
#165row-1652121 0x00000001 0 0x0000000D 1 0x00002000
#166row-1662136 0x00000001 0 0x0000000D 0 0x00000000
#167row-1672138 0x00000001 1 0x0000000D 0 0x00000000
#168row-1682153 0x80000001 0 0x0000000E 1 0x00004000
#169row-1692169 0x80000001 0 0x0000000E 0 0x00020000
#170row-1702182 0x80000001 1 0x0000000E 0 0xFFFE0000
#171row-1712197 0x7FFFFFFF 0 0x0000000E 1 0xFFFFC000
#172row-1722213 0x7FFFFFFF 0 0x0000000E 0 0x0001FFFF
#173row-1732215 0x7FFFFFFF 1 0x0000000E 0 0x0001FFFF
#174row-1742230 0xFFFFFFFF 0 0x0000000E 1 0xFFFFC000
#175row-1752246 0xFFFFFFFF 0 0x0000000E 0 0x0003FFFF
#176row-1762259 0xFFFFFFFF 1 0x0000000E 0 0xFFFFFFFF
#177row-1772274 0x00000001 0 0x0000000E 1 0x00004000
#178row-1782289 0x00000001 0 0x0000000E 0 0x00000000
#179row-1792291 0x00000001 1 0x0000000E 0 0x00000000
#180row-1802306 0x80000001 0 0x0000000F 1 0x00008000
#181row-1812322 0x80000001 0 0x0000000F 0 0x00010000
#182row-1822337 0x80000001 1 0x0000000F 0 0xFFFF0000
#183row-1832352 0x7FFFFFFF 0 0x0000000F 1 0xFFFF8000
#184row-1842368 0x7FFFFFFF 0 0x0000000F 0 0x0000FFFF
#185row-1852370 0x7FFFFFFF 1 0x0000000F 0 0x0000FFFF
#186row-1862385 0xFFFFFFFF 0 0x0000000F 1 0xFFFF8000
#187row-1872401 0xFFFFFFFF 0 0x0000000F 0 0x0001FFFF
#188row-1882416 0xFFFFFFFF 1 0x0000000F 0 0xFFFFFFFF
#189row-1892431 0x00000001 0 0x0000000F 1 0x00008000
#190row-1902446 0x00000001 0 0x0000000F 0 0x00000000
#191row-1912448 0x00000001 1 0x0000000F 0 0x00000000
#192row-1922463 0x80000001 0 0x00000010 1 0x00010000
#193row-1932479 0x80000001 0 0x00000010 0 0x00008000
#194row-1942486 0x80000001 1 0x00000010 0 0xFFFF8000
#195row-1952501 0x7FFFFFFF 0 0x00000010 1 0xFFFF0000
#196row-1962517 0x7FFFFFFF 0 0x00000010 0 0x00007FFF
#197row-1972519 0x7FFFFFFF 1 0x00000010 0 0x00007FFF
#198row-1982534 0xFFFFFFFF 0 0x00000010 1 0xFFFF0000
#199row-1992550 0xFFFFFFFF 0 0x00000010 0 0x0000FFFF
#200row-2002557 0xFFFFFFFF 1 0x00000010 0 0xFFFFFFFF
#201row-2012572 0x00000001 0 0x00000010 1 0x00010000
#202row-2022587 0x00000001 0 0x00000010 0 0x00000000
#203row-2032589 0x00000001 1 0x00000010 0 0x00000000
#204row-2042604 0x80000001 0 0x00000011 1 0x00020000
#205row-2052620 0x80000001 0 0x00000011 0 0x00004000
#206row-2062635 0x80000001 1 0x00000011 0 0xFFFFC000
#207row-2072650 0x7FFFFFFF 0 0x00000011 1 0xFFFE0000
#208row-2082666 0x7FFFFFFF 0 0x00000011 0 0x00003FFF
#209row-2092668 0x7FFFFFFF 1 0x00000011 0 0x00003FFF
#210row-2102683 0xFFFFFFFF 0 0x00000011 1 0xFFFE0000
#211row-2112699 0xFFFFFFFF 0 0x00000011 0 0x00007FFF
#212row-2122714 0xFFFFFFFF 1 0x00000011 0 0xFFFFFFFF
#213row-2132729 0x00000001 0 0x00000011 1 0x00020000
#214row-2142744 0x00000001 0 0x00000011 0 0x00000000
#215row-2152746 0x00000001 1 0x00000011 0 0x00000000
#216row-2162761 0x80000001 0 0x00000012 1 0x00040000
#217row-2172777 0x80000001 0 0x00000012 0 0x00002000
#218row-2182790 0x80000001 1 0x00000012 0 0xFFFFE000
#219row-2192805 0x7FFFFFFF 0 0x00000012 1 0xFFFC0000
#220row-2202821 0x7FFFFFFF 0 0x00000012 0 0x00001FFF
#221row-2212823 0x7FFFFFFF 1 0x00000012 0 0x00001FFF
#222row-2222838 0xFFFFFFFF 0 0x00000012 1 0xFFFC0000
#223row-2232854 0xFFFFFFFF 0 0x00000012 0 0x00003FFF
#224row-2242867 0xFFFFFFFF 1 0x00000012 0 0xFFFFFFFF
#225row-2252882 0x00000001 0 0x00000012 1 0x00040000
#226row-2262897 0x00000001 0 0x00000012 0 0x00000000
#227row-2272899 0x00000001 1 0x00000012 0 0x00000000
#228row-2282914 0x80000001 0 0x00000013 1 0x00080000
#229row-2292930 0x80000001 0 0x00000013 0 0x00001000
#230row-2302945 0x80000001 1 0x00000013 0 0xFFFFF000
#231row-2312960 0x7FFFFFFF 0 0x00000013 1 0xFFF80000
#232row-2322976 0x7FFFFFFF 0 0x00000013 0 0x00000FFF
#233row-2332978 0x7FFFFFFF 1 0x00000013 0 0x00000FFF
#234row-2342993 0xFFFFFFFF 0 0x00000013 1 0xFFF80000
#235row-2353009 0xFFFFFFFF 0 0x00000013 0 0x00001FFF
#236row-2363024 0xFFFFFFFF 1 0x00000013 0 0xFFFFFFFF
#237row-2373039 0x00000001 0 0x00000013 1 0x00080000
#238row-2383054 0x00000001 0 0x00000013 0 0x00000000
#239row-2393056 0x00000001 1 0x00000013 0 0x00000000
#240row-2403071 0x80000001 0 0x00000014 1 0x00100000
#241row-2413087 0x80000001 0 0x00000014 0 0x00000800
#242row-2423098 0x80000001 1 0x00000014 0 0xFFFFF800
#243row-2433113 0x7FFFFFFF 0 0x00000014 1 0xFFF00000
#244row-2443129 0x7FFFFFFF 0 0x00000014 0 0x000007FF
#245row-2453131 0x7FFFFFFF 1 0x00000014 0 0x000007FF
#246row-2463146 0xFFFFFFFF 0 0x00000014 1 0xFFF00000
#247row-2473162 0xFFFFFFFF 0 0x00000014 0 0x00000FFF
#248row-2483173 0xFFFFFFFF 1 0x00000014 0 0xFFFFFFFF
#249row-2493188 0x00000001 0 0x00000014 1 0x00100000
#250row-2503203 0x00000001 0 0x00000014 0 0x00000000
#251row-2513205 0x00000001 1 0x00000014 0 0x00000000
#252row-2523220 0x80000001 0 0x00000015 1 0x00200000
#253row-2533236 0x80000001 0 0x00000015 0 0x00000400
#254row-2543251 0x80000001 1 0x00000015 0 0xFFFFFC00
#255row-2553266 0x7FFFFFFF 0 0x00000015 1 0xFFE00000
#256row-2563282 0x7FFFFFFF 0 0x00000015 0 0x000003FF
#257row-2573284 0x7FFFFFFF 1 0x00000015 0 0x000003FF
#258row-2583299 0xFFFFFFFF 0 0x00000015 1 0xFFE00000
#259row-2593315 0xFFFFFFFF 0 0x00000015 0 0x000007FF
#260row-2603330 0xFFFFFFFF 1 0x00000015 0 0xFFFFFFFF
#261row-2613345 0x00000001 0 0x00000015 1 0x00200000
#262row-2623360 0x00000001 0 0x00000015 0 0x00000000
#263row-2633362 0x00000001 1 0x00000015 0 0x00000000
#264row-2643377 0x80000001 0 0x00000016 1 0x00400000
#265row-2653393 0x80000001 0 0x00000016 0 0x00000200
#266row-2663406 0x80000001 1 0x00000016 0 0xFFFFFE00
#267row-2673421 0x7FFFFFFF 0 0x00000016 1 0xFFC00000
#268row-2683437 0x7FFFFFFF 0 0x00000016 0 0x000001FF
#269row-2693439 0x7FFFFFFF 1 0x00000016 0 0x000001FF
#270row-2703454 0xFFFFFFFF 0 0x00000016 1 0xFFC00000
#271row-2713470 0xFFFFFFFF 0 0x00000016 0 0x000003FF
#272row-2723483 0xFFFFFFFF 1 0x00000016 0 0xFFFFFFFF
#273row-2733498 0x00000001 0 0x00000016 1 0x00400000
#274row-2743513 0x00000001 0 0x00000016 0 0x00000000
#275row-2753515 0x00000001 1 0x00000016 0 0x00000000
#276row-2763530 0x80000001 0 0x00000017 1 0x00800000
#277row-2773546 0x80000001 0 0x00000017 0 0x00000100
#278row-2783561 0x80000001 1 0x00000017 0 0xFFFFFF00
#279row-2793576 0x7FFFFFFF 0 0x00000017 1 0xFF800000
#280row-2803592 0x7FFFFFFF 0 0x00000017 0 0x000000FF
#281row-2813594 0x7FFFFFFF 1 0x00000017 0 0x000000FF
#282row-2823609 0xFFFFFFFF 0 0x00000017 1 0xFF800000
#283row-2833625 0xFFFFFFFF 0 0x00000017 0 0x000001FF
#284row-2843640 0xFFFFFFFF 1 0x00000017 0 0xFFFFFFFF
#285row-2853655 0x00000001 0 0x00000017 1 0x00800000
#286row-2863670 0x00000001 0 0x00000017 0 0x00000000
#287row-2873672 0x00000001 1 0x00000017 0 0x00000000
#288row-2883687 0x80000001 0 0x00000018 1 0x01000000
#289row-2893703 0x80000001 0 0x00000018 0 0x00000080
#290row-2903712 0x80000001 1 0x00000018 0 0xFFFFFF80
#291row-2913727 0x7FFFFFFF 0 0x00000018 1 0xFF000000
#292row-2923743 0x7FFFFFFF 0 0x00000018 0 0x0000007F
#293row-2933745 0x7FFFFFFF 1 0x00000018 0 0x0000007F
#294row-2943760 0xFFFFFFFF 0 0x00000018 1 0xFF000000
#295row-2953776 0xFFFFFFFF 0 0x00000018 0 0x000000FF
#296row-2963785 0xFFFFFFFF 1 0x00000018 0 0xFFFFFFFF
#297row-2973800 0x00000001 0 0x00000018 1 0x01000000
#298row-2983815 0x00000001 0 0x00000018 0 0x00000000
#299row-2993817 0x00000001 1 0x00000018 0 0x00000000
#300row-3003832 0x80000001 0 0x00000019 1 0x02000000
#301row-3013848 0x80000001 0 0x00000019 0 0x00000040
#302row-3023863 0x80000001 1 0x00000019 0 0xFFFFFFC0
#303row-3033878 0x7FFFFFFF 0 0x00000019 1 0xFE000000
#304row-3043894 0x7FFFFFFF 0 0x00000019 0 0x0000003F
#305row-3053896 0x7FFFFFFF 1 0x00000019 0 0x0000003F
#306row-3063911 0xFFFFFFFF 0 0x00000019 1 0xFE000000
#307row-3073927 0xFFFFFFFF 0 0x00000019 0 0x0000007F
#308row-3083942 0xFFFFFFFF 1 0x00000019 0 0xFFFFFFFF
#309row-3093957 0x00000001 0 0x00000019 1 0x02000000
#310row-3103972 0x00000001 0 0x00000019 0 0x00000000
#311row-3113974 0x00000001 1 0x00000019 0 0x00000000
#312row-3123989 0x80000001 0 0x0000001A 1 0x04000000
#313row-3134005 0x80000001 0 0x0000001A 0 0x00000020
#314row-3144018 0x80000001 1 0x0000001A 0 0xFFFFFFE0
#315row-3154033 0x7FFFFFFF 0 0x0000001A 1 0xFC000000
#316row-3164049 0x7FFFFFFF 0 0x0000001A 0 0x0000001F
#317row-3174051 0x7FFFFFFF 1 0x0000001A 0 0x0000001F
#318row-3184066 0xFFFFFFFF 0 0x0000001A 1 0xFC000000
#319row-3194082 0xFFFFFFFF 0 0x0000001A 0 0x0000003F
#320row-3204095 0xFFFFFFFF 1 0x0000001A 0 0xFFFFFFFF
#321row-3214110 0x00000001 0 0x0000001A 1 0x04000000
#322row-3224125 0x00000001 0 0x0000001A 0 0x00000000
#323row-3234127 0x00000001 1 0x0000001A 0 0x00000000
#324row-3244142 0x80000001 0 0x0000001B 1 0x08000000
#325row-3254158 0x80000001 0 0x0000001B 0 0x00000010
#326row-3264173 0x80000001 1 0x0000001B 0 0xFFFFFFF0
#327row-3274188 0x7FFFFFFF 0 0x0000001B 1 0xF8000000
#328row-3284204 0x7FFFFFFF 0 0x0000001B 0 0x0000000F
#329row-3294206 0x7FFFFFFF 1 0x0000001B 0 0x0000000F
#330row-3304221 0xFFFFFFFF 0 0x0000001B 1 0xF8000000
#331row-3314237 0xFFFFFFFF 0 0x0000001B 0 0x0000001F
#332row-3324252 0xFFFFFFFF 1 0x0000001B 0 0xFFFFFFFF
#333row-3334267 0x00000001 0 0x0000001B 1 0x08000000
#334row-3344282 0x00000001 0 0x0000001B 0 0x00000000
#335row-3354284 0x00000001 1 0x0000001B 0 0x00000000
#336row-3364299 0x80000001 0 0x0000001C 1 0x10000000
#337row-3374315 0x80000001 0 0x0000001C 0 0x00000008
#338row-3384326 0x80000001 1 0x0000001C 0 0xFFFFFFF8
#339row-3394341 0x7FFFFFFF 0 0x0000001C 1 0xF0000000
#340row-3404357 0x7FFFFFFF 0 0x0000001C 0 0x00000007
#341row-3414359 0x7FFFFFFF 1 0x0000001C 0 0x00000007
#342row-3424374 0xFFFFFFFF 0 0x0000001C 1 0xF0000000
#343row-3434390 0xFFFFFFFF 0 0x0000001C 0 0x0000000F
#344row-3444401 0xFFFFFFFF 1 0x0000001C 0 0xFFFFFFFF
#345row-3454416 0x00000001 0 0x0000001C 1 0x10000000
#346row-3464431 0x00000001 0 0x0000001C 0 0x00000000
#347row-3474433 0x00000001 1 0x0000001C 0 0x00000000
#348row-3484448 0x80000001 0 0x0000001D 1 0x20000000
#349row-3494464 0x80000001 0 0x0000001D 0 0x00000004
#350row-3504479 0x80000001 1 0x0000001D 0 0xFFFFFFFC
#351row-3514494 0x7FFFFFFF 0 0x0000001D 1 0xE0000000
#352row-3524510 0x7FFFFFFF 0 0x0000001D 0 0x00000003
#353row-3534512 0x7FFFFFFF 1 0x0000001D 0 0x00000003
#354row-3544527 0xFFFFFFFF 0 0x0000001D 1 0xE0000000
#355row-3554543 0xFFFFFFFF 0 0x0000001D 0 0x00000007
#356row-3564558 0xFFFFFFFF 1 0x0000001D 0 0xFFFFFFFF
#357row-3574573 0x00000001 0 0x0000001D 1 0x20000000
#358row-3584588 0x00000001 0 0x0000001D 0 0x00000000
#359row-3594590 0x00000001 1 0x0000001D 0 0x00000000
#360row-3604605 0x80000001 0 0x0000001E 1 0x40000000
#361row-3614621 0x80000001 0 0x0000001E 0 0x00000002
#362row-3624634 0x80000001 1 0x0000001E 0 0xFFFFFFFE
#363row-3634649 0x7FFFFFFF 0 0x0000001E 1 0xC0000000
#364row-3644665 0x7FFFFFFF 0 0x0000001E 0 0x00000001
#365row-3654667 0x7FFFFFFF 1 0x0000001E 0 0x00000001
#366row-3664682 0xFFFFFFFF 0 0x0000001E 1 0xC0000000
#367row-3674698 0xFFFFFFFF 0 0x0000001E 0 0x00000003
#368row-3684711 0xFFFFFFFF 1 0x0000001E 0 0xFFFFFFFF
#369row-3694726 0x00000001 0 0x0000001E 1 0x40000000
#370row-3704741 0x00000001 0 0x0000001E 0 0x00000000
#371row-3714743 0x00000001 1 0x0000001E 0 0x00000000
#372row-3724758 0x80000001 0 0x0000001F 1 0x80000000
#373row-3734774 0x80000001 0 0x0000001F 0 0x00000001
#374row-3744789 0x80000001 1 0x0000001F 0 0xFFFFFFFF
#375row-3754804 0x7FFFFFFF 0 0x0000001F 1 0x80000000
#376row-3764819 0x7FFFFFFF 0 0x0000001F 0 0x00000000
#377row-3774821 0x7FFFFFFF 1 0x0000001F 0 0x00000000
#378row-3784836 0xFFFFFFFF 0 0x0000001F 1 0x80000000
#379row-3794852 0xFFFFFFFF 0 0x0000001F 0 0x00000001
#380row-3804867 0xFFFFFFFF 1 0x0000001F 0 0xFFFFFFFF
#381row-3814882 0x00000001 0 0x0000001F 1 0x80000000
#382row-3824897 0x00000001 0 0x0000001F 0 0x00000000
#383row-3834899 0x00000001 1 0x0000001F 0 0x00000000
#384row-3844914 0x80000001 0 0x00000020 1 0x80000001
#385row-3854930 0x80000001 0 0x00000020 0 0x80000001
#386row-3864934 0x80000001 1 0x00000020 0 0x80000001
#387row-3874950 0x7FFFFFFF 0 0x00000020 1 0x7FFFFFFF
#388row-3884966 0x7FFFFFFF 0 0x00000020 0 0x7FFFFFFF
#389row-3894968 0x7FFFFFFF 1 0x00000020 0 0x7FFFFFFF
#390row-3904983 0xFFFFFFFF 0 0x00000020 1 0xFFFFFFFF
#391row-3914999 0xFFFFFFFF 0 0x00000020 0 0xFFFFFFFF
#392row-3925003 0xFFFFFFFF 1 0x00000020 0 0xFFFFFFFF
#393row-3935019 0x00000001 0 0x00000020 1 0x00000001
#394row-3945035 0x00000001 0 0x00000020 0 0x00000001
#395row-3955037 0x00000001 1 0x00000020 0 0x00000001
#396row-3965052 0x80000001 0 0x00000021 1 0x00000002
#397row-3975068 0x80000001 0 0x00000021 0 0x40000000
#398row-3985083 0x80000001 1 0x00000021 0 0xC0000000
#399row-3995098 0x7FFFFFFF 0 0x00000021 1 0xFFFFFFFE
#400row-4005114 0x7FFFFFFF 0 0x00000021 0 0x3FFFFFFF
#401row-4015116 0x7FFFFFFF 1 0x00000021 0 0x3FFFFFFF
#402row-4025131 0xFFFFFFFF 0 0x00000021 1 0xFFFFFFFE
#403row-4035147 0xFFFFFFFF 0 0x00000021 0 0x7FFFFFFF
#404row-4045162 0xFFFFFFFF 1 0x00000021 0 0xFFFFFFFF
#405row-4055177 0x00000001 0 0x00000021 1 0x00000002
#406row-4065192 0x00000001 0 0x00000021 0 0x00000000
#407row-4075194 0x00000001 1 0x00000021 0 0x00000000
#408row-4085209 0x80000001 0 0x0000003F 1 0x80000000
#409row-4095225 0x80000001 0 0x0000003F 0 0x00000001
#410row-4105240 0x80000001 1 0x0000003F 0 0xFFFFFFFF
#411row-4115255 0x7FFFFFFF 0 0x0000003F 1 0x80000000
#412row-4125270 0x7FFFFFFF 0 0x0000003F 0 0x00000000
#413row-4135272 0x7FFFFFFF 1 0x0000003F 0 0x00000000
#414row-4145287 0xFFFFFFFF 0 0x0000003F 1 0x80000000
#415row-4155303 0xFFFFFFFF 0 0x0000003F 0 0x00000001
#416row-4165318 0xFFFFFFFF 1 0x0000003F 0 0xFFFFFFFF
#417row-4175333 0x00000001 0 0x0000003F 1 0x80000000
#418row-4185348 0x00000001 0 0x0000003F 0 0x00000000
#419row-4195350 0x00000001 1 0x0000003F 0 0x00000000
#420row-4205365 0x80000001 0 0xFFFFFFFF 1 0x80000000
#421row-4215381 0x80000001 0 0xFFFFFFFF 0 0x00000001
#422row-4225396 0x80000001 1 0xFFFFFFFF 0 0xFFFFFFFF
#423row-4235411 0x7FFFFFFF 0 0xFFFFFFFF 1 0x80000000
#424row-4245426 0x7FFFFFFF 0 0xFFFFFFFF 0 0x00000000
#425row-4255428 0x7FFFFFFF 1 0xFFFFFFFF 0 0x00000000
#426row-4265443 0xFFFFFFFF 0 0xFFFFFFFF 1 0x80000000
#427row-4275459 0xFFFFFFFF 0 0xFFFFFFFF 0 0x00000001
#428row-4285474 0xFFFFFFFF 1 0xFFFFFFFF 0 0xFFFFFFFF
#429row-4295489 0x00000001 0 0xFFFFFFFF 1 0x80000000
#430row-4305504 0x00000001 0 0xFFFFFFFF 0 0x00000000
#431row-4315506 0x00000001 1 0xFFFFFFFF 0 0x00000000
#432row-4325522 0bZX10ZX10ZX10ZX10ZX10ZX10ZX10ZX10 0 0x00000000 1 0bXX10XX10XX10XX10XX10XX10XX10XX10
#433row-4335538 0bZX10ZX10ZX10ZX10ZX10ZX10ZX10ZX10 0 0x00000000 0 0bXX10XX10XX10XX10XX10XX10XX10XX10
#434row-4345542 0bZX10ZX10ZX10ZX10ZX10ZX10ZX10ZX10 1 0x00000000 0 0bXX10XX10XX10XX10XX10XX10XX10XX10
#435row-4355558 0b0ZX10ZX10ZX10ZX10ZX10ZX10ZX10ZX1 0 0x00000005 1 0bXX10XX10XX10XX10XX10XX10XX100000
#436row-4365574 0b0ZX10ZX10ZX10ZX10ZX10ZX10ZX10ZX1 0 0x00000005 0 0b000000XX10XX10XX10XX10XX10XX10XX
#437row-4375576 0b0ZX10ZX10ZX10ZX10ZX10ZX10ZX10ZX1 1 0x00000005 0 0b000000XX10XX10XX10XX10XX10XX10XX
#438row-4385591 0bX10ZX10ZX10ZX10ZX10ZX10ZX10ZX10Z 0 0x0000001F 1 0bX0000000000000000000000000000000
#439row-4395607 0bX10ZX10ZX10ZX10ZX10ZX10ZX10ZX10Z 0 0x0000001F 0 0b0000000000000000000000000000000X
#440row-4405622 0bX10ZX10ZX10ZX10ZX10ZX10ZX10ZX10Z 1 0x0000001F 0 0bXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#441row-4415637 0x00000000 0 0b00000000000000000000000000000X00 1 0x00000000
#442row-4425640 0x00000000 0 0b00000000000000000000000000000X00 0 0x00000000
#443row-4435642 0x00000000 1 0b00000000000000000000000000000X00 0 0x00000000
#444row-4445645 0x00000000 0 0b00000000000000000000000000000Z00 1 0x00000000
#445row-4455648 0x00000000 0 0b00000000000000000000000000000Z00 0 0x00000000
#446row-4465650 0x00000000 1 0b00000000000000000000000000000Z00 0 0x00000000

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 recorded cases cover both directions, sign fill, every interesting distance and ignored upper amount bits.

Embedded simulation

Open RV32IALUShifter in the simulator

Tests

RV32IALUShifterTest checks directions, sign fill, distances, ignored upper amount bits and four-state inputs. Source: RV32IALUShifter.cpp.

4.3.3.5. RV32IALUCompare

IO pins

Pin Direction Width Description
DIFF Input 32 A − B from the add/subtract part
CARRY_IN, OVERFLOW_IN Input 1 each The subtraction's no-borrow and signed overflow
ENABLE Input 1 Enables the comparisons
EQ, LT_SIGNED, LT_UNSIGNED Output 1 each Comparison results
SLT_RESULT, SLTU_RESULT Output 32 each The less-than results as words: bit 0 holds the result, bits 31:1 are zero

Behavior

The part reads an existing subtraction instead of comparing two operands itself. Signed less-than corrects the sign of the difference with the overflow bit. When ENABLE is low, every comparison is zero, so EQ is not an always-valid equality test; branches select SUB to obtain all three.

C++ example

namespace rv32i_alu_example {
struct Compare { bool EQ, LT_SIGNED, LT_UNSIGNED; uint32_t SLT_RESULT, SLTU_RESULT; };
Compare compare(uint32_t diff, bool carry, bool overflow, bool enable) {
    const bool s = enable && (bool(diff & SIGN) != overflow);
    const bool u = enable && !carry;
    return {enable && diff == 0, s, u, uint32_t(s), uint32_t(u)};
}
}

Unknown inputs

A low ENABLE masks unknown subtraction inputs. When enabled, the outputs follow four-state zero detection, XOR and inversion. The upper bits of the result words stay 0.

Implementation

Structural implementation

A Chapter 2 ZeroDetect<32> named ARITHMETIC_ZERO gives equality. A sign splitter, XOR, NOT and AND gates give the less-than results, and joiners widen them into words.

Behavioral implementation

The compact form evaluates the same gates bit by bit with the gate rules (a low input forces AND low, a high input forces OR high, other X or Z inputs give X; wiring passes Z unchanged), so it gives the same outputs as the structural circuit for every four-state input, and it runs on delays proven on that circuit (delay model). CompactFormEquivalenceTest runs both forms on binary, dense four-state and single-unknown vectors.

Examples

All 34 recorded rows of RV32IALUCompareTest, 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 CARRY_INInput · 1 bit DIFFInput · 32 bit ENABLEInput · 1 bit OVERFLOW_INInput · 1 bit EQExpected output · 1 bit LT_SIGNEDExpected output · 1 bit LT_UNSIGNEDExpected output · 1 bit SLTU_RESULTExpected output · 32 bit SLT_RESULTExpected output · 32 bit
#0row-07 0 0x00000000 0 0 0 0 0 0x00000000 0x00000000
#1row-115 0 0x00000001 0 0 0 0 0 0x00000000 0x00000000
#2row-221 0 0x80000000 0 0 0 0 0 0x00000000 0x00000000
#3row-327 0 0xFFFFFFFF 0 0 0 0 0 0x00000000 0x00000000
#4row-435 0 0x00000000 1 0 1 0 1 0x00000001 0x00000000
#5row-543 0 0x00000001 1 0 0 0 1 0x00000001 0x00000000
#6row-649 0 0x80000000 1 0 0 1 1 0x00000001 0x00000001
#7row-755 0 0xFFFFFFFF 1 0 0 1 1 0x00000001 0x00000001
#8row-863 1 0x00000000 0 0 0 0 0 0x00000000 0x00000000
#9row-971 1 0x00000001 0 0 0 0 0 0x00000000 0x00000000
#10row-1077 1 0x80000000 0 0 0 0 0 0x00000000 0x00000000
#11row-1183 1 0xFFFFFFFF 0 0 0 0 0 0x00000000 0x00000000
#12row-1291 1 0x00000000 1 0 1 0 0 0x00000000 0x00000000
#13row-1399 1 0x00000001 1 0 0 0 0 0x00000000 0x00000000
#14row-14105 1 0x80000000 1 0 0 1 0 0x00000000 0x00000001
#15row-15111 1 0xFFFFFFFF 1 0 0 1 0 0x00000000 0x00000001
#16row-16119 0 0x00000000 0 1 0 0 0 0x00000000 0x00000000
#17row-17127 0 0x00000001 0 1 0 0 0 0x00000000 0x00000000
#18row-18133 0 0x80000000 0 1 0 0 0 0x00000000 0x00000000
#19row-19139 0 0xFFFFFFFF 0 1 0 0 0 0x00000000 0x00000000
#20row-20147 0 0x00000000 1 1 1 1 1 0x00000001 0x00000001
#21row-21155 0 0x00000001 1 1 0 1 1 0x00000001 0x00000001
#22row-22161 0 0x80000000 1 1 0 0 1 0x00000001 0x00000000
#23row-23167 0 0xFFFFFFFF 1 1 0 0 1 0x00000001 0x00000000
#24row-24175 1 0x00000000 0 1 0 0 0 0x00000000 0x00000000
#25row-25183 1 0x00000001 0 1 0 0 0 0x00000000 0x00000000
#26row-26189 1 0x80000000 0 1 0 0 0 0x00000000 0x00000000
#27row-27195 1 0xFFFFFFFF 0 1 0 0 0 0x00000000 0x00000000
#28row-28203 1 0x00000000 1 1 1 1 0 0x00000000 0x00000001
#29row-29211 1 0x00000001 1 1 0 1 0 0x00000000 0x00000001
#30row-30217 1 0x80000000 1 1 0 0 0 0x00000000 0x00000000
#31row-31223 1 0xFFFFFFFF 1 1 0 0 0 0x00000000 0x00000000
#32row-32231 X 0bXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 0 X 0 0 0 0x00000000 0x00000000
#33row-33233 Z 0bZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 0 Z 0 0 0 0x00000000 0x00000000

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 recorded cases combine every enable, carry and overflow value with zero, one and sign-boundary differences, then add four-state inputs with the comparisons disabled.

Embedded simulation

Open RV32IALUCompare in the simulator

Tests

RV32IALUCompareTest checks enable masking, equality, the sign/overflow correction and the result words. Source: RV32IALUCompare.cpp.

4.3.3.6. RV32IALUResultSelect

IO pins

Pin Direction Width Description
ARITHMETIC_RESULT, AND_RESULT, OR_RESULT, XOR_RESULT, SHIFT_RESULT Input 32 each Part results
SLT_RESULT, SLTU_RESULT, A, B Input 32 each Comparison words and pass-through operands
LOCAL_OP Input 3 Index within a group
HIGH_HALF Input 1 Selects the upper group
OUT_OF_RANGE Input 1 Forces zero
OUT Output 32 Selected word

Behavior

The lower group, by LOCAL_OP, is arithmetic, arithmetic, AND, OR, XOR, shift, shift, shift. The upper group is SLT, SLTU, A, B, and zero for indices 4–7. OUT_OF_RANGE overrides both groups with zero.

C++ example

namespace rv32i_alu_example {
uint32_t select(uint32_t arithmetic, uint32_t and_result, uint32_t or_result,
                uint32_t xor_result, uint32_t shifted, uint32_t slt, uint32_t sltu,
                uint32_t a, uint32_t b, unsigned local, bool high, bool invalid) {
    const std::array<uint32_t,8> low{arithmetic,arithmetic,and_result,or_result,xor_result,shifted,shifted,shifted};
    const std::array<uint32_t,8> upper{slt,sltu,a,b,0,0,0,0};
    return invalid ? 0 : (high ? upper : low).at(local);
}
}

Unknown inputs

Known controls mask the unselected words; unknown controls follow the selector's AND/OR gates. The repeated arithmetic and shift choices keep separate gate terms, so an unknown selector bit gives the same outputs as the equivalent gate-built mux.

Implementation

Structural implementation

Opcode minterms qualify nine result sources. Nine word gates MASK_0 … MASK_8 (ANDGate<32>) mask the nine source words with their selects, each spread across the word by wiring, and word ORs (ORGate<32>) combine them in a balanced tree (RESULT_…): per bit the same nine ANDs and OR tree as a bit-by-bit circuit. Reserved codes select no source and give zero. RV32ILogicOptimizationTest compares this circuit with a gate-built mux reference for all 1,024 four-state selector combinations, each with four data patterns.

Behavioral implementation

The compact form evaluates the same gates bit by bit with the gate rules (a low input forces AND low, a high input forces OR high, other X or Z inputs give X; wiring passes Z unchanged), so it gives the same outputs as the structural circuit for every four-state input, and it runs on delays proven on that circuit (delay model). CompactFormEquivalenceTest runs both forms on binary, dense four-state and single-unknown vectors.

Examples

All 66 recorded rows of RV32IALUResultSelectTest, 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 · 32 bit AND_RESULTInput · 32 bit ARITHMETIC_RESULTInput · 32 bit BInput · 32 bit HIGH_HALFInput · 1 bit LOCAL_OPInput · 3 bit OR_RESULTInput · 32 bit OUT_OF_RANGEInput · 1 bit SHIFT_RESULTInput · 32 bit SLTU_RESULTInput · 32 bit SLT_RESULTInput · 32 bit XOR_RESULTInput · 32 bit OUTExpected output · 32 bit
#0row-010 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 0 0x0 0x3016745A 0 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x12345678
#1row-116 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 0 0x1 0x3016745A 0 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x12345678
#2row-226 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 0 0x2 0x3016745A 0 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x03254769
#3row-336 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 0 0x3 0x3016745A 0 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x3016745A
#4row-446 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 0 0x4 0x3016745A 0 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x2107654B
#5row-557 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 0 0x5 0x3016745A 0 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x5670123C
#6row-669 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 0 0x6 0x3016745A 0 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x5670123C
#7row-776 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 0 0x7 0x3016745A 0 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x5670123C
#8row-886 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 1 0x0 0x3016745A 0 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x4761032D
#9row-996 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 1 0x1 0x3016745A 0 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x7452301E
#10row-10106 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 1 0x2 0x3016745A 0 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x6543210F
#11row-11116 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 1 0x3 0x3016745A 0 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x9ABCDEF0
#12row-12122 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 1 0x4 0x3016745A 0 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x00000000
#13row-13126 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 1 0x5 0x3016745A 0 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x00000000
#14row-14130 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 1 0x6 0x3016745A 0 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x00000000
#15row-15134 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 1 0x7 0x3016745A 0 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x00000000
#16row-16139 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 0 0x0 0x3016745A 1 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x00000000
#17row-17144 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 0 0x1 0x3016745A 1 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x00000000
#18row-18149 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 0 0x2 0x3016745A 1 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x00000000
#19row-19154 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 0 0x3 0x3016745A 1 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x00000000
#20row-20159 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 0 0x4 0x3016745A 1 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x00000000
#21row-21164 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 0 0x5 0x3016745A 1 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x00000000
#22row-22169 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 0 0x6 0x3016745A 1 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x00000000
#23row-23174 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 0 0x7 0x3016745A 1 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x00000000
#24row-24179 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 1 0x0 0x3016745A 1 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x00000000
#25row-25184 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 1 0x1 0x3016745A 1 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x00000000
#26row-26189 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 1 0x2 0x3016745A 1 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x00000000
#27row-27194 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 1 0x3 0x3016745A 1 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x00000000
#28row-28198 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 1 0x4 0x3016745A 1 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x00000000
#29row-29202 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 1 0x5 0x3016745A 1 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x00000000
#30row-30206 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 1 0x6 0x3016745A 1 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x00000000
#31row-31210 0x6543210F 0x03254769 0x12345678 0x9ABCDEF0 1 0x7 0x3016745A 1 0x5670123C 0x7452301E 0x4761032D 0x2107654B 0x00000000
#32row-32221 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 0 0x0 0xCFE98BA5 0 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0xEDCBA987
#33row-33227 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 0 0x1 0xCFE98BA5 0 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0xEDCBA987
#34row-34237 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 0 0x2 0xCFE98BA5 0 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0xFCDAB896
#35row-35247 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 0 0x3 0xCFE98BA5 0 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0xCFE98BA5
#36row-36257 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 0 0x4 0xCFE98BA5 0 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0xDEF89AB4
#37row-37268 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 0 0x5 0xCFE98BA5 0 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0xA98FEDC3
#38row-38280 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 0 0x6 0xCFE98BA5 0 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0xA98FEDC3
#39row-39287 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 0 0x7 0xCFE98BA5 0 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0xA98FEDC3
#40row-40297 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 1 0x0 0xCFE98BA5 0 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0xB89EFCD2
#41row-41307 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 1 0x1 0xCFE98BA5 0 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0x8BADCFE1
#42row-42317 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 1 0x2 0xCFE98BA5 0 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0x9ABCDEF0
#43row-43327 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 1 0x3 0xCFE98BA5 0 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0x6543210F
#44row-44333 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 1 0x4 0xCFE98BA5 0 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0x00000000
#45row-45337 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 1 0x5 0xCFE98BA5 0 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0x00000000
#46row-46341 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 1 0x6 0xCFE98BA5 0 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0x00000000
#47row-47345 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 1 0x7 0xCFE98BA5 0 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0x00000000
#48row-48350 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 0 0x0 0xCFE98BA5 1 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0x00000000
#49row-49355 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 0 0x1 0xCFE98BA5 1 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0x00000000
#50row-50360 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 0 0x2 0xCFE98BA5 1 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0x00000000
#51row-51365 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 0 0x3 0xCFE98BA5 1 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0x00000000
#52row-52370 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 0 0x4 0xCFE98BA5 1 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0x00000000
#53row-53375 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 0 0x5 0xCFE98BA5 1 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0x00000000
#54row-54380 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 0 0x6 0xCFE98BA5 1 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0x00000000
#55row-55385 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 0 0x7 0xCFE98BA5 1 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0x00000000
#56row-56390 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 1 0x0 0xCFE98BA5 1 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0x00000000
#57row-57395 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 1 0x1 0xCFE98BA5 1 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0x00000000
#58row-58400 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 1 0x2 0xCFE98BA5 1 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0x00000000
#59row-59405 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 1 0x3 0xCFE98BA5 1 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0x00000000
#60row-60409 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 1 0x4 0xCFE98BA5 1 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0x00000000
#61row-61413 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 1 0x5 0xCFE98BA5 1 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0x00000000
#62row-62417 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 1 0x6 0xCFE98BA5 1 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0x00000000
#63row-63421 0x9ABCDEF0 0xFCDAB896 0xEDCBA987 0x6543210F 1 0x7 0xCFE98BA5 1 0xA98FEDC3 0x8BADCFE1 0xB89EFCD2 0xDEF89AB4 0x00000000
#64row-64426 0bXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 0bXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 0bXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 0bXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 0 0x0 0bXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 1 0bXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 0bXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 0bXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 0bXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 0x00000000
#65row-65428 0bZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 0bZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 0bZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 0bZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 0 0x0 0bZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 1 0bZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 0bZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 0bZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 0bZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 0x00000000

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 recorded cases use distinguishable source words with every binary opcode, then four-state source words.

Embedded simulation

Open RV32IALUResultSelect in the simulator

Tests

RV32IALUResultSelectTest checks every local index with both groups and the zero override. Source: RV32IALUResultSelect.cpp.

4.3.3.7. RV32IALU

IO pins

Pin Direction Width Description
A, B Input 32 each Operands
OP Input 5 Operation code
OUT Output 32 Result
EQ, LT_SIGNED, LT_UNSIGNED Output 1 each Comparisons, valid for SUB, SLT and SLTU; otherwise 0

Behavior

OP Name OUT Comparisons
0 ADD A + B 0
1 SUB A − B Valid
2 AND A & B 0
3 OR A \| B 0
4 XOR A ^ B 0
5 SLL A << B[4:0] 0
6 SRL Logical A >> B[4:0] 0
7 SRA Arithmetic A >> B[4:0] 0
8 SLT 1 if signed A < B, else 0 Valid
9 SLTU 1 if unsigned A < B, else 0 Valid
10 PASS_A A 0
11 PASS_B B 0
12 CLEAR 0 0
13–31 Reserved 0 0

The decoder selects SUB for conditional branches and reads all three comparisons; it selects ADD for addresses and jump targets, PASS_B for LUI and CLEAR for instructions that write no ALU result. Instruction legality is the decoder's job, so reserved codes simply give zero.

C++ example

This reference combines the part references above.

namespace rv32i_alu_example {
struct Result { uint32_t OUT; bool EQ, LT_SIGNED, LT_UNSIGNED; };
Result alu(uint32_t a, uint32_t b, unsigned op) {
    const auto c = control(op);
    const auto ar = addsub(a, b, c.SUB);
    const auto l = logic(a, b);
    const auto sh = shift(a, b, c.SHIFT_LEFT, c.SHIFT_ARITHMETIC);
    const auto cmp = compare(ar.OUT, ar.C_OUT, ar.OVERFLOW, c.SUB);
    const auto out = select(ar.OUT, l.AND_OUT, l.OR_OUT, l.XOR_OUT, sh,
        cmp.SLT_RESULT, cmp.SLTU_RESULT, a, b, c.LOCAL_OP, c.HIGH_HALF, c.OUT_OF_RANGE);
    return {out, cmp.EQ, cmp.LT_SIGNED, cmp.LT_UNSIGNED};
}
}

Unknown inputs

The structural ALU can mask unknown values in parts whose result is not selected. The compact form instead makes every output unknown if any bit of A, B or OP is X or Z, even an unused operand. Its equivalence with the gates therefore covers known (0/1) inputs only.

Implementation

Structural implementation

The root contains CONTROL, ARITHMETIC (the add/subtract part), LOGIC, SHIFT, COMPARE and RESULT_SELECT. The subtraction result, carry and overflow feed the compare part, and every part's result feeds the selector.

Behavioral implementation

The compact form computes the result and comparisons with the RISC-V value rule that the compact cores also use, then publishes them on delays proven on the gates, one set per operation code. The instruction oracle checks the same operations independently.

Timing. Paths of the complete ALU 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.

Pathunitticksembeddedpsdesktopps
Operation to result OP → OUT251,5301,067
Operand to result A → OUT201,230857
Operand to equality A → EQ191,092760

Examples

All 46 recorded rows of RV32IALUTest, 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 · 32 bit BInput · 32 bit OPInput · 5 bit EQExpected output · 1 bit LT_SIGNEDExpected output · 1 bit LT_UNSIGNEDExpected output · 1 bit OUTExpected output · 32 bit
#0row-017 0x00000001 0x00000002 0x00 0 0 0 0x00000003
#1row-137 0xFFFFFFFF 0x00000001 0x00 0 0 0 0x00000000
#2row-250 0xFFFFFFFF 0xFFFFFFFF 0x00 0 0 0 0xFFFFFFFE
#3row-371 0x7FFFFFFF 0x00000001 0x00 0 0 0 0x80000000
#4row-488 0x80000000 0x80000000 0x00 0 0 0 0x00000000
#5row-5108 0x00000005 0x00000005 0x01 1 0 0 0x00000000
#6row-6124 0x00000000 0x00000001 0x01 0 1 1 0xFFFFFFFF
#7row-7136 0x80000000 0x7FFFFFFF 0x01 0 1 0 0x00000001
#8row-8152 0x7FFFFFFF 0xFFFFFFFF 0x01 0 0 1 0x80000000
#9row-9171 0xF0F0F0F0 0x0FF00FF0 0x02 0 0 0 0x00F000F0
#10row-10180 0xF0F0F0F0 0x0FF00FF0 0x03 0 0 0 0xFFF0FFF0
#11row-11198 0xF0F0F0F0 0x0FF00FF0 0x04 0 0 0 0xFF00FF00
#12row-12218 0x00000001 0x0000001F 0x05 0 0 0 0x80000000
#13row-13237 0x00000001 0x00000020 0x05 0 0 0 0x00000001
#14row-14259 0x80000000 0x0000001F 0x06 0 0 0 0x00000001
#15row-15276 0x80000000 0x00000021 0x06 0 0 0 0x40000000
#16row-16296 0x80000000 0x0000001F 0x07 0 0 0 0xFFFFFFFF
#17row-17313 0x80000000 0x00000021 0x07 0 0 0 0xC0000000
#18row-18334 0xFFFFFFFF 0x00000001 0x08 0 1 0 0x00000001
#19row-19350 0x80000000 0x00000000 0x08 0 1 0 0x00000001
#20row-20368 0x7FFFFFFF 0x80000000 0x08 0 0 1 0x00000000
#21row-21384 0xFFFFFFFF 0x00000001 0x09 0 1 0 0x00000000
#22row-22400 0x00000000 0xFFFFFFFF 0x09 0 0 1 0x00000001
#23row-23416 0x7FFFFFFF 0x80000000 0x09 0 0 1 0x00000001
#24row-24434 0x12345678 0x9ABCDEF0 0x0A 0 0 0 0x12345678
#25row-25444 0x12345678 0x9ABCDEF0 0x0B 0 0 0 0x9ABCDEF0
#26row-26462 0x12345678 0x9ABCDEF0 0x0C 0 0 0 0x00000000
#27row-27466 0x12345678 0x9ABCDEF0 0x0D 0 0 0 0x00000000
#28row-28484 0x12345678 0x9ABCDEF0 0x0E 0 0 0 0x00000000
#29row-29488 0x12345678 0x9ABCDEF0 0x0F 0 0 0 0x00000000
#30row-30506 0x12345678 0x9ABCDEF0 0x10 0 0 0 0x00000000
#31row-31511 0x12345678 0x9ABCDEF0 0x11 0 0 0 0x00000000
#32row-32529 0x12345678 0x9ABCDEF0 0x12 0 0 0 0x00000000
#33row-33534 0x12345678 0x9ABCDEF0 0x13 0 0 0 0x00000000
#34row-34552 0x12345678 0x9ABCDEF0 0x14 0 0 0 0x00000000
#35row-35557 0x12345678 0x9ABCDEF0 0x15 0 0 0 0x00000000
#36row-36575 0x12345678 0x9ABCDEF0 0x16 0 0 0 0x00000000
#37row-37580 0x12345678 0x9ABCDEF0 0x17 0 0 0 0x00000000
#38row-38598 0x12345678 0x9ABCDEF0 0x18 0 0 0 0x00000000
#39row-39603 0x12345678 0x9ABCDEF0 0x19 0 0 0 0x00000000
#40row-40621 0x12345678 0x9ABCDEF0 0x1A 0 0 0 0x00000000
#41row-41626 0x12345678 0x9ABCDEF0 0x1B 0 0 0 0x00000000
#42row-42644 0x12345678 0x9ABCDEF0 0x1C 0 0 0 0x00000000
#43row-43648 0x12345678 0x9ABCDEF0 0x1D 0 0 0 0x00000000
#44row-44666 0x12345678 0x9ABCDEF0 0x1E 0 0 0 0x00000000
#45row-45670 0x12345678 0x9ABCDEF0 0x1F 0 0 0 0x00000000

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 recorded cases cover every operation at its boundaries and every reserved code.

Embedded simulation

Open RV32IALU in the simulator

Tests

RV32IALUTest checks all outputs on the structural and compact forms. RV32IALUSweepTest adds an 8 × 8 boundary grid on every operation and 1,024 seeded random vectors over all 32 operation codes, against C++ integer results on both forms. ALUHierarchyTest checks the six named parts and the single shared prefix adder. RV32IBuildingBlocksDocumentationTest compiles the C++ examples on this page and replays them against the recorded binary cases. Sources: RV32IALU.hpp, RV32IALU.cpp.