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

Subversion Repositories xilinx_virtex_fp_library

[/] [xilinx_virtex_fp_library/] [trunk/] [SinglePathFPAdderMappedConversions/] [leading_zeros.v] - Blame information for rev 15

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

Line No. Rev Author Line
1 15 constantin
`timescale 1ns / 1ps
2
//////////////////////////////////////////////////////////////////////////////////
3
// Company: 
4
// Engineer: 
5
// 
6
// Create Date:    18:50:09 10/17/2013 
7
// Design Name: 
8
// Module Name:    leading_zeros 
9
// Project Name: 
10
// Target Devices: 
11
// Tool versions: 
12
// Description: 
13
//
14
// Dependencies: 
15
//
16
// Revision: 
17
// Revision 0.01 - File Created
18
// Additional Comments: 
19
//
20
//////////////////////////////////////////////////////////////////////////////////
21
module leading_zeros #( parameter SIZE_INT = 24,        //mantissa bits
22
                                                                parameter SIZE_COUNTER  = 5,    //log2(size_mantissa) + 1 = 5)
23
                                                                parameter PIPELINE = 2)
24
                                                        (a, ovf, lz);
25
 
26
        input [SIZE_INT-1:0]    a;
27
        input                   ovf;
28
        output [SIZE_COUNTER-1:0] lz;
29
 
30
 
31
        parameter       nr_levels = SIZE_COUNTER - 1;
32
        parameter       max_pow_2 = 2 ** SIZE_COUNTER;
33
        parameter       size_lz = SIZE_COUNTER;
34
 
35
        wire [max_pow_2-1:0] a_complete;
36
        wire [max_pow_2-1:0] v_d[nr_levels-1:0];
37
        wire [max_pow_2-1:0] v_q[nr_levels-1:0];
38
        wire [max_pow_2-1:0] p_d[nr_levels-1:0];
39
        wire [max_pow_2-1:0] p_q[nr_levels-1:0];
40
        wire [size_lz-1:0]   lzc;
41
 
42
        assign a_complete[max_pow_2 - 1 : max_pow_2 - 1 - SIZE_INT + 1] = a;
43
        generate
44
                if (max_pow_2 != SIZE_INT)
45
                begin : gen_if
46
                        assign a_complete[max_pow_2 - 1 - SIZE_INT : 0] = 0;
47
                end
48
        endgenerate
49
 
50
        generate
51
                begin : level_0
52
                        genvar i;
53
                        for (i = max_pow_2/4 - 1; i >= 0; i = i - 1)
54
                        begin : level_0
55
                                assign v_d[0][i] = (a_complete[4 * i + 3 : 4 * i] == 4'b0000) ? 1'b0 : 1'b1;
56
                                assign p_d[0][2*i+1:2*i] = (a_complete[4 * i + 3] == 1'b1) ? 2'b00 :
57
                                                                (a_complete[4 * i + 2] == 1'b1) ? 2'b01 :
58
                                                                (a_complete[4 * i + 1] == 1'b1) ? 2'b10 : 2'b11;
59
                        end
60
                end
61
        endgenerate
62
 
63
        generate
64
                begin : level_generation_begin
65
                        genvar i;
66
                        for (i = 1; i <= nr_levels - 1; i = i + 1)
67
                        begin : level_generation
68
                                //begin : v_levels_begin
69
                                        genvar j;
70
                                        for (j = 0; j <= max_pow_2/(2 ** (i + 2)) - 1; j = j + 1)
71
                                        begin : v_levels
72
                                                assign v_d[i][j] = v_q[i - 1][2*j+1] | v_q[i - 1][2*j];
73
                                        end
74
                                //end
75
 
76
                                //begin : p_levels_begin
77
                                //      genvar j;
78
                                        for (j = 0; j <= max_pow_2/(2 ** (i + 2)) - 1; j = j + 1)
79
                                        begin : p_levels
80
                                                assign p_d[i][(i+2)*j+i+1] = (~(v_q[i - 1][2*j+1]));
81
                                                assign p_d[i][(i+2)*j+i : (i+2)*j] = (v_q[i - 1][2*j+1] == 1'b1) ? p_q[i - 1][j*(2*i+2)+2*i+1 : j*(2*i+2) + i + 1] : p_q[i - 1][j*(2*i+2)+i : j*(2*i+2)];
82
                                        end
83
                                //end
84
                        end
85
                end
86
        endgenerate
87
 
88
        generate
89
                if (PIPELINE != 0)
90
                begin : pipeline_stages
91
                        //begin : INSERTION_begin
92
                                genvar i;
93
                                for (i = 0; i <= nr_levels - 2; i = i + 1)
94
                                begin : INSERTION
95
                                        if ((i + 1) % nr_levels/(PIPELINE + 1) == 0)
96
                                        begin : INS
97
                                                d_ff #(max_pow_2) P_Di(.clk(clk), .rst(rst), .d(p_d[i]), .q(p_q[i]));
98
                                                d_ff #(max_pow_2) V_Di(.clk(clk), .rst(rst), .d(v_d[i]), .q(v_q[i]));
99
                                        end
100
 
101
                                        if ((i + 1) % nr_levels/(PIPELINE + 1) != 0)
102
                                        begin : NO_INS
103
                                                assign p_q[i] = p_d[i];
104
                                                assign v_q[i] = v_d[i];
105
                                        end
106
                                end
107
                        //end
108
                        assign p_q[nr_levels - 1] = p_d[nr_levels - 1];
109
                        assign v_q[nr_levels - 1] = v_d[nr_levels - 1];
110
                end
111
        endgenerate
112
 
113
        generate
114
                if (PIPELINE == 0)
115
                begin : no_pipeline
116
                        //begin : xhdl4
117
                                genvar i;
118
                                for (i = 0; i <= nr_levels - 1; i = i + 1)
119
                                begin : NO_INSERTION
120
                                        assign p_q[i] = p_d[i];
121
                                        assign v_q[i] = v_d[i];
122
                                end
123
                        //end
124
                end
125
        endgenerate
126
 
127
        assign lzc[size_lz - 1:0] = p_q[nr_levels - 1][size_lz - 1:0];
128
 
129
        generate
130
                begin : lz_ovf_begin
131
                        genvar i;
132
                        for (i = 0; i <= size_lz - 1; i = i + 1)
133
                        begin : lz_ovf
134
                                assign lz[i] = lzc[i] & ((~ovf));
135
                        end
136
                end
137
        endgenerate
138
 
139
endmodule

powered by: WebSVN 2.1.0

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