Algorithm Search⌘K

Data structurecore

Multiple-input signature register

Also called MISR, signature register.

An LFSR that XORs several circuit outputs into its stages every clock, compressing a long response stream into one signature compared at the end of BIST.

Time
O(m (k / w + 1)) worst · average · best
Space
O(k / w + 1) extra
Where
k = the number of stages; m = the number of input words; w = the word size in bits
Properties
deterministiciterative
Origin
B. Könemann, J. Mucha, G. Zwiehoff, 1979

A multiple-input signature register, or MISR, is a linear feedback shift register with kk stages and one extra XOR at the input of every stage, so that it takes a kk-bit word from the circuit under test at each clock. Read as a polynomial over GF(2), one clock computes r←(x r+w) mod qr \leftarrow (x\,r + w) \bmod q for a feedback polynomial qq of degree kk, so after a whole test the register holds the remainder of one long polynomial, built from all kk input streams, divided by qq. It is the usual response compactor of built-in self-test and of scan compression. This page is about the register as a data structure: its state, its operations, why the signature is a remainder, and which errors it can and cannot lose. How often a random error is lost is on the page signature aliasing probability.

In plain words

A test produces millions of output bits. Storing all of them and the right answers is costly. A signature register keeps only a short summary.

It is a row of a few flip-flops. At every clock, each flip-flop takes the bit from its neighbor, mixes in one output bit of the circuit, and, when the last flip-flop holds a 1, also mixes in a fixed feedback pattern. After the test, the row holds a short code, the signature, and the chip compares it with the code of a good chip.

The code works like the remainder of a long division. A single wrong bit always changes it. But some patterns of several wrong bits leave it unchanged, and then a bad chip passes.

The abstract type

The type has two fixed parameters and one value.

  • The number of stages k≥1k \ge 1, and the feedback polynomial q(x)=xk+qk−1xk−1+⋯+q1x+q0q(x) = x^k + q_{k-1} x^{k-1} + \cdots + q_1 x + q_0 over GF(2), of degree exactly kk.
  • The value is a register r=(r0,…,rk−1)r = (r_0, \ldots, r_{k-1}) of kk bits, read as the polynomial r(x)=r0+r1x+⋯+rk−1xk−1r(x) = r_0 + r_1 x + \cdots + r_{k-1} x^{k-1} of degree less than kk. An input word w=(w0,…,wk−1)w = (w_0, \ldots, w_{k-1}) is read the same way.

The operations are:

  • RESET(s): set rr to the seed ss, usually 0.
  • CLOCK(w): one clock with the input word ww.
  • SIGNATURE(): return rr.

The specification is the formula of the signature. After RESET(s) and the clocks CLOCK(w_0), ..., CLOCK(w_{m-1}),

SIGNATURE()=(xms(x)+∑t=0m−1xm−1−t wt(x)) mod q(x).\mathrm{SIGNATURE}() = \Big( x^m s(x) + \sum_{t=0}^{m-1} x^{m-1-t}\, w_t(x) \Big) \bmod q(x).

There is a second way to read the same sum. Write the stream of input ii as the polynomial Wi(x)=∑twt,i xm−1−tW_i(x) = \sum_t w_{t,i}\, x^{m-1-t}, where wt,iw_{t,i} is bit ii of word tt, so the first bit has the highest power, as in long division. Then ∑txm−1−twt(x)=∑ixiWi(x)\sum_t x^{m-1-t} w_t(x) = \sum_i x^i W_i(x). A MISR is a single-input signature register fed with the XOR of the kk input streams, stream ii shifted up by ii places. This one line explains both the strength and the weakness of the register, below.

Representation

The register is one kk-bit word, with bit ii for stage rir_i, and the low part q−xkq - x^k of the polynomial is a second kk-bit constant. This is the internal-XOR form, also called the Galois form, of an LFSR: stage 0 takes q0rk−1⊕w0q_0 r_{k-1} \oplus w_0, and stage i≥1i \ge 1 takes ri−1⊕qirk−1⊕wir_{i-1} \oplus q_i r_{k-1} \oplus w_i. In hardware it is kk flip-flops, one XOR per input, and one XOR per nonzero coefficient qiq_i with 1≤i≤k−11 \le i \le k-1. All stages change on the same clock, so the register takes one word per clock at the full clock rate.

Operations

  1. CLOCK(r, w)
  2. 1msb ← bit k − 1 of r
  3. 2r ← r shifted one place toward stage k − 1, bit k − 1 dropped and stage 0 set to 0
  4. 3if msb = 1 then r ← r XOR (q − x^k)
  5. 4r ← r XOR w

RESET(s) stores ss in rr and SIGNATURE() returns rr, each in one word operation.

Lines L1 to L3 compute x r(x) mod q(x)x\,r(x) \bmod q(x). The shift multiplies by xx. If the top stage was 0, then x rx\,r has degree less than kk and is already reduced. If it was 1, then x r=xk+(the shifted bits)x\,r = x^k + (\text{the shifted bits}), and xk≡q(x)−xk(modq)x^k \equiv q(x) - x^k \pmod q, since over GF(2) minus is plus, so line L3 adds the low part of qq. Line L4 adds the input word. So one clock is

r←(x r+w) mod q.r \leftarrow (x\,r + w) \bmod q.

This is one step of long division of a polynomial by qq, in the same way as the single-input register on the built-in self-test page and the cyclic redundancy check, except that kk new bits enter at once.

Example

Take k=3k = 3 and q=x3+x+1q = x^3 + x + 1, so q−x3=x+1q - x^3 = x + 1, the word 011. Start from r=000r = 000 and clock five words. Words and registers are written r2r1r0r_2 r_1 r_0, high stage first.

clock tt rr before msb after L2 after L3 wtw_t after L4
0 000 0 000 000 101 101
1 101 1 010 001 011 010
2 010 0 100 100 110 010
3 010 0 100 100 001 101
4 101 1 010 001 100 101

The signature is 101, the polynomial x2+1x^2 + 1. The formula gives the same value. The words are w0=x2+1w_0 = x^2 + 1, w1=x+1w_1 = x + 1, w2=x2+xw_2 = x^2 + x, w3=1w_3 = 1 and w4=x2w_4 = x^2, so

x4w0+x3w1+x2w2+x w3+w4=x6+x4+x2+x.x^4 w_0 + x^3 w_1 + x^2 w_2 + x\,w_3 + w_4 = x^6 + x^4 + x^2 + x.

Modulo qq, x3=x+1x^3 = x + 1, x4=x2+xx^4 = x^2 + x and x6=(x+1)2=x2+1x^6 = (x + 1)^2 = x^2 + 1, and the sum reduces to x2+1x^2 + 1.

Now put errors on the stream. An error on input 0 at clock 3, so that w3=000w_3 = 000, adds x4−3⋅x0=xx^{4-3} \cdot x^0 = x to the polynomial, and the signature becomes 101⊕010=111101 \oplus 010 = 111. The error is caught. Two errors, one on input 0 at clock 1 and one on input 1 at clock 2, add x3⋅x0x^{3} \cdot x^0 and x2⋅x1x^{2} \cdot x^1, the same monomial x3x^3 twice. They cancel, and the signature stays 101, although two bits of the stream are wrong. The second error reaches stage 1 at the clock when the first error, shifted up from stage 0, is also there.

Correctness

Facts 1 and 2 hold for every qq of degree kk, and fact 3 needs q0=1q_0 = 1. They are proved on the proof page.

  1. The signature is a remainder. After mm clocks from the seed ss, the register holds (xms+∑txm−1−twt) mod q\big(x^m s + \sum_t x^{m-1-t} w_t\big) \bmod q. The proof is by induction on the clocks, with the step r←(x r+w) mod qr \leftarrow (x\,r + w) \bmod q.
  2. Linearity, and the error polynomial. If the good circuit gives the words wtw_t and a faulty one gives wt⊕etw_t \oplus e_t, then the two signatures differ by E mod qE \bmod q, where E(x)=∑txm−1−tet(x)=∑t∑iet,i xm−1−t+iE(x) = \sum_t x^{m-1-t} e_t(x) = \sum_t \sum_i e_{t,i}\, x^{m-1-t+i}. The faulty chip passes exactly when qq divides EE. The seed drops out.
  3. A single wrong bit never aliases. A single wrong bit gives E=xjE = x^j. Since q0=1q_0 = 1, qq is not a power of xx, and the only irreducible factor of xjx^j is xx, so qq does not divide xjx^j.

Fact 2 also says which pairs of errors alias. The error bit (t,i)(t, i), at clock tt on input ii, gives the monomial xm−1−t+ix^{m-1-t+i}, so the two error bits (t,i)(t, i) and (t+1,i+1)(t + 1, i + 1) give the same monomial and always cancel, whatever qq is. Two error bits with different exponents a>ba > b alias exactly when qq divides xb(xa−b+1)x^b (x^{a-b} + 1), that is when qq divides xa−b+1x^{a-b} + 1. For a primitive qq this happens exactly when 2k−12^k - 1 divides a−ba - b, since 2k−12^k - 1 is then the least n≥1n \ge 1 for which qq divides xn+1x^n + 1.

Proof: The MISR signature is a remainder, and a single wrong bit always changes itfull

We use the notation of the page. The ring is GF(2)[x], so plus and minus are the same. The register rr and the input words wtw_t are polynomials of degree less than kk, and qq has degree exactly k≥1k \ge 1. For a polynomial aa, a mod qa \bmod q is the unique polynomial bb of degree less than kk with q∣a−bq \mid a - b.

Lemma 1 (one clock). For a register rr and a word ww, lines L1 to L4 of CLOCK leave r′=(x r+w) mod qr' = (x\,r + w) \bmod q.

Proof. Write r=rk−1xk−1+r<r = r_{k-1} x^{k-1} + r_{<} with deg⁡r<<k−1\deg r_< < k - 1. Line L1 reads rk−1r_{k-1}. Line L2 forms x r<x\,r_<, which has degree less than kk. If rk−1=0r_{k-1} = 0, then x r=x r<x\,r = x\,r_< and line L3 does nothing. If rk−1=1r_{k-1} = 1, then x r=xk+x r<x\,r = x^k + x\,r_<, and line L3 forms x r<+(q−xk)=x r+qx\,r_< + (q - x^k) = x\,r + q. In both cases the result after line L3 has degree less than kk and differs from x rx\,r by a multiple of qq, so it is x r mod qx\,r \bmod q. Line L4 adds ww, which has degree less than kk, so the sum still has degree less than kk and differs from x r+wx\,r + w by a multiple of qq. So it is (x r+w) mod q(x\,r + w) \bmod q. ■\blacksquare

Theorem 1 (the signature). After RESET(s) and the clocks with w0,…,wm−1w_0, \ldots, w_{m-1}, the register holds

Sm=(xms+∑t=0m−1xm−1−twt) mod q.S_m = \Big( x^m s + \sum_{t=0}^{m-1} x^{m-1-t} w_t \Big) \bmod q.

Proof. By induction on mm. For m=0m = 0, RESET(s) stores ss, and ss has degree less than kk, so s=s mod qs = s \bmod q. Assume the claim for mm. By Lemma 1 the next clock gives

(xSm+wm) mod q=(xm+1s+∑t=0m−1xm−twt+wm) mod q,\big(x S_m + w_m\big) \bmod q = \Big( x^{m+1} s + \sum_{t=0}^{m-1} x^{m-t} w_t + w_m \Big) \bmod q,

since xSmx S_m differs from xx times the polynomial in the claim for mm by a multiple of qq. The sum is xm+1s+∑t=0mxm−twtx^{m+1} s + \sum_{t=0}^{m} x^{m-t} w_t, which is the claim for m+1m + 1. ■\blacksquare

Corollary 1 (the stream view). Write wt,iw_{t,i} for the coefficient of xix^i in wtw_t and Wi=∑twt,i xm−1−tW_i = \sum_t w_{t,i}\, x^{m-1-t}. Then ∑txm−1−twt=∑t∑iwt,i xm−1−t+i=∑ixiWi\sum_t x^{m-1-t} w_t = \sum_t \sum_i w_{t,i}\, x^{m-1-t+i} = \sum_i x^i W_i, so the signature is (xms+∑ixiWi) mod q\big(x^m s + \sum_i x^i W_i\big) \bmod q. ■\blacksquare

Theorem 2 (errors). Let the good words be wtw_t and the faulty words wt+etw_t + e_t, with the same seed ss. The two signatures differ by E mod qE \bmod q, where

E=∑t=0m−1xm−1−tet=∑t,iet,i xm−1−t+i.E = \sum_{t=0}^{m-1} x^{m-1-t} e_t = \sum_{t, i} e_{t,i}\, x^{m-1-t+i}.

So the faulty signature equals the good one exactly when qq divides EE.

Proof. The map a↦a mod qa \mapsto a \bmod q is linear over GF(2): if q∣a−a′q \mid a - a' and q∣b−b′q \mid b - b' then q∣(a+b)−(a′+b′)q \mid (a + b) - (a' + b'). By Theorem 1 the faulty signature is (xms+∑txm−1−twt+E) mod q\big(x^m s + \sum_t x^{m-1-t} w_t + E\big) \bmod q, which is the good signature plus E mod qE \bmod q. The two are equal exactly when E mod q=0E \bmod q = 0, that is when q∣Eq \mid E. ■\blacksquare

Theorem 3 (single wrong bits). If q0=1q_0 = 1, then a stream with exactly one wrong bit never gives the good signature.

Proof. One wrong bit, at clock tt on input ii, gives E=xjE = x^j with j=m−1−t+i≥0j = m - 1 - t + i \ge 0. Suppose q∣xjq \mid x^j, so xj=q ux^j = q\,u for some uu. Put x=0x = 0. If j≥1j \ge 1 the left side is 0 and the right side is q0u(0)=u(0)q_0 u(0) = u(0), so u(0)=0u(0) = 0 and x∣ux \mid u, and we may divide both sides by xx and repeat with j−1j - 1. After jj steps we reach 1=q u′1 = q\,u', which is impossible since deg⁡q=k≥1\deg q = k \ge 1. So q∤Eq \nmid E, and by Theorem 2 the signatures differ. ■\blacksquare

Theorem 4 (pairs of wrong bits). Two wrong bits (t,i)(t, i) and (t′,i′)(t', i') give the exponents a=m−1−t+ia = m - 1 - t + i and b=m−1−t′+i′b = m - 1 - t' + i'.

  1. If a=ba = b, the pair always aliases. This happens in particular for (t,i)(t, i) and (t+1,i+1)(t + 1, i + 1).
  2. If a>ba > b and q0=1q_0 = 1, the pair aliases exactly when q∣xa−b+1q \mid x^{a-b} + 1.

Proof. If a=ba = b, then E=xa+xa=0E = x^a + x^a = 0, and qq divides 0. For (t+1,i+1)(t + 1, i + 1) the exponent is m−1−(t+1)+(i+1)=am - 1 - (t + 1) + (i + 1) = a. If a>ba > b, then E=xb(xa−b+1)E = x^b (x^{a-b} + 1). As in Theorem 3, q0=1q_0 = 1 means that qq and xbx^b have no common factor other than 1, since every common factor divides xbx^b and so is a power of xx, and x∤qx \nmid q. So q∣Eq \mid E exactly when q∣xa−b+1q \mid x^{a-b} + 1. ■\blacksquare

For a primitive qq of degree kk, the least n≥1n \ge 1 with q∣xn+1q \mid x^n + 1 is 2k−12^k - 1, and q∣xn+1q \mid x^n + 1 exactly when 2k−12^k - 1 divides nn. So with a primitive qq, two wrong bits with different exponents alias exactly when their exponents differ by a multiple of 2k−12^k - 1.

Complexity

For k≤wk \le w, the word size, each operation is O(1)O(1) word operations, so a stream of mm words costs O(m)O(m) time. For larger kk, a clock touches ⌈k/w⌉\lceil k / w \rceil words. The extra space is the register itself. In hardware, one clock is one word, so the register keeps up with the circuit at full speed, and the area is kk flip-flops and O(k)O(k) XOR gates. The signature is kk bits however long the test is.

Variants

  • Single-input register. With kk circuit outputs and a one-bit input, first XOR the outputs into one bit, then divide. A MISR saves this XOR tree and keeps more information, since the outputs enter at different stages.
  • External-XOR form. The feedback can also be taken as one XOR of tapped stages into stage 0, the Fibonacci form of the LFSR, with the input words still XORed into every stage. The map from streams to signatures is again linear and onto, so the count of aliasing streams is the same, but the set of aliasing streams is a different one, and the signature is not the plain remainder of fact 1.
  • Space compactor first. With hundreds of scan chains and a 32-bit or 64-bit MISR, an XOR network first reduces the chain outputs to the width of the register. The X-compact network is one with proved properties when some outputs are unknown.
  • Masking. A mask register forces chosen chain outputs to 0 on chosen clocks, so that unknown values do not enter the register.
  • Several signatures. Reading the signature after every pattern or every block, instead of once at the end, shortens the stream that one aliasing event can hide and gives data for diagnosis.
  • BILBO. The register of Könemann, Mucha and Zwiehoff works as a normal register, a scan register, a pattern generator with the inputs held at 0, or a MISR.

When to use it

Use a MISR whenever a long response must be checked on the chip or carried out through few pins: the output side of built-in self-test, the output side of scan compression such as embedded deterministic test, and checks of memory contents. The pattern side of these schemes uses the same register with the inputs off, as in LFSR reseeding. Do not use it when every response bit is needed, for example for diagnosis with a fault dictionary, unless the signature is read often or the test is run again with the register bypassed.

Pitfalls

  • Unknown values. One unknown bit XX on an input makes every later state of the register unknown, since the next state depends on it linearly and nothing removes it. Block or mask every source of XX before the register.
  • Errors in neighbor stages. Fact 2 shows that an error on input ii at clock tt and one on input i+1i + 1 at clock t+1t + 1 cancel. A fault that drives two neighbor scan chains in this pattern aliases for every polynomial. Do not connect outputs that share logic to neighbor stages, or use a space compactor that mixes them first.
  • A polynomial without the term 1. If q0=0q_0 = 0, then xx divides qq, the step r↦x r mod qr \mapsto x\,r \bmod q is not one to one, and the register forgets part of its past. For q=x3q = x^3 it is a plain shift register, and an error on input 2 at clock 0 is gone after one more clock. For q=x3+x2=x2(x+1)q = x^3 + x^2 = x^2 (x + 1), two wrong bits on input 2 at any two neighbor clocks give E=xb(x+1)E = x^b (x + 1) with b≥2b \ge 2, a multiple of qq, and alias.
  • The good signature depends on everything. The seed, the number of clocks, the order of the inputs and every bit of the good response enter the signature. A change in any of them needs a new good signature from simulation.
  • One signature hides where the error was. Pass or fail is all that a final signature tells. Diagnosis needs the failing clocks, which means reading the register more often or running the test again in a mode that bypasses it.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

multiple_input_signature_register.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/multiple-input-signature-register/. The authors are listed in prov/CM81DK.jsonl.
"""A multiple-input signature register (MISR) with internal XOR feedback.

The register has k stages r_0, ..., r_(k-1). Read as a polynomial over GF(2),
r(x) = r_0 + r_1 x + ... + r_(k-1) x^(k-1). The feedback polynomial is
q(x) = x^k + q_(k-1) x^(k-1) + ... + q_0, stored as an int with bit i equal to
the coefficient of x^i (so bit k is set). One clock with the input word
w = (w_0, ..., w_(k-1)) does

    r <- (x * r(x) + w(x)) mod q(x),

which in hardware is a shift toward the high stage, an XOR of the low k bits
of q into the stages when the top stage was 1, and an XOR of the input word.
After m clocks from the seed s, the register holds
(x^m s(x) + sum_t x^(m-1-t) w_t(x)) mod q(x).

Each clock costs O(1) operations on k-bit words (O(k) bit operations).
"""

from __future__ import annotations

from typing import Iterable


class MISR:
    """A k-bit MISR with feedback polynomial q of degree k."""

    def __init__(self, k: int, q: int, seed: int = 0) -> None:
        """Precondition: k >= 1, q has degree exactly k, and 0 <= seed < 2^k."""
        if k < 1 or q >> k != 1:
            raise ValueError("q must have degree exactly k")
        self.k = k
        self.q = q
        self.mask = (1 << k) - 1
        self.low = q & self.mask  # q(x) - x^k
        self.r = 0
        self.reset(seed)

    def reset(self, seed: int = 0) -> None:
        """Load a seed into the stages. O(1)."""
        if not 0 <= seed <= self.mask:
            raise ValueError("the seed must have k bits")
        self.r = seed

    def clock(self, w: int) -> None:
        """One clock with the k-bit input word w (bit i enters stage i). O(1) word operations."""
        if not 0 <= w <= self.mask:
            raise ValueError("the input word must have k bits")
        msb = (self.r >> (self.k - 1)) & 1  # @line L1
        self.r = (self.r << 1) & self.mask  # @line L2
        if msb:
            self.r ^= self.low  # @line L3
        self.r ^= w  # @line L4

    def compact(self, words: Iterable[int]) -> int:
        """Clock every word of a response stream and return the signature. O(m) for m words."""
        for w in words:
            self.clock(w)
        return self.r

    def signature(self) -> int:
        """The current contents of the register."""
        return self.r

    def check_invariant(self) -> bool:
        return 0 <= self.r <= self.mask and self.q >> self.k == 1


def signature_of(k: int, q: int, words: Iterable[int], seed: int = 0) -> int:
    """The signature of a whole stream from a seed."""
    return MISR(k, q, seed).compact(words)
test_multiple_input_signature_register.py 170 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/multiple-input-signature-register/. The authors are listed in prov/CM81DK.jsonl.

import random
from itertools import product

import pytest

from multiple_input_signature_register import MISR, signature_of

Q3 = 0b1011  # x^3 + x + 1, primitive
Q4 = 0b10011  # x^4 + x + 1, primitive
Q8 = 0x11D  # x^8 + x^4 + x^3 + x^2 + 1, primitive


def polymod(a: int, q: int) -> int:
    """Reference: remainder of a(x) by q(x) over GF(2), by long division from the top bit."""
    dq = q.bit_length() - 1
    while a and a.bit_length() - 1 >= dq:
        a ^= q << (a.bit_length() - 1 - dq)
    return a


def folded(words, seed: int) -> int:
    """The polynomial x^m s(x) + sum_t x^(m-1-t) w_t(x) of a stream of m words."""
    m = len(words)
    d = seed << m
    for t, w in enumerate(words):
        d ^= w << (m - 1 - t)
    return d


def test_page_example():
    # The example of the page: k = 3, q = x^3 + x + 1, five words, seed 0.
    words = [0b101, 0b011, 0b110, 0b001, 0b100]
    m = MISR(3, Q3)
    states = []
    for w in words:
        m.clock(w)
        states.append(m.signature())
        assert m.check_invariant()
    assert states == [0b101, 0b010, 0b010, 0b101, 0b101]
    assert m.signature() == polymod(folded(words, 0), Q3)


def test_one_stage_is_parity():
    # k = 1, q = x + 1: the register is the parity of all input bits.
    rng = random.Random(1)
    for _ in range(200):
        words = [rng.randint(0, 1) for _ in range(rng.randint(0, 20))]
        assert signature_of(1, 0b11, words) == sum(words) % 2


def test_empty_stream_keeps_seed():
    assert signature_of(4, Q4, [], seed=0b1010) == 0b1010


def test_bad_arguments():
    with pytest.raises(ValueError):
        MISR(3, 0b111)  # degree 2, not 3
    with pytest.raises(ValueError):
        MISR(3, Q3).clock(8)
    with pytest.raises(ValueError):
        MISR(3, Q3, seed=9)


@pytest.mark.parametrize("k", [1, 2, 3, 4, 5, 8, 16])
def test_signature_is_remainder(k):
    rng = random.Random(100 + k)
    for _ in range(300):
        q = (1 << k) | rng.randrange(1 << k)  # any polynomial of degree k, primitive or not
        seed = rng.randrange(1 << k)
        words = [rng.randrange(1 << k) for _ in range(rng.randint(0, 40))]
        assert signature_of(k, q, words, seed) == polymod(folded(words, seed), q)


def test_linearity():
    rng = random.Random(7)
    for _ in range(500):
        k = rng.randint(1, 8)
        q = (1 << k) | rng.randrange(1 << k)
        n = rng.randint(1, 20)
        good = [rng.randrange(1 << k) for _ in range(n)]
        err = [rng.randrange(1 << k) for _ in range(n)]
        seed = rng.randrange(1 << k)
        bad = [g ^ e for g, e in zip(good, err)]
        assert signature_of(k, q, bad, seed) == signature_of(k, q, good, seed) ^ signature_of(k, q, err)


@pytest.mark.parametrize("k,q,m", [(2, 0b111, 3), (3, Q3, 3), (3, 0b1001, 3), (2, 0b100, 4), (4, Q4, 2)])
def test_exhaustive_alias_count(k, q, m):
    # Every nonzero error stream of m words: exactly 2^(mk - k) - 1 of them alias, for every q of degree k.
    count = 0
    for err in product(range(1 << k), repeat=m):
        if any(err) and signature_of(k, q, list(err)) == 0:
            count += 1
    assert count == 2 ** (m * k - k) - 1


def test_single_bit_errors_never_alias():
    rng = random.Random(3)
    for _ in range(200):
        k = rng.randint(1, 8)
        q = (1 << k) | rng.randrange(1 << k)
        if q == 1 << k:
            continue
        m = rng.randint(1, 12)
        for t in range(m):
            for i in range(k):
                err = [0] * m
                err[t] = 1 << i
                assert signature_of(k, q, err) != 0


def test_monomial_feedback_aliases_single_bits():
    # q = x^k is a plain shift register: a bit that leaves the top stage is lost.
    err = [0b100, 0, 0]
    assert signature_of(3, 0b1000, err) == 0


def test_cancelling_pair_always_aliases():
    # An error in stage i at clock t and in stage i + 1 at clock t + 1 cancels, for every q.
    rng = random.Random(11)
    for _ in range(300):
        k = rng.randint(2, 10)
        q = (1 << k) | rng.randrange(1 << k)
        m = rng.randint(2, 15)
        t = rng.randrange(m - 1)
        i = rng.randrange(k - 1)
        err = [0] * m
        err[t] ^= 1 << i
        err[t + 1] ^= 1 << (i + 1)
        assert signature_of(k, q, err) == 0


def test_alias_rate_random_streams():
    # Equally likely nonzero error streams: the measured rate is close to (2^(mk-k) - 1)/(2^(mk) - 1), about 2^-k.
    rng = random.Random(2024)
    k, m, n = 8, 16, 40000
    hits = 0
    for _ in range(n):
        err = [rng.randrange(1 << k) for _ in range(m)]
        if not any(err):
            continue
        if signature_of(k, Q8, err) == 0:
            hits += 1
    p = 2.0 ** -k
    sigma = (p * (1 - p) / n) ** 0.5
    assert abs(hits / n - p) < 5 * sigma


def test_against_model_random_operations():
    # Long random sequences of reset and clock, against a model that keeps the folded polynomial.
    rng = random.Random(99)
    for _ in range(100):
        k = rng.randint(1, 12)
        q = (1 << k) | rng.randrange(1 << k)
        m = MISR(k, q)
        words, seed = [], 0
        for _ in range(60):
            if rng.random() < 0.1:
                seed = rng.randrange(1 << k)
                m.reset(seed)
                words = []
            else:
                w = rng.randrange(1 << k)
                m.clock(w)
                words.append(w)
            assert m.check_invariant()
            assert m.signature() == polymod(folded(words, seed), q)

History

The BILBO register of Könemann, Mucha and Zwiehoff (1979) put a signature mode with one input per stage into the registers of the circuit itself, and this is the multiple-input signature register of logic BIST. The description as polynomial division over GF(2), and the count of aliasing error streams under the model in which all of them are equally likely, are in Smith (1980) and in the book of Bardell, McAnney and Savir (1987).

References

  1. B. Könemann, J. Mucha and G. Zwiehoff, Built-in logic block observation techniques, Digest of Papers, 1979 Test Conference, 37 to 41, 1979, the BILBO register and its signature mode with one input per stage
  2. Paul H. Bardell, William H. McAnney and Jacob Savir, Built-In Test for VLSI, Pseudorandom Techniques, Wiley-Interscience, 1987, the chapters Test Response Compression Techniques and Shift-Register Polynomial Division (the multiple-input register as polynomial division)
  3. Miron Abramovici, Melvin A. Breuer and Arthur D. Friedman, Digital Systems Testing and Testable Design, IEEE Press, 1994, the chapter Compression Techniques (signature analysis and parallel signature analysis)
  4. J. E. Smith, Measures of the effectiveness of fault signature analysis, IEEE Transactions on Computers C-29(6), 510 to 514, 1980, the count of aliasing error streams when all of them are equally likely

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.average
  • a full proof of time.best
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/CM81DK/text.yaml