RTL Studio Open IDE

Arithmetic & Math

8-Bit Absolute Value — L1 Upgrade

Registered 8-bit absolute value calculator with sticky overflow detection for -128.

About this block

Simulate it in the Verilog IDE

Easyverilogsimsyn

8-Bit Absolute Value — L1 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 a registered 8-bit absolute value calculator for two's complement signed integers.

It features a sticky overflow flag that detects the unique edge case of input -128 (0x80), which cannot be represented as a positive 8-bit signed integer.

Once triggered, the overflow flag remains set until reset, ensuring system-level awareness of this arithmetic limitation.

  • Positive Inputs: Passed through unchanged.
  • Negative Inputs: Converted to positive using two's complement inversion.
  • Overflow Handling: The input -128 triggers the ovf_sticky flag. This flag is asynchronous-resettable but otherwise latches high permanently during operation to indicate that an overflow event has occurred.
  1. Choose Open in IDE. RTL Studio loads the packaged workspace for 8-Bit Absolute Value — L1 Upgrade.
  2. Read the Verilog module in the editor. The catalog line for this block: Registered 8-bit absolute value calculator with sticky overflow detection for -128.
  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 (positive edge triggered)
rst_nInput1Active-low asynchronous reset
enInput1Synchronous enable signal
dinInput8Signed 8-bit input data
doutOutput8Absolute value output
ovf_stickyOutput1Sticky overflow flag (latches high on -128)

Architecture

The design consists of a registered datapath with combinational overflow detection logic.

  1. Combinational Detection: Checks if din == 8'h80 (-128).
  2. Registered Datapath: On the positive clock edge, if en is high:

- Computes absolute value: ~din + 1 if negative, else din. - Updates dout. - Updates ovf_sticky: If overflow was detected, the flag is set to 1. It never clears unless rst_n is asserted.

Verification

The provided testbench (tb/tb_absolute_value_registered_sticky_8bit.v) validates six scenarios:

Test CaseInputExpected doutExpected ovf_stickyDescription
TC1550Positive input
TC2-550Negative input
TC3-1281281Overflow edge case
TC410101Subsequent input after overflow
TC5001Zero after overflow
TC6HoldHoldHoldDisabled state

Run the simulation to verify these results. The log should report PASS for all test cases.

More in Arithmetic & Math

All Arithmetic & Math blocks