resource_architecture_equivalence_formal.v 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. `timescale 1ns/1ps
  2. module resource_fsm_equivalence_formal;
  3. (* gclk *) reg clk;
  4. reg rst_n;
  5. reg past_valid;
  6. initial begin rst_n = 0; past_valid = 0; end
  7. always @(posedge clk) begin rst_n <= 1; past_valid <= 1; end
  8. (* anyseq *) reg advance;
  9. (* anyseq *) reg recover;
  10. wire [2:0] binary_state;
  11. wire [2:0] onehot_state;
  12. wire [6:0] onehot_raw_state;
  13. ab_fsm_binary u_fsm_binary(clk, rst_n, advance, recover, binary_state);
  14. ab_fsm_onehot u_fsm_onehot(clk, rst_n, advance, recover, onehot_state, onehot_raw_state);
  15. always @(posedge clk) begin
  16. if (rst_n && past_valid) begin
  17. assert(binary_state == onehot_state);
  18. // Strengthen induction: the externally decoded state must retain
  19. // the exact reachable one-hot representation.
  20. assert(onehot_raw_state == (7'b0000001 << binary_state));
  21. end
  22. end
  23. endmodule
  24. module resource_pi_equivalence_formal;
  25. (* gclk *) reg clk;
  26. reg rst_n;
  27. reg past_valid;
  28. initial begin rst_n = 0; past_valid = 0; end
  29. always @(posedge clk) begin rst_n <= 1; past_valid <= 1; end
  30. (* anyseq *) reg pi_sample;
  31. (* anyseq *) reg signed [15:0] pi_error;
  32. wire signed [31:0] positional_control;
  33. wire signed [31:0] incremental_control;
  34. wire signed [31:0] positional_integral_state;
  35. wire signed [15:0] incremental_previous_error_state;
  36. ab_pi_positional u_pi_positional(
  37. clk, rst_n, pi_sample, pi_error, positional_control, positional_integral_state);
  38. ab_pi_incremental u_pi_incremental(
  39. clk, rst_n, pi_sample, pi_error, incremental_control, incremental_previous_error_state);
  40. wire signed [31:0] previous_error_ext =
  41. {{16{incremental_previous_error_state[15]}}, incremental_previous_error_state};
  42. wire signed [31:0] previous_p_term =
  43. previous_error_ext + (previous_error_ext <<< 1);
  44. always @(posedge clk) begin
  45. if (rst_n && past_valid) begin
  46. assert(positional_control == incremental_control);
  47. // Positional PI keeps I explicitly; incremental PI folds P into
  48. // control. This relation is the inductive state correspondence.
  49. assert(positional_control == positional_integral_state + previous_p_term);
  50. end
  51. end
  52. endmodule
  53. module resource_crc_equivalence_formal;
  54. (* gclk *) reg clk;
  55. reg rst_n;
  56. reg past_valid;
  57. initial begin rst_n = 0; past_valid = 0; end
  58. always @(posedge clk) begin rst_n <= 1; past_valid <= 1; end
  59. (* anyseq *) reg crc_clear;
  60. (* anyseq *) reg crc_rx_valid;
  61. (* anyseq *) reg [7:0] crc_rx_data;
  62. (* anyseq *) reg crc_tx_valid;
  63. (* anyseq *) reg [7:0] crc_tx_data;
  64. wire [15:0] independent_rx_crc, independent_tx_crc;
  65. wire [15:0] shared_rx_crc, shared_tx_crc;
  66. ab_crc_independent u_crc_independent(
  67. clk, rst_n, crc_clear, crc_rx_valid, crc_rx_data,
  68. crc_tx_valid, crc_tx_data, independent_rx_crc, independent_tx_crc);
  69. ab_crc_shared u_crc_shared(
  70. clk, rst_n, crc_clear, crc_rx_valid, crc_rx_data,
  71. crc_tx_valid, crc_tx_data, shared_rx_crc, shared_tx_crc);
  72. always @(posedge clk) begin
  73. if (rst_n && past_valid) begin
  74. // Host request parsing and response transmission never overlap.
  75. assume(!(crc_rx_valid && crc_tx_valid));
  76. assert(independent_rx_crc == shared_rx_crc);
  77. assert(independent_tx_crc == shared_tx_crc);
  78. end
  79. end
  80. endmodule