broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(*args):
    depth, mode, ops = args
    mem = [0] * depth
    out = []
    for we, addr, wdata, be, re in ops:
        ok = 0 <= addr < depth
        old = mem[addr] if ok else None
        new = old
        if we and ok:
            for lane in range(2):
                if be >> lane & 1:
                    mask = 0xFF << (8 * lane)
                    new = (new & ~mask) | (wdata & mask)
            mem[addr] = new
        if re:
            if not ok:
                out.append(0)
            else:
                out.append(new if mode == 'write_first' else old)
        else:
            out.append(None)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('full write then read-first read', [5, 'read_first', [[1, 1, 43981, 3, 1], [0, 1, 0, 0, 1]]], [0, 43981]), ('write-first partial write', [5, 'write_first', [[1, 2, 4660, 3, 0], [1, 2, 65535, 1, 1], [0, 2, 0, 0, 1]]], [None, 4863, 4863]), ('high lane only', [5, 'read_first', [[1, 3, 23041, 2, 0], [0, 3, 0, 0, 1]]], [None, 23040]), ('address zero', [5, 'write_first', [[1, 0, 3855, 3, 1], [0, 0, 0, 0, 1]]], [3855, 3855]), ('negative address rejected', [5, 'read_first', [[1, -1, 30583, 3, 1], [0, 4, 0, 0, 1]]], ['x', 0]), ('out of range read', [5, 'read_first', [[0, 6, 0, 0, 1], [0, 1, 0, 0, 0]]], ['x', None]), ('read-first returns old data', [5, 'read_first', [[1, 1, 4369, 3, 0], [1, 1, 8738, 3, 1], [0, 1, 0, 0, 1]]], [None, 4369, 8738])], [('full write then read-first read', [4, 'read_first', [[1, 1, 43981, 3, 1], [0, 1, 0, 0, 1]]], [0, 43981]), ('write-first partial write', [4, 'write_first', [[1, 2, 4660, 3, 0], [1, 2, 65535, 1, 1], [0, 2, 0, 0, 1]]], [None, 4863, 4863]), ('high lane only', [4, 'read_first', [[1, 3, 23042, 2, 0], [0, 3, 0, 0, 1]]], [None, 23040]), ('address zero', [4, 'write_first', [[1, 0, 3855, 3, 1], [0, 0, 0, 0, 1]]], [3855, 3855]), ('negative address rejected', [4, 'read_first', [[1, -1, 30583, 3, 1], [0, 3, 0, 0, 1]]], ['x', 0]), ('out of range read', [4, 'read_first', [[0, 6, 0, 0, 1], [0, 1, 0, 0, 0]]], ['x', None]), ('read-first returns old data', [4, 'read_first', [[1, 1, 4369, 3, 0], [1, 1, 17476, 3, 1], [0, 1, 0, 0, 1]]], [None, 4369, 17476])], [('full write then read-first read', [5, 'read_first', [[1, 1, 43981, 3, 1], [0, 1, 0, 0, 1]]], [0, 43981]), ('write-first partial write', [5, 'write_first', [[1, 2, 4660, 3, 0], [1, 2, 65535, 1, 1], [0, 2, 0, 0, 1]]], [None, 4863, 4863]), ('high lane only', [5, 'read_first', [[1, 3, 23043, 2, 0], [0, 3, 0, 0, 1]]], [None, 23040]), ('address zero', [5, 'write_first', [[1, 0, 3855, 3, 1], [0, 0, 0, 0, 1]]], [3855, 3855]), ('negative address rejected', [5, 'read_first', [[1, -1, 30583, 3, 1], [0, 4, 0, 0, 1]]], ['x', 0]), ('out of range read', [5, 'read_first', [[0, 8, 0, 0, 1], [0, 1, 0, 0, 0]]], ['x', None]), ('read-first returns old data', [5, 'read_first', [[1, 1, 4369, 3, 0], [1, 1, 26214, 3, 1], [0, 1, 0, 0, 1]]], [None, 4369, 26214])], [('full write then read-first read', [4, 'read_first', [[1, 1, 43981, 3, 1], [0, 1, 0, 0, 1]]], [0, 43981]), ('write-first partial write', [4, 'write_first', [[1, 2, 4660, 3, 0], [1, 2, 65535, 1, 1], [0, 2, 0, 0, 1]]], [None, 4863, 4863]), ('high lane only', [4, 'read_first', [[1, 3, 23044, 2, 0], [0, 3, 0, 0, 1]]], [None, 23040]), ('address zero', [4, 'write_first', [[1, 0, 3855, 3, 1], [0, 0, 0, 0, 1]]], [3855, 3855]), ('negative address rejected', [4, 'read_first', [[1, -1, 30583, 3, 1], [0, 3, 0, 0, 1]]], ['x', 0]), ('out of range read', [4, 'read_first', [[0, 8, 0, 0, 1], [0, 1, 0, 0, 0]]], ['x', None]), ('read-first returns old data', [4, 'read_first', [[1, 1, 4369, 3, 0], [1, 1, 34952, 3, 1], [0, 1, 0, 0, 1]]], [None, 4369, 34952])], [('full write then read-first read', [5, 'read_first', [[1, 1, 43981, 3, 1], [0, 1, 0, 0, 1]]], [0, 43981]), ('write-first partial write', [5, 'write_first', [[1, 2, 4660, 3, 0], [1, 2, 65535, 1, 1], [0, 2, 0, 0, 1]]], [None, 4863, 4863]), ('high lane only', [5, 'read_first', [[1, 3, 23045, 2, 0], [0, 3, 0, 0, 1]]], [None, 23040]), ('address zero', [5, 'write_first', [[1, 0, 3855, 3, 1], [0, 0, 0, 0, 1]]], [3855, 3855]), ('negative address rejected', [5, 'read_first', [[1, -1, 30583, 3, 1], [0, 4, 0, 0, 1]]], ['x', 0]), ('out of range read', [5, 'read_first', [[0, 10, 0, 0, 1], [0, 1, 0, 0, 0]]], ['x', None]), ('read-first returns old data', [5, 'read_first', [[1, 1, 4369, 3, 0], [1, 1, 43690, 3, 1], [0, 1, 0, 0, 1]]], [None, 4369, 43690])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(*args):
    depth, mode, ops = args
    mem = [0] * depth
    out = []
    for we, addr, wdata, be, re in ops:
        ok = 0 <= addr < depth
        old = mem[addr] if ok else None
        new = old
        if we and ok:
            for lane in range(2):
                if be >> lane & 1:
                    mask = 0xFF << (8 * lane)
                    new = (new & ~mask) | (wdata & mask)
            mem[addr] = new
        if re:
            if not ok:
                out.append(None)
            else:
                out.append(new if mode == 'write_first' else old)
        else:
            out.append(None)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('full write then read-first read', [5, 'read_first', [[1, 1, 43981, 3, 1], [0, 1, 0, 0, 1]]], [0, 43981]), ('write-first partial write', [5, 'write_first', [[1, 2, 4660, 3, 0], [1, 2, 65535, 1, 1], [0, 2, 0, 0, 1]]], [None, 4863, 4863]), ('high lane only', [5, 'read_first', [[1, 3, 23041, 2, 0], [0, 3, 0, 0, 1]]], [None, 23040]), ('address zero', [5, 'write_first', [[1, 0, 3855, 3, 1], [0, 0, 0, 0, 1]]], [3855, 3855]), ('negative address rejected', [5, 'read_first', [[1, -1, 30583, 3, 1], [0, 4, 0, 0, 1]]], ['x', 0]), ('out of range read', [5, 'read_first', [[0, 6, 0, 0, 1], [0, 1, 0, 0, 0]]], ['x', None]), ('read-first returns old data', [5, 'read_first', [[1, 1, 4369, 3, 0], [1, 1, 8738, 3, 1], [0, 1, 0, 0, 1]]], [None, 4369, 8738])], [('full write then read-first read', [4, 'read_first', [[1, 1, 43981, 3, 1], [0, 1, 0, 0, 1]]], [0, 43981]), ('write-first partial write', [4, 'write_first', [[1, 2, 4660, 3, 0], [1, 2, 65535, 1, 1], [0, 2, 0, 0, 1]]], [None, 4863, 4863]), ('high lane only', [4, 'read_first', [[1, 3, 23042, 2, 0], [0, 3, 0, 0, 1]]], [None, 23040]), ('address zero', [4, 'write_first', [[1, 0, 3855, 3, 1], [0, 0, 0, 0, 1]]], [3855, 3855]), ('negative address rejected', [4, 'read_first', [[1, -1, 30583, 3, 1], [0, 3, 0, 0, 1]]], ['x', 0]), ('out of range read', [4, 'read_first', [[0, 6, 0, 0, 1], [0, 1, 0, 0, 0]]], ['x', None]), ('read-first returns old data', [4, 'read_first', [[1, 1, 4369, 3, 0], [1, 1, 17476, 3, 1], [0, 1, 0, 0, 1]]], [None, 4369, 17476])], [('full write then read-first read', [5, 'read_first', [[1, 1, 43981, 3, 1], [0, 1, 0, 0, 1]]], [0, 43981]), ('write-first partial write', [5, 'write_first', [[1, 2, 4660, 3, 0], [1, 2, 65535, 1, 1], [0, 2, 0, 0, 1]]], [None, 4863, 4863]), ('high lane only', [5, 'read_first', [[1, 3, 23043, 2, 0], [0, 3, 0, 0, 1]]], [None, 23040]), ('address zero', [5, 'write_first', [[1, 0, 3855, 3, 1], [0, 0, 0, 0, 1]]], [3855, 3855]), ('negative address rejected', [5, 'read_first', [[1, -1, 30583, 3, 1], [0, 4, 0, 0, 1]]], ['x', 0]), ('out of range read', [5, 'read_first', [[0, 8, 0, 0, 1], [0, 1, 0, 0, 0]]], ['x', None]), ('read-first returns old data', [5, 'read_first', [[1, 1, 4369, 3, 0], [1, 1, 26214, 3, 1], [0, 1, 0, 0, 1]]], [None, 4369, 26214])], [('full write then read-first read', [4, 'read_first', [[1, 1, 43981, 3, 1], [0, 1, 0, 0, 1]]], [0, 43981]), ('write-first partial write', [4, 'write_first', [[1, 2, 4660, 3, 0], [1, 2, 65535, 1, 1], [0, 2, 0, 0, 1]]], [None, 4863, 4863]), ('high lane only', [4, 'read_first', [[1, 3, 23044, 2, 0], [0, 3, 0, 0, 1]]], [None, 23040]), ('address zero', [4, 'write_first', [[1, 0, 3855, 3, 1], [0, 0, 0, 0, 1]]], [3855, 3855]), ('negative address rejected', [4, 'read_first', [[1, -1, 30583, 3, 1], [0, 3, 0, 0, 1]]], ['x', 0]), ('out of range read', [4, 'read_first', [[0, 8, 0, 0, 1], [0, 1, 0, 0, 0]]], ['x', None]), ('read-first returns old data', [4, 'read_first', [[1, 1, 4369, 3, 0], [1, 1, 34952, 3, 1], [0, 1, 0, 0, 1]]], [None, 4369, 34952])], [('full write then read-first read', [5, 'read_first', [[1, 1, 43981, 3, 1], [0, 1, 0, 0, 1]]], [0, 43981]), ('write-first partial write', [5, 'write_first', [[1, 2, 4660, 3, 0], [1, 2, 65535, 1, 1], [0, 2, 0, 0, 1]]], [None, 4863, 4863]), ('high lane only', [5, 'read_first', [[1, 3, 23045, 2, 0], [0, 3, 0, 0, 1]]], [None, 23040]), ('address zero', [5, 'write_first', [[1, 0, 3855, 3, 1], [0, 0, 0, 0, 1]]], [3855, 3855]), ('negative address rejected', [5, 'read_first', [[1, -1, 30583, 3, 1], [0, 4, 0, 0, 1]]], ['x', 0]), ('out of range read', [5, 'read_first', [[0, 10, 0, 0, 1], [0, 1, 0, 0, 0]]], ['x', None]), ('read-first returns old data', [5, 'read_first', [[1, 1, 4369, 3, 0], [1, 1, 43690, 3, 1], [0, 1, 0, 0, 1]]], [None, 4369, 43690])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Reading past the end of the memory yields 0 instead of 'x'.

Input [depth, mode, ops]; memory holds 16-bit words initialised to 0. Each op [we, addr, wdata, be, re]: be bit k enables byte lane k (bits 8k..8k+7). Addresses outside 0..depth-1 ignore writes and read 'x'. A read in the same cycle as a write returns the old word in mode 'read_first' and the merged new word in 'write_first'. re=0 yields None.

split: open-access


meaning: Fixture-count band, not measured model difficulty

deps: stdlib

prompt:
The dump repeats values that did not change, with extra timestamp markers.

Input [sigs, samples]: sigs are [name, id, width, initial]; samples are time-sorted [t, name, value] with values as 0/1/x/z strings, possibly shorter than the width or redundant. Output starts with '#0' and one line per signal's initial value. Afterwards only real value changes are written, each timestamp marker '#t' at most once and only when a change happens at t. Width-1 signals print value+id; vectors print 'b'+value+' '+id with leading zeros removed (at least one digit kept) and a run of leading x or z collapsed to one character.

split: open-access


prompt:
A '#t' marker appears for a time at which nothing changed.

Input [sigs, samples]: sigs are [name, id, width, initial]; samples are time-sorted [t, name, value] with values as 0/1/x/z strings, possibly shorter than the width or redundant. Output starts with '#0' and one line per signal's initial value. Afterwards only real value changes are written, each timestamp marker '#t' at most once and only when a change happens at t. Width-1 signals print value+id; vectors print 'b'+value+' '+id with leading zeros removed (at least one digit kept) and a run of leading x or z collapsed to one character.

split: open-access


prompt:
A vector returning to zero is dumped as 'b <id>' with an empty value.

Input [sigs, samples]: sigs are [name, id, width, initial]; samples are time-sorted [t, name, value] with values as 0/1/x/z strings, possibly shorter than the width or redundant. Output starts with '#0' and one line per signal's initial value. Afterwards only real value changes are written, each timestamp marker '#t' at most once and only when a change happens at t. Width-1 signals print value+id; vectors print 'b'+value+' '+id with leading zeros removed (at least one digit kept) and a run of leading x or z collapsed to one character.

split: open-access


prompt:
A vector sample given as a single digit is dumped in scalar form without the b prefix.

Input [sigs, samples]: sigs are [name, id, width, initial]; samples are time-sorted [t, name, value] with values as 0/1/x/z strings, possibly shorter than the width or redundant. Output starts with '#0' and one line per signal's initial value. Afterwards only real value changes are written, each timestamp marker '#t' at most once and only when a change happens at t. Width-1 signals print value+id; vectors print 'b'+value+' '+id with leading zeros removed (at least one digit kept) and a run of leading x or z collapsed to one character.

split: open-access


prompt:
An all-unknown vector is dumped as 'bxxx' instead of 'bx'.

Input [sigs, samples]: sigs are [name, id, width, initial]; samples are time-sorted [t, name, value] with values as 0/1/x/z strings, possibly shorter than the width or redundant. Output starts with '#0' and one line per signal's initial value. Afterwards only real value changes are written, each timestamp marker '#t' at most once and only when a change happens at t. Width-1 signals print value+id; vectors print 'b'+value+' '+id with leading zeros removed (at least one digit kept) and a run of leading x or z collapsed to one character.

split: open-access


prompt:
Hazard pairs are reported on mirrored minterm numbers.

Input [nv, terms]: product terms are strings over '0','1','-' with character 0 the most significant variable. Minterm m is covered by a term when every non-'-' position matches bit (m >> (nv-1-k)) & 1. A static-1 hazard is a pair of adjacent minterms (differing in one bit), both in the on-set, that no single term covers together. Return sorted [low, high] pairs.

split: open-access


prompt:
Terms with a 0 literal cover minterms where that variable is 1.

Input [nv, terms]: product terms are strings over '0','1','-' with character 0 the most significant variable. Minterm m is covered by a term when every non-'-' position matches bit (m >> (nv-1-k)) & 1. A static-1 hazard is a pair of adjacent minterms (differing in one bit), both in the on-set, that no single term covers together. Return sorted [low, high] pairs.

split: open-access


prompt:
Each hazard appears as both [a, b] and [b, a].

Input [nv, terms]: product terms are strings over '0','1','-' with character 0 the most significant variable. Minterm m is covered by a term when every non-'-' position matches bit (m >> (nv-1-k)) & 1. A static-1 hazard is a pair of adjacent minterms (differing in one bit), both in the on-set, that no single term covers together. Return sorted [low, high] pairs.

split: open-access


prompt:
Adjacent minterms sharing a consensus term are still reported as hazards.

Input [nv, terms]: product terms are strings over '0','1','-' with character 0 the most significant variable. Minterm m is covered by a term when every non-'-' position matches bit (m >> (nv-1-k)) & 1. A static-1 hazard is a pair of adjacent minterms (differing in one bit), both in the on-set, that no single term covers together. Return sorted [low, high] pairs.

split: open-access


prompt:
Pairs that differ in more than one variable are tested and real one-bit neighbours are skipped.

Input [nv, terms]: product terms are strings over '0','1','-' with character 0 the most significant variable. Minterm m is covered by a term when every non-'-' position matches bit (m >> (nv-1-k)) & 1. A static-1 hazard is a pair of adjacent minterms (differing in one bit), both in the on-set, that no single term covers together. Return sorted [low, high] pairs.

split: open-access


prompt:
J=K=1 leaves the output unchanged.

Input [kind, q0, ins] with one [a, b] pair per clock edge. jk (a=J, b=K): 00 hold, 10 set, 01 reset, 11 toggle. sr (a=S, b=R): 10 set, 01 reset, 00 hold, 11 is forbidden and makes q 'x'. t (a=T): 1 toggles, 0 holds, 'x' makes q 'x'. Toggling 'x' gives 'x'. Return q after each edge.

split: open-access


prompt:
Asserting J clears the flop and asserting K sets it.

Input [kind, q0, ins] with one [a, b] pair per clock edge. jk (a=J, b=K): 00 hold, 10 set, 01 reset, 11 toggle. sr (a=S, b=R): 10 set, 01 reset, 00 hold, 11 is forbidden and makes q 'x'. t (a=T): 1 toggles, 0 holds, 'x' makes q 'x'. Toggling 'x' gives 'x'. Return q after each edge.

split: open-access


prompt:
S=R=1 produces a definite 0 instead of 'x'.

Input [kind, q0, ins] with one [a, b] pair per clock edge. jk (a=J, b=K): 00 hold, 10 set, 01 reset, 11 toggle. sr (a=S, b=R): 10 set, 01 reset, 00 hold, 11 is forbidden and makes q 'x'. t (a=T): 1 toggles, 0 holds, 'x' makes q 'x'. Toggling 'x' gives 'x'. Return q after each edge.

split: open-access


prompt:
A T flip-flop with T='x' keeps its value instead of going unknown.

Input [kind, q0, ins] with one [a, b] pair per clock edge. jk (a=J, b=K): 00 hold, 10 set, 01 reset, 11 toggle. sr (a=S, b=R): 10 set, 01 reset, 00 hold, 11 is forbidden and makes q 'x'. t (a=T): 1 toggles, 0 holds, 'x' makes q 'x'. Toggling 'x' gives 'x'. Return q after each edge.

split: open-access


prompt:
Energy is overestimated for nets that pass through x.

Input [init, waves, cap]: waves[net] is a list of cycles, each a list of sub-cycle values ('0','1','x'). A 0<->1 change costs 2 half-toggles, a change to or from x costs 1, no change 0. Total energy sums half-toggles times cap over every event, comparing each event with the previous event on that net (across cycle boundaries). Functional energy compares only the last value of each non-empty cycle with the previous such value. Nets without a cap entry are unloaded (cap 0). Return [functional, total].

split: open-access


prompt:
Glitchy cycles report functional activity based on a transient value rather than the settled value.

Input [init, waves, cap]: waves[net] is a list of cycles, each a list of sub-cycle values ('0','1','x'). A 0<->1 change costs 2 half-toggles, a change to or from x costs 1, no change 0. Total energy sums half-toggles times cap over every event, comparing each event with the previous event on that net (across cycle boundaries). Functional energy compares only the last value of each non-empty cycle with the previous such value. Nets without a cap entry are unloaded (cap 0). Return [functional, total].

split: open-access


prompt:
Total energy counts transitions from the initial value at each cycle start instead of from the last event.

Input [init, waves, cap]: waves[net] is a list of cycles, each a list of sub-cycle values ('0','1','x'). A 0<->1 change costs 2 half-toggles, a change to or from x costs 1, no change 0. Total energy sums half-toggles times cap over every event, comparing each event with the previous event on that net (across cycle boundaries). Functional energy compares only the last value of each non-empty cycle with the previous such value. Nets without a cap entry are unloaded (cap 0). Return [functional, total].

split: open-access


prompt:
Nets without a capacitance annotation add energy to the estimate.

Input [init, waves, cap]: waves[net] is a list of cycles, each a list of sub-cycle values ('0','1','x'). A 0<->1 change costs 2 half-toggles, a change to or from x costs 1, no change 0. Total energy sums half-toggles times cap over every event, comparing each event with the previous event on that net (across cycle boundaries). Functional energy compares only the last value of each non-empty cycle with the previous such value. Nets without a cap entry are unloaded (cap 0). Return [functional, total].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(*args):
    kind, sel, data = args
    cands = [0]
    for s in sel:
        if s in '01':
            cands = [c * 2 + int(s) for c in cands]
        else:
            cands = [c * 2 for c in cands]
    if kind == 'mux':
        vals = sorted({data[c] for c in cands})
        return vals[0] if len(vals) == 1 and vals[0] in '01' else 'x'
    en = data[0]
    out = []
    for i in range(2 ** len(sel)):
        if en == '0':
            out.append('0')
        elif i in cands and (len(cands) > 1 or en != '1'):
            out.append('x')
        elif i in cands:
            out.append('1')
        else:
            out.append('0')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x1', ['0', '1', '0', '1']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '10', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '01', ['x']], ['0', 'x', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x0', ['1', '0', '1', '0']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '01', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '00', ['x']], ['x', '0', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x1', ['0', '1', '0', '1']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '10', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '01', ['x']], ['0', 'x', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x0', ['1', '0', '1', '0']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '01', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '00', ['x']], ['x', '0', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x1', ['0', '1', '0', '1']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '10', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '01', ['x']], ['0', 'x', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(*args):
    kind, sel, data = args
    cands = [0]
    for s in sel:
        if s in '01':
            cands = [c * 2 + int(s) for c in cands]
        else:
            cands = [c * 2 + 1 for c in cands]
    if kind == 'mux':
        vals = sorted({data[c] for c in cands})
        return vals[0] if len(vals) == 1 and vals[0] in '01' else 'x'
    en = data[0]
    out = []
    for i in range(2 ** len(sel)):
        if en == '0':
            out.append('0')
        elif i in cands and (len(cands) > 1 or en != '1'):
            out.append('x')
        elif i in cands:
            out.append('1')
        else:
            out.append('0')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x1', ['0', '1', '0', '1']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '10', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '01', ['x']], ['0', 'x', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x0', ['1', '0', '1', '0']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '01', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '00', ['x']], ['x', '0', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x1', ['0', '1', '0', '1']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '10', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '01', ['x']], ['0', 'x', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x0', ['1', '0', '1', '0']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '01', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '00', ['x']], ['x', '0', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x1', ['0', '1', '0', '1']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '10', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '01', ['x']], ['0', 'x', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A multiplexer with an unknown select passes input 0 instead of merging candidates.

Input [kind, sel, data]: sel is MSB-first over 0/1/x/z; an x or z select bit makes both values of that bit candidates. mux: the output is the common value of all candidate data inputs if they agree and are 0 or 1, else 'x'. dec: data[0] is the enable; enable 0 gives all '0'; otherwise candidate lines are '1' only when there is a single candidate and the enable is 1, else 'x'; non-candidate lines are '0'.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(*args):
    kind, sel, data = args
    cands = [0]
    for s in sel:
        if s in '01':
            cands = [c * 2 + int(s) for c in cands]
        else:
            cands = [c * 2 + b for c in cands for b in (0, 1)]
    if kind == 'mux':
        vals = sorted({data[c] for c in cands})
        return vals[0] if len(vals) == 1 else 'x'
    en = data[0]
    out = []
    for i in range(2 ** len(sel)):
        if en == '0':
            out.append('0')
        elif i in cands and (len(cands) > 1 or en != '1'):
            out.append('x')
        elif i in cands:
            out.append('1')
        else:
            out.append('0')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x1', ['0', '1', '0', '1']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '10', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '01', ['x']], ['0', 'x', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x0', ['1', '0', '1', '0']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '01', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '00', ['x']], ['x', '0', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x1', ['0', '1', '0', '1']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '10', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '01', ['x']], ['0', 'x', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x0', ['1', '0', '1', '0']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '01', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '00', ['x']], ['x', '0', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x1', ['0', '1', '0', '1']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '10', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '01', ['x']], ['0', 'x', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(*args):
    kind, sel, data = args
    cands = [0]
    for s in sel:
        if s in '01':
            cands = [c * 2 + int(s) for c in cands]
        else:
            cands = [c * 2 + b for c in cands for b in (0, 1)]
    if kind == 'mux':
        vals = sorted({data[c] for c in cands})
        return vals[0] if len(vals) == 1 and vals[0] != 'x' else 'x'
    en = data[0]
    out = []
    for i in range(2 ** len(sel)):
        if en == '0':
            out.append('0')
        elif i in cands and (len(cands) > 1 or en != '1'):
            out.append('x')
        elif i in cands:
            out.append('1')
        else:
            out.append('0')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x1', ['0', '1', '0', '1']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '10', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '01', ['x']], ['0', 'x', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x0', ['1', '0', '1', '0']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '01', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '00', ['x']], ['x', '0', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x1', ['0', '1', '0', '1']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '10', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '01', ['x']], ['0', 'x', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x0', ['1', '0', '1', '0']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '01', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '00', ['x']], ['x', '0', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x1', ['0', '1', '0', '1']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '10', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '01', ['x']], ['0', 'x', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Two candidate inputs both at 'z' produce 'z' instead of 'x'.

Input [kind, sel, data]: sel is MSB-first over 0/1/x/z; an x or z select bit makes both values of that bit candidates. mux: the output is the common value of all candidate data inputs if they agree and are 0 or 1, else 'x'. dec: data[0] is the enable; enable 0 gives all '0'; otherwise candidate lines are '1' only when there is a single candidate and the enable is 1, else 'x'; non-candidate lines are '0'.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(*args):
    kind, sel, data = args
    cands = [0]
    for s in sel:
        if s in '01':
            cands = [c * 2 + int(s) for c in cands]
        else:
            cands = [c * 2 + b for c in cands for b in (0, 1)]
    if kind == 'mux':
        vals = sorted({data[c] for c in cands})
        return vals[0] if len(vals) == 1 and vals[0] in '01' else 'x'
    en = data[0]
    out = []
    for i in range(2 ** len(sel)):
        if en == '0':
            out.append('0')
        elif len(cands) > 1 or en != '1':
            out.append('x')
        elif i in cands:
            out.append('1')
        else:
            out.append('0')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x1', ['0', '1', '0', '1']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '10', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '01', ['x']], ['0', 'x', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x0', ['1', '0', '1', '0']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '01', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '00', ['x']], ['x', '0', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x1', ['0', '1', '0', '1']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '10', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '01', ['x']], ['0', 'x', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x0', ['1', '0', '1', '0']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '01', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '00', ['x']], ['x', '0', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x1', ['0', '1', '0', '1']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '10', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '01', ['x']], ['0', 'x', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(*args):
    kind, sel, data = args
    cands = [0]
    for s in sel:
        if s in '01':
            cands = [c * 2 + int(s) for c in cands]
        else:
            cands = [c * 2 + b for c in cands for b in (0, 1)]
    if kind == 'mux':
        vals = sorted({data[c] for c in cands})
        return vals[0] if len(vals) == 1 and vals[0] in '01' else 'x'
    en = data[0]
    out = []
    for i in range(2 ** len(sel)):
        if en == '0':
            out.append('0')
        elif len(cands) > 1 and i in cands or en == 'x':
            out.append('x')
        elif i in cands:
            out.append('1')
        else:
            out.append('0')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x1', ['0', '1', '0', '1']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '10', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '01', ['x']], ['0', 'x', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x0', ['1', '0', '1', '0']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '01', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '00', ['x']], ['x', '0', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x1', ['0', '1', '0', '1']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '10', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '01', ['x']], ['0', 'x', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x0', ['1', '0', '1', '0']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '01', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '00', ['x']], ['x', '0', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x1', ['0', '1', '0', '1']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '10', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '01', ['x']], ['0', 'x', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A decoder with one unknown select bit drives x on lines that cannot be selected.

Input [kind, sel, data]: sel is MSB-first over 0/1/x/z; an x or z select bit makes both values of that bit candidates. mux: the output is the common value of all candidate data inputs if they agree and are 0 or 1, else 'x'. dec: data[0] is the enable; enable 0 gives all '0'; otherwise candidate lines are '1' only when there is a single candidate and the enable is 1, else 'x'; non-candidate lines are '0'.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(*args):
    kind, sel, data = args
    cands = [0]
    for s in sel:
        if s in '01':
            cands = [c * 2 + int(s) for c in cands]
        else:
            cands = [c * 2 + b for c in cands for b in (0, 1)]
    if kind == 'mux':
        vals = sorted({data[c] for c in cands})
        return vals[0] if len(vals) == 1 and vals[0] in '01' else 'x'
    en = data[0]
    out = []
    for i in range(2 ** len(sel)):
        if en == '0':
            out.append('0')
        elif i in cands and (len(cands) > 1):
            out.append('x')
        elif i in cands:
            out.append('1')
        else:
            out.append('0')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x1', ['0', '1', '0', '1']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '10', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '01', ['x']], ['0', 'x', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x0', ['1', '0', '1', '0']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '01', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '00', ['x']], ['x', '0', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x1', ['0', '1', '0', '1']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '10', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '01', ['x']], ['0', 'x', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x0', ['1', '0', '1', '0']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '01', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '00', ['x']], ['x', '0', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x1', ['0', '1', '0', '1']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '10', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '01', ['x']], ['0', 'x', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(*args):
    kind, sel, data = args
    cands = [0]
    for s in sel:
        if s in '01':
            cands = [c * 2 + int(s) for c in cands]
        else:
            cands = [c * 2 + b for c in cands for b in (0, 1)]
    if kind == 'mux':
        vals = sorted({data[c] for c in cands})
        return vals[0] if len(vals) == 1 and vals[0] in '01' else 'x'
    en = data[0]
    out = []
    for i in range(2 ** len(sel)):
        if en == '0':
            out.append('0')
        elif i in cands and (len(cands) > 1 or en == 'z'):
            out.append('x')
        elif i in cands:
            out.append('1')
        else:
            out.append('0')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x1', ['0', '1', '0', '1']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '10', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '01', ['x']], ['0', 'x', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x0', ['1', '0', '1', '0']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '01', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '00', ['x']], ['x', '0', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x1', ['0', '1', '0', '1']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '10', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '01', ['x']], ['0', 'x', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x0', ['1', '0', '1', '0']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '01', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '00', ['x']], ['x', '0', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])], [('mux unknown select differing data', ['mux', 'x', ['0', '1']], 'x'), ('mux unknown select agreeing data', ['mux', 'x', ['1', '1']], '1'), ('mux4 unknown low select bit', ['mux', '1x', ['0', '1', '1', '1']], '1'), ('mux4 unknown high select bit', ['mux', 'x1', ['0', '1', '0', '1']], '1'), ('mux unknown select floating data', ['mux', 'z', ['z', 'z']], 'x'), ('mux4 known select', ['mux', '10', ['0', '1', '1', '0']], '1'), ('decoder unknown select bit', ['dec', '1x', ['1']], ['0', '0', 'x', 'x']), ('decoder unknown enable', ['dec', '01', ['x']], ['0', 'x', '0', '0']), ('decoder enabled', ['dec', '10', ['1']], ['0', '0', '1', '0'])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
With enable 'x' the selected line reads 1.

Input [kind, sel, data]: sel is MSB-first over 0/1/x/z; an x or z select bit makes both values of that bit candidates. mux: the output is the common value of all candidate data inputs if they agree and are 0 or 1, else 'x'. dec: data[0] is the enable; enable 0 gives all '0'; otherwise candidate lines are '1' only when there is a single candidate and the enable is 1, else 'x'; non-candidate lines are '0'.

split: open-access


prompt:
The counter visits the value m before returning to 0.

Input [m, q0, ops]: ops per clock [load, value, en, up]. Before the edge tc = en==1 and ((up==1 and q==m-1) or (up==0 and q==0)). At the edge load==1 sets q = value mod m (load has priority and ignores en); else en==1 counts up or down modulo m. Return [q after edge, tc] per clock.

split: open-access


prompt:
Counting down from 0 stays at 0 instead of wrapping to m-1.

Input [m, q0, ops]: ops per clock [load, value, en, up]. Before the edge tc = en==1 and ((up==1 and q==m-1) or (up==0 and q==0)). At the edge load==1 sets q = value mod m (load has priority and ignores en); else en==1 counts up or down modulo m. Return [q after edge, tc] per clock.

split: open-access


prompt:
tc is high whenever the counter sits at its terminal value, even with enable low.

Input [m, q0, ops]: ops per clock [load, value, en, up]. Before the edge tc = en==1 and ((up==1 and q==m-1) or (up==0 and q==0)). At the edge load==1 sets q = value mod m (load has priority and ignores en); else en==1 counts up or down modulo m. Return [q after edge, tc] per clock.

split: open-access


prompt:
A synchronous load issued with enable low does not change the counter.

Input [m, q0, ops]: ops per clock [load, value, en, up]. Before the edge tc = en==1 and ((up==1 and q==m-1) or (up==0 and q==0)). At the edge load==1 sets q = value mod m (load has priority and ignores en); else en==1 counts up or down modulo m. Return [q after edge, tc] per clock.

split: open-access


prompt:
Loading a value above the modulus puts the counter in an illegal state.

Input [m, q0, ops]: ops per clock [load, value, en, up]. Before the edge tc = en==1 and ((up==1 and q==m-1) or (up==0 and q==0)). At the edge load==1 sets q = value mod m (load has priority and ignores en); else en==1 counts up or down modulo m. Return [q after edge, tc] per clock.

split: open-access


prompt:
The chain moves data backwards and scan-in enters at the scan-out end.

Input [chain, logic, state, ops]: chain lists flops from scan-in to scan-out. 'shift' with bit b: scan-out observes the last flop before the edge, then every flop takes its predecessor's old value and the first takes b. 'capture': every flop loads its functional next state logic[f] = [op, inputs] (and/xor/not) computed from the old state of all flops simultaneously. Return [scan-out bits, final chain values].

split: open-access


prompt:
The unloaded bit stream is missing the first bit and one position late.

Input [chain, logic, state, ops]: chain lists flops from scan-in to scan-out. 'shift' with bit b: scan-out observes the last flop before the edge, then every flop takes its predecessor's old value and the first takes b. 'capture': every flop loads its functional next state logic[f] = [op, inputs] (and/xor/not) computed from the old state of all flops simultaneously. Return [scan-out bits, final chain values].

split: open-access


prompt:
One shift fills the entire chain with the scan-in bit.

Input [chain, logic, state, ops]: chain lists flops from scan-in to scan-out. 'shift' with bit b: scan-out observes the last flop before the edge, then every flop takes its predecessor's old value and the first takes b. 'capture': every flop loads its functional next state logic[f] = [op, inputs] (and/xor/not) computed from the old state of all flops simultaneously. Return [scan-out bits, final chain values].

split: open-access


prompt:
Flops later in the chain capture values computed from already-updated earlier flops.

Input [chain, logic, state, ops]: chain lists flops from scan-in to scan-out. 'shift' with bit b: scan-out observes the last flop before the edge, then every flop takes its predecessor's old value and the first takes b. 'capture': every flop loads its functional next state logic[f] = [op, inputs] (and/xor/not) computed from the old state of all flops simultaneously. Return [scan-out bits, final chain values].

split: open-access


prompt:
Changing enable while the clock is high chops or creates clock pulses.

Input [samples] of [clk, en, te]. The enable latch starts at 0 and is transparent while clk is 0 (q = en or te), holding while clk is 1. The gated clock is clk and q. Return [gated clock per sample, number of gated rising edges counting from an initial low].

split: open-access


prompt:
The gated clock follows enable changes during the high phase.

Input [samples] of [clk, en, te]. The enable latch starts at 0 and is transparent while clk is 0 (q = en or te), holding while clk is 1. The gated clock is clk and q. Return [gated clock per sample, number of gated rising edges counting from an initial low].

split: open-access


prompt:
With te=1 and en=0 the gated clock stays low during scan shift.

Input [samples] of [clk, en, te]. The enable latch starts at 0 and is transparent while clk is 0 (q = en or te), holding while clk is 1. The gated clock is clk and q. Return [gated clock per sample, number of gated rising edges counting from an initial low].

split: open-access


prompt:
A gated pulse spanning several samples is counted several times.

Input [samples] of [clk, en, te]. The enable latch starts at 0 and is transparent while clk is 0 (q = en or te), holding while clk is 1. The gated clock is clk and q. Return [gated clock per sample, number of gated rising edges counting from an initial low].

split: open-access


prompt:
A clock high in the very first sample passes through before the latch has captured an enable.

Input [samples] of [clk, en, te]. The enable latch starts at 0 and is transparent while clk is 0 (q = en or te), holding while clk is 1. The gated clock is clk and q. Return [gated clock per sample, number of gated rising edges counting from an initial low].

split: open-access


prompt:
The full flag never asserts at the true full condition.

Input [depth, ops] with depth a power of two >= 4 and ops 'w','r','n'. Pointers are binary modulo 2*depth. Each step first computes flags from gray codes (g = b ^ (b >> 1)) using the other side's pointer as it was two steps earlier: full when gray(w) equals gray(r_sync) with its top two bits inverted, empty when gray(r) equals gray(w_sync). A write happens only if not full, a read only if not empty. Return [[full, empty] per step, [writes accepted, reads accepted]].

split: open-access


prompt:
The FIFO never reports full and overflows.

Input [depth, ops] with depth a power of two >= 4 and ops 'w','r','n'. Pointers are binary modulo 2*depth. Each step first computes flags from gray codes (g = b ^ (b >> 1)) using the other side's pointer as it was two steps earlier: full when gray(w) equals gray(r_sync) with its top two bits inverted, empty when gray(r) equals gray(w_sync). A write happens only if not full, a read only if not empty. Return [[full, empty] per step, [writes accepted, reads accepted]].

split: open-access


prompt:
Flags react one step early compared with a two-flop synchronizer.

Input [depth, ops] with depth a power of two >= 4 and ops 'w','r','n'. Pointers are binary modulo 2*depth. Each step first computes flags from gray codes (g = b ^ (b >> 1)) using the other side's pointer as it was two steps earlier: full when gray(w) equals gray(r_sync) with its top two bits inverted, empty when gray(r) equals gray(w_sync). A write happens only if not full, a read only if not empty. Return [[full, empty] per step, [writes accepted, reads accepted]].

split: open-access


prompt:
Writes past full advance the pointer and corrupt the flags.

Input [depth, ops] with depth a power of two >= 4 and ops 'w','r','n'. Pointers are binary modulo 2*depth. Each step first computes flags from gray codes (g = b ^ (b >> 1)) using the other side's pointer as it was two steps earlier: full when gray(w) equals gray(r_sync) with its top two bits inverted, empty when gray(r) equals gray(w_sync). A write happens only if not full, a read only if not empty. Return [[full, empty] per step, [writes accepted, reads accepted]].

split: open-access


prompt:
Full and empty become indistinguishable after one wrap.

Input [depth, ops] with depth a power of two >= 4 and ops 'w','r','n'. Pointers are binary modulo 2*depth. Each step first computes flags from gray codes (g = b ^ (b >> 1)) using the other side's pointer as it was two steps earlier: full when gray(w) equals gray(r_sync) with its top two bits inverted, empty when gray(r) equals gray(w_sync). A write happens only if not full, a read only if not empty. Return [[full, empty] per step, [writes accepted, reads accepted]].

split: open-access


prompt:
Subtraction with carry set comes out one too small and with carry clear one too large.

Input [a, c, ops] for an 8-bit accumulator with carry c; V starts 0. adc m: s = a+m+c, A = s & 0xFF, C = s > 0xFF, V = signed overflow of the 8-bit add. sbc m is adc of (m xor 0xFF) with the same carry (carry set means no borrow). cmp m: C = a >= m (unsigned), N/Z from (a-m) & 0xFF, A and V unchanged. After each op report [A, N, V, Z, C] where N is bit 7 and Z is result == 0.

split: open-access


prompt:
Adding a positive to a negative that changes the accumulator sign reports signed overflow.

Input [a, c, ops] for an 8-bit accumulator with carry c; V starts 0. adc m: s = a+m+c, A = s & 0xFF, C = s > 0xFF, V = signed overflow of the 8-bit add. sbc m is adc of (m xor 0xFF) with the same carry (carry set means no borrow). cmp m: C = a >= m (unsigned), N/Z from (a-m) & 0xFF, A and V unchanged. After each op report [A, N, V, Z, C] where N is bit 7 and Z is result == 0.

split: open-access


prompt:
An addition that lands exactly on 0xFF reports carry.

Input [a, c, ops] for an 8-bit accumulator with carry c; V starts 0. adc m: s = a+m+c, A = s & 0xFF, C = s > 0xFF, V = signed overflow of the 8-bit add. sbc m is adc of (m xor 0xFF) with the same carry (carry set means no borrow). cmp m: C = a >= m (unsigned), N/Z from (a-m) & 0xFF, A and V unchanged. After each op report [A, N, V, Z, C] where N is bit 7 and Z is result == 0.

split: open-access


prompt:
Comparing equal values clears carry, so a branch on carry set after CMP misses equal operands.

Input [a, c, ops] for an 8-bit accumulator with carry c; V starts 0. adc m: s = a+m+c, A = s & 0xFF, C = s > 0xFF, V = signed overflow of the 8-bit add. sbc m is adc of (m xor 0xFF) with the same carry (carry set means no borrow). cmp m: C = a >= m (unsigned), N/Z from (a-m) & 0xFF, A and V unchanged. After each op report [A, N, V, Z, C] where N is bit 7 and Z is result == 0.

split: open-access


prompt:
An addition that wraps to 0x00 with carry does not set Z.

Input [a, c, ops] for an 8-bit accumulator with carry c; V starts 0. adc m: s = a+m+c, A = s & 0xFF, C = s > 0xFF, V = signed overflow of the 8-bit add. sbc m is adc of (m xor 0xFF) with the same carry (carry set means no borrow). cmp m: C = a >= m (unsigned), N/Z from (a-m) & 0xFF, A and V unchanged. After each op report [A, N, V, Z, C] where N is bit 7 and Z is result == 0.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(*args):
    pc, disp, taken = args
    nxt = (pc + 2) & 0xFFFF
    if not taken:
        return [nxt, 2]
    off = disp - 256 if disp >= 128 else disp
    tgt = (pc + off) & 0xFFFF
    cyc = 3 + (1 if (tgt & 0xFF00) != (nxt & 0xFF00) else 0)
    return [tgt, cyc]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('forward branch same page', [4097, 16, True], [4115, 3]), ('backward branch', [4224, 239, True], [4209, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4337, 32, True], [4371, 4]), ('backward page crossing from next page start', [16638, 253, True], [16637, 4]), ('branch not taken', [20481, 64, False], [20483, 2]), ('wrap below zero', [2, 129, True], [65413, 4]), ('wrap above top', [65520, 126, True], [112, 4]), ('zero displacement taken', [24577, 0, True], [24579, 3])], [('forward branch same page', [4098, 16, True], [4116, 3]), ('backward branch', [4224, 238, True], [4208, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4338, 32, True], [4372, 4]), ('backward page crossing from next page start', [16638, 252, True], [16636, 4]), ('branch not taken', [20482, 64, False], [20484, 2]), ('wrap below zero', [2, 130, True], [65414, 4]), ('wrap above top', [65520, 125, True], [111, 4]), ('zero displacement taken', [24578, 0, True], [24580, 3])], [('forward branch same page', [4099, 16, True], [4117, 3]), ('backward branch', [4224, 237, True], [4207, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4339, 32, True], [4373, 4]), ('backward page crossing from next page start', [16638, 251, True], [16635, 4]), ('branch not taken', [20483, 64, False], [20485, 2]), ('wrap below zero', [2, 131, True], [65415, 4]), ('wrap above top', [65520, 124, True], [110, 4]), ('zero displacement taken', [24579, 0, True], [24581, 3])], [('forward branch same page', [4100, 16, True], [4118, 3]), ('backward branch', [4224, 236, True], [4206, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4340, 32, True], [4374, 4]), ('backward page crossing from next page start', [16638, 250, True], [16634, 4]), ('branch not taken', [20484, 64, False], [20486, 2]), ('wrap below zero', [2, 132, True], [65416, 4]), ('wrap above top', [65520, 123, True], [109, 4]), ('zero displacement taken', [24580, 0, True], [24582, 3])], [('forward branch same page', [4101, 16, True], [4119, 3]), ('backward branch', [4224, 235, True], [4205, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4341, 32, True], [4375, 4]), ('backward page crossing from next page start', [16638, 249, True], [16633, 4]), ('branch not taken', [20485, 64, False], [20487, 2]), ('wrap below zero', [2, 133, True], [65417, 4]), ('wrap above top', [65520, 122, True], [108, 4]), ('zero displacement taken', [24581, 0, True], [24583, 3])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(*args):
    pc, disp, taken = args
    nxt = (pc + 2) & 0xFFFF
    if not taken:
        return [nxt, 2]
    off = disp - 256 if disp >= 128 else disp
    tgt = (pc + 1 + off) & 0xFFFF
    cyc = 3 + (1 if (tgt & 0xFF00) != (nxt & 0xFF00) else 0)
    return [tgt, cyc]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('forward branch same page', [4097, 16, True], [4115, 3]), ('backward branch', [4224, 239, True], [4209, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4337, 32, True], [4371, 4]), ('backward page crossing from next page start', [16638, 253, True], [16637, 4]), ('branch not taken', [20481, 64, False], [20483, 2]), ('wrap below zero', [2, 129, True], [65413, 4]), ('wrap above top', [65520, 126, True], [112, 4]), ('zero displacement taken', [24577, 0, True], [24579, 3])], [('forward branch same page', [4098, 16, True], [4116, 3]), ('backward branch', [4224, 238, True], [4208, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4338, 32, True], [4372, 4]), ('backward page crossing from next page start', [16638, 252, True], [16636, 4]), ('branch not taken', [20482, 64, False], [20484, 2]), ('wrap below zero', [2, 130, True], [65414, 4]), ('wrap above top', [65520, 125, True], [111, 4]), ('zero displacement taken', [24578, 0, True], [24580, 3])], [('forward branch same page', [4099, 16, True], [4117, 3]), ('backward branch', [4224, 237, True], [4207, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4339, 32, True], [4373, 4]), ('backward page crossing from next page start', [16638, 251, True], [16635, 4]), ('branch not taken', [20483, 64, False], [20485, 2]), ('wrap below zero', [2, 131, True], [65415, 4]), ('wrap above top', [65520, 124, True], [110, 4]), ('zero displacement taken', [24579, 0, True], [24581, 3])], [('forward branch same page', [4100, 16, True], [4118, 3]), ('backward branch', [4224, 236, True], [4206, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4340, 32, True], [4374, 4]), ('backward page crossing from next page start', [16638, 250, True], [16634, 4]), ('branch not taken', [20484, 64, False], [20486, 2]), ('wrap below zero', [2, 132, True], [65416, 4]), ('wrap above top', [65520, 123, True], [109, 4]), ('zero displacement taken', [24580, 0, True], [24582, 3])], [('forward branch same page', [4101, 16, True], [4119, 3]), ('backward branch', [4224, 235, True], [4205, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4341, 32, True], [4375, 4]), ('backward page crossing from next page start', [16638, 249, True], [16633, 4]), ('branch not taken', [20485, 64, False], [20487, 2]), ('wrap below zero', [2, 133, True], [65417, 4]), ('wrap above top', [65520, 122, True], [108, 4]), ('zero displacement taken', [24581, 0, True], [24583, 3])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Every taken branch lands two bytes early.

Input [pc, disp, taken] for a 2-byte conditional branch at pc in a 16-bit address space. The next instruction is (pc+2) & 0xFFFF; disp is an 8-bit two's complement offset from that address. Not taken: [next, 2]. Taken: target = (next + offset) & 0xFFFF and cost 3 cycles plus 1 when target and next lie on different 256-byte pages. Return [pc', cycles].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(*args):
    pc, disp, taken = args
    nxt = (pc + 2) & 0xFFFF
    if not taken:
        return [nxt, 2]
    off = disp - 256 if disp > 128 else disp
    tgt = (nxt + off) & 0xFFFF
    cyc = 3 + (1 if (tgt & 0xFF00) != (nxt & 0xFF00) else 0)
    return [tgt, cyc]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('forward branch same page', [4097, 16, True], [4115, 3]), ('backward branch', [4224, 239, True], [4209, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4337, 32, True], [4371, 4]), ('backward page crossing from next page start', [16638, 253, True], [16637, 4]), ('branch not taken', [20481, 64, False], [20483, 2]), ('wrap below zero', [2, 129, True], [65413, 4]), ('wrap above top', [65520, 126, True], [112, 4]), ('zero displacement taken', [24577, 0, True], [24579, 3])], [('forward branch same page', [4098, 16, True], [4116, 3]), ('backward branch', [4224, 238, True], [4208, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4338, 32, True], [4372, 4]), ('backward page crossing from next page start', [16638, 252, True], [16636, 4]), ('branch not taken', [20482, 64, False], [20484, 2]), ('wrap below zero', [2, 130, True], [65414, 4]), ('wrap above top', [65520, 125, True], [111, 4]), ('zero displacement taken', [24578, 0, True], [24580, 3])], [('forward branch same page', [4099, 16, True], [4117, 3]), ('backward branch', [4224, 237, True], [4207, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4339, 32, True], [4373, 4]), ('backward page crossing from next page start', [16638, 251, True], [16635, 4]), ('branch not taken', [20483, 64, False], [20485, 2]), ('wrap below zero', [2, 131, True], [65415, 4]), ('wrap above top', [65520, 124, True], [110, 4]), ('zero displacement taken', [24579, 0, True], [24581, 3])], [('forward branch same page', [4100, 16, True], [4118, 3]), ('backward branch', [4224, 236, True], [4206, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4340, 32, True], [4374, 4]), ('backward page crossing from next page start', [16638, 250, True], [16634, 4]), ('branch not taken', [20484, 64, False], [20486, 2]), ('wrap below zero', [2, 132, True], [65416, 4]), ('wrap above top', [65520, 123, True], [109, 4]), ('zero displacement taken', [24580, 0, True], [24582, 3])], [('forward branch same page', [4101, 16, True], [4119, 3]), ('backward branch', [4224, 235, True], [4205, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4341, 32, True], [4375, 4]), ('backward page crossing from next page start', [16638, 249, True], [16633, 4]), ('branch not taken', [20485, 64, False], [20487, 2]), ('wrap below zero', [2, 133, True], [65417, 4]), ('wrap above top', [65520, 122, True], [108, 4]), ('zero displacement taken', [24581, 0, True], [24583, 3])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(*args):
    pc, disp, taken = args
    nxt = (pc + 2) & 0xFFFF
    if not taken:
        return [nxt, 2]
    off = disp if disp < 127 else disp - 256
    tgt = (nxt + off) & 0xFFFF
    cyc = 3 + (1 if (tgt & 0xFF00) != (nxt & 0xFF00) else 0)
    return [tgt, cyc]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('forward branch same page', [4097, 16, True], [4115, 3]), ('backward branch', [4224, 239, True], [4209, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4337, 32, True], [4371, 4]), ('backward page crossing from next page start', [16638, 253, True], [16637, 4]), ('branch not taken', [20481, 64, False], [20483, 2]), ('wrap below zero', [2, 129, True], [65413, 4]), ('wrap above top', [65520, 126, True], [112, 4]), ('zero displacement taken', [24577, 0, True], [24579, 3])], [('forward branch same page', [4098, 16, True], [4116, 3]), ('backward branch', [4224, 238, True], [4208, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4338, 32, True], [4372, 4]), ('backward page crossing from next page start', [16638, 252, True], [16636, 4]), ('branch not taken', [20482, 64, False], [20484, 2]), ('wrap below zero', [2, 130, True], [65414, 4]), ('wrap above top', [65520, 125, True], [111, 4]), ('zero displacement taken', [24578, 0, True], [24580, 3])], [('forward branch same page', [4099, 16, True], [4117, 3]), ('backward branch', [4224, 237, True], [4207, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4339, 32, True], [4373, 4]), ('backward page crossing from next page start', [16638, 251, True], [16635, 4]), ('branch not taken', [20483, 64, False], [20485, 2]), ('wrap below zero', [2, 131, True], [65415, 4]), ('wrap above top', [65520, 124, True], [110, 4]), ('zero displacement taken', [24579, 0, True], [24581, 3])], [('forward branch same page', [4100, 16, True], [4118, 3]), ('backward branch', [4224, 236, True], [4206, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4340, 32, True], [4374, 4]), ('backward page crossing from next page start', [16638, 250, True], [16634, 4]), ('branch not taken', [20484, 64, False], [20486, 2]), ('wrap below zero', [2, 132, True], [65416, 4]), ('wrap above top', [65520, 123, True], [109, 4]), ('zero displacement taken', [24580, 0, True], [24582, 3])], [('forward branch same page', [4101, 16, True], [4119, 3]), ('backward branch', [4224, 235, True], [4205, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4341, 32, True], [4375, 4]), ('backward page crossing from next page start', [16638, 249, True], [16633, 4]), ('branch not taken', [20485, 64, False], [20487, 2]), ('wrap below zero', [2, 133, True], [65417, 4]), ('wrap above top', [65520, 122, True], [108, 4]), ('zero displacement taken', [24581, 0, True], [24583, 3])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A branch with displacement 0x80 jumps forward 128 bytes instead of back 128.

Input [pc, disp, taken] for a 2-byte conditional branch at pc in a 16-bit address space. The next instruction is (pc+2) & 0xFFFF; disp is an 8-bit two's complement offset from that address. Not taken: [next, 2]. Taken: target = (next + offset) & 0xFFFF and cost 3 cycles plus 1 when target and next lie on different 256-byte pages. Return [pc', cycles].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(*args):
    pc, disp, taken = args
    nxt = (pc + 2) & 0xFFFF
    if not taken:
        return [nxt, 2]
    off = disp - 256 if disp >= 128 else disp
    tgt = nxt + off
    cyc = 3 + (1 if (tgt & 0xFF00) != (nxt & 0xFF00) else 0)
    return [tgt, cyc]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('forward branch same page', [4097, 16, True], [4115, 3]), ('backward branch', [4224, 239, True], [4209, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4337, 32, True], [4371, 4]), ('backward page crossing from next page start', [16638, 253, True], [16637, 4]), ('branch not taken', [20481, 64, False], [20483, 2]), ('wrap below zero', [2, 129, True], [65413, 4]), ('wrap above top', [65520, 126, True], [112, 4]), ('zero displacement taken', [24577, 0, True], [24579, 3])], [('forward branch same page', [4098, 16, True], [4116, 3]), ('backward branch', [4224, 238, True], [4208, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4338, 32, True], [4372, 4]), ('backward page crossing from next page start', [16638, 252, True], [16636, 4]), ('branch not taken', [20482, 64, False], [20484, 2]), ('wrap below zero', [2, 130, True], [65414, 4]), ('wrap above top', [65520, 125, True], [111, 4]), ('zero displacement taken', [24578, 0, True], [24580, 3])], [('forward branch same page', [4099, 16, True], [4117, 3]), ('backward branch', [4224, 237, True], [4207, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4339, 32, True], [4373, 4]), ('backward page crossing from next page start', [16638, 251, True], [16635, 4]), ('branch not taken', [20483, 64, False], [20485, 2]), ('wrap below zero', [2, 131, True], [65415, 4]), ('wrap above top', [65520, 124, True], [110, 4]), ('zero displacement taken', [24579, 0, True], [24581, 3])], [('forward branch same page', [4100, 16, True], [4118, 3]), ('backward branch', [4224, 236, True], [4206, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4340, 32, True], [4374, 4]), ('backward page crossing from next page start', [16638, 250, True], [16634, 4]), ('branch not taken', [20484, 64, False], [20486, 2]), ('wrap below zero', [2, 132, True], [65416, 4]), ('wrap above top', [65520, 123, True], [109, 4]), ('zero displacement taken', [24580, 0, True], [24582, 3])], [('forward branch same page', [4101, 16, True], [4119, 3]), ('backward branch', [4224, 235, True], [4205, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4341, 32, True], [4375, 4]), ('backward page crossing from next page start', [16638, 249, True], [16633, 4]), ('branch not taken', [20485, 64, False], [20487, 2]), ('wrap below zero', [2, 133, True], [65417, 4]), ('wrap above top', [65520, 122, True], [108, 4]), ('zero displacement taken', [24581, 0, True], [24583, 3])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(*args):
    pc, disp, taken = args
    nxt = (pc + 2) & 0xFFFF
    if not taken:
        return [nxt, 2]
    off = disp - 256 if disp >= 128 else disp
    tgt = min(max(nxt + off, 0), 0xFFFF)
    cyc = 3 + (1 if (tgt & 0xFF00) != (nxt & 0xFF00) else 0)
    return [tgt, cyc]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('forward branch same page', [4097, 16, True], [4115, 3]), ('backward branch', [4224, 239, True], [4209, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4337, 32, True], [4371, 4]), ('backward page crossing from next page start', [16638, 253, True], [16637, 4]), ('branch not taken', [20481, 64, False], [20483, 2]), ('wrap below zero', [2, 129, True], [65413, 4]), ('wrap above top', [65520, 126, True], [112, 4]), ('zero displacement taken', [24577, 0, True], [24579, 3])], [('forward branch same page', [4098, 16, True], [4116, 3]), ('backward branch', [4224, 238, True], [4208, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4338, 32, True], [4372, 4]), ('backward page crossing from next page start', [16638, 252, True], [16636, 4]), ('branch not taken', [20482, 64, False], [20484, 2]), ('wrap below zero', [2, 130, True], [65414, 4]), ('wrap above top', [65520, 125, True], [111, 4]), ('zero displacement taken', [24578, 0, True], [24580, 3])], [('forward branch same page', [4099, 16, True], [4117, 3]), ('backward branch', [4224, 237, True], [4207, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4339, 32, True], [4373, 4]), ('backward page crossing from next page start', [16638, 251, True], [16635, 4]), ('branch not taken', [20483, 64, False], [20485, 2]), ('wrap below zero', [2, 131, True], [65415, 4]), ('wrap above top', [65520, 124, True], [110, 4]), ('zero displacement taken', [24579, 0, True], [24581, 3])], [('forward branch same page', [4100, 16, True], [4118, 3]), ('backward branch', [4224, 236, True], [4206, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4340, 32, True], [4374, 4]), ('backward page crossing from next page start', [16638, 250, True], [16634, 4]), ('branch not taken', [20484, 64, False], [20486, 2]), ('wrap below zero', [2, 132, True], [65416, 4]), ('wrap above top', [65520, 123, True], [109, 4]), ('zero displacement taken', [24580, 0, True], [24582, 3])], [('forward branch same page', [4101, 16, True], [4119, 3]), ('backward branch', [4224, 235, True], [4205, 3]), ('most negative displacement', [8336, 128, True], [8210, 3]), ('largest positive displacement', [12288, 127, True], [12417, 3]), ('forward page crossing', [4341, 32, True], [4375, 4]), ('backward page crossing from next page start', [16638, 249, True], [16633, 4]), ('branch not taken', [20485, 64, False], [20487, 2]), ('wrap below zero', [2, 133, True], [65417, 4]), ('wrap above top', [65520, 122, True], [108, 4]), ('zero displacement taken', [24581, 0, True], [24583, 3])]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Branches near address 0 or 0xFFFF produce negative or 17-bit targets.

Input [pc, disp, taken] for a 2-byte conditional branch at pc in a 16-bit address space. The next instruction is (pc+2) & 0xFFFF; disp is an 8-bit two's complement offset from that address. Not taken: [next, 2]. Taken: target = (next + offset) & 0xFFFF and cost 3 cycles plus 1 when target and next lie on different 256-byte pages. Return [pc', cycles].

split: open-access