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/] [SinglePathFPAdder/] [SinglePathFPAdder.v] - Blame information for rev 17

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

Line No. Rev Author Line
1 8 constantin
`timescale 1ns / 1ps
2
//////////////////////////////////////////////////////////////////////////////////
3
// Company: 
4
// Engineer: 
5
// 
6
// Create Date:    16:09:49 11/04/2013 
7
// Design Name: 
8
// Module Name:    SinglePathFPAdder 
9
// Project Name: 
10
// Target Devices: 
11
// Tool versions: 
12
// Description: A ± B
13
//
14
// Dependencies: 
15
//
16
// Revision: 
17
// Revision 0.01 - File Created
18
// Additional Comments: 
19
//
20
//////////////////////////////////////////////////////////////////////////////////
21 9 constantin
module SinglePathFPAdder #(     parameter size_mantissa                         = 24, //calculate the size containing the hiden bit 1.M
22 8 constantin
                                                                                parameter size_exponent                         = 8,
23
                                                                                parameter size_exception_field  = 2,
24
                                                                                parameter size_counter                          = 5,    //log2(size_mantissa) + 1 = 5)
25
                                                                                parameter [size_exception_field - 1 : 0] zero                    = 0, //00
26
                                                                                parameter [size_exception_field - 1 : 0] normal_number= 1, //01
27
                                                                                parameter [size_exception_field - 1 : 0] infinity                = 2, //10
28
                                                                                parameter [size_exception_field - 1 : 0] NaN                             = 3, //11
29
                                                                                parameter pipeline                                      = 0,
30
                                                                                parameter pipeline_pos                          = 0,     // 8 bits
31
                                                                                parameter double_size_mantissa          = size_mantissa + size_mantissa,
32
                                                                                parameter double_size_counter           = size_counter + 1,
33
                                                                                parameter size  = size_mantissa + size_exponent + size_exception_field)
34
 
35 9 constantin
                                                                        (       input sub,
36
                                                                                input [size - 1 : 0] a_number_i,
37
                                                                                input [size - 1 : 0] b_number_i,
38
                                                                                output[size - 1 : 0] resulted_number_o);
39 8 constantin
 
40 9 constantin
 
41
        wire [size_exception_field - 1 : 0] sp_case_a_number, sp_case_b_number;
42 8 constantin
        wire [size_mantissa - 1 : 0] m_a_number, m_b_number;
43
        wire [size_exponent - 1 : 0] e_a_number, e_b_number;
44
        wire s_a_number, s_b_number;
45
 
46 9 constantin
        wire [size_exponent     : 0] a_greater_exponent, b_greater_exponent;
47
        wire [size_exponent - 1 : 0] unadjusted_exponent;
48 14 constantin
        wire [1 : 0] adjust_exponent;
49 9 constantin
 
50 8 constantin
        wire [size_exponent - 1 : 0] exp_difference;
51 9 constantin
        wire [size_exponent     : 0] exp_inter;
52
        wire [size_mantissa - 1 : 0] shifted_m_b;
53
        wire [size_mantissa - 1 : 0] initial_rounding_bits, inter_rounding_bits, final_rounding_bits;
54 8 constantin
        wire eff_op;
55
 
56 9 constantin
        wire [size_counter  - 1 : 0] lzs;
57
        wire [size_mantissa + 1 : 0] adder_mantissa;
58
        wire [size_mantissa + 1 : 0] rounded_mantissa;
59
        wire [size_mantissa     : 0] unnormalized_mantissa, unrounded_mantissa;
60 8 constantin
 
61 9 constantin
        wire [size_exception_field - 1 : 0] resulted_exception_field;
62
        wire [size_mantissa - 1 : 0] resulted_mantissa;
63
        wire [size_exponent - 1 : 0] resulted_exponent;
64 8 constantin
        wire resulted_sign;
65
 
66 9 constantin
        wire dummy_bit;
67
        wire zero_flag;
68 8 constantin
 
69 9 constantin
 
70 8 constantin
        assign e_a_number       = a_number_i[size_mantissa + size_exponent - 1 : size_mantissa - 1];
71
        assign e_b_number = b_number_i[size_mantissa + size_exponent - 1 : size_mantissa - 1];
72
        assign s_a_number = a_number_i[size - size_exception_field - 1];
73
        assign s_b_number = b_number_i[size - size_exception_field - 1];
74
        assign sp_case_a_number = a_number_i[size - 1 : size - size_exception_field];
75
        assign sp_case_b_number = b_number_i[size - 1 : size - size_exception_field];
76 9 constantin
 
77
 
78
        //find the greater exponent
79
        assign a_greater_exponent = e_a_number - e_b_number;
80
        assign b_greater_exponent = e_b_number - e_a_number;
81
 
82 8 constantin
        //find the difference between exponents
83 9 constantin
        assign exp_difference   = (a_greater_exponent[size_exponent])? b_greater_exponent[size_exponent - 1 : 0] : a_greater_exponent[size_exponent - 1 : 0];
84
        assign exp_inter                = (b_greater_exponent[size_exponent])? {1'b0, e_a_number} : {1'b0, e_b_number};
85
 
86
        //set shifter always on m_b_number
87
        assign {m_a_number, m_b_number} = (b_greater_exponent[size_exponent])?
88
                                                                                                        {{1'b1, a_number_i[size_mantissa - 2 :0]}, {1'b1, b_number_i[size_mantissa - 2 :0]}} :
89
                                                                                                        {{1'b1, b_number_i[size_mantissa - 2 :0]}, {1'b1, a_number_i[size_mantissa - 2 :0]}};
90
 
91
        //shift m_b_number                              
92 8 constantin
        shifter #(      .INPUT_SIZE(size_mantissa),
93 9 constantin
                                .SHIFT_SIZE(size_exponent),
94
                                .OUTPUT_SIZE(double_size_mantissa),
95
                                .DIRECTION(1'b0), //0=right, 1=left
96
                                .PIPELINE(pipeline),
97
                                .POSITION(pipeline_pos))
98 8 constantin
                m_b_shifter_instance(   .a(m_b_number),//mantissa
99 9 constantin
                                                                .arith(1'b0),//logical shift
100
                                                                .shft(exp_difference),
101
                                                                .shifted_a({shifted_m_b, initial_rounding_bits}));
102 8 constantin
 
103
        //istantiate effective_operation_component
104
        effective_op effective_op_instance( .a_sign(s_a_number), .b_sign(s_b_number), .sub(sub), .eff_op(eff_op));
105 9 constantin
 
106
        //compute unnormalized_mantissa
107
        assign adder_mantissa = (eff_op)? ({1'b0, m_a_number} - {1'b0, shifted_m_b}) : ({1'b0, m_a_number} + {1'b0, shifted_m_b});
108 8 constantin
 
109 9 constantin
        assign {unnormalized_mantissa, inter_rounding_bits} =
110
                                                                (adder_mantissa[size_mantissa + 1])?    ({~adder_mantissa[size_mantissa : 0], ~initial_rounding_bits}) :
111
                                                                                                                                                ({adder_mantissa[size_mantissa  : 0], initial_rounding_bits});
112
 
113 8 constantin
        //compute leading_zeros over unnormalized mantissa
114 9 constantin
        leading_zeros #(        .SIZE_INT(size_mantissa + 1), .SIZE_COUNTER(size_counter), .PIPELINE(pipeline))
115
                leading_zeros_instance (.a(unnormalized_mantissa[size_mantissa : 0]),
116
                                                                                .ovf(unnormalized_mantissa[size_mantissa]),
117 8 constantin
                                                                                .lz(lzs));
118 9 constantin
 
119 8 constantin
        //compute shifting over unnormalized_mantissa
120 9 constantin
        shifter #(      .INPUT_SIZE(double_size_mantissa + 1),
121
                                        .SHIFT_SIZE(size_counter),
122
                                        .OUTPUT_SIZE(double_size_mantissa + 2),
123 8 constantin
                                        .DIRECTION(1'b1), //0=right, 1=left
124
                                        .PIPELINE(pipeline),
125
                                        .POSITION(pipeline_pos))
126 9 constantin
                shifter_instance(       .a({unnormalized_mantissa, inter_rounding_bits}),//mantissa
127 8 constantin
                                                                .arith(1'b0),//logical shift
128
                                                                .shft(lzs),
129 9 constantin
                                                                .shifted_a({unrounded_mantissa, final_rounding_bits, dummy_bit}));
130
 
131
        //instantiate rounding_component
132
        rounding #(     .SIZE_MOST_S_MANTISSA(size_mantissa + 2),
133
                                .SIZE_LEAST_S_MANTISSA(size_mantissa))
134
                rounding_instance(      .unrounded_mantissa({1'b0, unrounded_mantissa}),
135
                                    .dummy_bits(final_rounding_bits),
136
                                    .rounded_mantissa(rounded_mantissa));
137 8 constantin
 
138 9 constantin
        //adjust exponent in case of overflow
139
        assign adjust_exponent = (rounded_mantissa[size_mantissa + 1])? 2'd2 : 2'd1;
140 8 constantin
 
141
        //compute resulted_exponent
142 9 constantin
        assign unadjusted_exponent = exp_inter - lzs;
143
        assign resulted_exponent = unadjusted_exponent + adjust_exponent;
144 8 constantin
 
145 9 constantin
        assign resulted_mantissa = (rounded_mantissa[size_mantissa + 1])? (rounded_mantissa[size_mantissa + 1 : 2]) : (rounded_mantissa[size_mantissa : 1]);
146 8 constantin
 
147
        //compute exception_field
148
        special_cases   #(      .size_exception_field(size_exception_field),
149
                                                        .zero(zero),
150
                                                        .normal_number(normal_number),
151
                                                        .infinity(infinity),
152
                                                        .NaN(NaN))
153
                special_cases_instance( .sp_case_a_number(sp_case_a_number),
154
                                                                                .sp_case_b_number(sp_case_b_number),
155
                                                                                .sp_case_result_o(resulted_exception_field));
156 17 constantin
 
157 9 constantin
        //set zero_flag in case of equal numbers
158 17 constantin
        assign zero_flag = ~((|{resulted_mantissa,resulted_exception_field[1]}) & (|resulted_exception_field));
159 9 constantin
 
160
        //compute resulted_sign
161
        assign resulted_sign = (eff_op)?
162
                                        (!a_greater_exponent[size_exponent]? (!b_greater_exponent[size_exponent]? ~adder_mantissa[size_mantissa+1] : s_a_number) : ~s_b_number) :
163
                                        s_a_number;
164
 
165
        assign resulted_number_o = (zero_flag)? {size{1'b0}} :
166
                                                                        {resulted_exception_field, resulted_sign, resulted_exponent, resulted_mantissa[size_mantissa - 2 : 0]};
167
 
168 8 constantin
endmodule

powered by: WebSVN 2.1.0

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