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 |
10 |
constantin |
parameter [size_exception_field - 1 : 0] normal_number = 1, //01
|
27 |
8 |
constantin |
parameter [size_exception_field - 1 : 0] infinity = 2, //10
|
28 |
|
|
parameter [size_exception_field - 1 : 0] NaN = 3, //11
|
29 |
10 |
constantin |
parameter [1 : 0] FP_operation = 0,
|
30 |
|
|
parameter [1 : 0] FP_to_int = 1,
|
31 |
|
|
parameter [1 : 0] int_operation = 3,
|
32 |
|
|
|
33 |
8 |
constantin |
parameter pipeline = 0,
|
34 |
|
|
parameter pipeline_pos = 0, // 8 bits
|
35 |
|
|
parameter double_size_mantissa = size_mantissa + size_mantissa,
|
36 |
|
|
parameter double_size_counter = size_counter + 1,
|
37 |
|
|
parameter size = size_mantissa + size_exponent + size_exception_field)
|
38 |
|
|
|
39 |
10 |
constantin |
( input [1:0] conversion,
|
40 |
|
|
input sub,
|
41 |
9 |
constantin |
input [size - 1 : 0] a_number_i,
|
42 |
|
|
input [size - 1 : 0] b_number_i,
|
43 |
|
|
output[size - 1 : 0] resulted_number_o);
|
44 |
8 |
constantin |
|
45 |
9 |
constantin |
wire [size_exception_field - 1 : 0] sp_case_a_number, sp_case_b_number;
|
46 |
8 |
constantin |
wire [size_mantissa - 1 : 0] m_a_number, m_b_number;
|
47 |
|
|
wire [size_exponent - 1 : 0] e_a_number, e_b_number;
|
48 |
9 |
constantin |
wire s_a_number, s_b_number;
|
49 |
|
|
|
50 |
|
|
wire [size_exponent : 0] a_greater_exponent, b_greater_exponent;
|
51 |
|
|
|
52 |
8 |
constantin |
wire [size_exponent - 1 : 0] exp_difference;
|
53 |
9 |
constantin |
wire [size_exponent : 0] exp_inter;
|
54 |
|
|
wire [size_mantissa - 1 : 0] shifted_m_b;
|
55 |
|
|
wire [size_mantissa - 1 : 0] initial_rounding_bits, inter_rounding_bits;
|
56 |
|
|
wire eff_op;
|
57 |
8 |
constantin |
|
58 |
9 |
constantin |
wire [size_mantissa + 1 : 0] adder_mantissa;
|
59 |
|
|
wire [size_mantissa : 0] unnormalized_mantissa;
|
60 |
|
|
|
61 |
8 |
constantin |
wire [size_mantissa-1 : 0] fp_resulted_m_o, cp_resulted_m_o;
|
62 |
|
|
wire [size_exponent-1 : 0] fp_resulted_e_o, cp_resulted_e_o;
|
63 |
|
|
|
64 |
9 |
constantin |
wire [size_exception_field - 1 : 0] resulted_exception_field;
|
65 |
8 |
constantin |
wire resulted_sign;
|
66 |
9 |
constantin |
|
67 |
|
|
wire zero_flag;
|
68 |
|
|
|
69 |
8 |
constantin |
|
70 |
|
|
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 |
|
|
//find the difference between exponents
|
83 |
|
|
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 |
8 |
constantin |
|
91 |
10 |
constantin |
effective_op effective_op_instance( .a_sign(s_a_number), .b_sign(s_b_number), .sub(sub), .eff_op(eff_op));
|
92 |
8 |
constantin |
|
93 |
10 |
constantin |
|
94 |
8 |
constantin |
//instantiate FarPath component
|
95 |
9 |
constantin |
FarPath #( .size_in_mantissa(size_mantissa),
|
96 |
8 |
constantin |
.size_out_mantissa(size_mantissa),
|
97 |
|
|
.size_exponent(size_exponent),
|
98 |
|
|
.pipeline(pipeline),
|
99 |
|
|
.pipeline_pos(pipeline_pos),
|
100 |
|
|
.size_counter(size_counter),
|
101 |
9 |
constantin |
.double_size_in_mantissa(double_size_mantissa))
|
102 |
10 |
constantin |
FarPath_instance ( .m_a_number(m_a_number),
|
103 |
|
|
.m_b_number(m_b_number),
|
104 |
|
|
.eff_op(eff_op),
|
105 |
|
|
.exp_difference(exp_difference),
|
106 |
9 |
constantin |
.exp_inter(exp_inter),
|
107 |
|
|
.resulted_m_o(fp_resulted_m_o),
|
108 |
|
|
.resulted_e_o(fp_resulted_e_o));
|
109 |
|
|
|
110 |
|
|
//instantiate ClosePath component
|
111 |
|
|
ClosePath #(.size_in_mantissa(size_mantissa),
|
112 |
8 |
constantin |
.size_out_mantissa(size_mantissa),
|
113 |
|
|
.size_exponent(size_exponent),
|
114 |
|
|
.pipeline(pipeline),
|
115 |
|
|
.pipeline_pos(pipeline_pos),
|
116 |
|
|
.size_counter(size_counter),
|
117 |
9 |
constantin |
.double_size_in_mantissa(double_size_mantissa))
|
118 |
10 |
constantin |
ClosePath_instance( .m_a_number(m_a_number),
|
119 |
|
|
.m_b_number(m_b_number),
|
120 |
|
|
.exp_difference(exp_difference[0]),
|
121 |
9 |
constantin |
.exp_inter(exp_inter),
|
122 |
|
|
.resulted_m_o(cp_resulted_m_o),
|
123 |
10 |
constantin |
.resulted_e_o(cp_resulted_e_o),
|
124 |
|
|
.ovf(ovf));
|
125 |
9 |
constantin |
|
126 |
|
|
//compute exception_field
|
127 |
|
|
special_cases #( .size_exception_field(size_exception_field),
|
128 |
|
|
.zero(zero),
|
129 |
|
|
.normal_number(normal_number),
|
130 |
|
|
.infinity(infinity),
|
131 |
|
|
.NaN(NaN))
|
132 |
|
|
special_cases_instance( .sp_case_a_number(sp_case_a_number),
|
133 |
|
|
.sp_case_b_number(sp_case_b_number),
|
134 |
|
|
.sp_case_result_o(resulted_exception_field));
|
135 |
|
|
|
136 |
|
|
//set zero_flag in case of equal numbers
|
137 |
10 |
constantin |
assign zero_flag = (exp_difference > 1 | !eff_op)? ~(|fp_resulted_m_o) : ~(|cp_resulted_m_o);
|
138 |
|
|
|
139 |
|
|
assign resulted_sign = (exp_difference > 1 | !eff_op)? (!a_greater_exponent[size_exponent]? s_a_number : s_b_number) : ~ovf;
|
140 |
|
|
|
141 |
9 |
constantin |
assign resulted_number_o = (zero_flag)? {size{1'b0}} :
|
142 |
10 |
constantin |
(exp_difference > 1 | !eff_op)? {resulted_exception_field, resulted_sign, fp_resulted_e_o, fp_resulted_m_o[size_mantissa-2 : 0]}:
|
143 |
8 |
constantin |
{resulted_exception_field, resulted_sign, cp_resulted_e_o, cp_resulted_m_o[size_mantissa-2 : 0]};
|
144 |
|
|
endmodule
|