OpenCores
URL https://opencores.org/ocsvn/srdydrdy_lib/srdydrdy_lib/trunk

Subversion Repositories srdydrdy_lib

[/] [srdydrdy_lib/] [trunk/] [examples/] [bridge/] [rtl/] [basic_hashfunc.v] - Diff between revs 4 and 8

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 4 Rev 8
/*
/*
 *  Simple parameterized hash function
 *  Simple parameterized hash function
 *
 *
 * Takes an input item and folds it back upon itself using xor
 * Takes an input item and folds it back upon itself using xor
 * as a reduction function.  Works only for hash tables with
 * as a reduction function.  Works only for hash tables with
 * a natural power of 2.
 * a natural power of 2.
 */
 */
module basic_hashfunc
module basic_hashfunc
  #(parameter input_sz=48,
  #(parameter input_sz=48,
    parameter table_sz=1024,
    parameter table_sz=1024,
    parameter fsz=clogb2(table_sz))
    parameter fsz=$clog2(table_sz))
  (
  (
   input [input_sz-1:0]  hf_in,
   input [input_sz-1:0]  hf_in,
   output reg [fsz-1:0]  hf_out);
   output reg [fsz-1:0]  hf_out);
 
 
  //localparam folds = (input_sz/fsz) + ( (input_sz%fsz) == 0) ? 0 : 1;
  // const function not supported by Icarus Verilog
  localparam folds = num_folds(input_sz, fsz);
  //localparam folds = num_folds(input_sz, fsz);
 
  localparam folds = 5;
 
 
  wire [folds*fsz-1:0]   tmp_array;
  wire [folds*fsz-1:0]   tmp_array;
 
 
  assign tmp_array = hf_in;
  assign tmp_array = hf_in;
 
 
  integer                f, b;
  integer                f, b;
 
 
  always @*
  always @*
    begin
    begin
      for (b=0; b<fsz; b=b+1)
      for (b=0; b<fsz; b=b+1)
        begin
        begin
          hf_out[b] = 0;
          hf_out[b] = 0;
          for (f=0; f<folds; f=f+1)
          for (f=0; f<folds; f=f+1)
            hf_out[b] = hf_out[b]^tmp_array[f*fsz+b];
            hf_out[b] = hf_out[b]^tmp_array[f*fsz+b];
        end
        end
    end
    end
 
 
  function integer num_folds;
  function integer num_folds;
    input [31:0] in_sz;
    input [31:0] in_sz;
    input [31:0] func_sz;
    input [31:0] func_sz;
    integer      tmp_in_sz;
    integer      tmp_in_sz;
    begin
    begin
      num_folds = 0;
      num_folds = 0;
      tmp_in_sz = in_sz;
      tmp_in_sz = in_sz;
      while (tmp_in_sz > 0)
      while (tmp_in_sz > 0)
        begin
        begin
          tmp_in_sz = tmp_in_sz - func_sz;
          tmp_in_sz = tmp_in_sz - func_sz;
          num_folds = num_folds + 1;
          num_folds = num_folds + 1;
        end
        end
    end
    end
  endfunction
  endfunction
 
 
  function integer clogb2;
/* -----\/----- EXCLUDED -----\/-----
    input [31:0] depth;
  function integer clogb2;
    integer      i;
    input [31:0] depth;
    begin
    integer      i;
      i = depth;
    begin
      for (clogb2=0; i>0; clogb2=clogb2+1)
      i = depth;
        i = i >> 1;
      for (clogb2=0; i>0; clogb2=clogb2+1)
    end
        i = i >> 1;
  endfunction // for
    end
 
  endfunction // for
 
 -----/\----- EXCLUDED -----/\----- */
 
 
endmodule // hashfunc
endmodule // hashfunc
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.