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

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:    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 13 constantin
        wire swap;
67 9 constantin
 
68
        wire zero_flag;
69
 
70 8 constantin
 
71
        assign e_a_number       = a_number_i[size_mantissa + size_exponent - 1 : size_mantissa - 1];
72
        assign e_b_number = b_number_i[size_mantissa + size_exponent - 1 : size_mantissa - 1];
73
        assign s_a_number = a_number_i[size - size_exception_field - 1];
74
        assign s_b_number = b_number_i[size - size_exception_field - 1];
75
        assign sp_case_a_number = a_number_i[size - 1 : size - size_exception_field];
76
        assign sp_case_b_number = b_number_i[size - 1 : size - size_exception_field];
77 9 constantin
 
78
 
79
        //find the greater exponent
80
        assign a_greater_exponent = e_a_number - e_b_number;
81
        assign b_greater_exponent = e_b_number - e_a_number;
82
 
83
        //find the difference between exponents
84
        assign exp_difference   = (a_greater_exponent[size_exponent])? b_greater_exponent[size_exponent - 1 : 0] : a_greater_exponent[size_exponent - 1 : 0];
85
        assign exp_inter                = (b_greater_exponent[size_exponent])? {1'b0, e_a_number} : {1'b0, e_b_number};
86
 
87
        //set shifter always on m_b_number
88 13 constantin
        assign {swap, m_a_number, m_b_number} = (b_greater_exponent[size_exponent])?
89
                                                                                                        {1'b0, {1'b1, a_number_i[size_mantissa - 2 :0]}, {1'b1, b_number_i[size_mantissa - 2 :0]}} :
90
                                                                                                        {1'b1, {1'b1, b_number_i[size_mantissa - 2 :0]}, {1'b1, a_number_i[size_mantissa - 2 :0]}};
91 8 constantin
 
92 10 constantin
        effective_op effective_op_instance( .a_sign(s_a_number), .b_sign(s_b_number), .sub(sub), .eff_op(eff_op));
93 8 constantin
 
94 10 constantin
 
95 8 constantin
        //instantiate FarPath component
96 9 constantin
        FarPath #(      .size_in_mantissa(size_mantissa),
97 8 constantin
                                        .size_out_mantissa(size_mantissa),
98
                                        .size_exponent(size_exponent),
99
                                        .pipeline(pipeline),
100
                                        .pipeline_pos(pipeline_pos),
101
                                        .size_counter(size_counter),
102 9 constantin
                                        .double_size_in_mantissa(double_size_mantissa))
103 10 constantin
                FarPath_instance (      .m_a_number(m_a_number),
104
                                                        .m_b_number(m_b_number),
105
                                                        .eff_op(eff_op),
106
                                                        .exp_difference(exp_difference),
107 9 constantin
                                    .exp_inter(exp_inter),
108
                                    .resulted_m_o(fp_resulted_m_o),
109
                                    .resulted_e_o(fp_resulted_e_o));
110
 
111
        //instantiate ClosePath component
112
        ClosePath #(.size_in_mantissa(size_mantissa),
113 8 constantin
                                        .size_out_mantissa(size_mantissa),
114
                                        .size_exponent(size_exponent),
115
                                        .pipeline(pipeline),
116
                                        .pipeline_pos(pipeline_pos),
117
                                        .size_counter(size_counter),
118 9 constantin
                                        .double_size_in_mantissa(double_size_mantissa))
119 10 constantin
                ClosePath_instance(     .m_a_number(m_a_number),
120
                                                        .m_b_number(m_b_number),
121
                                                        .exp_difference(exp_difference[0]),
122 9 constantin
                                                                .exp_inter(exp_inter),
123
                                                                .resulted_m_o(cp_resulted_m_o),
124 10 constantin
                                                                .resulted_e_o(cp_resulted_e_o),
125
                                                                .ovf(ovf));
126 9 constantin
 
127
        //compute exception_field
128
        special_cases   #(      .size_exception_field(size_exception_field),
129
                                                        .zero(zero),
130
                                                        .normal_number(normal_number),
131
                                                        .infinity(infinity),
132
                                                        .NaN(NaN))
133
                special_cases_instance( .sp_case_a_number(sp_case_a_number),
134
                                                                                .sp_case_b_number(sp_case_b_number),
135
                                                                                .sp_case_result_o(resulted_exception_field));
136
 
137
        //set zero_flag in case of equal numbers
138 10 constantin
        assign zero_flag = (exp_difference > 1 | !eff_op)? ~(|fp_resulted_m_o) : ~(|cp_resulted_m_o);
139
 
140 13 constantin
        assign resulted_sign = (exp_difference > 1 | !eff_op)? (!a_greater_exponent[size_exponent]? s_a_number : (eff_op? ~s_b_number : s_b_number)) : (ovf ^ swap);
141
 
142 9 constantin
        assign resulted_number_o = (zero_flag)? {size{1'b0}} :
143 10 constantin
                                                                        (exp_difference > 1 | !eff_op)?         {resulted_exception_field, resulted_sign, fp_resulted_e_o, fp_resulted_m_o[size_mantissa-2 : 0]}:
144 8 constantin
                                                                                                                                                {resulted_exception_field, resulted_sign, cp_resulted_e_o, cp_resulted_m_o[size_mantissa-2 : 0]};
145
endmodule

powered by: WebSVN 2.1.0

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