OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1200/] [rtl/] [verilog/] [or1200_fpu_pre_norm_addsub.v] - Blame information for rev 669

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 258 julius
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  or1200_fpu_pre_norm_addsub                                  ////
4
////                                                              ////
5
////  This file is part of the OpenRISC 1200 project              ////
6
////  http://opencores.org/project,or1k                           ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  pre-normalization entity for the addition/subtraction unit  ////
10
////                                                              ////
11
////  To Do:                                                      ////
12
////                                                              ////
13
////                                                              ////
14
////  Author(s):                                                  ////
15
////      - Original design (FPU100) -                            ////
16
////        Jidan Al-eryani, jidan@gmx.net                        ////
17
////      - Conv. to Verilog and inclusion in OR1200 -            ////
18
////        Julius Baxter, julius@opencores.org                   ////
19
////                                                              ////
20
//////////////////////////////////////////////////////////////////////
21
//
22
//  Copyright (C) 2006, 2010
23
//
24
//      This source file may be used and distributed without        
25
//      restriction provided that this copyright statement is not   
26
//      removed from the file and that any derivative work contains 
27
//      the original copyright notice and the associated disclaimer.
28
//                                                           
29
//              THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     
30
//      EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   
31
//      TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   
32
//      FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      
33
//      OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         
34
//      INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    
35
//      (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   
36
//      GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        
37
//      BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  
38
//      LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  
39
//      (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  
40
//      OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         
41
//      POSSIBILITY OF SUCH DAMAGE. 
42
//
43
 
44
module or1200_fpu_pre_norm_addsub (
45
 
46
                        clk_i,
47
                        opa_i,
48
                        opb_i,
49
                        fracta_28_o,
50
                        fractb_28_o,
51
                        exp_o
52
                        );
53
 
54
   parameter FP_WIDTH = 32;
55
   parameter MUL_SERIAL = 0; // 0 for parallel multiplier, 1 for serial
56
   parameter MUL_COUNT = 11; //11 for parallel multiplier, 34 for serial
57
   parameter FRAC_WIDTH = 23;
58
   parameter EXP_WIDTH = 8;
59
   parameter ZERO_VECTOR = 31'd0;
60
   parameter INF = 31'b1111111100000000000000000000000;
61
   parameter QNAN = 31'b1111111110000000000000000000000;
62
   parameter SNAN = 31'b1111111100000000000000000000001;
63
 
64
 
65
   input clk_i;
66
   input [FP_WIDTH-1:0] opa_i;
67
   input [FP_WIDTH-1:0] opb_i;
68
   // carry(1) & hidden(1) & fraction(23) & guard(1) & round(1) & sticky(1)
69
   output reg [FRAC_WIDTH+4:0] fracta_28_o;
70
   output reg [FRAC_WIDTH+4:0] fractb_28_o;
71
   output reg [EXP_WIDTH-1:0]  exp_o;
72
 
73
   reg [EXP_WIDTH-1 : 0]       s_exp_o ;
74
   wire [FRAC_WIDTH+4 : 0]     s_fracta_28_o, s_fractb_28_o ;
75
   wire [EXP_WIDTH-1 : 0]      s_expa;
76
   wire [EXP_WIDTH-1 : 0]      s_expb ;
77
   wire [FRAC_WIDTH-1 : 0]     s_fracta;
78
   wire [FRAC_WIDTH-1 : 0]     s_fractb ;
79
   wire [FRAC_WIDTH+4 : 0]     s_fracta_28;
80
 
81
   wire [FRAC_WIDTH+4 : 0]     s_fractb_28 ;
82
 
83
   wire [FRAC_WIDTH+4 : 0]     s_fract_sm_28;
84
   wire [FRAC_WIDTH+4 : 0]     s_fract_shr_28 ;
85
 
86
   reg [EXP_WIDTH-1 : 0]       s_exp_diff ;
87
   reg [5 : 0]                  s_rzeros ;
88
   wire                        s_expa_eq_expb;
89
   wire                        s_expa_gt_expb;
90
   wire                        s_fracta_1;
91
   wire                        s_fractb_1;
92
   wire                        s_op_dn,s_opa_dn, s_opb_dn;
93
   wire [1 : 0]         s_mux_diff ;
94
   wire                        s_mux_exp;
95
   wire                        s_sticky;
96
 
97
 
98
   assign s_expa = opa_i[30:23];
99
   assign s_expb = opb_i[30:23];
100
   assign s_fracta = opa_i[22:0];
101
   assign s_fractb = opb_i[22:0];
102
 
103
   always @(posedge clk_i)
104
     begin
105
        exp_o <= s_exp_o;
106
        fracta_28_o <= s_fracta_28_o;
107
        fractb_28_o <= s_fractb_28_o;
108
     end
109
 
110
   assign s_expa_eq_expb = (s_expa == s_expb);
111
 
112
   assign s_expa_gt_expb = (s_expa > s_expb);
113
 
114
   // '1' if fraction is not zero
115
   assign s_fracta_1 = |s_fracta;
116
   assign s_fractb_1 = |s_fractb;
117
 
118
   // opa or Opb is denormalized
119
   assign s_opa_dn = !(|s_expa);
120
   assign s_opb_dn = !(|s_expb);
121
   assign s_op_dn = s_opa_dn | s_opb_dn;
122
 
123
   // Output larger exponent
124
   assign s_mux_exp = s_expa_gt_expb;
125
 
126
   always @(posedge clk_i)
127
     s_exp_o <= s_mux_exp ? s_expa : s_expb;
128
 
129
   // convert to an easy to handle floating-point format
130
   assign s_fracta_28 = s_opa_dn ?
131
                        {2'b00, s_fracta, 3'b000} : {2'b01, s_fracta, 3'b000};
132
   assign s_fractb_28 = s_opb_dn ?
133
                        {2'b00, s_fractb, 3'b000} : {2'b01, s_fractb, 3'b000};
134
 
135
   assign s_mux_diff = {s_expa_gt_expb, s_opa_dn ^ s_opb_dn};
136
 
137
   // calculate howmany postions the fraction will be shifted
138
   always @(posedge clk_i)
139
     begin
140
        case(s_mux_diff)
141
           2'b00: s_exp_diff <= s_expb - s_expa;
142
           2'b01: s_exp_diff <= s_expb - (s_expa + 8'd1);
143
           2'b10: s_exp_diff <= s_expa - s_expb;
144
           2'b11: s_exp_diff <= s_expa - (s_expb + 8'd1);
145
        endcase
146
     end
147
 
148
   assign s_fract_sm_28 =  s_expa_gt_expb ? s_fractb_28 : s_fracta_28;
149
 
150
   // shift-right the fraction if necessary
151
   assign s_fract_shr_28 = s_fract_sm_28 >> s_exp_diff;
152
 
153
   // count the zeros from right to check if result is inexact
154
   always @(s_fract_sm_28)
155 364 julius
     casez(s_fract_sm_28) // synopsys full_case parallel_case
156
       28'b???????????????????????????1: s_rzeros = 0;
157
       28'b??????????????????????????10: s_rzeros = 1;
158
       28'b?????????????????????????100: s_rzeros = 2;
159
       28'b????????????????????????1000: s_rzeros = 3;
160
       28'b???????????????????????10000: s_rzeros = 4;
161
       28'b??????????????????????100000: s_rzeros = 5;
162
       28'b?????????????????????1000000: s_rzeros = 6;
163
       28'b????????????????????10000000: s_rzeros = 7;
164
       28'b???????????????????100000000: s_rzeros = 8;
165
       28'b??????????????????1000000000: s_rzeros = 9;
166
       28'b?????????????????10000000000: s_rzeros = 10;
167
       28'b????????????????100000000000: s_rzeros = 11;
168
       28'b???????????????1000000000000: s_rzeros = 12;
169
       28'b??????????????10000000000000: s_rzeros = 13;
170
       28'b?????????????100000000000000: s_rzeros = 14;
171
       28'b????????????1000000000000000: s_rzeros = 15;
172
       28'b???????????10000000000000000: s_rzeros = 16;
173
       28'b??????????100000000000000000: s_rzeros = 17;
174
       28'b?????????1000000000000000000: s_rzeros = 18;
175
       28'b????????10000000000000000000: s_rzeros = 19;
176
       28'b???????100000000000000000000: s_rzeros = 20;
177
       28'b??????1000000000000000000000: s_rzeros = 21;
178
       28'b?????10000000000000000000000: s_rzeros = 22;
179
       28'b????100000000000000000000000: s_rzeros = 23;
180
       28'b???1000000000000000000000000: s_rzeros = 24;
181
       28'b??10000000000000000000000000: s_rzeros = 25;
182
       28'b?100000000000000000000000000: s_rzeros = 26;
183
       28'b1000000000000000000000000000: s_rzeros = 27;
184
       28'b0000000000000000000000000000: s_rzeros = 28;
185 258 julius
     endcase // casex (s_fract_sm_28)
186
 
187 364 julius
   assign s_sticky = (s_exp_diff > {2'b00,s_rzeros}) & (|s_fract_sm_28);
188 258 julius
 
189
   assign s_fracta_28_o = s_expa_gt_expb ?
190
                          s_fracta_28 :
191
                          {s_fract_shr_28[27:1],(s_sticky|s_fract_shr_28[0])};
192
 
193
   assign s_fractb_28_o =  s_expa_gt_expb ?
194
                           {s_fract_shr_28[27:1],(s_sticky|s_fract_shr_28[0])} :
195
                           s_fractb_28;
196
 
197
endmodule // or1200_fpu_pre_norm_addsub
198
 
199
 

powered by: WebSVN 2.1.0

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