| 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 |
|
|
(sub, a_number_i, b_number_i, resulted_number_o);
|
| 36 |
|
|
input sub;
|
| 37 |
|
|
input [size - 1 : 0] a_number_i;
|
| 38 |
|
|
input [size - 1 : 0] b_number_i;
|
| 39 |
|
|
output[size - 1 : 0] resulted_number_o;
|
| 40 |
|
|
|
| 41 |
|
|
wire [size_mantissa - 1 : 0] m_a_number, m_b_number;
|
| 42 |
|
|
wire [size_exponent - 1 : 0] e_a_number, e_b_number;
|
| 43 |
|
|
wire s_a_number, s_b_number;
|
| 44 |
|
|
wire [size_exception_field - 1 : 0] sp_case_a_number, sp_case_b_number;
|
| 45 |
|
|
|
| 46 |
|
|
wire [size_exponent - 1 : 0] exp_difference;
|
| 47 |
|
|
wire [size_exponent - 1 : 0] modify_exp_a, modify_exp_b;
|
| 48 |
|
|
wire [double_size_mantissa - 1 : 0] shifted_m_a, shifted_m_b;
|
| 49 |
|
|
|
| 50 |
|
|
wire [size_mantissa-1 : 0] fp_resulted_m_o, cp_resulted_m_o;
|
| 51 |
|
|
wire [size_exponent-1 : 0] fp_resulted_e_o, cp_resulted_e_o;
|
| 52 |
|
|
|
| 53 |
|
|
wire resulted_sign;
|
| 54 |
|
|
wire [size_exception_field - 1 : 0] resulted_exception_field;
|
| 55 |
|
|
|
| 56 |
|
|
assign m_a_number = {1'b1, a_number_i[size_mantissa - 2 :0]};
|
| 57 |
|
|
assign m_b_number = {1'b1, b_number_i[size_mantissa - 2 :0]};
|
| 58 |
|
|
assign e_a_number = a_number_i[size_mantissa + size_exponent - 1 : size_mantissa - 1];
|
| 59 |
|
|
assign e_b_number = b_number_i[size_mantissa + size_exponent - 1 : size_mantissa - 1];
|
| 60 |
|
|
assign s_a_number = a_number_i[size - size_exception_field - 1];
|
| 61 |
|
|
assign s_b_number = b_number_i[size - size_exception_field - 1];
|
| 62 |
|
|
assign sp_case_a_number = a_number_i[size - 1 : size - size_exception_field];
|
| 63 |
|
|
assign sp_case_b_number = b_number_i[size - 1 : size - size_exception_field];
|
| 64 |
|
|
|
| 65 |
|
|
//find the difference between exponents
|
| 66 |
|
|
assign exp_difference = (e_a_number > e_b_number)? (e_a_number - e_b_number) : (e_b_number - e_a_number);
|
| 67 |
|
|
assign {modify_exp_a, modify_exp_b} = (e_a_number > e_b_number)? {8'd0, exp_difference} : {exp_difference, 8'd0};
|
| 68 |
|
|
|
| 69 |
|
|
//shift the right mantissa
|
| 70 |
|
|
shifter #( .INPUT_SIZE(size_mantissa),
|
| 71 |
|
|
.SHIFT_SIZE(size_exponent),
|
| 72 |
|
|
.OUTPUT_SIZE(double_size_mantissa),
|
| 73 |
|
|
.DIRECTION(1'b0),
|
| 74 |
|
|
.PIPELINE(pipeline),
|
| 75 |
|
|
.POSITION(pipeline_pos))
|
| 76 |
|
|
m_a_shifter_instance( .a(m_a_number),
|
| 77 |
|
|
.arith(1'b0),
|
| 78 |
|
|
.shft(modify_exp_a),
|
| 79 |
|
|
.shifted_a(shifted_m_a));
|
| 80 |
|
|
|
| 81 |
|
|
shifter #( .INPUT_SIZE(size_mantissa),
|
| 82 |
|
|
.SHIFT_SIZE(size_exponent),
|
| 83 |
|
|
.OUTPUT_SIZE(double_size_mantissa),
|
| 84 |
|
|
.DIRECTION(1'b0),
|
| 85 |
|
|
.PIPELINE(pipeline),
|
| 86 |
|
|
.POSITION(pipeline_pos))
|
| 87 |
|
|
m_b_shifter_instance( .a(m_b_number),
|
| 88 |
|
|
.arith(1'b0),
|
| 89 |
|
|
.shft(modify_exp_b),
|
| 90 |
|
|
.shifted_a(shifted_m_b));
|
| 91 |
|
|
|
| 92 |
|
|
//istantiate effective_operation_component
|
| 93 |
|
|
effective_op effective_op_instance( .a_sign(s_a_number), .b_sign(s_b_number), .sub(sub), .eff_op(eff_op));
|
| 94 |
|
|
|
| 95 |
|
|
|
| 96 |
|
|
|
| 97 |
|
|
//instantiate special_cases component
|
| 98 |
|
|
special_cases #( .size_exception_field(size_exception_field),
|
| 99 |
|
|
.zero(zero),
|
| 100 |
|
|
.normal_number(normal_number),
|
| 101 |
|
|
.infinity(infinity),
|
| 102 |
|
|
.NaN(NaN))
|
| 103 |
|
|
special_cases_instance ( .sp_case_a_number(sp_case_a_number),
|
| 104 |
|
|
.sp_case_b_number(sp_case_b_number),
|
| 105 |
|
|
.sp_case_result_o(resulted_exception_field));
|
| 106 |
|
|
|
| 107 |
|
|
//instantiate FarPath component
|
| 108 |
|
|
FarPath #( .size_in_mantissa(double_size_mantissa),
|
| 109 |
|
|
.size_out_mantissa(size_mantissa),
|
| 110 |
|
|
.size_exponent(size_exponent),
|
| 111 |
|
|
.pipeline(pipeline),
|
| 112 |
|
|
.pipeline_pos(pipeline_pos),
|
| 113 |
|
|
.size_counter(size_counter),
|
| 114 |
|
|
.double_size_counter(double_size_counter),
|
| 115 |
|
|
.double_size_mantissa(double_size_mantissa))
|
| 116 |
|
|
FarPath_instance ( .eff_op(eff_op),
|
| 117 |
|
|
.m_a_number(shifted_m_a),
|
| 118 |
|
|
.m_b_number(shifted_m_b),
|
| 119 |
|
|
.e_a_number(e_a_number),
|
| 120 |
|
|
.e_b_number(e_b_number),
|
| 121 |
|
|
.resulted_m_o(fp_resulted_m_o),
|
| 122 |
|
|
.resulted_e_o(fp_resulted_e_o));
|
| 123 |
|
|
|
| 124 |
|
|
|
| 125 |
|
|
//instantiate ClosePath component
|
| 126 |
|
|
ClosePath #(.size_in_mantissa(double_size_mantissa),
|
| 127 |
|
|
.size_out_mantissa(size_mantissa),
|
| 128 |
|
|
.size_exponent(size_exponent),
|
| 129 |
|
|
.pipeline(pipeline),
|
| 130 |
|
|
.pipeline_pos(pipeline_pos),
|
| 131 |
|
|
.size_counter(size_counter),
|
| 132 |
|
|
.double_size_counter(double_size_counter),
|
| 133 |
|
|
.double_size_mantissa(double_size_mantissa))
|
| 134 |
|
|
ClosePath_instance( .eff_op(eff_op),
|
| 135 |
|
|
.m_a_number(shifted_m_a),
|
| 136 |
|
|
.m_b_number(shifted_m_b),
|
| 137 |
|
|
.e_a_number(e_a_number),
|
| 138 |
|
|
.e_b_number(e_b_number),
|
| 139 |
|
|
.resulted_m_o(cp_resulted_m_o),
|
| 140 |
|
|
.resulted_e_o(cp_resulted_e_o));
|
| 141 |
|
|
|
| 142 |
|
|
assign resulted_sign = (eff_op)? ((shifted_m_a > shifted_m_b)? s_a_number : ~s_a_number) : s_a_number;
|
| 143 |
|
|
|
| 144 |
|
|
assign resulted_number_o = (exp_difference > 1)? {resulted_exception_field, resulted_sign, fp_resulted_e_o, fp_resulted_m_o[size_mantissa-2 : 0]}:
|
| 145 |
|
|
{resulted_exception_field, resulted_sign, cp_resulted_e_o, cp_resulted_m_o[size_mantissa-2 : 0]};
|
| 146 |
|
|
endmodule
|