As a side-project I started digging a bit into the arithmetic circuits, in the context of generating a new, faster version of Tethorax in Verilog. The ripple-carry adder currently implemented in the core is a prime candidate for changing since its one of the slowest adders posible. So after reading about the PPAs I bumped into the Kogge-Stone adder (KSA) and here we are.
You can find many designs online (e.g., [1], [2], [3], ...) which however are of fixed precision and follow a somewhat structural (non-behavioral) design. This KSA was developed with the purpose of being a standalone, completely modular adder in terms of precision (and synthesizable).
A KSA of n-bits precision is comprised of
A KSA is done computing when all carry bit possition (
This means that:
- either the carry is generated at the current stage
$i \rightarrow G_i$ - or the carry is generated at some previous stage
$j \rightarrow G_j$ and is propagated up to position$i \rightarrow P_k$
For instance, let us compute
In the figure above, each circle for the levels k 1 to 3 represents a dot operator (see [α] for more info). However, the dot operators come in two variants (colored in green/yellow). The green variant produces a G and a P value, with inputs comming directly from the previous level (k-1). The yellow variant produces only a G value and marks the completion of the computation of the respective carry bit
In a n-bit KSA, with
- the generation of
$n \rightarrow$ G values - the generation of
$n - 2^{k} \rightarrow$ P values
Hence, in total, we have:
-
$k \times n \rightarrow$ G values -
$k \times n - (n + 2) \rightarrow$ P values
These numbers can be trivially verified by counting the number of P and G statements in various precision KSA implementations (see [β]).
However, ableit the number of G values is the 1b'0
and remain unused.
After all
The first subscript corresponds to the bit index whereas the second subscript corresponds to the level k of the computation.
Reminder:
$log_2(n)$ gives the total number of steps k.
Lastly, the 1
if a carry is generated in the most significant bit location at the final computation level k. That is,
A testbench is also provided. You can modify the total number of tests you wish to perform by altering the parameter NUMBER_OF_TESTS
and also the KSA's precision by modifying the parameter PRECISION
. The testbench implements a somewhat fuzzing approach by generating random integers and feeding them to the KSA, while checking for each operand pair whether the result is the expected one.
The design can be compiled and executed using the simulator of your choice. I am using Icarus verilog as:
# Compilation
iverilog -g2005-sv kogge_stone_adder.sv tb.sv -o ksa
# Execution
vvp ksa
# Exit vvp
finish
You can cite this design by using the following @misc entry in Bibtex
@misc{misc:ksa,
author = "{Deligiannis, I. Nikolaos}",
title = "{A Verilog KSA Implementation with Modular Precision.}",
howpublished = "\url{https://github.com/NikosDelijohn/ksa}",
year = "2024"
}
[ α ] Abbas, K. (2020). Arithmetic. In: Handbook of Digital CMOS Technology, Circuits, and Systems. Springer, Cham. https://doi.org/10.1007/978-3-030-37195-1_11
[ β ] Kogge–Stone Adder. In Wikipedia. https://en.wikipedia.org/wiki/Kogge%E2%80%93Stone_adder