08 Optimized Implementation of Logic Functions

This chapter goes beyond the two-level SOP/POS minimization of Chapter 2 into multilevel logic synthesis and advanced optimization techniques used in real CAD tools. Factoring, functional decomposition, and multilevel NAND/NOR circuit synthesis are presented as methods to reduce circuit cost when fan-in or other constraints apply. Alternative representations of logic functions are introduced: the cubical representation (using cubes and covers), and binary decision diagrams (BDDs), which are used extensively in modern CAD tools for verification and optimization. The Quine-McCluskey tabular minimization method is presented as an algorithmic alternative to Karnaugh maps that can handle functions with many variables. A cubical technique for minimization is also covered. Practical considerations for dealing with very large functions are discussed.

本章從第 2 章的兩層 SOP/POS 最小化進一步推廣到多層邏輯合成 (multilevel logic synthesis),介紹現代 CAD 工具實際使用的進階最佳化技術。因式分解 (factoring)功能分解 (functional decomposition),以及 NAND/NOR 多層電路合成被作為在扇入 (fan-in) 或其他限制下降低電路成本的方法。本章還介紹邏輯函式的替代表示法:立方體表示 (cubical representation) 使用 cube 與 cover 描述函式;二元決策圖 (BDD, binary decision diagram) 則在現代 CAD 工具中廣泛用於驗證與最佳化。Quine-McCluskey 表格化最小化法則是一種能處理多變數函式的演算法替代方案——當卡諾圖 (Karnaugh map) 變得不切實際時可改用。本章亦介紹立方體最小化技術,並討論處理超大型函式時的實務考量。

Walk through Quine-McCluskey on a small example

Q-M minimizes any Boolean function in two phases:

  1. Generate all prime implicants by repeatedly merging adjacent terms that differ in exactly one bit.
  2. Pick a minimum cover from those primes using a prime-implicant chart.

Below is a worked example with $f(A,B,C) = \sum m(0,1,3,7)$. Click each phase to expand.

Phase 1a — list minterms grouped by Hamming weight
GroupMinterm$ABC$
0$m_0$000
1$m_1$001
2$m_3$011
3$m_7$111

Each row is a minterm where $f=1$. Grouping by 1-count means only adjacent groups can possibly merge — pairs across non-adjacent groups always differ in at least 2 bits.

Phase 1b — combine pairs differing in one bit (build 2-cubes)

Compare each minterm in group $k$ against each in group $k+1$. If the two binary patterns differ in exactly one position, replace that bit with "−":

$m_0$ (000) $m_1$ (001) $m_3$ (011) $m_7$ (111) 00− (0,1) 0−1 (1,3) −11 (3,7)

Each merged pair is a 2-cube — covers two minterms with one literal eliminated. Mark both source minterms as "used".

Phase 1c — try to combine 2-cubes into 4-cubes

Two 2-cubes combine if they have the same dash position AND differ in exactly one of the remaining bits.

  • $00{-}$ vs $0{-}1$ — different dash positions → can't combine
  • $00{-}$ vs $-11$ — different dash positions → can't combine
  • $0{-}1$ vs $-11$ — different dash positions → can't combine

No further combination possible. All three 2-cubes are prime implicants. If any 2-cube had been combined further, only the larger result would be prime.

Worked example: when 2-cubes do combine successfully

Take a 4-variable function $f(x_1, x_2, x_3, x_4) = \sum m(0, 1, 4, 5)$. The four minterms in binary:

Minterm$x_1 x_2 x_3 x_4$
$m_0$0000
$m_1$0001
$m_4$0100
$m_5$0101

Step 1 — pair minterms into 2-cubes (one bit changes per pair):

  • $m_0 \,(0000)$ + $m_1 \,(0001)$ → 000−  (differ in $x_4$, dash at position 4)
  • $m_4 \,(0100)$ + $m_5 \,(0101)$ → 010−  (differ in $x_4$, dash at position 4)
  • $m_0 \,(0000)$ + $m_4 \,(0100)$ → 0−00  (differ in $x_2$, dash at position 2)
  • $m_1 \,(0001)$ + $m_5 \,(0101)$ → 0−01  (differ in $x_2$, dash at position 2)

Step 2 — try to combine the 2-cubes into 4-cubes:

Attempt A: $000{-}$ + $010{-}$

  • Same dash position? YES — both have the dash at position 4.
  • Other bits: $\mathbf{000}-$ vs $\mathbf{010}-$ → differ in exactly one position (the $x_2$ bit: 0 vs 1). YES.
  • → Combines to 0−0−  (covers $m_0, m_1, m_4, m_5$ — a 4-cube). $x_2$ now also a dash; $x_1=0$ and $x_3=0$ remain.

Attempt B: $0{-}00$ + $0{-}01$

  • Same dash position? YES — both have the dash at position 2.
  • Other bits: $0{-}\mathbf{00}$ vs $0{-}\mathbf{01}$ → differ in exactly one position (the $x_4$ bit). YES.
  • → Combines to 0−0−  (same 4-cube as Attempt A — both routes converge).

Counter-attempt: $000{-}$ + $0{-}00$ — does this combine?

  • Same dash position? NO — first dash at position 4, second at position 2.
  • Rule fails immediately → can't combine. (Even though they share three bits, the dashes don't align.)

Result: the 4-cube $0{-}0{-}$ corresponds to the prime implicant $\overline{x_1}\,\overline{x_3}$ (only $x_1=0$ and $x_3=0$ are fixed). One 4-input AND gate replaces what would otherwise be four 2-input AND gates and a 4-input OR — that's the cost saving the merger produces.

K-map sanity-check. On a 4-variable K-map with rows $x_1 x_2$ and columns $x_3 x_4$, the four minterms $m_0, m_1, m_4, m_5$ all sit in the $x_3=0$ column-pair AND the $x_1=0$ row-pair — a clean $2\times 2$ quad. The cube $0{-}0{-}$ encodes exactly that quad: $x_1=0$ row, $x_3=0$ column, $x_2$ and $x_4$ both free.

Pattern recognition tip: after Phase 1b, sort your 2-cubes by dash position. Cubes with different dash positions are guaranteed not to combine, so you only need to check pairs within each dash-position group. This is what makes Q-M's tabular approach efficient compared to brute-force pairwise checks.

Phase 2 — build the prime-implicant chart and pick essentials

Rows = prime implicants, columns = original minterms. ✓ marks where the prime covers that minterm.

PrimeTerm$m_0$$m_1$$m_3$$m_7$
$P_1$$00{-}$ = $\overline{A}\,\overline{B}$
$P_2$$0{-}1$ = $\overline{A}\,C$
$P_3$$-11$ = $B\,C$

$m_0$ has only one ✓ (in $P_1$) → $P_1$ is essential.
$m_7$ has only one ✓ (in $P_3$) → $P_3$ is essential.
After picking $P_1, P_3$: $m_0, m_1, m_3, m_7$ all covered. $P_2$ is redundant.

Result

The minimum-cost SOP is:

$$f = \overline{A}\,\overline{B} + B\,C$$

2 product terms, 4 literals total + one 2-input OR. Q-M guarantees this is optimal among SOP realizations.

Why Q-M scales: a K-map needs $2^n$ cells (32 for 5 vars, 64 for 6). Q-M's table size is bounded by the number of actual minterms — typically far smaller than $2^n$. Q-M also generalizes naturally to don't-cares (treat them as minterms during Phase 1, then exclude them from the cover requirement in Phase 2) and to multi-output minimization. CAD tools use a hashed/bitmask variant of Q-M (or its successor Espresso) under the hood.

Multilevel Synthesis Factoring Functional Decomposition Cubical Representation BDDs Quine-McCluskey Technology Mapping
8.1MediumTier 1?R
Factor the expression f = x₁x₃ + x₁x₄ + x₂x₃ + x₂x₄ to produce a multilevel implementation. What is the cost saving over the SOP form?
8.3MediumTier 1?R
Use the Quine-McCluskey method to find all prime implicants of f(x₁,x₂,x₃,x₄) = Σm(0,1,2,5,6,7,8,9,14).
8.4MediumTier 1?R
Construct a BDD (Binary Decision Diagram) for the function f = x₁x₂ + x̄₁x₃ with variable ordering x₁ < x₂ < x₃.
8.7EasyTier 1?R
What is the difference between a two-level and a multilevel logic implementation? Give the advantages and disadvantages of each.
8.12HardTier 1?R
Use functional decomposition to find an efficient implementation of f(x₁,...,x₅) = Σm(1,2,7,9,10,18,19,25,31) + D(0,15,20,26). Compare with the best SOP.
8.31HardTier 1E?R
Implement the 4-variable function $f = x_1 x_2 \overline{x_4} + \overline{x_2} x_3 x_4 + x_1 x_2 x_3$ using 3-input lookup tables (3-LUTs). Show that a straightforward mapping needs four 3-LUTs and find a smarter decomposition that uses only three 3-LUTs.