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

Subversion Repositories bubblesortmodule

[/] [bubblesortmodule/] [trunk/] [rtl/] [verilog/] [bitsplit.v] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 avramionut
//////////////////////////////////////////////////////////////////////
2
////
3
//// Copyright (C) 2014 avram ionut, avramionut@opencores.org
4
////
5
//// This source file may be used and distributed without
6
//// restriction provided that this copyright statement is not
7
//// removed from the file and that any derivative work contains
8
//// the original copyright notice and the associated disclaimer.
9
////
10
//// This source file is free software; you can redistribute it
11
//// and/or modify it under the terms of the GNU Lesser General
12
//// Public License as published by the Free Software Foundation;
13
//// either version 2.1 of the License, or (at your option) any
14
//// later version.
15
////
16
//// This source is distributed in the hope that it will be
17
//// useful, but WITHOUT ANY WARRANTY; without even the implied
18
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19
//// PURPOSE. See the GNU Lesser General Public License for more
20
//// details.
21
////
22
//// You should have received a copy of the GNU Lesser General
23
//// Public License along with this source; if not, download it
24
//// from http://www.opencores.org/lgpl.shtml
25
////
26
//
27
// Revisions: 
28
// Revision 0.01 - File Created
29
// Additional Comments: 
30
//                     
31
//
32
//////////////////////////////////////////////////////////////////////////////////
33
module bitsplit(
34
    input   clk,
35
    input   bit1_i,
36
    input   bit2_i,
37
    output  largebit_o,
38
    output  smallbit_o,
39
    input   swap_i,
40
    output  swap_o,
41
    input   run_i,
42
    output  run_o
43
    );
44
 
45
    reg     r_bit1;
46
    reg     r_bit2;
47
    reg     r_small_bit;
48
    reg     r_large_bit;
49
    reg     r_compare_result;
50
    reg     r_freeze_compare;
51
    reg [0:1]   r_swap;
52
    reg [0:1]   r_run;
53
 
54
    wire    w_different_bits;
55
 
56
    always @(posedge clk)
57
        begin
58
            if (~run_i) begin
59
                r_freeze_compare <= 0;      end
60
            else if (w_different_bits) begin
61
                r_freeze_compare <= 1;      end
62
        end
63
 
64
    always @(posedge clk)
65
        begin
66
            if (~run_i) begin
67
                r_compare_result <= 0;      end
68
            else if (~r_freeze_compare) begin
69
                if (bit1_i & ~bit2_i)   begin
70
                    r_compare_result <= 1;  end
71
                else begin
72
                    r_compare_result <= 0;  end
73
                end
74
        end
75
 
76
    always @(posedge clk)
77
        begin
78
            r_bit1 <= bit1_i;
79
            r_bit2 <= bit2_i;
80
            if (~r_compare_result) begin
81
                r_small_bit <= r_bit1;
82
                r_large_bit <= r_bit2;   end
83
            else begin
84
                r_small_bit <= r_bit2;
85
                r_large_bit <= r_bit1;   end
86
        end
87
 
88
    always @(posedge clk)
89
        begin
90
            r_swap[0] <= swap_i;
91
            r_swap[1] <= r_swap[0] | r_compare_result;
92
        end
93
 
94
    always @(posedge clk)
95
        begin
96
            r_run[0] <= run_i;
97
            r_run[1] <= r_run[0];
98
        end
99
 
100
    assign w_different_bits = bit1_i ^ bit2_i;
101
 
102
    assign largebit_o = r_large_bit;
103
    assign smallbit_o = r_small_bit;
104
    assign swap_o = r_swap[1];
105
    assign run_o = r_run[1];
106
 
107
endmodule
108
 

powered by: WebSVN 2.1.0

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