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) != (pc & 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 = (nxt + off) & 0xFFFF
    cyc = 3 + (1 if (nxt & 0xFF) + off > 0xFF 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 whose opcode sits at the end of a page is charged a crossing cycle incorrectly or misses one.

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 = 2 + (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)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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 if off else 2) + (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:
Taken branches cost one cycle too few.

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


prompt:
Pushed bytes land one slot below where pulls read them.

Input [pc, sp, ops] for an 8-bit stack pointer addressing page 0x100. push stores at 0x100+sp then decrements sp (wrapping in 8 bits); pull increments sp (wrapping) then reads (unwritten bytes read 0). jsr t (3 bytes at pc) pushes (pc+2) high byte then low byte and jumps; rts pulls low then high and resumes at that address + 1 (16-bit wrap). pha v pushes v, pla pulls; both and nop advance pc by 1. Return [[pc, sp, pulled value or None] per op, sorted [address, byte] of written stack memory].

split: open-access


prompt:
Returning from a subroutine skips the first byte of the following instruction.

Input [pc, sp, ops] for an 8-bit stack pointer addressing page 0x100. push stores at 0x100+sp then decrements sp (wrapping in 8 bits); pull increments sp (wrapping) then reads (unwritten bytes read 0). jsr t (3 bytes at pc) pushes (pc+2) high byte then low byte and jumps; rts pulls low then high and resumes at that address + 1 (16-bit wrap). pha v pushes v, pla pulls; both and nop advance pc by 1. Return [[pc, sp, pulled value or None] per op, sorted [address, byte] of written stack memory].

split: open-access


prompt:
Execution returns onto the last byte of the call instruction.

Input [pc, sp, ops] for an 8-bit stack pointer addressing page 0x100. push stores at 0x100+sp then decrements sp (wrapping in 8 bits); pull increments sp (wrapping) then reads (unwritten bytes read 0). jsr t (3 bytes at pc) pushes (pc+2) high byte then low byte and jumps; rts pulls low then high and resumes at that address + 1 (16-bit wrap). pha v pushes v, pla pulls; both and nop advance pc by 1. Return [[pc, sp, pulled value or None] per op, sorted [address, byte] of written stack memory].

split: open-access


prompt:
Pushing past the bottom of the stack page overwrites the same byte repeatedly.

Input [pc, sp, ops] for an 8-bit stack pointer addressing page 0x100. push stores at 0x100+sp then decrements sp (wrapping in 8 bits); pull increments sp (wrapping) then reads (unwritten bytes read 0). jsr t (3 bytes at pc) pushes (pc+2) high byte then low byte and jumps; rts pulls low then high and resumes at that address + 1 (16-bit wrap). pha v pushes v, pla pulls; both and nop advance pc by 1. Return [[pc, sp, pulled value or None] per op, sorted [address, byte] of written stack memory].

split: open-access


prompt:
Pulling with sp at 0xFF reads 0x200 and reports sp 0x100.

Input [pc, sp, ops] for an 8-bit stack pointer addressing page 0x100. push stores at 0x100+sp then decrements sp (wrapping in 8 bits); pull increments sp (wrapping) then reads (unwritten bytes read 0). jsr t (3 bytes at pc) pushes (pc+2) high byte then low byte and jumps; rts pulls low then high and resumes at that address + 1 (16-bit wrap). pha v pushes v, pla pulls; both and nop advance pc by 1. Return [[pc, sp, pulled value or None] per op, sorted [address, byte] of written stack memory].

split: open-access


prompt:
zp,X with a large index addresses page one instead of wrapping inside page zero.

Input [mode, operand, x, y, mem] with mem mapping decimal-string addresses to bytes (missing = 0). zp: operand & 0xFF. zpx: (operand + x) & 0xFF. abs: operand. absx: (operand + x) & 0xFFFF. absy: (operand + y) & 0xFFFF. ind: little-endian pointer at operand, where the high byte is fetched from the same page ((operand & 0xFF00) | ((operand + 1) & 0xFF)). indx: pointer at zero-page (operand + x) & 0xFF, high byte from the next zero-page byte (wrapping). indy: pointer at zero-page operand (high byte wrapping in zero page), plus y, wrapped to 16 bits.

split: open-access


prompt:
JMP (xxFF) fetches its high byte from the following page instead of wrapping within the page.

Input [mode, operand, x, y, mem] with mem mapping decimal-string addresses to bytes (missing = 0). zp: operand & 0xFF. zpx: (operand + x) & 0xFF. abs: operand. absx: (operand + x) & 0xFFFF. absy: (operand + y) & 0xFFFF. ind: little-endian pointer at operand, where the high byte is fetched from the same page ((operand & 0xFF00) | ((operand + 1) & 0xFF)). indx: pointer at zero-page (operand + x) & 0xFF, high byte from the next zero-page byte (wrapping). indy: pointer at zero-page operand (high byte wrapping in zero page), plus y, wrapped to 16 bits.

split: open-access


prompt:
(zp,X) with a pointer at 0xFF reads its high byte from 0x100.

Input [mode, operand, x, y, mem] with mem mapping decimal-string addresses to bytes (missing = 0). zp: operand & 0xFF. zpx: (operand + x) & 0xFF. abs: operand. absx: (operand + x) & 0xFFFF. absy: (operand + y) & 0xFFFF. ind: little-endian pointer at operand, where the high byte is fetched from the same page ((operand & 0xFF00) | ((operand + 1) & 0xFF)). indx: pointer at zero-page (operand + x) & 0xFF, high byte from the next zero-page byte (wrapping). indy: pointer at zero-page operand (high byte wrapping in zero page), plus y, wrapped to 16 bits.

split: open-access


prompt:
(zp),Y dereferences the wrong zero-page pointer.

Input [mode, operand, x, y, mem] with mem mapping decimal-string addresses to bytes (missing = 0). zp: operand & 0xFF. zpx: (operand + x) & 0xFF. abs: operand. absx: (operand + x) & 0xFFFF. absy: (operand + y) & 0xFFFF. ind: little-endian pointer at operand, where the high byte is fetched from the same page ((operand & 0xFF00) | ((operand + 1) & 0xFF)). indx: pointer at zero-page (operand + x) & 0xFF, high byte from the next zero-page byte (wrapping). indy: pointer at zero-page operand (high byte wrapping in zero page), plus y, wrapped to 16 bits.

split: open-access


prompt:
abs,Y accesses the address offset by X, so table lookups indexed by Y read the wrong element.

Input [mode, operand, x, y, mem] with mem mapping decimal-string addresses to bytes (missing = 0). zp: operand & 0xFF. zpx: (operand + x) & 0xFF. abs: operand. absx: (operand + x) & 0xFFFF. absy: (operand + y) & 0xFFFF. ind: little-endian pointer at operand, where the high byte is fetched from the same page ((operand & 0xFF00) | ((operand + 1) & 0xFF)). indx: pointer at zero-page (operand + x) & 0xFF, high byte from the next zero-page byte (wrapping). indy: pointer at zero-page operand (high byte wrapping in zero page), plus y, wrapped to 16 bits.

split: open-access


prompt:
addi with a negative immediate adds a large positive constant.

Input [word]: a 32-bit instruction. By opcode (low 7 bits): I-type 0x13/0x03/0x67 imm = sext(word[31:20]); S-type 0x23 imm = sext(word[31:25]:word[11:7]); B-type 0x63 imm = sext(word[31]:word[7]:word[30:25]:word[11:8]:0) (13 bits); U-type 0x37/0x17 imm = word & 0xFFFFF000 as signed 32-bit; J-type 0x6F imm = sext(word[31]:word[19:12]:word[20]:word[30:21]:0) (21 bits). Return [format, imm].

split: open-access


prompt:
Store addresses use the source register number as the low offset bits.

Input [word]: a 32-bit instruction. By opcode (low 7 bits): I-type 0x13/0x03/0x67 imm = sext(word[31:20]); S-type 0x23 imm = sext(word[31:25]:word[11:7]); B-type 0x63 imm = sext(word[31]:word[7]:word[30:25]:word[11:8]:0) (13 bits); U-type 0x37/0x17 imm = word & 0xFFFFF000 as signed 32-bit; J-type 0x6F imm = sext(word[31]:word[19:12]:word[20]:word[30:21]:0) (21 bits). Return [format, imm].

split: open-access


prompt:
Branches with only one of offset bits 11/12 set go to the wrong target and may flip direction.

Input [word]: a 32-bit instruction. By opcode (low 7 bits): I-type 0x13/0x03/0x67 imm = sext(word[31:20]); S-type 0x23 imm = sext(word[31:25]:word[11:7]); B-type 0x63 imm = sext(word[31]:word[7]:word[30:25]:word[11:8]:0) (13 bits); U-type 0x37/0x17 imm = word & 0xFFFFF000 as signed 32-bit; J-type 0x6F imm = sext(word[31]:word[19:12]:word[20]:word[30:21]:0) (21 bits). Return [format, imm].

split: open-access


prompt:
lui loads the 20-bit field without shifting it into the upper bits.

Input [word]: a 32-bit instruction. By opcode (low 7 bits): I-type 0x13/0x03/0x67 imm = sext(word[31:20]); S-type 0x23 imm = sext(word[31:25]:word[11:7]); B-type 0x63 imm = sext(word[31]:word[7]:word[30:25]:word[11:8]:0) (13 bits); U-type 0x37/0x17 imm = word & 0xFFFFF000 as signed 32-bit; J-type 0x6F imm = sext(word[31]:word[19:12]:word[20]:word[30:21]:0) (21 bits). Return [format, imm].

split: open-access


prompt:
jal targets are off by half of their low offset bits.

Input [word]: a 32-bit instruction. By opcode (low 7 bits): I-type 0x13/0x03/0x67 imm = sext(word[31:20]); S-type 0x23 imm = sext(word[31:25]:word[11:7]); B-type 0x63 imm = sext(word[31]:word[7]:word[30:25]:word[11:8]:0) (13 bits); U-type 0x37/0x17 imm = word & 0xFFFFF000 as signed 32-bit; J-type 0x6F imm = sext(word[31]:word[19:12]:word[20]:word[30:21]:0) (21 bits). Return [format, imm].

split: open-access


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

N = 1
observations = []
def solve(*args):
    op, a, b = args
    M = 0xFFFFFFFF
    def s(v):
        return v - (1 << 32) if v >> 31 else v
    if op == 'divu':
        return M if b == 0 else a // b
    if op == 'remu':
        return a if b == 0 else a % b
    sa, sb = s(a), s(b)
    if b == 0:
        return M if op == 'div' else a
    q = sa // sb
    if op == 'div':
        return q & M
    return (sa - q * sb) & M
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('signed division truncates toward zero', ['div', 4294967287, 2], 4294967292), ('signed division negative divisor', ['div', 9, 4294967294], 4294967292), ('signed remainder sign follows dividend', ['rem', 4294967287, 2], 4294967295), ('remainder with negative divisor', ['rem', 9, 4294967294], 1), ('signed divide by zero', ['div', 6, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967286, 0], 4294967286), ('unsigned divide by zero', ['divu', 4, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483649, 0], 2147483649), ('unsigned division of high values', ['divu', 4294967279, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967286, 4294967294], 5)], [('signed division truncates toward zero', ['div', 4294967285, 2], 4294967291), ('signed division negative divisor', ['div', 11, 4294967294], 4294967291), ('signed remainder sign follows dividend', ['rem', 4294967285, 2], 4294967295), ('remainder with negative divisor', ['rem', 11, 4294967294], 1), ('signed divide by zero', ['div', 7, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967285, 0], 4294967285), ('unsigned divide by zero', ['divu', 5, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483650, 0], 2147483650), ('unsigned division of high values', ['divu', 4294967278, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967285, 4294967294], 5)], [('signed division truncates toward zero', ['div', 4294967283, 2], 4294967290), ('signed division negative divisor', ['div', 13, 4294967294], 4294967290), ('signed remainder sign follows dividend', ['rem', 4294967283, 2], 4294967295), ('remainder with negative divisor', ['rem', 13, 4294967294], 1), ('signed divide by zero', ['div', 8, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967284, 0], 4294967284), ('unsigned divide by zero', ['divu', 6, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483651, 0], 2147483651), ('unsigned division of high values', ['divu', 4294967277, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967284, 4294967294], 6)], [('signed division truncates toward zero', ['div', 4294967281, 2], 4294967289), ('signed division negative divisor', ['div', 15, 4294967294], 4294967289), ('signed remainder sign follows dividend', ['rem', 4294967281, 2], 4294967295), ('remainder with negative divisor', ['rem', 15, 4294967294], 1), ('signed divide by zero', ['div', 9, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967283, 0], 4294967283), ('unsigned divide by zero', ['divu', 7, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483652, 0], 2147483652), ('unsigned division of high values', ['divu', 4294967276, 3], 1431655758), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967283, 4294967294], 6)], [('signed division truncates toward zero', ['div', 4294967279, 2], 4294967288), ('signed division negative divisor', ['div', 17, 4294967294], 4294967288), ('signed remainder sign follows dividend', ['rem', 4294967279, 2], 4294967295), ('remainder with negative divisor', ['rem', 17, 4294967294], 1), ('signed divide by zero', ['div', 10, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967282, 0], 4294967282), ('unsigned divide by zero', ['divu', 8, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483653, 0], 2147483653), ('unsigned division of high values', ['divu', 4294967275, 3], 1431655758), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967282, 4294967294], 7)]]
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):
    op, a, b = args
    M = 0xFFFFFFFF
    def s(v):
        return v - (1 << 32) if v >> 31 else v
    if op == 'divu':
        return M if b == 0 else a // b
    if op == 'remu':
        return a if b == 0 else a % b
    sa, sb = s(a), s(b)
    if b == 0:
        return M if op == 'div' else a
    q = -(-sa // sb) if sa < 0 else sa // sb
    if op == 'div':
        return q & M
    return (sa - q * sb) & M
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('signed division truncates toward zero', ['div', 4294967287, 2], 4294967292), ('signed division negative divisor', ['div', 9, 4294967294], 4294967292), ('signed remainder sign follows dividend', ['rem', 4294967287, 2], 4294967295), ('remainder with negative divisor', ['rem', 9, 4294967294], 1), ('signed divide by zero', ['div', 6, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967286, 0], 4294967286), ('unsigned divide by zero', ['divu', 4, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483649, 0], 2147483649), ('unsigned division of high values', ['divu', 4294967279, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967286, 4294967294], 5)], [('signed division truncates toward zero', ['div', 4294967285, 2], 4294967291), ('signed division negative divisor', ['div', 11, 4294967294], 4294967291), ('signed remainder sign follows dividend', ['rem', 4294967285, 2], 4294967295), ('remainder with negative divisor', ['rem', 11, 4294967294], 1), ('signed divide by zero', ['div', 7, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967285, 0], 4294967285), ('unsigned divide by zero', ['divu', 5, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483650, 0], 2147483650), ('unsigned division of high values', ['divu', 4294967278, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967285, 4294967294], 5)], [('signed division truncates toward zero', ['div', 4294967283, 2], 4294967290), ('signed division negative divisor', ['div', 13, 4294967294], 4294967290), ('signed remainder sign follows dividend', ['rem', 4294967283, 2], 4294967295), ('remainder with negative divisor', ['rem', 13, 4294967294], 1), ('signed divide by zero', ['div', 8, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967284, 0], 4294967284), ('unsigned divide by zero', ['divu', 6, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483651, 0], 2147483651), ('unsigned division of high values', ['divu', 4294967277, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967284, 4294967294], 6)], [('signed division truncates toward zero', ['div', 4294967281, 2], 4294967289), ('signed division negative divisor', ['div', 15, 4294967294], 4294967289), ('signed remainder sign follows dividend', ['rem', 4294967281, 2], 4294967295), ('remainder with negative divisor', ['rem', 15, 4294967294], 1), ('signed divide by zero', ['div', 9, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967283, 0], 4294967283), ('unsigned divide by zero', ['divu', 7, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483652, 0], 2147483652), ('unsigned division of high values', ['divu', 4294967276, 3], 1431655758), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967283, 4294967294], 6)], [('signed division truncates toward zero', ['div', 4294967279, 2], 4294967288), ('signed division negative divisor', ['div', 17, 4294967294], 4294967288), ('signed remainder sign follows dividend', ['rem', 4294967279, 2], 4294967295), ('remainder with negative divisor', ['rem', 17, 4294967294], 1), ('signed divide by zero', ['div', 10, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967282, 0], 4294967282), ('unsigned divide by zero', ['divu', 8, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483653, 0], 2147483653), ('unsigned division of high values', ['divu', 4294967275, 3], 1431655758), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967282, 4294967294], 7)]]
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:
div of a negative by a positive value returns a quotient one too small.

Input [op, a, b] with a, b as unsigned 32-bit register values. div/rem interpret them as signed; quotient truncates toward zero and the remainder takes the dividend's sign; division by zero gives quotient all ones (0xFFFFFFFF) and remainder = dividend; the overflow case -2^31 / -1 gives -2^31 with remainder 0. divu/remu are unsigned; divu by zero gives 0xFFFFFFFF and remu by zero gives the dividend. Results are returned as unsigned 32-bit values.

split: open-access


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

N = 1
observations = []
def solve(*args):
    op, a, b = args
    M = 0xFFFFFFFF
    def s(v):
        return v - (1 << 32) if v >> 31 else v
    if op == 'divu':
        return M if b == 0 else a // b
    if op == 'remu':
        return a if b == 0 else a % b
    sa, sb = s(a), s(b)
    if b == 0:
        return 0 if op == 'div' else a
    q = abs(sa) // abs(sb)
    if (sa < 0) != (sb < 0):
        q = -q
    if op == 'div':
        return q & M
    return (sa - q * sb) & M
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('signed division truncates toward zero', ['div', 4294967287, 2], 4294967292), ('signed division negative divisor', ['div', 9, 4294967294], 4294967292), ('signed remainder sign follows dividend', ['rem', 4294967287, 2], 4294967295), ('remainder with negative divisor', ['rem', 9, 4294967294], 1), ('signed divide by zero', ['div', 6, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967286, 0], 4294967286), ('unsigned divide by zero', ['divu', 4, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483649, 0], 2147483649), ('unsigned division of high values', ['divu', 4294967279, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967286, 4294967294], 5)], [('signed division truncates toward zero', ['div', 4294967285, 2], 4294967291), ('signed division negative divisor', ['div', 11, 4294967294], 4294967291), ('signed remainder sign follows dividend', ['rem', 4294967285, 2], 4294967295), ('remainder with negative divisor', ['rem', 11, 4294967294], 1), ('signed divide by zero', ['div', 7, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967285, 0], 4294967285), ('unsigned divide by zero', ['divu', 5, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483650, 0], 2147483650), ('unsigned division of high values', ['divu', 4294967278, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967285, 4294967294], 5)], [('signed division truncates toward zero', ['div', 4294967283, 2], 4294967290), ('signed division negative divisor', ['div', 13, 4294967294], 4294967290), ('signed remainder sign follows dividend', ['rem', 4294967283, 2], 4294967295), ('remainder with negative divisor', ['rem', 13, 4294967294], 1), ('signed divide by zero', ['div', 8, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967284, 0], 4294967284), ('unsigned divide by zero', ['divu', 6, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483651, 0], 2147483651), ('unsigned division of high values', ['divu', 4294967277, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967284, 4294967294], 6)], [('signed division truncates toward zero', ['div', 4294967281, 2], 4294967289), ('signed division negative divisor', ['div', 15, 4294967294], 4294967289), ('signed remainder sign follows dividend', ['rem', 4294967281, 2], 4294967295), ('remainder with negative divisor', ['rem', 15, 4294967294], 1), ('signed divide by zero', ['div', 9, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967283, 0], 4294967283), ('unsigned divide by zero', ['divu', 7, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483652, 0], 2147483652), ('unsigned division of high values', ['divu', 4294967276, 3], 1431655758), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967283, 4294967294], 6)], [('signed division truncates toward zero', ['div', 4294967279, 2], 4294967288), ('signed division negative divisor', ['div', 17, 4294967294], 4294967288), ('signed remainder sign follows dividend', ['rem', 4294967279, 2], 4294967295), ('remainder with negative divisor', ['rem', 17, 4294967294], 1), ('signed divide by zero', ['div', 10, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967282, 0], 4294967282), ('unsigned divide by zero', ['divu', 8, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483653, 0], 2147483653), ('unsigned division of high values', ['divu', 4294967275, 3], 1431655758), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967282, 4294967294], 7)]]
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):
    op, a, b = args
    M = 0xFFFFFFFF
    def s(v):
        return v - (1 << 32) if v >> 31 else v
    if op == 'divu':
        return M if b == 0 else a // b
    if op == 'remu':
        return a if b == 0 else a % b
    sa, sb = s(a), s(b)
    if b == 0:
        return M if op == 'div' else 0
    q = abs(sa) // abs(sb)
    if (sa < 0) != (sb < 0):
        q = -q
    if op == 'div':
        return q & M
    return (sa - q * sb) & M
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('signed division truncates toward zero', ['div', 4294967287, 2], 4294967292), ('signed division negative divisor', ['div', 9, 4294967294], 4294967292), ('signed remainder sign follows dividend', ['rem', 4294967287, 2], 4294967295), ('remainder with negative divisor', ['rem', 9, 4294967294], 1), ('signed divide by zero', ['div', 6, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967286, 0], 4294967286), ('unsigned divide by zero', ['divu', 4, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483649, 0], 2147483649), ('unsigned division of high values', ['divu', 4294967279, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967286, 4294967294], 5)], [('signed division truncates toward zero', ['div', 4294967285, 2], 4294967291), ('signed division negative divisor', ['div', 11, 4294967294], 4294967291), ('signed remainder sign follows dividend', ['rem', 4294967285, 2], 4294967295), ('remainder with negative divisor', ['rem', 11, 4294967294], 1), ('signed divide by zero', ['div', 7, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967285, 0], 4294967285), ('unsigned divide by zero', ['divu', 5, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483650, 0], 2147483650), ('unsigned division of high values', ['divu', 4294967278, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967285, 4294967294], 5)], [('signed division truncates toward zero', ['div', 4294967283, 2], 4294967290), ('signed division negative divisor', ['div', 13, 4294967294], 4294967290), ('signed remainder sign follows dividend', ['rem', 4294967283, 2], 4294967295), ('remainder with negative divisor', ['rem', 13, 4294967294], 1), ('signed divide by zero', ['div', 8, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967284, 0], 4294967284), ('unsigned divide by zero', ['divu', 6, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483651, 0], 2147483651), ('unsigned division of high values', ['divu', 4294967277, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967284, 4294967294], 6)], [('signed division truncates toward zero', ['div', 4294967281, 2], 4294967289), ('signed division negative divisor', ['div', 15, 4294967294], 4294967289), ('signed remainder sign follows dividend', ['rem', 4294967281, 2], 4294967295), ('remainder with negative divisor', ['rem', 15, 4294967294], 1), ('signed divide by zero', ['div', 9, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967283, 0], 4294967283), ('unsigned divide by zero', ['divu', 7, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483652, 0], 2147483652), ('unsigned division of high values', ['divu', 4294967276, 3], 1431655758), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967283, 4294967294], 6)], [('signed division truncates toward zero', ['div', 4294967279, 2], 4294967288), ('signed division negative divisor', ['div', 17, 4294967294], 4294967288), ('signed remainder sign follows dividend', ['rem', 4294967279, 2], 4294967295), ('remainder with negative divisor', ['rem', 17, 4294967294], 1), ('signed divide by zero', ['div', 10, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967282, 0], 4294967282), ('unsigned divide by zero', ['divu', 8, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483653, 0], 2147483653), ('unsigned division of high values', ['divu', 4294967275, 3], 1431655758), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967282, 4294967294], 7)]]
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:
div by zero returns 0 instead of all ones.

Input [op, a, b] with a, b as unsigned 32-bit register values. div/rem interpret them as signed; quotient truncates toward zero and the remainder takes the dividend's sign; division by zero gives quotient all ones (0xFFFFFFFF) and remainder = dividend; the overflow case -2^31 / -1 gives -2^31 with remainder 0. divu/remu are unsigned; divu by zero gives 0xFFFFFFFF and remu by zero gives the dividend. Results are returned as unsigned 32-bit values.

split: open-access


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

N = 1
observations = []
def solve(*args):
    op, a, b = args
    M = 0xFFFFFFFF
    def s(v):
        return v - (1 << 32) if v >> 31 else v
    if op == 'divu':
        return M if b == 0 else a // b
    if op == 'remu':
        return 0 if b == 0 else a % b
    sa, sb = s(a), s(b)
    if b == 0:
        return M if op == 'div' else a
    q = abs(sa) // abs(sb)
    if (sa < 0) != (sb < 0):
        q = -q
    if op == 'div':
        return q & M
    return (sa - q * sb) & M
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('signed division truncates toward zero', ['div', 4294967287, 2], 4294967292), ('signed division negative divisor', ['div', 9, 4294967294], 4294967292), ('signed remainder sign follows dividend', ['rem', 4294967287, 2], 4294967295), ('remainder with negative divisor', ['rem', 9, 4294967294], 1), ('signed divide by zero', ['div', 6, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967286, 0], 4294967286), ('unsigned divide by zero', ['divu', 4, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483649, 0], 2147483649), ('unsigned division of high values', ['divu', 4294967279, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967286, 4294967294], 5)], [('signed division truncates toward zero', ['div', 4294967285, 2], 4294967291), ('signed division negative divisor', ['div', 11, 4294967294], 4294967291), ('signed remainder sign follows dividend', ['rem', 4294967285, 2], 4294967295), ('remainder with negative divisor', ['rem', 11, 4294967294], 1), ('signed divide by zero', ['div', 7, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967285, 0], 4294967285), ('unsigned divide by zero', ['divu', 5, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483650, 0], 2147483650), ('unsigned division of high values', ['divu', 4294967278, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967285, 4294967294], 5)], [('signed division truncates toward zero', ['div', 4294967283, 2], 4294967290), ('signed division negative divisor', ['div', 13, 4294967294], 4294967290), ('signed remainder sign follows dividend', ['rem', 4294967283, 2], 4294967295), ('remainder with negative divisor', ['rem', 13, 4294967294], 1), ('signed divide by zero', ['div', 8, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967284, 0], 4294967284), ('unsigned divide by zero', ['divu', 6, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483651, 0], 2147483651), ('unsigned division of high values', ['divu', 4294967277, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967284, 4294967294], 6)], [('signed division truncates toward zero', ['div', 4294967281, 2], 4294967289), ('signed division negative divisor', ['div', 15, 4294967294], 4294967289), ('signed remainder sign follows dividend', ['rem', 4294967281, 2], 4294967295), ('remainder with negative divisor', ['rem', 15, 4294967294], 1), ('signed divide by zero', ['div', 9, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967283, 0], 4294967283), ('unsigned divide by zero', ['divu', 7, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483652, 0], 2147483652), ('unsigned division of high values', ['divu', 4294967276, 3], 1431655758), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967283, 4294967294], 6)], [('signed division truncates toward zero', ['div', 4294967279, 2], 4294967288), ('signed division negative divisor', ['div', 17, 4294967294], 4294967288), ('signed remainder sign follows dividend', ['rem', 4294967279, 2], 4294967295), ('remainder with negative divisor', ['rem', 17, 4294967294], 1), ('signed divide by zero', ['div', 10, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967282, 0], 4294967282), ('unsigned divide by zero', ['divu', 8, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483653, 0], 2147483653), ('unsigned division of high values', ['divu', 4294967275, 3], 1431655758), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967282, 4294967294], 7)]]
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):
    op, a, b = args
    M = 0xFFFFFFFF
    def s(v):
        return v - (1 << 32) if v >> 31 else v
    if op == 'divu':
        return M if b == 0 else a // b
    if op == 'remu':
        return M if b == 0 else a % b
    sa, sb = s(a), s(b)
    if b == 0:
        return M if op == 'div' else a
    q = abs(sa) // abs(sb)
    if (sa < 0) != (sb < 0):
        q = -q
    if op == 'div':
        return q & M
    return (sa - q * sb) & M
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('signed division truncates toward zero', ['div', 4294967287, 2], 4294967292), ('signed division negative divisor', ['div', 9, 4294967294], 4294967292), ('signed remainder sign follows dividend', ['rem', 4294967287, 2], 4294967295), ('remainder with negative divisor', ['rem', 9, 4294967294], 1), ('signed divide by zero', ['div', 6, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967286, 0], 4294967286), ('unsigned divide by zero', ['divu', 4, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483649, 0], 2147483649), ('unsigned division of high values', ['divu', 4294967279, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967286, 4294967294], 5)], [('signed division truncates toward zero', ['div', 4294967285, 2], 4294967291), ('signed division negative divisor', ['div', 11, 4294967294], 4294967291), ('signed remainder sign follows dividend', ['rem', 4294967285, 2], 4294967295), ('remainder with negative divisor', ['rem', 11, 4294967294], 1), ('signed divide by zero', ['div', 7, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967285, 0], 4294967285), ('unsigned divide by zero', ['divu', 5, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483650, 0], 2147483650), ('unsigned division of high values', ['divu', 4294967278, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967285, 4294967294], 5)], [('signed division truncates toward zero', ['div', 4294967283, 2], 4294967290), ('signed division negative divisor', ['div', 13, 4294967294], 4294967290), ('signed remainder sign follows dividend', ['rem', 4294967283, 2], 4294967295), ('remainder with negative divisor', ['rem', 13, 4294967294], 1), ('signed divide by zero', ['div', 8, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967284, 0], 4294967284), ('unsigned divide by zero', ['divu', 6, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483651, 0], 2147483651), ('unsigned division of high values', ['divu', 4294967277, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967284, 4294967294], 6)], [('signed division truncates toward zero', ['div', 4294967281, 2], 4294967289), ('signed division negative divisor', ['div', 15, 4294967294], 4294967289), ('signed remainder sign follows dividend', ['rem', 4294967281, 2], 4294967295), ('remainder with negative divisor', ['rem', 15, 4294967294], 1), ('signed divide by zero', ['div', 9, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967283, 0], 4294967283), ('unsigned divide by zero', ['divu', 7, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483652, 0], 2147483652), ('unsigned division of high values', ['divu', 4294967276, 3], 1431655758), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967283, 4294967294], 6)], [('signed division truncates toward zero', ['div', 4294967279, 2], 4294967288), ('signed division negative divisor', ['div', 17, 4294967294], 4294967288), ('signed remainder sign follows dividend', ['rem', 4294967279, 2], 4294967295), ('remainder with negative divisor', ['rem', 17, 4294967294], 1), ('signed divide by zero', ['div', 10, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967282, 0], 4294967282), ('unsigned divide by zero', ['divu', 8, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483653, 0], 2147483653), ('unsigned division of high values', ['divu', 4294967275, 3], 1431655758), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967282, 4294967294], 7)]]
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:
remu by zero returns 0 instead of the dividend.

Input [op, a, b] with a, b as unsigned 32-bit register values. div/rem interpret them as signed; quotient truncates toward zero and the remainder takes the dividend's sign; division by zero gives quotient all ones (0xFFFFFFFF) and remainder = dividend; the overflow case -2^31 / -1 gives -2^31 with remainder 0. divu/remu are unsigned; divu by zero gives 0xFFFFFFFF and remu by zero gives the dividend. Results are returned as unsigned 32-bit values.

split: open-access


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

N = 1
observations = []
def solve(*args):
    op, a, b = args
    M = 0xFFFFFFFF
    def s(v):
        return v - (1 << 32) if v >> 31 else v
    if op == 'divu':
        return M if b == 0 else a // b
    if op == 'remu':
        return a if b == 0 else a % b
    sa, sb = s(a), s(b)
    if b == 0:
        return M if op == 'div' else a
    q = abs(sa) // abs(sb)
    if (sa < 0) != (sb < 0):
        q = -q
    if op == 'div':
        return q & M
    return (sa % sb) & M
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('signed division truncates toward zero', ['div', 4294967287, 2], 4294967292), ('signed division negative divisor', ['div', 9, 4294967294], 4294967292), ('signed remainder sign follows dividend', ['rem', 4294967287, 2], 4294967295), ('remainder with negative divisor', ['rem', 9, 4294967294], 1), ('signed divide by zero', ['div', 6, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967286, 0], 4294967286), ('unsigned divide by zero', ['divu', 4, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483649, 0], 2147483649), ('unsigned division of high values', ['divu', 4294967279, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967286, 4294967294], 5)], [('signed division truncates toward zero', ['div', 4294967285, 2], 4294967291), ('signed division negative divisor', ['div', 11, 4294967294], 4294967291), ('signed remainder sign follows dividend', ['rem', 4294967285, 2], 4294967295), ('remainder with negative divisor', ['rem', 11, 4294967294], 1), ('signed divide by zero', ['div', 7, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967285, 0], 4294967285), ('unsigned divide by zero', ['divu', 5, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483650, 0], 2147483650), ('unsigned division of high values', ['divu', 4294967278, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967285, 4294967294], 5)], [('signed division truncates toward zero', ['div', 4294967283, 2], 4294967290), ('signed division negative divisor', ['div', 13, 4294967294], 4294967290), ('signed remainder sign follows dividend', ['rem', 4294967283, 2], 4294967295), ('remainder with negative divisor', ['rem', 13, 4294967294], 1), ('signed divide by zero', ['div', 8, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967284, 0], 4294967284), ('unsigned divide by zero', ['divu', 6, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483651, 0], 2147483651), ('unsigned division of high values', ['divu', 4294967277, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967284, 4294967294], 6)], [('signed division truncates toward zero', ['div', 4294967281, 2], 4294967289), ('signed division negative divisor', ['div', 15, 4294967294], 4294967289), ('signed remainder sign follows dividend', ['rem', 4294967281, 2], 4294967295), ('remainder with negative divisor', ['rem', 15, 4294967294], 1), ('signed divide by zero', ['div', 9, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967283, 0], 4294967283), ('unsigned divide by zero', ['divu', 7, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483652, 0], 2147483652), ('unsigned division of high values', ['divu', 4294967276, 3], 1431655758), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967283, 4294967294], 6)], [('signed division truncates toward zero', ['div', 4294967279, 2], 4294967288), ('signed division negative divisor', ['div', 17, 4294967294], 4294967288), ('signed remainder sign follows dividend', ['rem', 4294967279, 2], 4294967295), ('remainder with negative divisor', ['rem', 17, 4294967294], 1), ('signed divide by zero', ['div', 10, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967282, 0], 4294967282), ('unsigned divide by zero', ['divu', 8, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483653, 0], 2147483653), ('unsigned division of high values', ['divu', 4294967275, 3], 1431655758), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967282, 4294967294], 7)]]
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):
    op, a, b = args
    M = 0xFFFFFFFF
    def s(v):
        return v - (1 << 32) if v >> 31 else v
    if op == 'divu':
        return M if b == 0 else a // b
    if op == 'remu':
        return a if b == 0 else a % b
    sa, sb = s(a), s(b)
    if b == 0:
        return M if op == 'div' else a
    q = abs(sa) // abs(sb)
    if (sa < 0) != (sb < 0):
        q = -q
    if op == 'div':
        return q & M
    return (abs(sa) % abs(sb)) & M
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('signed division truncates toward zero', ['div', 4294967287, 2], 4294967292), ('signed division negative divisor', ['div', 9, 4294967294], 4294967292), ('signed remainder sign follows dividend', ['rem', 4294967287, 2], 4294967295), ('remainder with negative divisor', ['rem', 9, 4294967294], 1), ('signed divide by zero', ['div', 6, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967286, 0], 4294967286), ('unsigned divide by zero', ['divu', 4, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483649, 0], 2147483649), ('unsigned division of high values', ['divu', 4294967279, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967286, 4294967294], 5)], [('signed division truncates toward zero', ['div', 4294967285, 2], 4294967291), ('signed division negative divisor', ['div', 11, 4294967294], 4294967291), ('signed remainder sign follows dividend', ['rem', 4294967285, 2], 4294967295), ('remainder with negative divisor', ['rem', 11, 4294967294], 1), ('signed divide by zero', ['div', 7, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967285, 0], 4294967285), ('unsigned divide by zero', ['divu', 5, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483650, 0], 2147483650), ('unsigned division of high values', ['divu', 4294967278, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967285, 4294967294], 5)], [('signed division truncates toward zero', ['div', 4294967283, 2], 4294967290), ('signed division negative divisor', ['div', 13, 4294967294], 4294967290), ('signed remainder sign follows dividend', ['rem', 4294967283, 2], 4294967295), ('remainder with negative divisor', ['rem', 13, 4294967294], 1), ('signed divide by zero', ['div', 8, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967284, 0], 4294967284), ('unsigned divide by zero', ['divu', 6, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483651, 0], 2147483651), ('unsigned division of high values', ['divu', 4294967277, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967284, 4294967294], 6)], [('signed division truncates toward zero', ['div', 4294967281, 2], 4294967289), ('signed division negative divisor', ['div', 15, 4294967294], 4294967289), ('signed remainder sign follows dividend', ['rem', 4294967281, 2], 4294967295), ('remainder with negative divisor', ['rem', 15, 4294967294], 1), ('signed divide by zero', ['div', 9, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967283, 0], 4294967283), ('unsigned divide by zero', ['divu', 7, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483652, 0], 2147483652), ('unsigned division of high values', ['divu', 4294967276, 3], 1431655758), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967283, 4294967294], 6)], [('signed division truncates toward zero', ['div', 4294967279, 2], 4294967288), ('signed division negative divisor', ['div', 17, 4294967294], 4294967288), ('signed remainder sign follows dividend', ['rem', 4294967279, 2], 4294967295), ('remainder with negative divisor', ['rem', 17, 4294967294], 1), ('signed divide by zero', ['div', 10, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967282, 0], 4294967282), ('unsigned divide by zero', ['divu', 8, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483653, 0], 2147483653), ('unsigned division of high values', ['divu', 4294967275, 3], 1431655758), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967282, 4294967294], 7)]]
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:
rem of a negative dividend by a positive divisor returns a positive remainder.

Input [op, a, b] with a, b as unsigned 32-bit register values. div/rem interpret them as signed; quotient truncates toward zero and the remainder takes the dividend's sign; division by zero gives quotient all ones (0xFFFFFFFF) and remainder = dividend; the overflow case -2^31 / -1 gives -2^31 with remainder 0. divu/remu are unsigned; divu by zero gives 0xFFFFFFFF and remu by zero gives the dividend. Results are returned as unsigned 32-bit values.

split: open-access


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

N = 1
observations = []
def solve(*args):
    op, a, b = args
    M = 0xFFFFFFFF
    def s(v):
        return v - (1 << 32) if v >> 32 else v
    if op == 'divu':
        return M if b == 0 else a // b
    if op == 'remu':
        return a if b == 0 else a % b
    sa, sb = s(a), s(b)
    if b == 0:
        return M if op == 'div' else a
    q = abs(sa) // abs(sb)
    if (sa < 0) != (sb < 0):
        q = -q
    if op == 'div':
        return q & M
    return (sa - q * sb) & M
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('signed division truncates toward zero', ['div', 4294967287, 2], 4294967292), ('signed division negative divisor', ['div', 9, 4294967294], 4294967292), ('signed remainder sign follows dividend', ['rem', 4294967287, 2], 4294967295), ('remainder with negative divisor', ['rem', 9, 4294967294], 1), ('signed divide by zero', ['div', 6, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967286, 0], 4294967286), ('unsigned divide by zero', ['divu', 4, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483649, 0], 2147483649), ('unsigned division of high values', ['divu', 4294967279, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967286, 4294967294], 5)], [('signed division truncates toward zero', ['div', 4294967285, 2], 4294967291), ('signed division negative divisor', ['div', 11, 4294967294], 4294967291), ('signed remainder sign follows dividend', ['rem', 4294967285, 2], 4294967295), ('remainder with negative divisor', ['rem', 11, 4294967294], 1), ('signed divide by zero', ['div', 7, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967285, 0], 4294967285), ('unsigned divide by zero', ['divu', 5, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483650, 0], 2147483650), ('unsigned division of high values', ['divu', 4294967278, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967285, 4294967294], 5)], [('signed division truncates toward zero', ['div', 4294967283, 2], 4294967290), ('signed division negative divisor', ['div', 13, 4294967294], 4294967290), ('signed remainder sign follows dividend', ['rem', 4294967283, 2], 4294967295), ('remainder with negative divisor', ['rem', 13, 4294967294], 1), ('signed divide by zero', ['div', 8, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967284, 0], 4294967284), ('unsigned divide by zero', ['divu', 6, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483651, 0], 2147483651), ('unsigned division of high values', ['divu', 4294967277, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967284, 4294967294], 6)], [('signed division truncates toward zero', ['div', 4294967281, 2], 4294967289), ('signed division negative divisor', ['div', 15, 4294967294], 4294967289), ('signed remainder sign follows dividend', ['rem', 4294967281, 2], 4294967295), ('remainder with negative divisor', ['rem', 15, 4294967294], 1), ('signed divide by zero', ['div', 9, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967283, 0], 4294967283), ('unsigned divide by zero', ['divu', 7, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483652, 0], 2147483652), ('unsigned division of high values', ['divu', 4294967276, 3], 1431655758), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967283, 4294967294], 6)], [('signed division truncates toward zero', ['div', 4294967279, 2], 4294967288), ('signed division negative divisor', ['div', 17, 4294967294], 4294967288), ('signed remainder sign follows dividend', ['rem', 4294967279, 2], 4294967295), ('remainder with negative divisor', ['rem', 17, 4294967294], 1), ('signed divide by zero', ['div', 10, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967282, 0], 4294967282), ('unsigned divide by zero', ['divu', 8, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483653, 0], 2147483653), ('unsigned division of high values', ['divu', 4294967275, 3], 1431655758), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967282, 4294967294], 7)]]
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):
    op, a, b = args
    M = 0xFFFFFFFF
    def s(v):
        return v - (1 << 31) if v >> 31 else v
    if op == 'divu':
        return M if b == 0 else a // b
    if op == 'remu':
        return a if b == 0 else a % b
    sa, sb = s(a), s(b)
    if b == 0:
        return M if op == 'div' else a
    q = abs(sa) // abs(sb)
    if (sa < 0) != (sb < 0):
        q = -q
    if op == 'div':
        return q & M
    return (sa - q * sb) & M
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('signed division truncates toward zero', ['div', 4294967287, 2], 4294967292), ('signed division negative divisor', ['div', 9, 4294967294], 4294967292), ('signed remainder sign follows dividend', ['rem', 4294967287, 2], 4294967295), ('remainder with negative divisor', ['rem', 9, 4294967294], 1), ('signed divide by zero', ['div', 6, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967286, 0], 4294967286), ('unsigned divide by zero', ['divu', 4, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483649, 0], 2147483649), ('unsigned division of high values', ['divu', 4294967279, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967286, 4294967294], 5)], [('signed division truncates toward zero', ['div', 4294967285, 2], 4294967291), ('signed division negative divisor', ['div', 11, 4294967294], 4294967291), ('signed remainder sign follows dividend', ['rem', 4294967285, 2], 4294967295), ('remainder with negative divisor', ['rem', 11, 4294967294], 1), ('signed divide by zero', ['div', 7, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967285, 0], 4294967285), ('unsigned divide by zero', ['divu', 5, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483650, 0], 2147483650), ('unsigned division of high values', ['divu', 4294967278, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967285, 4294967294], 5)], [('signed division truncates toward zero', ['div', 4294967283, 2], 4294967290), ('signed division negative divisor', ['div', 13, 4294967294], 4294967290), ('signed remainder sign follows dividend', ['rem', 4294967283, 2], 4294967295), ('remainder with negative divisor', ['rem', 13, 4294967294], 1), ('signed divide by zero', ['div', 8, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967284, 0], 4294967284), ('unsigned divide by zero', ['divu', 6, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483651, 0], 2147483651), ('unsigned division of high values', ['divu', 4294967277, 3], 1431655759), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967284, 4294967294], 6)], [('signed division truncates toward zero', ['div', 4294967281, 2], 4294967289), ('signed division negative divisor', ['div', 15, 4294967294], 4294967289), ('signed remainder sign follows dividend', ['rem', 4294967281, 2], 4294967295), ('remainder with negative divisor', ['rem', 15, 4294967294], 1), ('signed divide by zero', ['div', 9, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967283, 0], 4294967283), ('unsigned divide by zero', ['divu', 7, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483652, 0], 2147483652), ('unsigned division of high values', ['divu', 4294967276, 3], 1431655758), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967283, 4294967294], 6)], [('signed division truncates toward zero', ['div', 4294967279, 2], 4294967288), ('signed division negative divisor', ['div', 17, 4294967294], 4294967288), ('signed remainder sign follows dividend', ['rem', 4294967279, 2], 4294967295), ('remainder with negative divisor', ['rem', 17, 4294967294], 1), ('signed divide by zero', ['div', 10, 0], 4294967295), ('signed remainder by zero', ['rem', 4294967282, 0], 4294967282), ('unsigned divide by zero', ['divu', 8, 0], 4294967295), ('unsigned remainder by zero', ['remu', 2147483653, 0], 2147483653), ('unsigned division of high values', ['divu', 4294967275, 3], 1431655758), ('signed overflow case', ['div', 2147483648, 4294967295], 2147483648), ('both negative', ['div', 4294967282, 4294967294], 7)]]
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:
div and rem treat negative register values as huge unsigned numbers.

Input [op, a, b] with a, b as unsigned 32-bit register values. div/rem interpret them as signed; quotient truncates toward zero and the remainder takes the dividend's sign; division by zero gives quotient all ones (0xFFFFFFFF) and remainder = dividend; the overflow case -2^31 / -1 gives -2^31 with remainder 0. divu/remu are unsigned; divu by zero gives 0xFFFFFFFF and remu by zero gives the dividend. Results are returned as unsigned 32-bit values.

split: open-access


prompt:
Multi-byte loads return byte-swapped values.

Input [mem, ops]: mem is a byte list; ops [op, addr, value] with lb/lbu/lh/lhu/lw loads and sb/sh/sw stores (sizes 1/2/4). An access whose address is not a multiple of its size yields 'misaligned' (checked first); one extending past memory yields 'fault'. Data is little-endian. lb/lh/lw sign-extend from their top bit, lbu/lhu zero-extend. Stores write the low size bytes of value and yield None. Return [results, final memory].

split: open-access


prompt:
lbu of a byte with bit 7 set returns a negative value.

Input [mem, ops]: mem is a byte list; ops [op, addr, value] with lb/lbu/lh/lhu/lw loads and sb/sh/sw stores (sizes 1/2/4). An access whose address is not a multiple of its size yields 'misaligned' (checked first); one extending past memory yields 'fault'. Data is little-endian. lb/lh/lw sign-extend from their top bit, lbu/lhu zero-extend. Stores write the low size bytes of value and yield None. Return [results, final memory].

split: open-access


prompt:
Halfword and word loads sign-extend based on their low byte.

Input [mem, ops]: mem is a byte list; ops [op, addr, value] with lb/lbu/lh/lhu/lw loads and sb/sh/sw stores (sizes 1/2/4). An access whose address is not a multiple of its size yields 'misaligned' (checked first); one extending past memory yields 'fault'. Data is little-endian. lb/lh/lw sign-extend from their top bit, lbu/lhu zero-extend. Stores write the low size bytes of value and yield None. Return [results, final memory].

split: open-access


prompt:
Byte and halfword accesses at legal unaligned addresses trap.

Input [mem, ops]: mem is a byte list; ops [op, addr, value] with lb/lbu/lh/lhu/lw loads and sb/sh/sw stores (sizes 1/2/4). An access whose address is not a multiple of its size yields 'misaligned' (checked first); one extending past memory yields 'fault'. Data is little-endian. lb/lh/lw sign-extend from their top bit, lbu/lhu zero-extend. Stores write the low size bytes of value and yield None. Return [results, final memory].

split: open-access


prompt:
sw and sh replicate the least significant byte across the whole access.

Input [mem, ops]: mem is a byte list; ops [op, addr, value] with lb/lbu/lh/lhu/lw loads and sb/sh/sw stores (sizes 1/2/4). An access whose address is not a multiple of its size yields 'misaligned' (checked first); one extending past memory yields 'fault'. Data is little-endian. lb/lh/lw sign-extend from their top bit, lbu/lhu zero-extend. Stores write the low size bytes of value and yield None. Return [results, final memory].

split: open-access


prompt:
hi is true after comparing equal values.

Input [cond]. Evaluate the condition for all 16 flag states, ordered as NZCV from 0000 to 1111 (N is the most significant), returning 1/0. eq Z; ne !Z; cs C; cc !C; mi N; pl !N; vs V; vc !V; hi C and !Z; ls !C or Z; ge N==V; lt N!=V; gt !Z and N==V; le Z or N!=V; al always. Carry here is set when an unsigned subtraction did not borrow.

split: open-access


prompt:
ls is false for strictly lower operands.

Input [cond]. Evaluate the condition for all 16 flag states, ordered as NZCV from 0000 to 1111 (N is the most significant), returning 1/0. eq Z; ne !Z; cs C; cc !C; mi N; pl !N; vs V; vc !V; hi C and !Z; ls !C or Z; ge N==V; lt N!=V; gt !Z and N==V; le Z or N!=V; al always. Carry here is set when an unsigned subtraction did not borrow.

split: open-access


prompt:
ge gives the wrong answer when the subtraction overflowed.

Input [cond]. Evaluate the condition for all 16 flag states, ordered as NZCV from 0000 to 1111 (N is the most significant), returning 1/0. eq Z; ne !Z; cs C; cc !C; mi N; pl !N; vs V; vc !V; hi C and !Z; ls !C or Z; ge N==V; lt N!=V; gt !Z and N==V; le Z or N!=V; al always. Carry here is set when an unsigned subtraction did not borrow.

split: open-access


prompt:
gt is true after comparing equal values.

Input [cond]. Evaluate the condition for all 16 flag states, ordered as NZCV from 0000 to 1111 (N is the most significant), returning 1/0. eq Z; ne !Z; cs C; cc !C; mi N; pl !N; vs V; vc !V; hi C and !Z; ls !C or Z; ge N==V; lt N!=V; gt !Z and N==V; le Z or N!=V; al always. Carry here is set when an unsigned subtraction did not borrow.

split: open-access


prompt:
le is false for strictly smaller signed values.

Input [cond]. Evaluate the condition for all 16 flag states, ordered as NZCV from 0000 to 1111 (N is the most significant), returning 1/0. eq Z; ne !Z; cs C; cc !C; mi N; pl !N; vs V; vc !V; hi C and !Z; ls !C or Z; ge N==V; lt N!=V; gt !Z and N==V; le Z or N!=V; al always. Carry here is set when an unsigned subtraction did not borrow.

split: open-access


prompt:
After writing x0, later instructions reading x0 see a nonzero value.

Input [prog]: [op, rd, a, b] with ops addi (x[a]+b), add, sub, lui (b<<12), slt (signed), sltu (unsigned), sltiu (x[a] < b sign-extended then taken unsigned), srai, srli, slli (shift amount b & 31). Registers x0..x31 start at 0 and hold unsigned 32-bit values; x0 always reads 0 and writes to it are discarded. Return sorted [index, value] of nonzero registers.

split: open-access


prompt:
Additions that overflow keep a 33rd bit and negative results stay negative.

Input [prog]: [op, rd, a, b] with ops addi (x[a]+b), add, sub, lui (b<<12), slt (signed), sltu (unsigned), sltiu (x[a] < b sign-extended then taken unsigned), srai, srli, slli (shift amount b & 31). Registers x0..x31 start at 0 and hold unsigned 32-bit values; x0 always reads 0 and writes to it are discarded. Return sorted [index, value] of nonzero registers.

split: open-access


prompt:
slt reports -1 as greater than 1.

Input [prog]: [op, rd, a, b] with ops addi (x[a]+b), add, sub, lui (b<<12), slt (signed), sltu (unsigned), sltiu (x[a] < b sign-extended then taken unsigned), srai, srli, slli (shift amount b & 31). Registers x0..x31 start at 0 and hold unsigned 32-bit values; x0 always reads 0 and writes to it are discarded. Return sorted [index, value] of nonzero registers.

split: open-access


prompt:
sltiu rd, rs, -1 is always false instead of true for every value except all ones.

Input [prog]: [op, rd, a, b] with ops addi (x[a]+b), add, sub, lui (b<<12), slt (signed), sltu (unsigned), sltiu (x[a] < b sign-extended then taken unsigned), srai, srli, slli (shift amount b & 31). Registers x0..x31 start at 0 and hold unsigned 32-bit values; x0 always reads 0 and writes to it are discarded. Return sorted [index, value] of nonzero registers.

split: open-access


prompt:
Arithmetic right shift of a negative value produces a large positive value.

Input [prog]: [op, rd, a, b] with ops addi (x[a]+b), add, sub, lui (b<<12), slt (signed), sltu (unsigned), sltiu (x[a] < b sign-extended then taken unsigned), srai, srli, slli (shift amount b & 31). Registers x0..x31 start at 0 and hold unsigned 32-bit values; x0 always reads 0 and writes to it are discarded. Return sorted [index, value] of nonzero registers.

split: open-access


prompt:
Shifting left by 32 or more clears the register instead of using the low five bits.

Input [prog]: [op, rd, a, b] with ops addi (x[a]+b), add, sub, lui (b<<12), slt (signed), sltu (unsigned), sltiu (x[a] < b sign-extended then taken unsigned), srai, srli, slli (shift amount b & 31). Registers x0..x31 start at 0 and hold unsigned 32-bit values; x0 always reads 0 and writes to it are discarded. Return sorted [index, value] of nonzero registers.

split: open-access


prompt:
Holding the NMI line high re-enters the NMI handler on every step.

Input [pc, i, steps] with steps [irq, nmi, instr]. Each step: an NMI 0->1 edge (the line starts low) is taken first; otherwise a high IRQ line is taken when the I flag is 0; otherwise the instruction runs (nop/cli/sei advance pc by 1, rti pops I then pc if the stack is non-empty). Taking an interrupt pushes pc then I, sets I=1 and jumps to 0x9000 (NMI) or 0x8000 (IRQ). The NMI edge detector samples the line every step. Return [event, pc, I] per step.

split: open-access


prompt:
An IRQ is taken while I is set.

Input [pc, i, steps] with steps [irq, nmi, instr]. Each step: an NMI 0->1 edge (the line starts low) is taken first; otherwise a high IRQ line is taken when the I flag is 0; otherwise the instruction runs (nop/cli/sei advance pc by 1, rti pops I then pc if the stack is non-empty). Taking an interrupt pushes pc then I, sets I=1 and jumps to 0x9000 (NMI) or 0x8000 (IRQ). The NMI edge detector samples the line every step. Return [event, pc, I] per step.

split: open-access


prompt:
A level IRQ that is still asserted re-enters its handler immediately.

Input [pc, i, steps] with steps [irq, nmi, instr]. Each step: an NMI 0->1 edge (the line starts low) is taken first; otherwise a high IRQ line is taken when the I flag is 0; otherwise the instruction runs (nop/cli/sei advance pc by 1, rti pops I then pc if the stack is non-empty). Taking an interrupt pushes pc then I, sets I=1 and jumps to 0x9000 (NMI) or 0x8000 (IRQ). The NMI edge detector samples the line every step. Return [event, pc, I] per step.

split: open-access


prompt:
rti restores the saved flag into pc and the saved pc into I.

Input [pc, i, steps] with steps [irq, nmi, instr]. Each step: an NMI 0->1 edge (the line starts low) is taken first; otherwise a high IRQ line is taken when the I flag is 0; otherwise the instruction runs (nop/cli/sei advance pc by 1, rti pops I then pc if the stack is non-empty). Taking an interrupt pushes pc then I, sets I=1 and jumps to 0x9000 (NMI) or 0x8000 (IRQ). The NMI edge detector samples the line every step. Return [event, pc, I] per step.

split: open-access


prompt:
A held NMI line is seen as a new edge on the step after entry.

Input [pc, i, steps] with steps [irq, nmi, instr]. Each step: an NMI 0->1 edge (the line starts low) is taken first; otherwise a high IRQ line is taken when the I flag is 0; otherwise the instruction runs (nop/cli/sei advance pc by 1, rti pops I then pc if the stack is non-empty). Taking an interrupt pushes pc then I, sets I=1 and jumps to 0x9000 (NMI) or 0x8000 (IRQ). The NMI edge detector samples the line every step. Return [event, pc, I] per step.

split: open-access


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

N = 1
observations = []
def solve(*args):
    code = args[0]
    def b(k):
        return code[k] if k < len(code) else 0
    i = 0
    lens = []
    while i < len(code):
        start = i
        osz = 4
        asz = 4
        while b(i) in (0x66, 0x67, 0xF0, 0xF2, 0xF3):
            if b(i) == 0x66: osz = 2
            if b(i) == 0x67: asz = 2
            i += 1
        op = b(i)
        i += 1
        if op == 0x0F:
            op = 0x0F00 | b(i)
            i += 1
        modrm = op in (0x01, 0x03, 0x89, 0x8B, 0x81, 0x83, 0x0FAF)
        imm = {0x81: osz, 0x83: 1, 0xE8: osz, 0xEB: 1, 0x0F84: osz}.get(op, osz if 0xB8 <= op <= 0xBF else 0)
        if modrm:
            m = b(i)
            i += 1
            mod, rm = m >> 6, m & 7
            if mod != 3:
                if asz == 2:
                    i += 2 if (mod == 0 and rm == 6) or mod == 2 else mod
                else:
                    if rm == 4:
                        base = b(i) & 7
                        i += 1
                        if False:
                            i += 4
                    i += 4 if (mod == 0 and rm == 5) or mod == 2 else mod
        i += imm
        lens.append(i - start)
    return lens
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144]], [1, 2, 3, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195]], [3, 4, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144]], [1, 2, 3, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195]], [3, 4, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 254]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195]], [3, 4, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195, 195]], [3, 4, 1, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 254]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195, 195, 195]], [3, 4, 1, 1, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])]]
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):
    code = args[0]
    def b(k):
        return code[k] if k < len(code) else 0
    i = 0
    lens = []
    while i < len(code):
        start = i
        osz = 4
        asz = 4
        while b(i) in (0x66, 0x67, 0xF0, 0xF2, 0xF3):
            if b(i) == 0x66: osz = 2
            if b(i) == 0x67: asz = 2
            i += 1
        op = b(i)
        i += 1
        if op == 0x0F:
            op = 0x0F00 | b(i)
            i += 1
        modrm = op in (0x01, 0x03, 0x89, 0x8B, 0x81, 0x83, 0x0FAF)
        imm = {0x81: osz, 0x83: 1, 0xE8: osz, 0xEB: 1, 0x0F84: osz}.get(op, osz if 0xB8 <= op <= 0xBF else 0)
        if modrm:
            m = b(i)
            i += 1
            mod, rm = m >> 6, m & 7
            if mod != 3:
                if asz == 2:
                    i += 2 if (mod == 0 and rm == 6) or mod == 2 else mod
                else:
                    if rm == 4:
                        base = b(i) & 7
                        i += 1
                        if base == 5:
                            i += 4
                    i += 4 if (mod == 0 and rm == 5) or mod == 2 else mod
        i += imm
        lens.append(i - start)
    return lens
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144]], [1, 2, 3, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195]], [3, 4, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144]], [1, 2, 3, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195]], [3, 4, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 254]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195]], [3, 4, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195, 195]], [3, 4, 1, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 254]], [6, 6, 2])], [('plain one-byte and modrm forms', [[144, 137, 195, 139, 69, 8, 195, 144, 144, 144, 144, 144]], [1, 2, 3, 1, 1, 1, 1, 1, 1]), ('sib with disp32 base', [[139, 4, 37, 1, 2, 3, 4, 139, 68, 36, 16, 139, 68, 37, 16, 144]], [7, 4, 4, 1]), ('operand size prefix on immediates', [[102, 184, 52, 18, 102, 129, 192, 1, 0, 184, 1, 2, 3, 4]], [4, 5, 5]), ('prefix after rep', [[243, 102, 184, 52, 18, 144, 144, 144, 144, 144, 240, 102, 129, 192, 16, 0]], [5, 1, 1, 1, 1, 1, 6]), ('sign-extended imm8 form', [[131, 192, 1, 131, 69, 8, 255, 195, 195, 195, 195, 195]], [3, 4, 1, 1, 1, 1, 1]), ('16-bit addressing', [[103, 139, 6, 52, 18, 103, 139, 71, 2, 103, 139, 135, 0, 16]], [5, 4, 5]), ('two-byte opcodes', [[15, 132, 1, 0, 0, 0, 15, 175, 193, 144]], [6, 3, 1]), ('rip-less disp32 and disp32 mod 2', [[139, 5, 0, 0, 1, 0, 139, 128, 0, 1, 0, 0, 235, 255]], [6, 6, 2])]]
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 SIB-addressed instruction with no base register is decoded four bytes short.

Input [code]: a byte list decoded as a toy x86-like ISA. Prefixes 0x66 (operand size 16), 0x67 (address size 16), 0xF0/0xF2/0xF3 in any order. 0x0F escapes to a two-byte opcode. ModRM follows 01/03/89/8B/81/83/0F AF. Immediates: 81, B8-BF, E8, 0F 84 take the operand size (2 or 4 bytes); 83 and EB take 1. 32-bit ModRM: mod 3 none; rm 4 adds a SIB byte and a SIB base of 5 with mod 0 adds disp32; mod 0 rm 5 adds disp32; mod 1 disp8; mod 2 disp32. 16-bit ModRM: mod 0 rm 6 or mod 2 add disp16, mod 1 disp8, no SIB. Return the length of each instruction.

split: open-access