Arithmetic & Math
8-Bit Min/Max Comparator — L1 Upgrade — L2 Upgrade
8-Bit Min/Max Comparator with sticky saturation flag and synchronous clear.
About this block
Simulate it in the Verilog IDE
8-Bit Min/Max Comparator — L1 Upgrade — L2 Upgrade is a Verilog reference block in the Arithmetic & Math catalog. Adders, multipliers, dividers, ALUs, and arithmetic datapaths. Marked Easy: a small block you can read, simulate, and synthesize in one sitting.
This IP core implements an 8-bit minimum and maximum comparator. It provides combinational outputs for the minimum and maximum values of two 8-bit inputs (a and b). Additionally, it features a synchronous sticky saturation flag (sat_flag) that latches high when specific overflow or underflow conditions are detected (e.g., comparing a positive number against zero in a way that implies boundary violation). The flag persists until explicitly cleared via the clear_sat input or reset via rst_n.
This design is suitable for arithmetic units requiring robust overflow/underflow monitoring with minimal latency for the comparison logic.
- Choose Open in IDE. RTL Studio loads the packaged workspace for 8-Bit Min/Max Comparator — L1 Upgrade — L2 Upgrade.
- Read the Verilog module in the editor. The catalog line for this block: 8-Bit Min/Max Comparator with sticky saturation flag and synchronous clear.
- Run the packaged testbench with the in-browser Verilator simulator, then open the VCD in the waveform viewer.
- Run Yosys in the same IDE for a generic netlist. Sky130 liberty mapping is a separate Pro library option.
RTL Studio is the Verilog simulator and IDE around this block: Slang lint, Verilator, VCD waveforms, and Yosys, in the browser. Simulation guide · Yosys guide.
Features
- Combinational Min/Max: Outputs
min_outandmax_outare updated immediately based on inputsaandb. - Sticky Saturation Flag:
sat_flaglatches to 1 when saturation conditions are met and holds its value until cleared. - Synchronous Control: All state changes (saturation set/clear) are synchronized to the clock edge.
- Reset and Clear: Supports active-low synchronous reset (
rst_n) and active-high synchronous clear (clear_sat) for the saturation flag. - 8-Bit Width: Designed for standard byte-oriented data paths.
- Verified: Fully simulated with Icarus Verilog.
Ports
| Port Name | Direction | Width | Description |
|---|---|---|---|
clk | Input | 1 | Clock input for synchronous logic. |
rst_n | Input | 1 | Active-low synchronous reset. Resets sat_flag to 0. |
clear_sat | Input | 1 | Active-high synchronous clear. Resets sat_flag to 0. |
a | Input | 8 | First input operand. |
b | Input | 8 | Second input operand. |
min_out | Output | 8 | Minimum value of a and b. |
max_out | Output | 8 | Maximum value of a and b. |
sat_flag | Output | 1 | Sticky saturation flag. Latches on specific boundary conditions. |
Verification
The provided testbench (tb_minmax_comparator_hold_8_sticky_sat_flag.v) validates:
- Reset Behavior: Ensures all outputs are zero after
rst_nis asserted. - Comparison Accuracy: Verifies correct min/max selection for various input pairs.
- Saturation Set: Checks that
sat_flagsets correctly when boundary conditions are met. - Saturation Clear: Verifies that
clear_satresets the flag. - Sticky Behavior: Confirms the flag remains set until cleared.
### Expected Simulation Output
Upon running the simulation, the log should display:
More in Arithmetic & Math
- 1-Bit Full Adder
- 1-Bit Full Adder — L1 Upgrade — L2 Upgrade
- 1-Bit Half Adder
- 16-Bit Carry-Select Adder
- 16-Bit Signed Adder with Overflow
- 2-Bit Saturating Up/Down Counter — L2 Upgrade
- 32-Bit Count Leading Zeros
- 32-Bit Equality Comparator — L1 Upgrade — L2 Upgrade
- 32-Bit Population Count — L1 Upgrade — L2 Upgrade
- 4-bit Adder-Subtractor with Overflow
- 4-Digit BCD Adder with Carry Propagation — L2 Upgrade
- 4-Input 8-Bit Adder Tree — L2 Upgrade
- 8-Bit Absolute Value — L1 Upgrade
- 8-Bit ALU Slice with Add/Sub and Logic Ops — L2 Upgrade
- 8-Bit Carry-Save Adder (3:2) — L2 Upgrade
- 8-Bit Count Trailing Zeros — L1 Upgrade — L2 Upgrade