Procházet zdrojové kódy

test(resource): add 6400 architecture A/B harness

root před 3 měsíci
rodič
revize
0e1cfd803f

+ 25 - 0
tests/formal/resource_architecture_equivalence.sby

@@ -0,0 +1,25 @@
+[tasks]
+fsm
+pi
+crc
+
+[options]
+mode prove
+depth 8
+wait on
+timeout 120
+
+[engines]
+fsm: smtbmc boolector
+pi: smtbmc z3
+crc: smtbmc boolector
+
+[script]
+read -formal architecture_ab_candidates.v resource_architecture_equivalence_formal.v
+fsm: prep -top resource_fsm_equivalence_formal
+pi: prep -top resource_pi_equivalence_formal
+crc: prep -top resource_crc_equivalence_formal
+
+[files]
+../resource/architecture_ab_candidates.v
+resource_architecture_equivalence_formal.v

+ 90 - 0
tests/formal/resource_architecture_equivalence_formal.v

@@ -0,0 +1,90 @@
+`timescale 1ns/1ps
+
+module resource_fsm_equivalence_formal;
+    (* gclk *) reg clk;
+    reg rst_n;
+    reg past_valid;
+    initial begin rst_n = 0; past_valid = 0; end
+    always @(posedge clk) begin rst_n <= 1; past_valid <= 1; end
+
+    (* anyseq *) reg advance;
+    (* anyseq *) reg recover;
+    wire [2:0] binary_state;
+    wire [2:0] onehot_state;
+    wire [6:0] onehot_raw_state;
+    ab_fsm_binary u_fsm_binary(clk, rst_n, advance, recover, binary_state);
+    ab_fsm_onehot u_fsm_onehot(clk, rst_n, advance, recover, onehot_state, onehot_raw_state);
+
+    always @(posedge clk) begin
+        if (rst_n && past_valid) begin
+            assert(binary_state == onehot_state);
+            // Strengthen induction: the externally decoded state must retain
+            // the exact reachable one-hot representation.
+            assert(onehot_raw_state == (7'b0000001 << binary_state));
+        end
+    end
+endmodule
+
+module resource_pi_equivalence_formal;
+    (* gclk *) reg clk;
+    reg rst_n;
+    reg past_valid;
+    initial begin rst_n = 0; past_valid = 0; end
+    always @(posedge clk) begin rst_n <= 1; past_valid <= 1; end
+
+    (* anyseq *) reg pi_sample;
+    (* anyseq *) reg signed [15:0] pi_error;
+    wire signed [31:0] positional_control;
+    wire signed [31:0] incremental_control;
+    wire signed [31:0] positional_integral_state;
+    wire signed [15:0] incremental_previous_error_state;
+    ab_pi_positional u_pi_positional(
+        clk, rst_n, pi_sample, pi_error, positional_control, positional_integral_state);
+    ab_pi_incremental u_pi_incremental(
+        clk, rst_n, pi_sample, pi_error, incremental_control, incremental_previous_error_state);
+
+    wire signed [31:0] previous_error_ext =
+        {{16{incremental_previous_error_state[15]}}, incremental_previous_error_state};
+    wire signed [31:0] previous_p_term =
+        previous_error_ext + (previous_error_ext <<< 1);
+
+    always @(posedge clk) begin
+        if (rst_n && past_valid) begin
+            assert(positional_control == incremental_control);
+            // Positional PI keeps I explicitly; incremental PI folds P into
+            // control.  This relation is the inductive state correspondence.
+            assert(positional_control == positional_integral_state + previous_p_term);
+        end
+    end
+endmodule
+
+module resource_crc_equivalence_formal;
+    (* gclk *) reg clk;
+    reg rst_n;
+    reg past_valid;
+    initial begin rst_n = 0; past_valid = 0; end
+    always @(posedge clk) begin rst_n <= 1; past_valid <= 1; end
+
+    (* anyseq *) reg crc_clear;
+    (* anyseq *) reg crc_rx_valid;
+    (* anyseq *) reg [7:0] crc_rx_data;
+    (* anyseq *) reg crc_tx_valid;
+    (* anyseq *) reg [7:0] crc_tx_data;
+    wire [15:0] independent_rx_crc, independent_tx_crc;
+    wire [15:0] shared_rx_crc, shared_tx_crc;
+    ab_crc_independent u_crc_independent(
+        clk, rst_n, crc_clear, crc_rx_valid, crc_rx_data,
+        crc_tx_valid, crc_tx_data, independent_rx_crc, independent_tx_crc);
+    ab_crc_shared u_crc_shared(
+        clk, rst_n, crc_clear, crc_rx_valid, crc_rx_data,
+        crc_tx_valid, crc_tx_data, shared_rx_crc, shared_tx_crc);
+
+    always @(posedge clk) begin
+        if (rst_n && past_valid) begin
+            // Host request parsing and response transmission never overlap.
+            assume(!(crc_rx_valid && crc_tx_valid));
+            assert(independent_rx_crc == shared_rx_crc);
+            assert(independent_tx_crc == shared_tx_crc);
+        end
+    end
+endmodule

+ 347 - 0
tests/resource/architecture_ab_candidates.v

@@ -0,0 +1,347 @@
+`timescale 1ns/1ps
+
+// Isolated, synthesisable architecture candidates for the eight remaining
+// 6400 resource A/B decisions.  These modules are not part of a product source
+// closure.  They intentionally expose the same observable transaction for
+// each pair so simulation/formal checks can precede resource comparison.
+
+module ab_fsm_binary (
+    input wire clk, input wire rst_n, input wire advance, input wire recover,
+    output reg [2:0] state_code
+);
+    always @(posedge clk or negedge rst_n) begin
+        if (!rst_n) state_code <= 3'd0;
+        else if (recover) state_code <= 3'd0;
+        else if (advance) begin
+            case (state_code)
+                3'd0: state_code <= 3'd1;
+                3'd1: state_code <= 3'd2;
+                3'd2: state_code <= 3'd3;
+                3'd3: state_code <= 3'd4;
+                3'd4: state_code <= 3'd5;
+                3'd5: state_code <= 3'd6;
+                default: state_code <= 3'd0;
+            endcase
+        end
+    end
+endmodule
+
+module ab_fsm_onehot (
+    input wire clk, input wire rst_n, input wire advance, input wire recover,
+    output reg [2:0] state_code, output wire [6:0] raw_state
+);
+    (* fsm_encoding = "one-hot" *) reg [6:0] state;
+    assign raw_state = state;
+    always @* begin
+        case (state)
+            7'b0000001: state_code = 3'd0;
+            7'b0000010: state_code = 3'd1;
+            7'b0000100: state_code = 3'd2;
+            7'b0001000: state_code = 3'd3;
+            7'b0010000: state_code = 3'd4;
+            7'b0100000: state_code = 3'd5;
+            7'b1000000: state_code = 3'd6;
+            default: state_code = 3'd0;
+        endcase
+    end
+    always @(posedge clk or negedge rst_n) begin
+        if (!rst_n) state <= 7'b0000001;
+        else if (recover) state <= 7'b0000001;
+        else if (advance) begin
+            case (state)
+                7'b0000001: state <= 7'b0000010;
+                7'b0000010: state <= 7'b0000100;
+                7'b0000100: state <= 7'b0001000;
+                7'b0001000: state <= 7'b0010000;
+                7'b0010000: state <= 7'b0100000;
+                7'b0100000: state <= 7'b1000000;
+                default: state <= 7'b0000001;
+            endcase
+        end
+    end
+endmodule
+
+// Dedicated serializers preserve simultaneous Host response and BMC poll
+// progress.  The shared candidate is smaller but intentionally exposes its
+// single-owner limitation so the concurrency test can reject it on function.
+module ab_bmc_tx_dedicated (
+    input wire clk, input wire rst_n,
+    input wire host_start, input wire [7:0] host_data,
+    input wire bmc_start, input wire [7:0] bmc_data,
+    output wire host_bit, output wire bmc_bit,
+    output wire host_busy, output wire bmc_busy
+);
+    reg [7:0] host_shift;
+    reg [7:0] bmc_shift;
+    reg [3:0] host_left;
+    reg [3:0] bmc_left;
+    assign host_bit = host_left == 0 ? 1'b1 : host_shift[0];
+    assign bmc_bit = bmc_left == 0 ? 1'b1 : bmc_shift[0];
+    assign host_busy = host_left != 0;
+    assign bmc_busy = bmc_left != 0;
+    always @(posedge clk or negedge rst_n) begin
+        if (!rst_n) begin
+            host_shift <= 0; bmc_shift <= 0; host_left <= 0; bmc_left <= 0;
+        end else begin
+            if (host_start && host_left == 0) begin host_shift <= host_data; host_left <= 8; end
+            else if (host_left != 0) begin host_shift <= {1'b1, host_shift[7:1]}; host_left <= host_left - 1'b1; end
+            if (bmc_start && bmc_left == 0) begin bmc_shift <= bmc_data; bmc_left <= 8; end
+            else if (bmc_left != 0) begin bmc_shift <= {1'b1, bmc_shift[7:1]}; bmc_left <= bmc_left - 1'b1; end
+        end
+    end
+endmodule
+
+module ab_bmc_tx_shared (
+    input wire clk, input wire rst_n,
+    input wire host_start, input wire [7:0] host_data,
+    input wire bmc_start, input wire [7:0] bmc_data,
+    output wire host_bit, output wire bmc_bit,
+    output wire host_busy, output wire bmc_busy
+);
+    reg [7:0] shift;
+    reg [3:0] left;
+    reg owner_bmc;
+    assign host_bit = (left != 0 && !owner_bmc) ? shift[0] : 1'b1;
+    assign bmc_bit = (left != 0 && owner_bmc) ? shift[0] : 1'b1;
+    assign host_busy = left != 0 && !owner_bmc;
+    assign bmc_busy = left != 0 && owner_bmc;
+    always @(posedge clk or negedge rst_n) begin
+        if (!rst_n) begin shift <= 0; left <= 0; owner_bmc <= 0; end
+        else if (left != 0) begin shift <= {1'b1, shift[7:1]}; left <= left - 1'b1; end
+        else if (host_start) begin shift <= host_data; left <= 8; owner_bmc <= 0; end
+        else if (bmc_start) begin shift <= bmc_data; left <= 8; owner_bmc <= 1; end
+    end
+endmodule
+
+module ab_store_ff (
+    input wire clk, input wire wr_en, input wire [7:0] wr_addr, input wire [7:0] wr_data,
+    input wire [7:0] rd_addr, output reg [7:0] rd_data
+);
+    (* ram_style = "registers", syn_ramstyle = "registers" *) reg [7:0] mem [0:255];
+    always @(posedge clk) begin
+        if (wr_en) mem[wr_addr] <= wr_data;
+        rd_data <= mem[rd_addr];
+    end
+endmodule
+
+module ab_store_eram (
+    input wire clk, input wire wr_en, input wire [7:0] wr_addr, input wire [7:0] wr_data,
+    input wire [7:0] rd_addr, output reg [7:0] rd_data
+);
+    (* ram_style = "block", syn_ramstyle = "block_ram" *) reg [7:0] mem [0:255];
+    always @(posedge clk) begin
+        if (wr_en) mem[wr_addr] <= wr_data;
+        rd_data <= mem[rd_addr];
+    end
+endmodule
+
+module ab_pi_positional #(
+    parameter signed [15:0] KP = 16'sd3,
+    parameter signed [15:0] KI = 16'sd1
+) (
+    input wire clk, input wire rst_n, input wire sample,
+    input wire signed [15:0] error, output reg signed [31:0] control,
+    output wire signed [31:0] integral_state
+);
+    reg signed [31:0] integral;
+    assign integral_state = integral;
+    wire signed [31:0] p_term = KP * error;
+    wire signed [31:0] i_term = KI * error;
+    always @(posedge clk or negedge rst_n) begin
+        if (!rst_n) begin integral <= 0; control <= 0; end
+        else if (sample) begin
+            integral <= integral + i_term;
+            control <= p_term + integral + i_term;
+        end
+    end
+endmodule
+
+module ab_pi_incremental #(
+    parameter signed [15:0] KP = 16'sd3,
+    parameter signed [15:0] KI = 16'sd1
+) (
+    input wire clk, input wire rst_n, input wire sample,
+    input wire signed [15:0] error, output reg signed [31:0] control,
+    output wire signed [15:0] previous_error_state
+);
+    reg signed [15:0] previous_error;
+    assign previous_error_state = previous_error;
+    wire signed [16:0] delta_error = error - previous_error;
+    wire signed [32:0] p_delta = KP * delta_error;
+    wire signed [31:0] p_delta_narrow = p_delta[31:0];
+    wire signed [31:0] i_delta = KI * error;
+    always @(posedge clk or negedge rst_n) begin
+        if (!rst_n) begin previous_error <= 0; control <= 0; end
+        else if (sample) begin
+            control <= control + p_delta_narrow + i_delta;
+            previous_error <= error;
+        end
+    end
+endmodule
+
+module ab_safety_parallel #(
+    parameter [7:0] LIMIT = 8'd77
+) (
+    input wire clk, input wire rst_n,
+    input wire wr_en, input wire [4:0] wr_index, input wire [7:0] wr_temperature,
+    input wire start, output reg busy, output reg done, output reg [23:0] mask
+);
+    reg [7:0] temperatures [0:23];
+    integer i;
+    always @(posedge clk or negedge rst_n) begin
+        if (!rst_n) begin busy <= 0; done <= 0; mask <= 0; end
+        else begin
+            done <= 0;
+            if (wr_en) temperatures[wr_index] <= wr_temperature;
+            if (start) begin
+                busy <= 1;
+                for (i = 0; i < 24; i = i + 1) mask[i] <= temperatures[i] >= LIMIT;
+            end else if (busy) begin busy <= 0; done <= 1; end
+        end
+    end
+endmodule
+
+module ab_safety_sequential #(
+    parameter [7:0] LIMIT = 8'd77
+) (
+    input wire clk, input wire rst_n,
+    input wire wr_en, input wire [4:0] wr_index, input wire [7:0] wr_temperature,
+    input wire start, output reg busy, output reg done, output reg [23:0] mask
+);
+    reg [7:0] temperatures [0:23];
+    reg [4:0] index;
+    always @(posedge clk or negedge rst_n) begin
+        if (!rst_n) begin busy <= 0; done <= 0; mask <= 0; index <= 0; end
+        else begin
+            done <= 0;
+            if (wr_en) temperatures[wr_index] <= wr_temperature;
+            if (start && !busy) begin busy <= 1; index <= 0; end
+            else if (busy) begin
+                mask[index] <= temperatures[index] >= LIMIT;
+                if (index == 23) begin busy <= 0; done <= 1; end
+                else index <= index + 1'b1;
+            end
+        end
+    end
+endmodule
+
+module ab_commit_copy (
+    input wire clk, input wire rst_n,
+    input wire wr_en, input wire [4:0] wr_index, input wire [15:0] wr_data,
+    input wire commit, input wire [4:0] rd_index, output wire [15:0] rd_data
+);
+    reg [15:0] staging [0:23];
+    reg [15:0] active [0:23];
+    integer i;
+    assign rd_data = active[rd_index];
+    always @(posedge clk or negedge rst_n) begin
+        if (!rst_n) begin end
+        else begin
+            if (wr_en) staging[wr_index] <= wr_data;
+            if (commit) for (i = 0; i < 24; i = i + 1) active[i] <= staging[i];
+        end
+    end
+endmodule
+
+module ab_commit_bank (
+    input wire clk, input wire rst_n,
+    input wire wr_en, input wire [4:0] wr_index, input wire [15:0] wr_data,
+    input wire commit, input wire [4:0] rd_index, output wire [15:0] rd_data
+);
+    reg [15:0] bank0 [0:23];
+    reg [15:0] bank1 [0:23];
+    reg active_bank;
+    assign rd_data = active_bank ? bank1[rd_index] : bank0[rd_index];
+    always @(posedge clk or negedge rst_n) begin
+        if (!rst_n) active_bank <= 0;
+        else begin
+            if (wr_en) begin
+                if (active_bank) bank0[wr_index] <= wr_data;
+                else bank1[wr_index] <= wr_data;
+            end
+            if (commit) active_bank <= ~active_bank;
+        end
+    end
+endmodule
+
+module ab_crc_independent (
+    input wire clk, input wire rst_n, input wire clear,
+    input wire rx_valid, input wire [7:0] rx_data,
+    input wire tx_valid, input wire [7:0] tx_data,
+    output reg [15:0] rx_crc, output reg [15:0] tx_crc
+);
+    function [15:0] next_crc;
+        input [15:0] current; input [7:0] data;
+        integer i; reg [15:0] value;
+        begin
+            value = current ^ {data, 8'h00};
+            for (i = 0; i < 8; i = i + 1)
+                value = value[15] ? (value << 1) ^ 16'h1021 : value << 1;
+            next_crc = value;
+        end
+    endfunction
+    always @(posedge clk or negedge rst_n) begin
+        if (!rst_n) begin rx_crc <= 16'hffff; tx_crc <= 16'hffff; end
+        else if (clear) begin rx_crc <= 16'hffff; tx_crc <= 16'hffff; end
+        else begin
+            if (rx_valid) rx_crc <= next_crc(rx_crc, rx_data);
+            if (tx_valid) tx_crc <= next_crc(tx_crc, tx_data);
+        end
+    end
+endmodule
+
+module ab_crc_shared (
+    input wire clk, input wire rst_n, input wire clear,
+    input wire rx_valid, input wire [7:0] rx_data,
+    input wire tx_valid, input wire [7:0] tx_data,
+    output reg [15:0] rx_crc, output reg [15:0] tx_crc
+);
+    function [15:0] next_crc;
+        input [15:0] current; input [7:0] data;
+        integer i; reg [15:0] value;
+        begin
+            value = current ^ {data, 8'h00};
+            for (i = 0; i < 8; i = i + 1)
+                value = value[15] ? (value << 1) ^ 16'h1021 : value << 1;
+            next_crc = value;
+        end
+    endfunction
+    wire select_rx = rx_valid;
+    wire [15:0] selected_crc = select_rx ? rx_crc : tx_crc;
+    wire [7:0] selected_data = select_rx ? rx_data : tx_data;
+    wire [15:0] updated_crc = next_crc(selected_crc, selected_data);
+    always @(posedge clk or negedge rst_n) begin
+        if (!rst_n) begin rx_crc <= 16'hffff; tx_crc <= 16'hffff; end
+        else if (clear) begin rx_crc <= 16'hffff; tx_crc <= 16'hffff; end
+        else if (rx_valid) rx_crc <= updated_crc;
+        else if (tx_valid) tx_crc <= updated_crc;
+    end
+endmodule
+
+module ab_snapshot_copy (
+    input wire clk, input wire rst_n, input wire capture, input wire [7:0] seed,
+    input wire [7:0] rd_addr, output wire [7:0] rd_data
+);
+    reg [7:0] snapshot [0:192];
+    integer i;
+    assign rd_data = snapshot[rd_addr];
+    /* verilator lint_off BLKLOOPINIT */
+    always @(posedge clk or negedge rst_n) begin
+        if (!rst_n) begin end
+        else if (capture)
+            for (i = 0; i < 193; i = i + 1) snapshot[i] <= i[7:0] ^ seed;
+    end
+    /* verilator lint_on BLKLOOPINIT */
+endmodule
+
+module ab_snapshot_stream (
+    input wire clk, input wire rst_n, input wire capture, input wire [7:0] seed,
+    input wire [7:0] rd_addr, output wire [7:0] rd_data
+);
+    reg [7:0] locked_seed;
+    assign rd_data = rd_addr ^ locked_seed;
+    always @(posedge clk or negedge rst_n) begin
+        if (!rst_n) locked_seed <= 0;
+        else if (capture) locked_seed <= seed;
+    end
+endmodule

+ 189 - 0
tests/sim/resource_architecture_candidates_tb.v

@@ -0,0 +1,189 @@
+`timescale 1ns/1ps
+
+module resource_architecture_candidates_tb;
+    reg clk = 0;
+    always #5 clk = ~clk;
+    reg rst_n = 0;
+
+    reg advance = 0;
+    reg recover = 0;
+    wire [2:0] binary_state;
+    wire [2:0] onehot_state;
+    wire [6:0] onehot_raw_state;
+    ab_fsm_binary u_fsm_binary(clk, rst_n, advance, recover, binary_state);
+    ab_fsm_onehot u_fsm_onehot(clk, rst_n, advance, recover, onehot_state, onehot_raw_state);
+
+    reg host_start = 0;
+    reg [7:0] host_data = 0;
+    reg bmc_start = 0;
+    reg [7:0] bmc_data = 0;
+    wire dedicated_host_bit, dedicated_bmc_bit, dedicated_host_busy, dedicated_bmc_busy;
+    wire shared_host_bit, shared_bmc_bit, shared_host_busy, shared_bmc_busy;
+    ab_bmc_tx_dedicated u_tx_dedicated(
+        clk, rst_n, host_start, host_data, bmc_start, bmc_data,
+        dedicated_host_bit, dedicated_bmc_bit, dedicated_host_busy, dedicated_bmc_busy);
+    ab_bmc_tx_shared u_tx_shared(
+        clk, rst_n, host_start, host_data, bmc_start, bmc_data,
+        shared_host_bit, shared_bmc_bit, shared_host_busy, shared_bmc_busy);
+
+    reg store_wr_en = 0;
+    reg [7:0] store_wr_addr = 0;
+    reg [7:0] store_wr_data = 0;
+    reg [7:0] store_rd_addr = 0;
+    wire [7:0] store_ff_data;
+    wire [7:0] store_eram_data;
+    ab_store_ff u_store_ff(clk, store_wr_en, store_wr_addr, store_wr_data, store_rd_addr, store_ff_data);
+    ab_store_eram u_store_eram(clk, store_wr_en, store_wr_addr, store_wr_data, store_rd_addr, store_eram_data);
+
+    reg pi_sample = 0;
+    reg signed [15:0] pi_error = 0;
+    wire signed [31:0] positional_control;
+    wire signed [31:0] incremental_control;
+    wire signed [31:0] positional_integral_state;
+    wire signed [15:0] incremental_previous_error_state;
+    ab_pi_positional u_pi_positional(
+        clk, rst_n, pi_sample, pi_error, positional_control, positional_integral_state);
+    ab_pi_incremental u_pi_incremental(
+        clk, rst_n, pi_sample, pi_error, incremental_control, incremental_previous_error_state);
+
+    reg safety_wr_en = 0;
+    reg [4:0] safety_wr_index = 0;
+    reg [7:0] safety_temperature = 0;
+    reg safety_start = 0;
+    wire safety_parallel_busy, safety_parallel_done;
+    wire safety_sequential_busy, safety_sequential_done;
+    wire [23:0] safety_parallel_mask, safety_sequential_mask;
+    ab_safety_parallel u_safety_parallel(
+        clk, rst_n, safety_wr_en, safety_wr_index, safety_temperature,
+        safety_start, safety_parallel_busy, safety_parallel_done, safety_parallel_mask);
+    ab_safety_sequential u_safety_sequential(
+        clk, rst_n, safety_wr_en, safety_wr_index, safety_temperature,
+        safety_start, safety_sequential_busy, safety_sequential_done, safety_sequential_mask);
+
+    reg commit_wr_en = 0;
+    reg [4:0] commit_wr_index = 0;
+    reg [15:0] commit_wr_data = 0;
+    reg commit = 0;
+    reg [4:0] commit_rd_index = 0;
+    wire [15:0] copy_rd_data;
+    wire [15:0] bank_rd_data;
+    ab_commit_copy u_commit_copy(
+        clk, rst_n, commit_wr_en, commit_wr_index, commit_wr_data,
+        commit, commit_rd_index, copy_rd_data);
+    ab_commit_bank u_commit_bank(
+        clk, rst_n, commit_wr_en, commit_wr_index, commit_wr_data,
+        commit, commit_rd_index, bank_rd_data);
+
+    reg crc_clear = 0;
+    reg crc_rx_valid = 0;
+    reg [7:0] crc_rx_data = 0;
+    reg crc_tx_valid = 0;
+    reg [7:0] crc_tx_data = 0;
+    wire [15:0] independent_rx_crc, independent_tx_crc;
+    wire [15:0] shared_rx_crc, shared_tx_crc;
+    ab_crc_independent u_crc_independent(
+        clk, rst_n, crc_clear, crc_rx_valid, crc_rx_data,
+        crc_tx_valid, crc_tx_data, independent_rx_crc, independent_tx_crc);
+    ab_crc_shared u_crc_shared(
+        clk, rst_n, crc_clear, crc_rx_valid, crc_rx_data,
+        crc_tx_valid, crc_tx_data, shared_rx_crc, shared_tx_crc);
+
+    reg snapshot_capture = 0;
+    reg [7:0] snapshot_seed = 0;
+    reg [7:0] snapshot_rd_addr = 0;
+    wire [7:0] snapshot_copy_data;
+    wire [7:0] snapshot_stream_data;
+    ab_snapshot_copy u_snapshot_copy(
+        clk, rst_n, snapshot_capture, snapshot_seed, snapshot_rd_addr, snapshot_copy_data);
+    ab_snapshot_stream u_snapshot_stream(
+        clk, rst_n, snapshot_capture, snapshot_seed, snapshot_rd_addr, snapshot_stream_data);
+
+    integer i;
+    initial begin
+        repeat (3) @(posedge clk);
+        #1; rst_n = 1;
+        @(posedge clk); #1;
+
+        for (i = 0; i < 15; i = i + 1) begin
+            advance = 1;
+            @(posedge clk); #1;
+            if (binary_state !== onehot_state) $fatal(1, "FSM mismatch at %0d", i);
+        end
+        advance = 0; recover = 1; @(posedge clk); #1;
+        recover = 0;
+        if (binary_state !== 0 || onehot_state !== 0) $fatal(1, "FSM recovery mismatch");
+
+        host_data = 8'h96; bmc_data = 8'h3c;
+        host_start = 1; bmc_start = 1; @(posedge clk); #1;
+        host_start = 0; bmc_start = 0;
+        if (!(dedicated_host_busy && dedicated_bmc_busy))
+            $fatal(1, "dedicated TX did not preserve simultaneous progress");
+        if (shared_host_busy && shared_bmc_busy)
+            $fatal(1, "shared TX unexpectedly represented two owners");
+        repeat (9) @(posedge clk);
+        #1;
+
+        for (i = 0; i < 16; i = i + 1) begin
+            store_wr_en = 1; store_wr_addr = i[7:0]; store_wr_data = i[7:0] ^ 8'ha5;
+            @(posedge clk); #1;
+        end
+        store_wr_en = 0;
+        for (i = 0; i < 16; i = i + 1) begin
+            store_rd_addr = i[7:0]; @(posedge clk); #1;
+            if (store_ff_data !== (i[7:0] ^ 8'ha5) || store_eram_data !== store_ff_data)
+                $fatal(1, "storage mismatch at %0d ff=%h eram=%h expected=%h",
+                    i, store_ff_data, store_eram_data, i[7:0] ^ 8'ha5);
+        end
+
+        for (i = -12; i <= 12; i = i + 3) begin
+            pi_error = i; pi_sample = 1; @(posedge clk); #1;
+            if (positional_control !== incremental_control)
+                $fatal(1, "PI mismatch error=%0d positional=%0d incremental=%0d",
+                    i, positional_control, incremental_control);
+        end
+        pi_sample = 0;
+
+        for (i = 0; i < 24; i = i + 1) begin
+            safety_wr_en = 1; safety_wr_index = i[4:0];
+            safety_temperature = (i % 3 == 0) ? 8'd77 : (8'd60 + i[7:0]);
+            @(posedge clk); #1;
+        end
+        safety_wr_en = 0; safety_start = 1; @(posedge clk); #1; safety_start = 0;
+        wait (safety_sequential_done); #1;
+        if (safety_parallel_mask !== safety_sequential_mask)
+            $fatal(1, "safety mask mismatch parallel=%h sequential=%h",
+                safety_parallel_mask, safety_sequential_mask);
+
+        for (i = 0; i < 24; i = i + 1) begin
+            commit_wr_en = 1; commit_wr_index = i[4:0]; commit_wr_data = 16'h3100 + i;
+            @(posedge clk); #1;
+        end
+        commit_wr_en = 0; commit = 1; @(posedge clk); #1; commit = 0;
+        for (i = 0; i < 24; i = i + 1) begin
+            commit_rd_index = i[4:0]; #1;
+            if (copy_rd_data !== bank_rd_data || copy_rd_data !== (16'h3100 + i))
+                $fatal(1, "commit mismatch at %0d", i);
+        end
+
+        crc_clear = 1; @(posedge clk); #1; crc_clear = 0;
+        for (i = 0; i < 32; i = i + 1) begin
+            if (i[0]) begin crc_rx_valid = 1; crc_rx_data = i[7:0] ^ 8'h5a; end
+            else begin crc_tx_valid = 1; crc_tx_data = i[7:0] ^ 8'ha5; end
+            @(posedge clk); #1;
+            crc_rx_valid = 0; crc_tx_valid = 0;
+            if (independent_rx_crc !== shared_rx_crc || independent_tx_crc !== shared_tx_crc)
+                $fatal(1, "CRC mismatch at %0d", i);
+        end
+
+        snapshot_seed = 8'hc3; snapshot_capture = 1; @(posedge clk); #1;
+        snapshot_capture = 0;
+        for (i = 0; i < 193; i = i + 1) begin
+            snapshot_rd_addr = i[7:0]; #1;
+            if (snapshot_copy_data !== snapshot_stream_data)
+                $fatal(1, "snapshot mismatch at %0d", i);
+        end
+
+        $display("RESOURCE_ARCHITECTURE_AB_BEHAVIOR_PASS");
+        $finish;
+    end
+endmodule

+ 307 - 0
tools/run_6400_architecture_ab.py

@@ -0,0 +1,307 @@
+#!/usr/bin/env python3
+"""Run the eight non-UART 6400 architecture resource A/B trials."""
+
+from __future__ import annotations
+
+import argparse
+from datetime import datetime, timezone
+import hashlib
+import json
+import os
+from pathlib import Path
+import shutil
+import subprocess
+import sys
+import time
+
+
+ROOT = Path(__file__).resolve().parents[1]
+SOURCE = ROOT / "tests/resource/architecture_ab_candidates.v"
+TESTBENCH = ROOT / "tests/sim/resource_architecture_candidates_tb.v"
+FORMAL = ROOT / "tests/formal/resource_architecture_equivalence.sby"
+FORMAL_HARNESS = ROOT / "tests/formal/resource_architecture_equivalence_formal.v"
+
+TRIALS = {
+    "fsm_encoding": {
+        "label": "binary FSM vs one-hot FSM",
+        "candidates": ("ab_fsm_binary", "ab_fsm_onehot"),
+        "production": "ab_fsm_binary",
+        "formal": "resource_architecture_equivalence",
+    },
+    "bmc_tx_serializer": {
+        "label": "independent BMC TX vs shared TX",
+        "candidates": ("ab_bmc_tx_dedicated", "ab_bmc_tx_shared"),
+        "production": "ab_bmc_tx_dedicated",
+        "formal": "not_applicable_shared_candidate_fails_required_concurrency",
+    },
+    "array_storage": {
+        "label": "FF arrays vs inferred eRAM",
+        "candidates": ("ab_store_ff", "ab_store_eram"),
+        "production": "ab_store_eram",
+        "formal": "identical_RTL_semantics_attributes_only",
+    },
+    "pi_form": {
+        "label": "positional PI vs incremental PI",
+        "candidates": ("ab_pi_positional", "ab_pi_incremental"),
+        "production": "ab_pi_incremental",
+        "formal": "resource_architecture_equivalence",
+    },
+    "safety_compare": {
+        "label": "parallel safety compare vs sequential scan",
+        "candidates": ("ab_safety_parallel", "ab_safety_sequential"),
+        "production": "ab_safety_sequential",
+        "formal": "production_P02_P04_P05_plus_transaction_simulation",
+    },
+    "atomic_commit": {
+        "label": "element copy vs bank pointer",
+        "candidates": ("ab_commit_copy", "ab_commit_bank"),
+        "production": "ab_commit_bank",
+        "formal": "production_P08_P09_plus_transaction_simulation",
+    },
+    "crc_datapath": {
+        "label": "independent CRC vs RX/TX shared CRC",
+        "candidates": ("ab_crc_independent", "ab_crc_shared"),
+        "production": "ab_crc_independent",
+        "formal": "resource_architecture_equivalence_nonoverlap_assumption",
+    },
+    "snapshot_materialization": {
+        "label": "payload copy vs streaming snapshot",
+        "candidates": ("ab_snapshot_copy", "ab_snapshot_stream"),
+        "production": "ab_snapshot_stream",
+        "formal": "production_P14_plus_all_193_offsets_simulation",
+    },
+}
+
+TOOL_PROBES = {
+    "python3": [sys.executable, "--version"],
+    "iverilog": ["iverilog", "-V"],
+    "vvp": ["vvp", "-V"],
+    "verilator": ["verilator", "--version"],
+    "yosys": ["yosys", "-V"],
+    # This pinned SBY build has no version option; --help is its successful
+    # identity probe and the executable digest supplies exact identity.
+    "sby": ["sby", "--help"],
+    "boolector": ["boolector", "--version"],
+    "z3": ["z3", "--version"],
+}
+
+
+def sha256(path: Path) -> str:
+    return hashlib.sha256(path.read_bytes()).hexdigest()
+
+
+def probe_tool(name: str, command: list[str]) -> dict[str, object]:
+    executable = shutil.which(command[0])
+    if executable is None:
+        raise RuntimeError(f"missing required tool: {command[0]}")
+    resolved = Path(executable).resolve()
+    completed = subprocess.run(
+        command,
+        cwd=ROOT,
+        stdout=subprocess.PIPE,
+        stderr=subprocess.STDOUT,
+        text=True,
+        check=False,
+    )
+    return {
+        "name": name,
+        "command": command,
+        "exit_code": completed.returncode,
+        "executable": str(resolved),
+        "executable_sha256": sha256(resolved),
+        "output": completed.stdout.strip(),
+    }
+
+
+def git(*args: str) -> str:
+    return subprocess.check_output(["git", *args], cwd=ROOT, text=True).strip()
+
+
+def run(command: list[str], *, cwd: Path, log: Path) -> dict[str, object]:
+    started = time.monotonic()
+    with log.open("wb") as stream:
+        completed = subprocess.run(
+            command,
+            cwd=cwd,
+            stdout=stream,
+            stderr=subprocess.STDOUT,
+            check=False,
+        )
+    return {
+        "command": command,
+        "exit_code": completed.returncode,
+        "duration_seconds": round(time.monotonic() - started, 3),
+        "log": str(log),
+        "log_sha256": sha256(log),
+    }
+
+
+def extract_json(text: str) -> dict[str, object]:
+    start = text.find("{")
+    end = text.rfind("}")
+    if start < 0 or end < start:
+        raise RuntimeError("Yosys stat output did not contain JSON")
+    return json.loads(text[start : end + 1])
+
+
+def yosys_stats(top: str, run_root: Path) -> dict[str, object]:
+    log = run_root / f"yosys-{top}.log"
+    script = (
+        f"read_verilog -sv {SOURCE}; "
+        f"hierarchy -check -top {top}; proc; opt; memory; opt; "
+        f"techmap; opt; abc -lut 4; clean; stat -json"
+    )
+    record = run(["yosys", "-q", "-p", script], cwd=ROOT, log=log)
+    if record["exit_code"] != 0:
+        raise RuntimeError(f"Yosys failed for {top}: {log}")
+    payload = extract_json(log.read_text(encoding="utf-8", errors="replace"))
+    modules = payload.get("modules", {})
+    if not isinstance(modules, dict) or not modules:
+        raise RuntimeError(f"Yosys returned no module stats for {top}")
+    module = next(iter(modules.values()))
+    if not isinstance(module, dict):
+        raise RuntimeError(f"malformed Yosys module stats for {top}")
+    cells = module.get("num_cells_by_type", {})
+    if not isinstance(cells, dict):
+        cells = {}
+    lut4 = sum(int(value) for name, value in cells.items() if "LUT" in name.upper())
+    dff = sum(int(value) for name, value in cells.items() if "DFF" in name.upper())
+    return {
+        "top": top,
+        "num_cells": int(module.get("num_cells", 0)),
+        "lut4": lut4,
+        "dff": dff,
+        "memory_bits": int(module.get("num_memory_bits", 0)),
+        "cell_types": cells,
+        "yosys": record,
+    }
+
+
+def main(argv: list[str] | None = None) -> int:
+    parser = argparse.ArgumentParser()
+    parser.add_argument("--output", type=Path)
+    parser.add_argument("--run-root", type=Path)
+    args = parser.parse_args(argv)
+
+    for tool in ("iverilog", "vvp", "verilator", "yosys", "sby", "boolector", "z3"):
+        if shutil.which(tool) is None:
+            raise SystemExit(f"missing required tool: {tool}")
+    toolchain = {name: probe_tool(name, command) for name, command in TOOL_PROBES.items()}
+    failed_probes = [name for name, item in toolchain.items() if item["exit_code"] != 0]
+    if failed_probes:
+        raise SystemExit(f"tool identity probes failed: {', '.join(failed_probes)}")
+    dirty = git("status", "--porcelain")
+    if dirty:
+        raise SystemExit(f"resource A/B requires a clean worktree:\n{dirty}")
+    commit = git("rev-parse", "HEAD")
+    tree = git("rev-parse", "HEAD^{tree}")
+    stamp = datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%SZ")
+    run_id = f"6400-resource-ab-{stamp}-{commit[:8]}"
+    run_root = args.run_root or Path(os.environ.get("PROD2U_RESOURCE_AB_RUN_ROOT", "/data/prod2u/cpld-runs")) / run_id
+    run_root.mkdir(parents=True, exist_ok=False)
+
+    simulation = run_root / "resource-architecture.vvp"
+    compile_record = run(
+        [
+            "iverilog", "-g2012", "-Wall", "-s", "resource_architecture_candidates_tb",
+            "-o", str(simulation), str(SOURCE), str(TESTBENCH),
+        ],
+        cwd=ROOT,
+        log=run_root / "iverilog.log",
+    )
+    simulation_record = run(
+        ["vvp", str(simulation)], cwd=ROOT, log=run_root / "simulation.log"
+    ) if compile_record["exit_code"] == 0 else {"exit_code": 1, "reason": "compile_failed"}
+    simulation_text = (run_root / "simulation.log").read_text(encoding="utf-8", errors="replace") if (run_root / "simulation.log").is_file() else ""
+    behavior_pass = simulation_record["exit_code"] == 0 and "RESOURCE_ARCHITECTURE_AB_BEHAVIOR_PASS" in simulation_text
+
+    lint_record = run(
+        [
+            "verilator", "--lint-only", "--Wall", "-Wno-fatal", "-Wno-MULTITOP",
+            "-Wno-DECLFILENAME", "-Wno-UNUSEDSIGNAL", str(SOURCE),
+        ],
+        cwd=ROOT,
+        log=run_root / "verilator.log",
+    )
+    formal_root = run_root / "formal"
+    formal_record = run(
+        ["sby", "-f", "--prefix", str(formal_root), str(FORMAL)],
+        cwd=FORMAL.parent,
+        log=run_root / "formal.log",
+    )
+
+    candidates: dict[str, dict[str, object]] = {}
+    stats_failed = False
+    for trial in TRIALS.values():
+        for top in trial["candidates"]:
+            if top in candidates:
+                continue
+            try:
+                candidates[top] = yosys_stats(top, run_root)
+            except Exception as exc:
+                stats_failed = True
+                candidates[top] = {"top": top, "error": f"{type(exc).__name__}: {exc}"}
+
+    trials: dict[str, dict[str, object]] = {}
+    for name, trial in TRIALS.items():
+        first, second = trial["candidates"]
+        function = {
+            first: "PASS",
+            second: "FAIL_REQUIRED_CONCURRENCY" if name == "bmc_tx_serializer" else "PASS",
+        }
+        trials[name] = {
+            **trial,
+            "function": function,
+            "candidate_metrics": {first: candidates[first], second: candidates[second]},
+            "td_timing": "PENDING_L13_TD_RESOURCE_RUN",
+            "decision": (
+                "retain_dedicated_required_concurrency"
+                if name == "bmc_tx_serializer"
+                else "retain_current_pending_TD_confirmation"
+            ),
+        }
+
+    clean_after = not bool(git("status", "--porcelain"))
+    status = "PASS" if (
+        behavior_pass
+        and lint_record["exit_code"] == 0
+        and formal_record["exit_code"] == 0
+        and not stats_failed
+        and clean_after
+    ) else "FAIL"
+    receipt = {
+        "schema": "prod2u-6400-architecture-resource-ab-v1",
+        "run_id": run_id,
+        "generated_at": datetime.now(timezone.utc).isoformat(),
+        "status": status,
+        "commit": commit,
+        "tree": tree,
+        "clean_before": not bool(dirty),
+        "clean_after": clean_after,
+        "command": "python3 tools/run_6400_architecture_ab.py",
+        "inputs": {
+            str(path.relative_to(ROOT)): sha256(path)
+            for path in (SOURCE, TESTBENCH, FORMAL, FORMAL_HARNESS)
+        },
+        "behavior": {"status": "PASS" if behavior_pass else "FAIL", "compile": compile_record, "run": simulation_record},
+        "lint": lint_record,
+        "formal": formal_record,
+        "toolchain": toolchain,
+        "trials": trials,
+        "container_image_id": os.environ.get("PROD2U_CONTAINER_IMAGE_ID"),
+        "container_digest": os.environ.get("PROD2U_CONTAINER_DIGEST"),
+        "hardware": "NOT RUN",
+    }
+    output = (args.output or run_root / "architecture-ab-receipt.json").resolve()
+    repository = ROOT.resolve()
+    if output == repository or repository in output.parents:
+        raise SystemExit("resource A/B receipt must be written outside the source worktree")
+    output.parent.mkdir(parents=True, exist_ok=True)
+    output.write_text(json.dumps(receipt, indent=2, sort_keys=True) + "\n", encoding="utf-8")
+    print(output)
+    print(f"RESOURCE_ARCHITECTURE_AB_{status} trials={len(TRIALS)}")
+    return 0 if status == "PASS" else 1
+
+
+if __name__ == "__main__":
+    raise SystemExit(main())