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

Subversion Repositories numbert_sort_device

[/] [numbert_sort_device/] [trunk/] [main/] [tree_sorter.sv] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 leshabiruk
 
2
 
3
////////////////////////////////////////////////////////////
4
//
5
// number sorting device, sequential, O(N)
6
//
7
//      autor:   Alexey Birukov, leshabirukov@opencores.org
8
//      license: LGPL
9
//
10
//      notes:
11
//      reset signal is not implemented, to make reset wait R_SZ clocks
12
//      while hold==0 and is_input==0 to empty the buffer
13
//      or implement reset signal by yourself
14
//
15
//      to make sorting in increasing order, use module call like this:
16
//  Sorting_Stack #(HBIT,R_SZ) cstack ( clk, hold, is_input, -1-data_in, _data_out      );
17
//  wire [HBIT:0] data_out= -1-_data_out;
18
//
19
////////////////////////////////////////////////////////////
20
 
21
// number sorting, tree-like implementation, sequential,
22
// energy efficient (theoreticaly)
23
//      see sort_tree_algorithm.png to catch the idea
24
 
25
 
26
//      following code is for recursive module idea
27
// description, it is not part of the project
28
 
29
module NodeType (  );
30
endmodule
31
 
32
 
33
 
34
module TreeTemplate (  );
35
 
36
parameter TREE_LEVEL= 4;
37
 
38
NodeType node();
39
 
40
generate
41
if ( TREE_LEVEL >0 )
42
begin
43
        TreeTemplate #( TREE_LEVEL-1 ) leftSubtree (  );
44
        TreeTemplate #( TREE_LEVEL-1 ) rightSubtree (  );
45
end
46
endgenerate
47
 
48
endmodule
49
 
50
 
51
//      here is the real implementation
52
 
53
module Sorting_Tree ( clk, hold, is_input, data_in, data_out    );
54
 
55
parameter HBIT= 15;
56
 
57
parameter R_SZ= 256;
58
parameter TREE_LEVEL= 4;
59
 
60
input clk;
61
input hold;
62
input is_input;
63
 
64
input [HBIT:0] data_in;
65
output [HBIT:0] data_out;
66
wire [HBIT:0] in_next= lead_1 ? d_out1 : d_out2;
67
 
68
wire [HBIT:0] d_out1;
69
wire [HBIT:0] d_out2;
70
 
71
generate
72
if ( TREE_LEVEL >0 )
73
begin
74
        Cell_Compare  #( HBIT ) top_buf ( clk, hold,  is_input, data_in, in_next, data_out );
75
        Sorting_Tree #( HBIT, R_SZ/2,     TREE_LEVEL-1 ) cstack1 ( clk, hold1, is_input, data_out, d_out1       );
76
        Sorting_Tree #( HBIT, (R_SZ-1)/2, TREE_LEVEL-1 ) cstack2 ( clk, hold2, is_input, data_out, d_out2       );
77
end
78
else
79
begin
80
        Sorting_Stack #( HBIT, R_SZ ) leaf ( clk, hold, is_input, data_in, data_out );
81
end
82
endgenerate
83
 
84
bit flipper;
85
 
86
wire lead_1= ( d_out1 > d_out2 );
87
wire hold1= hold | ~( is_input ? flipper : lead_1 );
88
wire hold2= hold |  ( is_input ? flipper : lead_1 );
89
 
90
always@(posedge clk )
91
if (~hold)
92
begin
93
  if (is_input)
94
  begin
95
         flipper <= ~flipper;
96
  end
97
end
98
 
99
endmodule
100
 
101
 
102
 

powered by: WebSVN 2.1.0

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