RTL Studio Open IDE

Arithmetic & Math

8-Bit Magnitude Comparator — L1 Upgrade — L2 Upgrade

Registered 8-bit magnitude comparator with sticky saturation flags for tracking historical comparison states.

About this block

Simulate it in the Verilog IDE

Mediumverilogsimsyn

8-Bit Magnitude Comparator — L1 Upgrade — L2 Upgrade is a Verilog reference block in the Arithmetic & Math catalog. Adders, multipliers, dividers, ALUs, and arithmetic datapaths. Marked Medium: more state or a wider datapath, still one workspace in the IDE.

This module implements a registered 8-bit magnitude comparator with sticky saturation flags. It compares two 8-bit inputs a and b to determine equality, greater-than, and less-than relationships. The comparison results are registered on the positive clock edge. Sticky saturation flags sat_pos and sat_neg latch when a > b or a < b respectively. These sticky flags can be cleared synchronously via the clear_sat signal. A synchronous active-low reset rst_n initializes all outputs to zero.

The design uses Icarus Verilog for simulation and synthesis.

This IP provides a registered magnitude comparator with persistent saturation tracking. It is suitable for applications requiring historical comparison state or overflow detection. The sticky flags allow downstream logic to detect magnitude differences over multiple cycles. Simulation results confirm correct functional behavior for all defined test cases.

  1. Choose Open in IDE. RTL Studio loads the packaged workspace for 8-Bit Magnitude Comparator — L1 Upgrade — L2 Upgrade.
  2. Read the Verilog module in the editor. The catalog line for this block: Registered 8-bit magnitude comparator with sticky saturation flags for tracking historical comparison states.
  3. Run the packaged testbench with the in-browser Verilator simulator, then open the VCD in the waveform viewer.
  4. 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.

Ports

Port NameDirectionWidthDescription
clkInput1Clock input for registered outputs and sticky logic.
rst_nInput1Active-low synchronous reset.
clear_satInput1Synchronously clears sticky saturation flags when asserted.
aInput8First operand for magnitude comparison.
bInput8Second operand for magnitude comparison.
eqOutput1Registered output: High if a == b.
gtOutput1Registered output: High if a > b.
ltOutput1Registered output: High if a < b.
sat_posOutput1Sticky flag: Latches high when a > b.
sat_negOutput1Sticky flag: Latches high when a < b.

Verification

The testbench tb_magnitude_comparator_registered_sticky_8bit_sticky_sat_flag.v verifies the following scenarios. All tests passed successfully in the Icarus Verilog simulation environment.

Test CaseDescriptionExpected Result
TC1Basic Equality (a == b)eq is high, gt and lt are low.
TC2Greater Than (a > b)gt is high, eq and lt are low.
TC3Less Than (a < b)lt is high, eq and gt are low.
TC4Sticky Sat Possat_pos latches high when a > b.
TC5Sticky Sat Negsat_neg latches high when a < b.
TC6Clear Saturationclear_sat resets sat_pos and sat_neg to zero.
TC7Reset BehaviorAll outputs go low on rst_n assertion.
TC8Sat Pos Persistencesat_pos remains high after a > b condition ends.
TC9Sat Neg Persistencesat_neg remains high after a < b condition ends.
TC10Edge Case ZeroCorrect comparison when both inputs are zero.

More in Arithmetic & Math

All Arithmetic & Math blocks