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 13

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 8 ghutchis
    parameter fsz=$clog2(table_sz))
12 4 ghutchis
  (
13
   input [input_sz-1:0]  hf_in,
14
   output reg [fsz-1:0]  hf_out);
15
 
16 8 ghutchis
  // const function not supported by Icarus Verilog
17
  //localparam folds = num_folds(input_sz, fsz);
18
  localparam folds = 5;
19 4 ghutchis
 
20
  wire [folds*fsz-1:0]   tmp_array;
21
 
22
  assign tmp_array = hf_in;
23
 
24
  integer                f, b;
25
 
26
  always @*
27
    begin
28
      for (b=0; b<fsz; b=b+1)
29
        begin
30
          hf_out[b] = 0;
31
          for (f=0; f<folds; f=f+1)
32
            hf_out[b] = hf_out[b]^tmp_array[f*fsz+b];
33
        end
34
    end
35
 
36
  function integer num_folds;
37
    input [31:0] in_sz;
38
    input [31:0] func_sz;
39
    integer      tmp_in_sz;
40
    begin
41
      num_folds = 0;
42
      tmp_in_sz = in_sz;
43
      while (tmp_in_sz > 0)
44
        begin
45
          tmp_in_sz = tmp_in_sz - func_sz;
46
          num_folds = num_folds + 1;
47
        end
48
    end
49
  endfunction
50
 
51 8 ghutchis
/* -----\/----- EXCLUDED -----\/-----
52 4 ghutchis
  function integer clogb2;
53
    input [31:0] depth;
54
    integer      i;
55
    begin
56
      i = depth;
57
      for (clogb2=0; i>0; clogb2=clogb2+1)
58
        i = i >> 1;
59
    end
60
  endfunction // for
61 8 ghutchis
 -----/\----- EXCLUDED -----/\----- */
62 4 ghutchis
 
63
endmodule // hashfunc

powered by: WebSVN 2.1.0

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