For bits , use two negation logic gates and two AND gates:The two unequal bit pairs activate their respective output; the equal pairs activate neither. In particular, a digital comparator never produces .
Split each input into its more and less significant -bit halves: and . Let the two digital comparators produce and . The more significant halves are equal exactly when . The comparator composition is thereforeImplement with a logical disjunction followed by a negation, then use two AND gates and two more logical disjunction logic gates. If , the difference has magnitude at least , whereas ; hence the more significant comparison decides the result. If , the lower comparison decides it. This proves correctness in every case using a constant number of extra logic gates.
Apply comparator composition recursively in a balanced binary tree, with one-bit digital comparators at its leaves. For a power of two , the circuit size and circuit depth satisfyThere are leaves and internal nodes, so the circuit size is and the combinational delay is . Here each fixed-fan-in logic gate has bounded delay. For arbitrary , pad both inputs with leading zero bits to the next power of two, which is less than ; this preserves their unsigned interpretation and both bounds.
Use a hierarchical leading-zero counter. A block of bits returns a zero flag and low count bits : its count leading zeros result is the concatenation . Thus means that the block is entirely zero and ; otherwise and is its leading-zero count. A one-bit block needs just and no low count bits.
For a block of bits, run two such Boolean circuits on the upper and lower halves in parallel. Write their flags as and their low count bits as . SetThe last expression is a two-input multiplexer. When the upper half is nonzero, its count is already the answer and . When only the upper half is zero, supplies the contribution while the multiplexers supply the lower half's count. When both halves are zero, the answer is , representing . This special encoding avoids an adder on the critical path.
Each node adds constant circuit depth, even though it uses logic gates for its parallel multiplexers. HenceIndeed the internal-node work is bounded by a constant times , and the leaves add . Delay is and size is , counting fixed-fan-in logic gates and the usual wire fan-out model.
Articles by others on the same topic
There are currently no matching articles.
