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

Subversion Repositories srdydrdy_lib

[/] [srdydrdy_lib/] [trunk/] [examples/] [bridge/] [rtl/] [basic_hashfunc.v] - Blame information for rev 4

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 ghutchis
/*
2
 *  Simple parameterized hash function
3
 *
4
 * Takes an input item and folds it back upon itself using xor
5
 * as a reduction function.  Works only for hash tables with
6
 * a natural power of 2.
7
 */
8
module basic_hashfunc
9
  #(parameter input_sz=48,
10
    parameter table_sz=1024,
11
    parameter fsz=clogb2(table_sz))
12
  (
13
   input [input_sz-1:0]  hf_in,
14
   output reg [fsz-1:0]  hf_out);
15
 
16
  //localparam folds = (input_sz/fsz) + ( (input_sz%fsz) == 0) ? 0 : 1;
17
  localparam folds = num_folds(input_sz, fsz);
18
 
19
  wire [folds*fsz-1:0]   tmp_array;
20
 
21
  assign tmp_array = hf_in;
22
 
23
  integer                f, b;
24
 
25
  always @*
26
    begin
27
      for (b=0; b<fsz; b=b+1)
28
        begin
29
          hf_out[b] = 0;
30
          for (f=0; f<folds; f=f+1)
31
            hf_out[b] = hf_out[b]^tmp_array[f*fsz+b];
32
        end
33
    end
34
 
35
  function integer num_folds;
36
    input [31:0] in_sz;
37
    input [31:0] func_sz;
38
    integer      tmp_in_sz;
39
    begin
40
      num_folds = 0;
41
      tmp_in_sz = in_sz;
42
      while (tmp_in_sz > 0)
43
        begin
44
          tmp_in_sz = tmp_in_sz - func_sz;
45
          num_folds = num_folds + 1;
46
        end
47
    end
48
  endfunction
49
 
50
  function integer clogb2;
51
    input [31:0] depth;
52
    integer      i;
53
    begin
54
      i = depth;
55
      for (clogb2=0; i>0; clogb2=clogb2+1)
56
        i = i >> 1;
57
    end
58
  endfunction // for
59
 
60
endmodule // hashfunc

powered by: WebSVN 2.1.0

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