data/full_repos/permissive/509468557/generators/ibex/src/main/resources/vsrc/ibex/vendor/lowrisc_ip/ip/prim/rtl/prim_keccak.sv
1: b'%Error: data/full_repos/permissive/509468557/generators/ibex/src/main/resources/vsrc/ibex/vendor/lowrisc_ip/ip/prim/rtl/prim_keccak.sv:6: Cannot find include file: prim_assert.sv\n`include "prim_assert.sv" \n         ^~~~~~~~~~~~~~~~\n        ... Looked in:\n             data/full_repos/permissive/509468557/generators/ibex/src/main/resources/vsrc/ibex/vendor/lowrisc_ip/ip/prim/rtl,data/full_repos/permissive/509468557/prim_assert.sv\n             data/full_repos/permissive/509468557/generators/ibex/src/main/resources/vsrc/ibex/vendor/lowrisc_ip/ip/prim/rtl,data/full_repos/permissive/509468557/prim_assert.sv.v\n             data/full_repos/permissive/509468557/generators/ibex/src/main/resources/vsrc/ibex/vendor/lowrisc_ip/ip/prim/rtl,data/full_repos/permissive/509468557/prim_assert.sv.sv\n             prim_assert.sv\n             prim_assert.sv.v\n             prim_assert.sv.sv\n             obj_dir/prim_assert.sv\n             obj_dir/prim_assert.sv.v\n             obj_dir/prim_assert.sv.sv\n%Error: data/full_repos/permissive/509468557/generators/ibex/src/main/resources/vsrc/ibex/vendor/lowrisc_ip/ip/prim/rtl/prim_keccak.sv:75: Define or directive not defined: \'`ASSERT_INIT\'\n  `ASSERT_INIT(ValidWidth_A, Width inside {25, 50, 100, 200, 400, 800, 1600})\n  ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/509468557/generators/ibex/src/main/resources/vsrc/ibex/vendor/lowrisc_ip/ip/prim/rtl/prim_keccak.sv:75: syntax error, unexpected \'(\'\n  `ASSERT_INIT(ValidWidth_A, Width inside {25, 50, 100, 200, 400, 800, 1600})\n               ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/509468557/generators/ibex/src/main/resources/vsrc/ibex/vendor/lowrisc_ip/ip/prim/rtl/prim_keccak.sv:76: Define or directive not defined: \'`ASSERT_INIT\'\n  `ASSERT_INIT(ValidW_A, W inside {1, 2, 4, 8, 16, 32, 64})\n  ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/509468557/generators/ibex/src/main/resources/vsrc/ibex/vendor/lowrisc_ip/ip/prim/rtl/prim_keccak.sv:77: Define or directive not defined: \'`ASSERT_INIT\'\n  `ASSERT_INIT(ValidL_A, L inside {0, 1, 2, 3, 4, 5, 6})\n  ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/509468557/generators/ibex/src/main/resources/vsrc/ibex/vendor/lowrisc_ip/ip/prim/rtl/prim_keccak.sv:78: Define or directive not defined: \'`ASSERT_INIT\'\n  `ASSERT_INIT(ValidRound_A, MaxRound <= 24)  \n  ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/509468557/generators/ibex/src/main/resources/vsrc/ibex/vendor/lowrisc_ip/ip/prim/rtl/prim_keccak.sv:91: syntax error, unexpected int, expecting IDENTIFIER or genvar\n    for (int y = 0 ; y < 5 ; y++) begin\n         ^~~\n%Error: data/full_repos/permissive/509468557/generators/ibex/src/main/resources/vsrc/ibex/vendor/lowrisc_ip/ip/prim/rtl/prim_keccak.sv:104: syntax error, unexpected int, expecting IDENTIFIER or genvar\n    for (int y = 0 ; y < 5 ; y++) begin\n         ^~~\n%Error: data/full_repos/permissive/509468557/generators/ibex/src/main/resources/vsrc/ibex/vendor/lowrisc_ip/ip/prim/rtl/prim_keccak.sv:124: syntax error, unexpected int, expecting IDENTIFIER or genvar\n    for (int x = 0 ; x < 5 ; x++) begin\n         ^~~\n%Error: data/full_repos/permissive/509468557/generators/ibex/src/main/resources/vsrc/ibex/vendor/lowrisc_ip/ip/prim/rtl/prim_keccak.sv:134: syntax error, unexpected int, expecting IDENTIFIER or genvar\n      for (int z = 0 ; z < W ; z++) begin\n           ^~~\n%Error: Exiting due to 10 error(s)\n'
module prim_keccak #(
  parameter int Width = 1600,


  localparam int W        = Width/25,
  localparam int L        = $clog2(W),
  localparam int MaxRound = 12 + 2*L,
  localparam int RndW     = $clog2(MaxRound+1)
) (
  input        [RndW-1:0]  rnd_i,
  input        [Width-1:0] s_i,
  output logic [Width-1:0] s_o
);




  typedef logic [4:0][4:0][W-1:0] box_t;
  typedef logic           [W-1:0] lane_t;
  typedef logic [4:0]     [W-1:0] plane_t;
  typedef logic [4:0][4:0]        slice_t;
  typedef logic      [4:0][W-1:0] sheet_t;
  typedef logic [4:0]             row_t;
  typedef logic      [4:0]        col_t;




  box_t state_in, keccak_f;
  box_t theta_data, rho_data, pi_data, chi_data, iota_data;
  assign state_in = bitarray_to_box(s_i);
  assign theta_data = theta(state_in);


  assign pi_data    = pi(rho_data);
  assign chi_data   = chi(pi_data);
  assign iota_data  = iota(chi_data, rnd_i);
  assign keccak_f   = iota_data;
  assign s_o        = box_to_bitarray(keccak_f);




  localparam int RhoOffset [5][5]  = '{

    '{   0,  36,   3, 105, 210},
    '{   1, 300,  10,  45,  66},
    '{ 190,   6, 171,  15, 253},
    '{  28,  55, 153,  21, 120},
    '{  91, 276, 231, 136,  78}
  };
  for (genvar x = 0 ; x < 5 ; x++) begin : gen_rho_x
    for (genvar y = 0 ; y < 5 ; y++) begin : gen_rho_y
      localparam int Offset = RhoOffset[x][y]%W;
      localparam int ShiftAmt = W- Offset;
      if (Offset == 0) begin : gen_offset0
        assign rho_data[x][y][W-1:0] = theta_data[x][y][W-1:0];
      end else begin : gen_others
        assign rho_data[x][y][W-1:0] = {theta_data[x][y][0+:ShiftAmt],
                                        theta_data[x][y][ShiftAmt+:Offset]};
      end
    end
  end





  `ASSERT_INIT(ValidWidth_A, Width inside {25, 50, 100, 200, 400, 800, 1600})
  `ASSERT_INIT(ValidW_A, W inside {1, 2, 4, 8, 16, 32, 64})
  `ASSERT_INIT(ValidL_A, L inside {0, 1, 2, 3, 4, 5, 6})
  `ASSERT_INIT(ValidRound_A, MaxRound <= 24)










  function automatic box_t bitarray_to_box(logic [Width-1:0] s_in);
    automatic box_t box;
    for (int y = 0 ; y < 5 ; y++) begin
      for (int x = 0 ; x < 5 ; x++) begin
        for (int z = 0 ; z < W ; z++) begin
          box[x][y][z] = s_in[W*(5*y+x) + z];
        end
      end
    end
    return box;
  endfunction : bitarray_to_box


  function automatic logic [Width-1:0] box_to_bitarray(box_t state);
    automatic logic [Width-1:0] bitarray;
    for (int y = 0 ; y < 5 ; y++) begin
      for (int x = 0 ; x < 5 ; x++) begin
        for (int z = 0 ; z < W ; z++) begin
          bitarray[W*(5*y+x)+z] = state[x][y][z];
        end
      end
    end
    return bitarray;
  endfunction : box_to_bitarray







  function automatic box_t theta(box_t state);
    plane_t c;
    plane_t d;
    box_t result;
    for (int x = 0 ; x < 5 ; x++) begin
      for (int z = 0 ; z < W ; z++) begin
        c[x][z] = state[x][0][z] ^ state[x][1][z]
                ^ state[x][2][z] ^ state[x][3][z] ^ state[x][4][z];
      end
    end
    for (int x = 0 ; x < 5 ; x++) begin
      int index_x1, index_x2;
      index_x1 = (x == 0) ? 4 : x-1;
      index_x2 = (x == 4) ? 0 : x+1;
      for (int z = 0 ; z < W ; z++) begin
        int index_z;
        index_z = (z == 0) ? W-1 : z-1;
        d[x][z] = c[index_x1][z] ^ c[index_x2][index_z];
      end
    end
    for (int x = 0 ; x < 5 ; x++) begin
      for (int y = 0 ; y < 5 ; y++) begin
        for (int z = 0 ; z < W ; z++) begin
          result[x][y][z] = state[x][y][z] ^ d[x][z];
        end
      end
    end
    return result;
  endfunction : theta










































  localparam int PiRotate [5][5] = '{

    '{   0,   3,   1,   4,   2},
    '{   1,   4,   2,   0,   3},
    '{   2,   0,   3,   1,   4},
    '{   3,   1,   4,   2,   0},
    '{   4,   2,   0,   3,   1}
  };
  function automatic box_t pi(box_t state);
    box_t result;
    for (int x = 0 ; x < 5 ; x++) begin
      for (int y = 0 ; y < 5 ; y++) begin
        int index_x;
        result[x][y][W-1:0] = state[PiRotate[x][y]][x][W-1:0];
      end
    end
    return result;
  endfunction : pi



  function automatic box_t chi(box_t state);
    box_t result;
    for (int x = 0 ; x < 5 ; x++) begin
      int index_x1, index_x2;
      index_x1 = (x == 4) ? 0 : x+1;
      index_x2 = (x >= 3) ? x-3 : x+2;
      for (int y = 0 ; y < 5 ; y++) begin
        for (int z = 0 ; z < W ; z++) begin
          result[x][y][z] = state[x][y][z] ^
                                ((~state[index_x1][y][z])
                                 & state[index_x2][y][z]);
        end
      end
    end
    return result;
  endfunction : chi




















  localparam logic [63:0] RC [24] = '{
     64'h 0000_0000_0000_0001,
     64'h 0000_0000_0000_8082,
     64'h 8000_0000_0000_808A,
     64'h 8000_0000_8000_8000,
     64'h 0000_0000_0000_808B,
     64'h 0000_0000_8000_0001,
     64'h 8000_0000_8000_8081,
     64'h 8000_0000_0000_8009,
     64'h 0000_0000_0000_008A,
     64'h 0000_0000_0000_0088,
     64'h 0000_0000_8000_8009,
     64'h 0000_0000_8000_000A,
     64'h 0000_0000_8000_808B,
     64'h 8000_0000_0000_008B,
     64'h 8000_0000_0000_8089,
     64'h 8000_0000_0000_8003,
     64'h 8000_0000_0000_8002,
     64'h 8000_0000_0000_0080,
     64'h 0000_0000_0000_800A,
     64'h 8000_0000_8000_000A,
     64'h 8000_0000_8000_8081,
     64'h 8000_0000_0000_8080,
     64'h 0000_0000_8000_0001,
     64'h 8000_0000_8000_8008
  };


  function automatic box_t iota(box_t state, logic [RndW-1:0] rnd);
    box_t result;
    result = state;
    result[0][0][W-1:0] = state[0][0][W-1:0] ^ RC[rnd][W-1:0];

    return result;
  endfunction : iota











endmodule
module prim_keccak #(
  parameter int Width = 1600,


  localparam int W        = Width/25,
  localparam int L        = $clog2(W),
  localparam int MaxRound = 12 + 2*L,
  localparam int RndW     = $clog2(MaxRound+1)
) (
  input        [RndW-1:0]  rnd_i,
  input        [Width-1:0] s_i,
  output logic [Width-1:0] s_o
);





  typedef logic [4:0][4:0][W-1:0] box_t;
  typedef logic           [W-1:0] lane_t;
  typedef logic [4:0]     [W-1:0] plane_t;
  typedef logic [4:0][4:0]        slice_t;
  typedef logic      [4:0][W-1:0] sheet_t;
  typedef logic [4:0]             row_t;
  typedef logic      [4:0]        col_t;




  box_t state_in, keccak_f;
  box_t theta_data, rho_data, pi_data, chi_data, iota_data;
  assign state_in = bitarray_to_box(s_i);
  assign theta_data = theta(state_in);


  assign pi_data    = pi(rho_data);
  assign chi_data   = chi(pi_data);
  assign iota_data  = iota(chi_data, rnd_i);
  assign keccak_f   = iota_data;
  assign s_o        = box_to_bitarray(keccak_f);




  localparam int RhoOffset [5][5]  = '{

    '{   0,  36,   3, 105, 210},
    '{   1, 300,  10,  45,  66},
    '{ 190,   6, 171,  15, 253},
    '{  28,  55, 153,  21, 120},
    '{  91, 276, 231, 136,  78}
  };
  for (genvar x = 0 ; x < 5 ; x++) begin : gen_rho_x
    for (genvar y = 0 ; y < 5 ; y++) begin : gen_rho_y
      localparam int Offset = RhoOffset[x][y]%W;
      localparam int ShiftAmt = W- Offset;
      if (Offset == 0) begin : gen_offset0
        assign rho_data[x][y][W-1:0] = theta_data[x][y][W-1:0];
      end else begin : gen_others
        assign rho_data[x][y][W-1:0] = {theta_data[x][y][0+:ShiftAmt],
                                        theta_data[x][y][ShiftAmt+:Offset]};
      end
    end
  end





  `ASSERT_INIT(ValidWidth_A, Width inside {25, 50, 100, 200, 400, 800, 1600})
  `ASSERT_INIT(ValidW_A, W inside {1, 2, 4, 8, 16, 32, 64})
  `ASSERT_INIT(ValidL_A, L inside {0, 1, 2, 3, 4, 5, 6})
  `ASSERT_INIT(ValidRound_A, MaxRound <= 24)










  function automatic box_t bitarray_to_box(logic [Width-1:0] s_in);
    automatic box_t box;
    for (int y = 0 ; y < 5 ; y++) begin
      for (int x = 0 ; x < 5 ; x++) begin
        for (int z = 0 ; z < W ; z++) begin
          box[x][y][z] = s_in[W*(5*y+x) + z];
        end
      end
    end
    return box;
  endfunction : bitarray_to_box


  function automatic logic [Width-1:0] box_to_bitarray(box_t state);
    automatic logic [Width-1:0] bitarray;
    for (int y = 0 ; y < 5 ; y++) begin
      for (int x = 0 ; x < 5 ; x++) begin
        for (int z = 0 ; z < W ; z++) begin
          bitarray[W*(5*y+x)+z] = state[x][y][z];
        end
      end
    end
    return bitarray;
  endfunction : box_to_bitarray







  function automatic box_t theta(box_t state);
    plane_t c;
    plane_t d;
    box_t result;
    for (int x = 0 ; x < 5 ; x++) begin
      for (int z = 0 ; z < W ; z++) begin
        c[x][z] = state[x][0][z] ^ state[x][1][z]
                ^ state[x][2][z] ^ state[x][3][z] ^ state[x][4][z];
      end
    end
    for (int x = 0 ; x < 5 ; x++) begin
      int index_x1, index_x2;
      index_x1 = (x == 0) ? 4 : x-1;
      index_x2 = (x == 4) ? 0 : x+1;
      for (int z = 0 ; z < W ; z++) begin
        int index_z;
        index_z = (z == 0) ? W-1 : z-1;
        d[x][z] = c[index_x1][z] ^ c[index_x2][index_z];
      end
    end
    for (int x = 0 ; x < 5 ; x++) begin
      for (int y = 0 ; y < 5 ; y++) begin
        for (int z = 0 ; z < W ; z++) begin
          result[x][y][z] = state[x][y][z] ^ d[x][z];
        end
      end
    end
    return result;
  endfunction : theta










































  localparam int PiRotate [5][5] = '{

    '{   0,   3,   1,   4,   2},
    '{   1,   4,   2,   0,   3},
    '{   2,   0,   3,   1,   4},
    '{   3,   1,   4,   2,   0},
    '{   4,   2,   0,   3,   1}
  };
  function automatic box_t pi(box_t state);
    box_t result;
    for (int x = 0 ; x < 5 ; x++) begin
      for (int y = 0 ; y < 5 ; y++) begin
        int index_x;
        result[x][y][W-1:0] = state[PiRotate[x][y]][x][W-1:0];
      end
    end
    return result;
  endfunction : pi



  function automatic box_t chi(box_t state);
    box_t result;
    for (int x = 0 ; x < 5 ; x++) begin
      int index_x1, index_x2;
      index_x1 = (x == 4) ? 0 : x+1;
      index_x2 = (x >= 3) ? x-3 : x+2;
      for (int y = 0 ; y < 5 ; y++) begin
        for (int z = 0 ; z < W ; z++) begin
          result[x][y][z] = state[x][y][z] ^
                                ((~state[index_x1][y][z])
                                 & state[index_x2][y][z]);
        end
      end
    end
    return result;
  endfunction : chi




















  localparam logic [63:0] RC [24] = '{
     64'h 0000_0000_0000_0001,
     64'h 0000_0000_0000_8082,
     64'h 8000_0000_0000_808A,
     64'h 8000_0000_8000_8000,
     64'h 0000_0000_0000_808B,
     64'h 0000_0000_8000_0001,
     64'h 8000_0000_8000_8081,
     64'h 8000_0000_0000_8009,
     64'h 0000_0000_0000_008A,
     64'h 0000_0000_0000_0088,
     64'h 0000_0000_8000_8009,
     64'h 0000_0000_8000_000A,
     64'h 0000_0000_8000_808B,
     64'h 8000_0000_0000_008B,
     64'h 8000_0000_0000_8089,
     64'h 8000_0000_0000_8003,
     64'h 8000_0000_0000_8002,
     64'h 8000_0000_0000_0080,
     64'h 0000_0000_0000_800A,
     64'h 8000_0000_8000_000A,
     64'h 8000_0000_8000_8081,
     64'h 8000_0000_0000_8080,
     64'h 0000_0000_8000_0001,
     64'h 8000_0000_8000_8008
  };


  function automatic box_t iota(box_t state, logic [RndW-1:0] rnd);
    box_t result;
    result = state;
    result[0][0][W-1:0] = state[0][0][W-1:0] ^ RC[rnd][W-1:0];

    return result;
  endfunction : iota











endmodule