1 |
8 |
constantin |
`timescale 1ns / 1ps
|
2 |
|
|
//////////////////////////////////////////////////////////////////////////////////
|
3 |
|
|
// Company:
|
4 |
|
|
// Engineer:
|
5 |
|
|
//
|
6 |
|
|
// Create Date: 00:31:28 11/19/2013
|
7 |
|
|
// Design Name:
|
8 |
|
|
// Module Name: DualPathFPAdder
|
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 |
|
|
module DualPathFPAdder #( parameter size_mantissa = 24, //1.M
|
22 |
|
|
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 |
wire [size_exception_field - 1 : 0] sp_case_a_number, sp_case_b_number;
|
41 |
8 |
constantin |
wire [size_mantissa - 1 : 0] m_a_number, m_b_number;
|
42 |
|
|
wire [size_exponent - 1 : 0] e_a_number, e_b_number;
|
43 |
9 |
constantin |
wire s_a_number, s_b_number;
|
44 |
|
|
|
45 |
|
|
wire [size_exponent : 0] a_greater_exponent, b_greater_exponent;
|
46 |
|
|
|
47 |
8 |
constantin |
wire [size_exponent - 1 : 0] exp_difference;
|
48 |
9 |
constantin |
wire [size_exponent : 0] exp_inter;
|
49 |
|
|
wire [size_mantissa - 1 : 0] shifted_m_b;
|
50 |
|
|
wire [size_mantissa - 1 : 0] initial_rounding_bits, inter_rounding_bits;
|
51 |
|
|
wire eff_op;
|
52 |
8 |
constantin |
|
53 |
9 |
constantin |
wire [size_mantissa + 1 : 0] adder_mantissa;
|
54 |
|
|
wire [size_mantissa : 0] unnormalized_mantissa;
|
55 |
|
|
|
56 |
8 |
constantin |
wire [size_mantissa-1 : 0] fp_resulted_m_o, cp_resulted_m_o;
|
57 |
|
|
wire [size_exponent-1 : 0] fp_resulted_e_o, cp_resulted_e_o;
|
58 |
|
|
|
59 |
9 |
constantin |
wire [size_exception_field - 1 : 0] resulted_exception_field;
|
60 |
8 |
constantin |
wire resulted_sign;
|
61 |
9 |
constantin |
|
62 |
|
|
wire zero_flag;
|
63 |
|
|
|
64 |
8 |
constantin |
|
65 |
|
|
assign e_a_number = a_number_i[size_mantissa + size_exponent - 1 : size_mantissa - 1];
|
66 |
|
|
assign e_b_number = b_number_i[size_mantissa + size_exponent - 1 : size_mantissa - 1];
|
67 |
|
|
assign s_a_number = a_number_i[size - size_exception_field - 1];
|
68 |
|
|
assign s_b_number = b_number_i[size - size_exception_field - 1];
|
69 |
|
|
assign sp_case_a_number = a_number_i[size - 1 : size - size_exception_field];
|
70 |
|
|
assign sp_case_b_number = b_number_i[size - 1 : size - size_exception_field];
|
71 |
9 |
constantin |
|
72 |
|
|
|
73 |
|
|
//find the greater exponent
|
74 |
|
|
assign a_greater_exponent = e_a_number - e_b_number;
|
75 |
|
|
assign b_greater_exponent = e_b_number - e_a_number;
|
76 |
|
|
|
77 |
|
|
//find the difference between exponents
|
78 |
|
|
assign exp_difference = (a_greater_exponent[size_exponent])? b_greater_exponent[size_exponent - 1 : 0] : a_greater_exponent[size_exponent - 1 : 0];
|
79 |
|
|
assign exp_inter = (b_greater_exponent[size_exponent])? {1'b0, e_a_number} : {1'b0, e_b_number};
|
80 |
|
|
|
81 |
|
|
//set shifter always on m_b_number
|
82 |
|
|
assign {m_a_number, m_b_number} = (b_greater_exponent[size_exponent])?
|
83 |
|
|
{{1'b1, a_number_i[size_mantissa - 2 :0]}, {1'b1, b_number_i[size_mantissa - 2 :0]}} :
|
84 |
|
|
{{1'b1, b_number_i[size_mantissa - 2 :0]}, {1'b1, a_number_i[size_mantissa - 2 :0]}};
|
85 |
8 |
constantin |
|
86 |
9 |
constantin |
//shift m_b_number
|
87 |
8 |
constantin |
shifter #( .INPUT_SIZE(size_mantissa),
|
88 |
9 |
constantin |
.SHIFT_SIZE(size_exponent),
|
89 |
|
|
.OUTPUT_SIZE(double_size_mantissa),
|
90 |
|
|
.DIRECTION(1'b0), //0=right, 1=left
|
91 |
|
|
.PIPELINE(pipeline),
|
92 |
|
|
.POSITION(pipeline_pos))
|
93 |
|
|
m_b_shifter_instance( .a(m_b_number),//mantissa
|
94 |
|
|
.arith(1'b0),//logical shift
|
95 |
|
|
.shft(exp_difference),
|
96 |
|
|
.shifted_a({shifted_m_b, initial_rounding_bits}));
|
97 |
8 |
constantin |
|
98 |
|
|
//istantiate effective_operation_component
|
99 |
9 |
constantin |
effective_op effective_op_instance( .a_sign(s_a_number), .b_sign(s_b_number), .sub(sub), .eff_op(eff_op));
|
100 |
|
|
|
101 |
|
|
//compute unnormalized_mantissa
|
102 |
|
|
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});
|
103 |
|
|
|
104 |
|
|
assign {unnormalized_mantissa, inter_rounding_bits} =
|
105 |
|
|
(adder_mantissa[size_mantissa + 1])? ({~adder_mantissa[size_mantissa : 0], ~initial_rounding_bits}) :
|
106 |
|
|
({adder_mantissa[size_mantissa : 0], initial_rounding_bits});
|
107 |
8 |
constantin |
|
108 |
|
|
//instantiate FarPath component
|
109 |
9 |
constantin |
FarPath #( .size_in_mantissa(size_mantissa),
|
110 |
8 |
constantin |
.size_out_mantissa(size_mantissa),
|
111 |
|
|
.size_exponent(size_exponent),
|
112 |
|
|
.pipeline(pipeline),
|
113 |
|
|
.pipeline_pos(pipeline_pos),
|
114 |
|
|
.size_counter(size_counter),
|
115 |
9 |
constantin |
.double_size_in_mantissa(double_size_mantissa))
|
116 |
|
|
FarPath_instance ( .unnormalized_mantissa(unnormalized_mantissa),
|
117 |
|
|
.inter_rounding_bits(inter_rounding_bits),
|
118 |
|
|
.exp_inter(exp_inter),
|
119 |
|
|
.resulted_m_o(fp_resulted_m_o),
|
120 |
|
|
.resulted_e_o(fp_resulted_e_o));
|
121 |
|
|
|
122 |
|
|
//instantiate ClosePath component
|
123 |
|
|
ClosePath #(.size_in_mantissa(size_mantissa),
|
124 |
8 |
constantin |
.size_out_mantissa(size_mantissa),
|
125 |
|
|
.size_exponent(size_exponent),
|
126 |
|
|
.pipeline(pipeline),
|
127 |
|
|
.pipeline_pos(pipeline_pos),
|
128 |
|
|
.size_counter(size_counter),
|
129 |
9 |
constantin |
.double_size_in_mantissa(double_size_mantissa))
|
130 |
|
|
ClosePath_instance( .unnormalized_mantissa(unnormalized_mantissa),
|
131 |
|
|
.inter_rounding_bits(inter_rounding_bits),
|
132 |
|
|
.exp_inter(exp_inter),
|
133 |
|
|
.resulted_m_o(cp_resulted_m_o),
|
134 |
|
|
.resulted_e_o(cp_resulted_e_o));
|
135 |
|
|
|
136 |
|
|
//compute exception_field
|
137 |
|
|
special_cases #( .size_exception_field(size_exception_field),
|
138 |
|
|
.zero(zero),
|
139 |
|
|
.normal_number(normal_number),
|
140 |
|
|
.infinity(infinity),
|
141 |
|
|
.NaN(NaN))
|
142 |
|
|
special_cases_instance( .sp_case_a_number(sp_case_a_number),
|
143 |
|
|
.sp_case_b_number(sp_case_b_number),
|
144 |
|
|
.sp_case_result_o(resulted_exception_field));
|
145 |
|
|
|
146 |
|
|
//set zero_flag in case of equal numbers
|
147 |
|
|
assign zero_flag = (exp_difference > 1)? ~(|fp_resulted_m_o) : ~(|cp_resulted_m_o);
|
148 |
8 |
constantin |
|
149 |
9 |
constantin |
assign resulted_sign = (eff_op)?
|
150 |
|
|
(!a_greater_exponent[size_exponent]? (!b_greater_exponent[size_exponent]? ~adder_mantissa[size_mantissa+1] : s_a_number) : ~s_b_number) :
|
151 |
|
|
s_a_number;
|
152 |
|
|
|
153 |
|
|
assign resulted_number_o = (zero_flag)? {size{1'b0}} :
|
154 |
|
|
(exp_difference > 1)? {resulted_exception_field, resulted_sign, fp_resulted_e_o, fp_resulted_m_o[size_mantissa-2 : 0]}:
|
155 |
8 |
constantin |
{resulted_exception_field, resulted_sign, cp_resulted_e_o, cp_resulted_m_o[size_mantissa-2 : 0]};
|
156 |
|
|
endmodule
|