Source code, verification and physical-design flow for the paper
B. E. Krapah and K. O. Boateng, "A Signed Digit-Parallel Reverse Converter for the Residue Number System {2^n−1, 2^n, 2^n+1}," preprint, Kwame Nkrumah University of Science and Technology (KNUST), 2026.
The main design, reverse_signed, converts a residue triple (r₋₁, r₀, r₁) to a signed 3n-bit two's complement integer X in [−M/2, M/2−1], where M = 2³ⁿ − 2ⁿ. Unsigned reverse converters for this moduli set need a separate sign-correction stage after conversion; this one produces the signed result directly. The repository also holds two signed forward converters and re-implementations of the published designs used for comparison.
It extends the digit-parallel method of Gallaher et al. (1997), with the boundary correction of Ananda Mohan (2000), to signed outputs.
Write X = 2²ⁿN₂ + 2ⁿN₁ + N₀, with N₂ signed. Forward conversion folds the segments, R₋₁ = N₂ + N₁ + N₀ − a(2ⁿ−1) and R₁ = N₂ − N₁ + N₀ + b(2ⁿ+1), where (a, b) is the correction pair. The reverse converter forms
- A = R₋₁ + R₁ − 2R₀ = 2N₂ − a(2ⁿ−1) + b(2ⁿ+1) (n+2 bits)
- B = R₋₁ − R₁ = 2N₁ − a(2ⁿ−1) − b(2ⁿ+1) (n+1 bits)
For signed inputs exactly 8 correction pairs occur, for every n ≥ 3. The pair is selected from the parity, the two most significant bits and a zero test of A, and the sign and two equality tests of B. The matching constants are added to A and B, both are halved to give N₂ and N₁, and X = N₂ | N₁ | R₀. The two boundary ties are pairs of aliasing words, and the rule resolves them toward [−M/2, M/2−1], so no separate sign-correction stage is needed. The proofs are in the paper.
| Module | File | What it is |
|---|---|---|
reverse_signed |
rtl/reverse_gallaher.sv |
This work. Signed digit-parallel reverse converter (8 cases). |
reverse_gallaher_unsigned |
rtl/reverse_gallaher.sv |
Baseline: unsigned digit-parallel converter (Gallaher 1997 + Mohan 2000). |
reverse_piestrak |
rtl/reverse_piestrak.sv |
Baseline: Piestrak (1995) high-speed unsigned converter. |
reverse_piestrak_signed |
rtl/reverse_piestrak.sv |
Baseline: reverse_piestrak followed by the usual sign correction (compare with M/2, then subtract M). |
forward_converter |
rtl/forward_converter.sv |
Signed forward converter by compare-and-select (paper appendix). |
baseline_krstic_signed |
rtl/baseline_krstic.sv |
Signed extension of the Krstić et al. (2016) carry-save encoder (paper appendix). |
baseline_krstic, baseline_krstic_d1 |
rtl/baseline_krstic.sv |
Baseline: the unsigned Krstić et al. encoder; _d1 exposes its diminished-1 output. |
All modules are combinational and take the parameter N (= n). Reverse converter ports: r_minus1[N-1:0], r0[N-1:0], r1[N:0] in, x[3N-1:0] out.
rtl/ SystemVerilog for every design above
verif/ref_model.py Python reference model and property checks
verif/gen_vectors*.py golden test vectors (signed and unsigned)
verif/tb_*.sv self-checking testbenches
verif/run*.sh Verilator regressions; logs in verif/results*.txt
flow/config*.json OpenLane 2 configurations
flow/sweep_n.py OpenLane sweep for forward_converter, N = 4..10
flow/sweep_baseline.py OpenLane sweep for every other design (flag selects the design)
flow/docker_baseline.sh runs sweep_baseline.py inside the OpenLane container
flow/extract*_metrics.py collect results/*.csv from the runs
flow/make_paper_*.py regenerate the paper's tables, figure data and results plot
results/*.csv per-N metrics from the signoff reports
OpenLane 2 v2.3.10, SkyWater sky130A (sky130_fd_sc_hd), SYNTH_STRATEGY = DELAY 0, 40 % core utilisation, the same settings for every design. Each design is timed against a 20 ns (50 MHz) virtual clock with 4 ns input and output delays and 0.25 ns uncertainty. The reverse converters and the Krstić designs pass DRC and LVS at every N (columns drc_errors and lvs_errors in results/).
reverse_signed:
| N | Output bits | Die area (µm²) | Cells | Delay tt (ns) | Delay ss (ns) | Power (mW) |
|---|---|---|---|---|---|---|
| 4 | 12 | 6007.01 | 231 | 2.66 | 5.34 | 0.093 |
| 5 | 15 | 6742.91 | 273 | 3.02 | 6.04 | 0.110 |
| 6 | 18 | 7765.51 | 331 | 3.10 | 6.07 | 0.125 |
| 7 | 21 | 9192.07 | 411 | 3.43 | 6.77 | 0.173 |
| 8 | 24 | 10406.90 | 456 | 3.59 | 6.94 | 0.191 |
| 9 | 27 | 10578.20 | 488 | 3.61 | 7.05 | 0.202 |
| 10 | 30 | 12698.50 | 582 | 3.63 | 7.33 | 0.269 |
Ratio of reverse_signed to each baseline, over N = 4..10:
| Baseline | Die area | Power | Delay tt |
|---|---|---|---|
reverse_piestrak_signed (signed output) |
0.70–0.83 | 0.53–0.68 | 0.62–0.82 |
reverse_gallaher_unsigned |
0.87–1.08 | 0.85–1.15 | 0.92–1.04 |
reverse_piestrak |
0.85–0.96 | 0.80–0.98 | 0.84–1.09 |
At N = 9, reverse_piestrak_signed misses the 11.75 ns path budget at the ss corner (slack −0.08 ns); reverse_signed keeps at least 4.4 ns of slack at every N.
- Delay: input-to-output critical path from post-route STA (data arrival minus the 4 ns input delay). tt = nom_tt_025C_1v80; ss = max_ss_100C_1v60, the worst setup corner. Setup slack at that corner = 11.75 ns − delay.
- Power: vectorless OpenSTA estimate (default input activity) with post-route parasitics, at the highest-power corner (max_ff_n40C_1v95). At nom_tt it is 12–13 % lower.
- The forward converter and Krstić results are in
results/metrics.csvandresults/baseline*_metrics.csv.
All designs pass every check, for N = 4..10 (logs in verif/results*.txt).
- Reverse converters (
verif/tb_reverse.sv):- golden residues from the reference model, over the whole 3n-bit word (words outside [−M/2, M/2−1] must come back as X ± M);
- for N ≤ 8, exhaustive: the round trip reverse(forward(X)) = X for every input word, and every canonical residue triple maps to an in-range X with exactly those residues;
- for N = 9 and 10, an edge set plus 10⁶ seeded random inputs.
- Forward converters (
verif/tb_forward_converter.sv,verif/tb_baseline_krstic.sv): exhaustive over every input for N ≤ 8; edge set plus 10⁶ random inputs for N = 9 and 10. The edge set covers both ends of the word, ±M/2 and every correction boundary. - Reference model (
verif/ref_model.py): exhaustive for N ≤ 8; uniqueness on [−M/2, M/2−1] checked exhaustively for N ≤ 7; aliasing of the 2ⁿ excluded extremes checked for every N.
Verification (needs Python 3 and Docker), from the repository root:
python verif/ref_model.py
python verif/gen_vectors.py # signed vectors, verif/vectors/vec_n<N>.hex
python verif/gen_vectors_baseline.py # unsigned vectors, verif/vectors/base_n<N>.hex
docker run --rm -v "$PWD":/work -w /work/verif --entrypoint bash verilator/verilator:v5.028 run_reverse.shrun.sh, run_baseline.sh and run_baseline_signed.sh run the forward-converter regressions the same way. In Git Bash on Windows, use MSYS_NO_PATHCONV=1 and "$(pwd -W)".
Physical design (needs OpenLane 2 v2.3.10, e.g. the ghcr.io/efabless/openlane2:2.3.10 image):
cd flow
python sweep_baseline.py --rev-signed # also --rev-unsigned, --rev-piestrak, --rev-piestrak-signed,
# --signed (Krstic signed), --d1, or no flag (Krstic unsigned)
python sweep_n.py # forward_converterOn Windows, run the sweeps in the OpenLane container on a Docker volume, not on the bind mount (see the header of flow/docker_baseline.sh). flow/extract_metrics.py and flow/extract_baseline_metrics.py collect the runs into results/.
Paper tables and figures, from the repository root: flow/make_paper_tables.py, flow/make_paper_figs.py and flow/make_paper_plot.py (usage in each file's header).
See CITATION.cff. The code is archived on Zenodo: https://doi.org/10.5281/zenodo.23894364. Until the paper is published, cite this archive.
Copyright 2026 Bless Elikem Krapah, Kwame Osei Boateng (KNUST).
Licensed under the Apache License, Version 2.0. See LICENSE.