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 8

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
module SinglePathFPAdder #(     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
 
37
        input sub;
38
        input [size - 1 : 0] a_number_i;
39
        input [size - 1 : 0] b_number_i;
40
        output[size - 1 : 0] resulted_number_o;
41
 
42
        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
        wire [size_exception_field - 1 : 0] sp_case_a_number, sp_case_b_number;
46
 
47
        wire [size_exponent - 1 : 0] exp_difference;
48
        wire [size_exponent - 1 : 0] modify_exp_a, modify_exp_b;
49
        wire [double_size_mantissa - 1 : 0] shifted_m_a, shifted_m_b;
50
        wire eff_op;
51
 
52
        wire [double_size_mantissa : 0] unnormalized_mantissa;
53
        wire [double_size_counter-1: 0] lzs;
54
        wire [size_mantissa-1: 0] unrounded_mantissa;
55
 
56
        wire [size_mantissa-1: 0] resulted_mantissa;
57
        wire [size_exponent-1: 0] resulted_exponent;
58
        wire resulted_sign;
59
        wire [size_exception_field - 1 : 0] resulted_exception_field;
60
 
61
        wire [size_mantissa + 1 : 0] dummy_bits;
62
 
63
        assign m_a_number = {1'b1, a_number_i[size_mantissa - 2 :0]};
64
        assign m_b_number       = {1'b1, b_number_i[size_mantissa - 2 :0]};
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
 
72
        //find the difference between exponents
73
        assign exp_difference = (e_a_number > e_b_number)? (e_a_number - e_b_number) : (e_b_number - e_a_number);
74
 
75
        assign {modify_exp_a, modify_exp_b} = (e_a_number > e_b_number)? {8'd0, exp_difference} : {exp_difference, 8'd0};
76
 
77
        //shift the right mantissa
78
        shifter #(      .INPUT_SIZE(size_mantissa),
79
                                        .SHIFT_SIZE(size_exponent),
80
                                        .OUTPUT_SIZE(double_size_mantissa),
81
                                        .DIRECTION(1'b0), //0=right, 1=left
82
                                        .PIPELINE(pipeline),
83
                                        .POSITION(pipeline_pos))
84
                m_a_shifter_instance(   .a(m_a_number),//mantissa
85
                                                                                .arith(1'b0),//logical shift
86
                                                                                .shft(modify_exp_a),
87
                                                                                .shifted_a(shifted_m_a));
88
 
89
        shifter #(      .INPUT_SIZE(size_mantissa),
90
                                        .SHIFT_SIZE(size_exponent),
91
                                        .OUTPUT_SIZE(double_size_mantissa),
92
                                        .DIRECTION(1'b0), //0=right, 1=left
93
                                        .PIPELINE(pipeline),
94
                                        .POSITION(pipeline_pos))
95
                m_b_shifter_instance(   .a(m_b_number),//mantissa
96
                                                                                .arith(1'b0),//logical shift
97
                                                                                .shft(modify_exp_b),
98
                                                                                .shifted_a(shifted_m_b));
99
 
100
        //istantiate effective_operation_component
101
        effective_op effective_op_instance( .a_sign(s_a_number), .b_sign(s_b_number), .sub(sub), .eff_op(eff_op));
102
 
103
        //compute unnormalized_mantissa
104
        assign unnormalized_mantissa = (eff_op)? ((shifted_m_a > shifted_m_b)? (shifted_m_a - shifted_m_b) : (shifted_m_b - shifted_m_a)) :
105
                                                                                                                        shifted_m_a + shifted_m_b;
106
 
107
        //compute leading_zeros over unnormalized mantissa
108
        leading_zeros #(        .SIZE_INT(double_size_mantissa + 1'b1), .SIZE_COUNTER(double_size_counter), .PIPELINE(pipeline))
109
                leading_zeros_instance (.a(unnormalized_mantissa),
110
                                                                                .ovf(1'b0),
111
                                                                                .lz(lzs));
112
 
113
        //compute shifting over unnormalized_mantissa
114
        shifter #(      .INPUT_SIZE(double_size_mantissa + 1'b1),
115
                                        .SHIFT_SIZE(double_size_counter),
116
                                        .OUTPUT_SIZE(double_size_mantissa + 2'd2),
117
                                        .DIRECTION(1'b1), //0=right, 1=left
118
                                        .PIPELINE(pipeline),
119
                                        .POSITION(pipeline_pos))
120
                shifter_instance(       .a(unnormalized_mantissa),//mantissa
121
                                                                .arith(1'b0),//logical shift
122
                                                                .shft(lzs),
123
                                                                .shifted_a({unrounded_mantissa, dummy_bits}));
124
 
125
        //
126
        //assign g = dummy_bits[size_mantissa + 1];
127
        //assign sticky = |(dummy_bits[size_mantissa : 0]);
128
        //assign round_dec = g & (unrounded_mantissa[0] | sticky);
129
 
130
        //instantiate rounding_component
131
        rounding #(     .SIZE_MOST_S_MANTISSA(size_mantissa),
132
                                .SIZE_LEAST_S_MANTISSA(size_mantissa + 2'd2))
133
                rounding_instance(      .unrounded_mantissa(unrounded_mantissa),
134
                                    .dummy_bits(dummy_bits),
135
                                    .rounded_mantissa(resulted_mantissa));
136
 
137
 
138
        //compute resulted_exponent
139
        assign resulted_exponent = (e_a_number >= e_b_number)? (e_a_number - lzs + 1'b1) : (e_b_number - lzs + 1'b1);
140
 
141
        //compute resulted_sign
142
        assign resulted_sign = (eff_op)? ((shifted_m_a > shifted_m_b)? s_a_number : ~s_a_number) : s_a_number;
143
 
144
        //compute exception_field
145
        special_cases   #(      .size_exception_field(size_exception_field),
146
                                                        .zero(zero),
147
                                                        .normal_number(normal_number),
148
                                                        .infinity(infinity),
149
                                                        .NaN(NaN))
150
                special_cases_instance( .sp_case_a_number(sp_case_a_number),
151
                                                                                .sp_case_b_number(sp_case_b_number),
152
                                                                                .sp_case_result_o(resulted_exception_field));
153
 
154
        //generate final result                                                 
155
        assign resulted_number_o = {resulted_exception_field, resulted_sign, resulted_exponent, resulted_mantissa[size_mantissa-2 : 0]};
156
 
157
endmodule

powered by: WebSVN 2.1.0

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