Branch data Line data Source code
1 : : /*****************************************************************************
2 : :
3 : : The following code is derived, directly or indirectly, from the SystemC
4 : : source code Copyright (c) 1996-2006 by all Contributors.
5 : : All Rights reserved.
6 : :
7 : : The contents of this file are subject to the restrictions and limitations
8 : : set forth in the SystemC Open Source License Version 2.4 (the "License");
9 : : You may not use this file except in compliance with such restrictions and
10 : : limitations. You may obtain instructions on how to receive a copy of the
11 : : License at http://www.systemc.org/. Software distributed by Contributors
12 : : under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
13 : : ANY KIND, either express or implied. See the License for the specific
14 : : language governing rights and limitations under the License.
15 : :
16 : : *****************************************************************************/
17 : :
18 : : /*****************************************************************************
19 : :
20 : : floating.cpp -- Floating Point Execution Unit.
21 : :
22 : : Original Author: Martin Wang, Synopsys, Inc.
23 : :
24 : : *****************************************************************************/
25 : :
26 : : /*****************************************************************************
27 : :
28 : : MODIFICATION LOG - modifiers, enter your name, affiliation, date and
29 : : changes you are making here.
30 : :
31 : : Name, Affiliation, Date: Nicolas Blanc, ETHZ, 2009
32 : : Description of Modification: many code updates
33 : :
34 : : Name, Affiliation, Date:
35 : : Description of Modification:
36 : :
37 : : *****************************************************************************/
38 : :
39 : :
40 : : #include "floating.h"
41 : :
42 : 1 : void floating::entry()
43 : : {
44 : : //LCOV_EXCL_BR_START
45 : 1 : sc_int<32> opcode_tmp = 0;
46 : 1 : sc_int<32> dout_tmp = 0;
47 : 1 : sc_uint<32> dest_tmp = 0;
48 : :
49 : 1 : sc_uint<32> fpua_sign_tmp;
50 : 1 : sc_uint<32> fpua_exponent_tmp;
51 : 1 : sc_uint<32> fpua_significand_tmp;
52 : 1 : sc_uint<32> fpub_sign_tmp;
53 : 1 : sc_uint<32> fpub_exponent_tmp;
54 : 1 : sc_uint<32> fpub_significand_tmp;
55 : 1 : const char *opcode_encode="";
56 : 1 : sc_uint<32> fpua_tmp;
57 : 1 : sc_uint<32> fpub_tmp;
58 : :
59 : 1 : sc_int<32> exponent_diff_tmp = 0;
60 : 1 : sc_int<32> exponent_tmp = 0;
61 : 1 : sc_uint<32> significant_result = 0;
62 : 1 : sc_uint<32> overflow_sign_tmp = 0;
63 : 1 : sc_uint<32> result_exp_tmp = 0;
64 : 1 : sc_uint<32> result_sign_tmp = 0;
65 : : //LCOV_EXCL_BR_STOP
66 : :
67 : : // main loop
68 : : // current implementation only worked if both operand have same sign bits
69 : : // overflow is ignored.
70 : : // initialization of output
71 : 1 : wait(3);//LCOV_EXCL_BR_LINE
72 : :
73 : : while(true)
74 : : {
75 [ - + ]: 4 : do {
76 : 4 : wait();//LCOV_EXCL_BR_LINE
77 [ + - ]: 4 : } while ( !(cs == true) );
78 : :
79 : : //LCOV_EXCL_BR_START
80 : 4 : opcode_tmp = opcode.read();
81 : :
82 : 4 : fpua_tmp = dina.read();
83 : 4 : fpub_tmp = dinb.read();
84 : : //LCOV_EXCL_BR_STOP
85 : :
86 : 4 : fpua_sign_tmp = (fpua_tmp & 0x80000000) >> 31 ;
87 : 4 : fpub_sign_tmp = (fpub_tmp & 0x80000000) >> 31 ;
88 : :
89 : 4 : fpua_exponent_tmp = (fpua_tmp & 0x7f800000) >> 23 ;
90 : 4 : fpub_exponent_tmp = (fpub_tmp & 0x7f800000) >> 23 ;
91 : :
92 : 4 : fpua_significand_tmp = (fpua_tmp & 0x007fffff) ;
93 : 4 : fpub_significand_tmp = (fpub_tmp & 0x007fffff) ;
94 : :
95 : : //LCOV_EXCL_BR_START
96 : 4 : exponent_diff_tmp = sc_int<32>(fpua_exponent_tmp) -
97 : 4 : sc_int<32>(fpub_exponent_tmp);
98 : : //LCOV_EXCL_BR_STOP
99 : :
100 [ + + ]: 4 : if (exponent_diff_tmp > 0)
101 : : {
102 : 3 : exponent_tmp = fpua_exponent_tmp;
103 : : //printf("shift significant B to Right\n");
104 : 3 : fpub_significand_tmp = fpub_significand_tmp >>
105 : 3 : exponent_diff_tmp ;
106 : 3 : fpub_exponent_tmp = fpua_exponent_tmp;
107 : : }
108 : : else
109 : : {
110 : 1 : exponent_tmp = fpub_exponent_tmp;
111 : : //printf("shift significant A to Right\n");
112 : 1 : fpua_significand_tmp = fpua_significand_tmp >>
113 : 1 : exponent_diff_tmp ;
114 : 1 : fpua_exponent_tmp = fpub_exponent_tmp;
115 : : }
116 : :
117 : 4 : wait();//LCOV_EXCL_BR_LINE
118 : :
119 : : // output MUX
120 [ + + - + : 4 : switch (opcode_tmp)
+ - ]
121 : : {
122 : : case 0: // Stall
123 : 1 : opcode_encode = "STALL";
124 : : //LCOV_EXCL_BR_START
125 : 1 : cout << "opcode: STALL" << endl;
126 : 1 : dout_tmp = dout_tmp;
127 : 1 : wait();
128 : : //LCOV_EXCL_BR_STOP
129 : 1 : break;
130 : : case 3: // add
131 : 1 : opcode_encode = "FADD";
132 : : //LCOV_EXCL_BR_START
133 : 1 : cout << "opcode: FADD" << endl;
134 : 1 : significant_result = sc_int<32>(fpua_significand_tmp) +
135 : 1 : sc_int<32>(fpub_significand_tmp);
136 : 1 : wait();
137 : : //LCOV_EXCL_BR_STOP
138 : 1 : break;
139 : : case 4: // sub
140 : 0 : opcode_encode = "FSUB";
141 : : //LCOV_EXCL_BR_START
142 : 0 : cout << "opcode: FSUB" << endl;
143 : 0 : significant_result = sc_int<32>(fpua_significand_tmp) -
144 : 0 : sc_int<32>(fpub_significand_tmp);
145 : 0 : wait();
146 : : //LCOV_EXCL_BR_STOP
147 : 0 : break;
148 : : case 5: // mul
149 : 1 : opcode_encode = "FMUL";
150 : : //LCOV_EXCL_BR_START
151 : 1 : cout << "opcode: FMUL" << endl;
152 : 1 : significant_result = sc_int<32>(fpua_significand_tmp) *
153 : 1 : sc_int<32>(fpub_significand_tmp);
154 : 1 : fpub_exponent_tmp *= 2; // exponent is doubled in value
155 : 1 : wait();
156 : : //LCOV_EXCL_BR_STOP
157 : 1 : break;
158 : : case 6: // div
159 : 1 : opcode_encode = "FDIV";
160 : : //LCOV_EXCL_BR_START
161 : 1 : cout << "opcode: FDIV" << endl;
162 : 1 : significant_result = sc_int<32>(fpua_significand_tmp) /
163 : 1 : sc_int<32>(fpub_significand_tmp);
164 : 1 : wait();
165 : : //LCOV_EXCL_BR_STOP
166 : 1 : break;
167 : : default:
168 : : //LCOV_EXCL_BR_START
169 : 0 : cout << "FPU: Bad Opcode " << opcode_tmp << endl;
170 : 0 : wait();
171 : : //LCOV_EXCL_BR_STOP
172 : 0 : break;
173 : : }
174 : :
175 : 4 : overflow_sign_tmp = (significant_result & 0xff800000) >> 23;
176 : 4 : dout_tmp = (significant_result << overflow_sign_tmp) & 0x007fffff;
177 : 4 : result_exp_tmp = fpub_exponent_tmp + overflow_sign_tmp;
178 : 4 : dout_tmp = dout_tmp | ((result_exp_tmp << 23) & 0x7f800000);
179 : 4 : result_sign_tmp = fpua_sign_tmp;
180 : 4 : dout_tmp = dout_tmp | ((result_sign_tmp << 31) & 0x80000000);
181 : : //LCOV_EXCL_BR_START
182 : 4 : dout.write(dout_tmp);
183 : :
184 : 4 : out_valid.write(true);
185 : 4 : wait();
186 : 4 : out_valid.write(false);
187 : 4 : wait();
188 : : //LCOV_EXCL_BR_STOP
189 : 0 : }
190 : 4 : }//LCOV_EXCL_BR_LINE
|