Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • Logic Synthesis Glossary
  • Logic Synthesis Cheatsheet
  • Synthesis Foundations14
  • Logic Optimisation and Mapping20
  • Constraints and Timing15
  • Sequential, FSM and Memory19
  • Datapath Synthesis14
  • Area, Power and Test14
    • Area, Power and Timing Trade-offs
    • Clock Gating and Low Power
    • DFT and Scan Insertion
      • The Scan Flop and Shift
      • DFT-Friendly RTL
      • Chain Stitching and Balancing
      • Scan Overhead in Area and Timing
  • Verification, ECO and Handoff15
  • Flows and Debugging15
  • Interview and Judgment11
Loading lesson

‹DFT and Scan Insertion
  1. Topics
  2. Logic Synthesis
  3. Area, Power and Test
  4. DFT and Scan Insertion
  5. Chain Stitching and Balancing

Part 6 · Area, Power and Test · Intermediate

Chain Stitching and Balancing

Stitching flops into balanced chains with exact shift-cycle arithmetic.

On this page

    From flops to chains

    Stitching assigns every scan flop to exactly one chain, illustrated here as round-robin. Real flows assign flops by clock domain, locality, pin limits and shift timing.

    Choice

    Effect

    One long chain

    One pin pair, but every pattern costs the full flop count.

    Several chains

    More pin pairs, and the longest chain sets the cost.

    Round-robin (this topic's illustration)

    Neighbour flops land on different chains in the model below, spreading congestion.

    Balanced lengths

    Balanced chains differ by at most one flop. With N flops and C chains, each chain holds floor(N/C) flops and the first N%C chains hold one more.

    The calc block works two cases. Ten flops over three chains give [4, 3, 3], and 1002 flops over four chains are compared against an unbalanced layout.

    Diagram
    N = 10 flops, C = 3 chains
    base = 10 // 3 = 3, extra = 10 % 3 = 1
    lengths = [4, 3, 3], longest L = 4
    check: 4 + 3 + 3 = 10
    
    N = 1002 flops, C = 4 chains
    base = 1002 // 4 = 250, extra = 1002 % 4 = 2
    lengths = [251, 251, 250, 250], L = 251
    unbalanced example [400, 300, 200, 102]: sum = 400 + 300 + 200 + 102 = 1002, L = 400
    saving per load = 400 - 251 = 149 shift cycles

    Shift-cycle arithmetic

    One pattern costs L shift cycles to load, one capture cycle, and L cycles to unload. Without load-unload overlap the total is 2L + 1 cycles per pattern.

    Ten flops as one chain cost 21 cycles per pattern, while balanced chains of [4, 3, 3] cost 9. The ratio is 21 / 9 = 7 / 3, about 2.33 times fewer cycles.

    A runnable chain model

    The program below stitches ten flops into three chains, checks the exact lengths and cycle counts, and shifts a pattern through every chain to prove the data comes back unchanged.

    example.py
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    import sys
    
    def balanced_lengths(n_flops, n_chains):
        base = n_flops // n_chains
        extra = n_flops % n_chains
        return [base + 1 if c < extra else base for c in range(n_chains)]
    
    def stitch(n_flops, n_chains):
        chains = [[] for _ in range(n_chains)]
        for i in range(n_flops):
            chains[i % n_chains].append(i)
        return chains
    
    def shift_loopback(length, pattern):
        reg = [0] * length
        for b in pattern:
            reg = [b] + reg[:-1]
        out = []
        for _ in range(length):
            out.append(reg[-1])
            reg = [0] + reg[:-1]
        return out
    
    def check(cond, msg):
        if not cond:
            print("FAIL: " + msg)
            sys.exit(1)
    
    lengths = balanced_lengths(10, 3)
    check(lengths == [4, 3, 3], "10 flops over 3 chains gives lengths 4 3 3")
    check(max(lengths) == 4, "longest of 4 3 3 sets 4 shift cycles")
    check(sum(lengths) == 10, "chain lengths sum to the flop count")
    chains = stitch(10, 3)
    check([len(c) for c in chains] == [4, 3, 3], "stitched chains measure 4 3 3")
    check(max(balanced_lengths(12, 4)) == 3, "12 flops over 4 chains need 3 cycles")
    check(max(balanced_lengths(7, 1)) == 7, "one chain of 7 needs 7 cycles")
    check(balanced_lengths(1002, 4) == [251, 251, 250, 250], "1002 flops over 4 chains gives 251 251 250 250")
    for c in chains:
        pattern = [i % 2 for i in c]
        check(shift_loopback(len(c), pattern) == pattern, "shift out reproduces shift in on every chain")
    print("PASS: 10 flops stitch to 4 3 3 with 4 shift cycles and loopback proved on all 3 chains")

    Common pitfall

    Balancing by count alone can still unbalance by delay. A short chain with slow shift buffers can set test time instead, so the stitcher also watches shift timing.

    Interview

    Likely probes: the balancing formula and who sets the cycles.

    • Lengths are floor(N/C) with the first N%C chains one longer.

    • The longest chain L sets every load and unload.

    • One pattern costs 2L + 1 cycles without overlap.

    Check yourself Ten flops split into three chains. What lengths result, and how many cycles load one pattern?

    Lengths [4, 3, 3]. Loading costs 4 cycles, set by the longest chain.

    Check yourself The program shifts a pattern in and back out of each chain. What does matching output prove?

    It proves each chain is a working shift register: what capture stores, scan-out can observe.

    Related topics

    • Scan Overhead in Area and Timing

    • Area, Power and Timing Trade-offs

    Previous

    97 / 139

    Next: Scan Overhead in Area and Timing

    Up next

    Up nextScan Overhead in Area and Timing

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • The Scan Flop and Shift