data/full_repos/permissive/493847347/tests/lut_test.v
1: b'%Warning-STMTDLY: data/full_repos/permissive/493847347/tests/lut_test.v:16: Unsupported: Ignoring delay on this delayed statement.\n  always #10 clk = ~clk;\n         ^\n                  ... Use "/* verilator lint_off STMTDLY */" and lint_on around source to disable this message.\n%Warning-STMTDLY: data/full_repos/permissive/493847347/tests/lut_test.v:74: Unsupported: Ignoring delay on this delayed statement.\n    #10 reset = 1\'b1;\n    ^\n%Warning-STMTDLY: data/full_repos/permissive/493847347/tests/lut_test.v:75: Unsupported: Ignoring delay on this delayed statement.\n    #10;\n    ^\n%Warning-STMTDLY: data/full_repos/permissive/493847347/tests/lut_test.v:76: Unsupported: Ignoring delay on this delayed statement.\n    #10 reset = 1\'b0;\n    ^\n%Warning-STMTDLY: data/full_repos/permissive/493847347/tests/lut_test.v:77: Unsupported: Ignoring delay on this delayed statement.\n    #10;\n    ^\n%Warning-STMTDLY: data/full_repos/permissive/493847347/tests/lut_test.v:83: Unsupported: Ignoring delay on this delayed statement.\n      #10\n      ^\n%Warning-STMTDLY: data/full_repos/permissive/493847347/tests/lut_test.v:85: Unsupported: Ignoring delay on this delayed statement.\n      #10;\n      ^\n%Warning-STMTDLY: data/full_repos/permissive/493847347/tests/lut_test.v:119: Unsupported: Ignoring delay on this delayed statement.\n    #10 reset = 1\'b1;\n    ^\n%Warning-STMTDLY: data/full_repos/permissive/493847347/tests/lut_test.v:120: Unsupported: Ignoring delay on this delayed statement.\n    #10;\n    ^\n%Warning-STMTDLY: data/full_repos/permissive/493847347/tests/lut_test.v:121: Unsupported: Ignoring delay on this delayed statement.\n    #10 reset = 1\'b0;\n    ^\n%Warning-STMTDLY: data/full_repos/permissive/493847347/tests/lut_test.v:122: Unsupported: Ignoring delay on this delayed statement.\n    #10;\n    ^\n%Warning-STMTDLY: data/full_repos/permissive/493847347/tests/lut_test.v:134: Unsupported: Ignoring delay on this delayed statement.\n      #10\n      ^\n%Warning-STMTDLY: data/full_repos/permissive/493847347/tests/lut_test.v:136: Unsupported: Ignoring delay on this delayed statement.\n      #10;\n      ^\n%Warning-STMTDLY: data/full_repos/permissive/493847347/tests/lut_test.v:150: Unsupported: Ignoring delay on this delayed statement.\n      #1;\n      ^\n%Warning-STMTDLY: data/full_repos/permissive/493847347/tests/lut_test.v:220: Unsupported: Ignoring delay on this delayed statement.\n    #100;\n    ^\n%Error: data/full_repos/permissive/493847347/tests/lut_test.v:106: Can\'t find definition of \'lut\' in dotted scope/variable: \'dut.lut\'\n    if (mem != dut.lut.mem) begin\n                   ^~~\n        ... Known scopes under \'dut\': <no cells found>\n%Error: data/full_repos/permissive/493847347/tests/lut_test.v:107: Can\'t find definition of \'lut\' in dotted scope/variable: \'dut.lut\'\n      $display("FAIL: \\n\\tinput:\\t%b\\n\\tstored:\\t%b", mem, dut.lut.mem);\n                                                               ^~~\n        ... Known scopes under \'dut\': <no cells found>\n%Error: Exiting due to 2 error(s), 15 warning(s)\n        ... See the manual and https://verilator.org for more assistance.\n'
module LUTTest;
  localparam K = 5;
  localparam FRAME_SIZE = 1;

  localparam LUT_MEM_SIZE = 1 << K;
`ifdef FRACTURABLE
  localparam N = LUT_MEM_SIZE + FRAME_SIZE;
`else
  localparam N = LUT_MEM_SIZE;
`endif

  reg reset;
  reg clk = 0;
  always #`CLOCK_PERIOD clk = ~clk;

  reg sc_clk;
  reg [K-1:0] lut_select = {K{1'b0}};
  reg sc_en = 1'b1;
  reg sc_data;
  wire sc_data_out;

  wire lut_out;

`ifdef FRACTURABLE
  wire lut_out1;
`endif

  LUT#(
    .INPUTS(K),
    .FRAME_WIDTH(1)
  ) dut (
    .s(lut_select),
`ifdef FRACTURABLE
    .z(lut_out),
    .z1(lut_out1),
`else
    .z(lut_out),
`endif

    .config_clk(sc_clk),
    .config_en(sc_en),


    .config_in(sc_data),
    .config_out(sc_data_out),

    .reset(reset)
  );

  reg [N - 1:0] mem;

  integer i;
  initial
  begin

    for (i = 0; i < N; i = i + 1) begin
      mem[i] = $random % 2;
    end

    $display("%3d-LUT mem size: %4d", K, N);
`ifdef FRACTURABLE
    $display("fracturable, frame size: %3d", FRAME_SIZE);
`endif





    $display("*** TEST 1: LUT memory is loaded as expected ***");


    #`CLOCK_PERIOD reset = 1'b1;
    #`CLOCK_PERIOD;
    #`CLOCK_PERIOD reset = 1'b0;
    #`CLOCK_PERIOD;

    for (i = 0; i < N; i = i + 1) begin
      sc_clk = 1'b0;

      sc_data = mem[N - 1 - i];
      #`CLOCK_PERIOD
      sc_clk = 1'b1;
      #`CLOCK_PERIOD;
    end


  `ifdef FRACTURABLE



    if (mem[LUT_MEM_SIZE/2+FRAME_SIZE-1:FRAME_SIZE] != dut.lut0.mem) begin
      $display("FAIL: \n\tlut 0 input:\t%b\n\tlut 0 stored:\t%b", mem[(N-1)/2:1], dut.lut0.mem);
    end else begin
      $display("OK  : lut0 input == output");
    end

    if (mem[LUT_MEM_SIZE+FRAME_SIZE+1:LUT_MEM_SIZE/2+FRAME_SIZE] != dut.lut1.mem) begin
      $display("FAIL: \n\tlut 1 input:\t%b\n\tlut 1 stored:\t%b", mem[N-2:(N-1)/2+1], dut.lut1.mem);
    end else begin
      $display("OK  : lut1 input == output");
    end

  `else
    if (mem != dut.lut.mem) begin
      $display("FAIL: \n\tinput:\t%b\n\tstored:\t%b", mem, dut.lut.mem);
    end else begin
      $display("OK  : input == output");
    end
  `endif


   

    $display("*** TEST 2: LUT outputs match selection pins ***");


    #`CLOCK_PERIOD reset = 1'b1;
    #`CLOCK_PERIOD;
    #`CLOCK_PERIOD reset = 1'b0;
    #`CLOCK_PERIOD;

`ifdef FRACTURABLE


    mem[0] = 1'b0;
`endif

    for (i = 0; i < N; i = i + 1) begin
      sc_clk = 1'b0;

      sc_data = mem[N - 1 - i];
      #`CLOCK_PERIOD
      sc_clk = 1'b1;
      #`CLOCK_PERIOD;
    end

`ifdef FRACTURABLE

    if (dut.fractured !== 1'b0) begin
      $display("FAIL: fractured bit not set correctly, %b vs %b", dut.fractured, mem[0]);
    end else begin
      $display("OK  : fractured bit set correctly, %b vs %b", dut.fractured, mem[0]);
    end
`endif

    for (i = 0; i < LUT_MEM_SIZE; i = i + 1) begin
      lut_select = i;
      #1;

`ifdef FRACTURABLE
      if (lut_out !== mem[i+FRAME_SIZE]) begin
        $display("FAIL:  z iter %d: %d -> %b vs %b", i, lut_select, lut_out, mem[i+FRAME_SIZE]);
      end else begin
        $display("OK  :  z iter %d: %d -> %b vs %b", i, lut_select, lut_out, mem[i+FRAME_SIZE]);
      end

      if (lut_out1 !== 1'b0) begin
        $display("FAIL: z1 iter %d: %d -> %b vs %b", i, lut_select, lut_out1, 1'b0);
      end else begin
        $display("OK  : z1 iter %d: %d -> %b vs %b", i, lut_select, lut_out1, 1'b0);
      end
`else
      if (lut_out !== mem[i]) begin
        $display("FAIL:  z iter %d: %d -> %b vs %b", i, lut_select, lut_out, mem[i]);
      end else begin
        $display("OK  :  z iter %d: %d -> %b vs %b", i, lut_select, lut_out, mem[i]);
      end
`endif
    end

`ifdef FRACTURABLE

    $display("*** TEST 3: Behaviour when fractured ***");


    #`CLOCK_PERIOD reset = 1'b1;
    #`CLOCK_PERIOD;
    #`CLOCK_PERIOD reset = 1'b0;
    #`CLOCK_PERIOD;



    mem[0] = 1'b1;

    for (i = 0; i < N; i = i + 1) begin
      sc_clk = 1'b0;

      sc_data = mem[N - 1 - i];
      #`CLOCK_PERIOD
      sc_clk = 1'b1;
      #`CLOCK_PERIOD;
    end

    if (dut.fractured !== 1'b1) begin
      $display("FAIL: fractured bit not set correctly, %b vs %b", dut.fractured, mem[0]);
    end else begin
      $display("OK  : fractured bit set correctly, %b vs %b", dut.fractured, mem[0]);
    end

    for (i = 0; i < LUT_MEM_SIZE/2; i = i + 1) begin
      lut_select = i;
      #1;

      if (lut_out !== mem[i+FRAME_SIZE]) begin
        $display("FAIL:  z iter %d: %d -> %b vs %b", i, lut_select, lut_out, mem[i+FRAME_SIZE]);
      end else begin
        $display("OK  :  z iter %d: %d -> %b vs %b", i, lut_select, lut_out, mem[i+FRAME_SIZE]);
      end

      if (lut_out1 !== mem[LUT_MEM_SIZE/2 + i+FRAME_SIZE]) begin
        $display("FAIL:  z iter %d: %d -> %b vs %b", i, lut_select, lut_out1, mem[LUT_MEM_SIZE/2 + i+FRAME_SIZE]);
      end else begin
        $display("OK  : z1 iter %d: %d -> %b vs %b", i, lut_select, lut_out1, mem[LUT_MEM_SIZE/2 + i+FRAME_SIZE]);
      end
    end
`endif

    #100;
    $finish;

  end

endmodule
module LUTTest;

  localparam K = 5;
  localparam FRAME_SIZE = 1;

  localparam LUT_MEM_SIZE = 1 << K;
`ifdef FRACTURABLE
  localparam N = LUT_MEM_SIZE + FRAME_SIZE;
`else
  localparam N = LUT_MEM_SIZE;
`endif

  reg reset;
  reg clk = 0;
  always #`CLOCK_PERIOD clk = ~clk;

  reg sc_clk;
  reg [K-1:0] lut_select = {K{1'b0}};
  reg sc_en = 1'b1;
  reg sc_data;
  wire sc_data_out;

  wire lut_out;

`ifdef FRACTURABLE
  wire lut_out1;
`endif

  LUT#(
    .INPUTS(K),
    .FRAME_WIDTH(1)
  ) dut (
    .s(lut_select),
`ifdef FRACTURABLE
    .z(lut_out),
    .z1(lut_out1),
`else
    .z(lut_out),
`endif

    .config_clk(sc_clk),
    .config_en(sc_en),


    .config_in(sc_data),
    .config_out(sc_data_out),

    .reset(reset)
  );

  reg [N - 1:0] mem;

  integer i;
  initial
  begin

    for (i = 0; i < N; i = i + 1) begin
      mem[i] = $random % 2;
    end

    $display("%3d-LUT mem size: %4d", K, N);
`ifdef FRACTURABLE
    $display("fracturable, frame size: %3d", FRAME_SIZE);
`endif





    $display("*** TEST 1: LUT memory is loaded as expected ***");


    #`CLOCK_PERIOD reset = 1'b1;
    #`CLOCK_PERIOD;
    #`CLOCK_PERIOD reset = 1'b0;
    #`CLOCK_PERIOD;

    for (i = 0; i < N; i = i + 1) begin
      sc_clk = 1'b0;

      sc_data = mem[N - 1 - i];
      #`CLOCK_PERIOD
      sc_clk = 1'b1;
      #`CLOCK_PERIOD;
    end


  `ifdef FRACTURABLE



    if (mem[LUT_MEM_SIZE/2+FRAME_SIZE-1:FRAME_SIZE] != dut.lut0.mem) begin
      $display("FAIL: \n\tlut 0 input:\t%b\n\tlut 0 stored:\t%b", mem[(N-1)/2:1], dut.lut0.mem);
    end else begin
      $display("OK  : lut0 input == output");
    end

    if (mem[LUT_MEM_SIZE+FRAME_SIZE+1:LUT_MEM_SIZE/2+FRAME_SIZE] != dut.lut1.mem) begin
      $display("FAIL: \n\tlut 1 input:\t%b\n\tlut 1 stored:\t%b", mem[N-2:(N-1)/2+1], dut.lut1.mem);
    end else begin
      $display("OK  : lut1 input == output");
    end

  `else
    if (mem != dut.lut.mem) begin
      $display("FAIL: \n\tinput:\t%b\n\tstored:\t%b", mem, dut.lut.mem);
    end else begin
      $display("OK  : input == output");
    end
  `endif


   

    $display("*** TEST 2: LUT outputs match selection pins ***");


    #`CLOCK_PERIOD reset = 1'b1;
    #`CLOCK_PERIOD;
    #`CLOCK_PERIOD reset = 1'b0;
    #`CLOCK_PERIOD;

`ifdef FRACTURABLE


    mem[0] = 1'b0;
`endif

    for (i = 0; i < N; i = i + 1) begin
      sc_clk = 1'b0;

      sc_data = mem[N - 1 - i];
      #`CLOCK_PERIOD
      sc_clk = 1'b1;
      #`CLOCK_PERIOD;
    end

`ifdef FRACTURABLE

    if (dut.fractured !== 1'b0) begin
      $display("FAIL: fractured bit not set correctly, %b vs %b", dut.fractured, mem[0]);
    end else begin
      $display("OK  : fractured bit set correctly, %b vs %b", dut.fractured, mem[0]);
    end
`endif

    for (i = 0; i < LUT_MEM_SIZE; i = i + 1) begin
      lut_select = i;
      #1;

`ifdef FRACTURABLE
      if (lut_out !== mem[i+FRAME_SIZE]) begin
        $display("FAIL:  z iter %d: %d -> %b vs %b", i, lut_select, lut_out, mem[i+FRAME_SIZE]);
      end else begin
        $display("OK  :  z iter %d: %d -> %b vs %b", i, lut_select, lut_out, mem[i+FRAME_SIZE]);
      end

      if (lut_out1 !== 1'b0) begin
        $display("FAIL: z1 iter %d: %d -> %b vs %b", i, lut_select, lut_out1, 1'b0);
      end else begin
        $display("OK  : z1 iter %d: %d -> %b vs %b", i, lut_select, lut_out1, 1'b0);
      end
`else
      if (lut_out !== mem[i]) begin
        $display("FAIL:  z iter %d: %d -> %b vs %b", i, lut_select, lut_out, mem[i]);
      end else begin
        $display("OK  :  z iter %d: %d -> %b vs %b", i, lut_select, lut_out, mem[i]);
      end
`endif
    end

`ifdef FRACTURABLE

    $display("*** TEST 3: Behaviour when fractured ***");


    #`CLOCK_PERIOD reset = 1'b1;
    #`CLOCK_PERIOD;
    #`CLOCK_PERIOD reset = 1'b0;
    #`CLOCK_PERIOD;



    mem[0] = 1'b1;

    for (i = 0; i < N; i = i + 1) begin
      sc_clk = 1'b0;

      sc_data = mem[N - 1 - i];
      #`CLOCK_PERIOD
      sc_clk = 1'b1;
      #`CLOCK_PERIOD;
    end

    if (dut.fractured !== 1'b1) begin
      $display("FAIL: fractured bit not set correctly, %b vs %b", dut.fractured, mem[0]);
    end else begin
      $display("OK  : fractured bit set correctly, %b vs %b", dut.fractured, mem[0]);
    end

    for (i = 0; i < LUT_MEM_SIZE/2; i = i + 1) begin
      lut_select = i;
      #1;

      if (lut_out !== mem[i+FRAME_SIZE]) begin
        $display("FAIL:  z iter %d: %d -> %b vs %b", i, lut_select, lut_out, mem[i+FRAME_SIZE]);
      end else begin
        $display("OK  :  z iter %d: %d -> %b vs %b", i, lut_select, lut_out, mem[i+FRAME_SIZE]);
      end

      if (lut_out1 !== mem[LUT_MEM_SIZE/2 + i+FRAME_SIZE]) begin
        $display("FAIL:  z iter %d: %d -> %b vs %b", i, lut_select, lut_out1, mem[LUT_MEM_SIZE/2 + i+FRAME_SIZE]);
      end else begin
        $display("OK  : z1 iter %d: %d -> %b vs %b", i, lut_select, lut_out1, mem[LUT_MEM_SIZE/2 + i+FRAME_SIZE]);
      end
    end
`endif

    #100;
    $finish;

  end

endmodule