Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / n2 / lib / cpu / src / N2_Fpu.h
CommitLineData
920dae64
AT
1/*
2* ========== Copyright Header Begin ==========================================
3*
4* OpenSPARC T2 Processor File: N2_Fpu.h
5* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
6* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
7*
8* The above named program is free software; you can redistribute it and/or
9* modify it under the terms of the GNU General Public
10* License version 2 as published by the Free Software Foundation.
11*
12* The above named program is distributed in the hope that it will be
13* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15* General Public License for more details.
16*
17* You should have received a copy of the GNU General Public
18* License along with this work; if not, write to the Free Software
19* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20*
21* ========== Copyright Header End ============================================
22*/
23
24#ifndef __N2_Fpu_h__
25#define __N2_Fpu_h__
26
27#include "SS_Fpu.h"
28
29extern "C" SS_Vaddr n2_exe_fadds( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
30extern "C" SS_Vaddr n2_exe_fsubs( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
31extern "C" SS_Vaddr n2_exe_fmuls( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
32extern "C" SS_Vaddr n2_exe_fdivs( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
33
34extern "C" SS_Vaddr n2_exe_fmovs( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
35extern "C" SS_Vaddr n2_exe_fnegs( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
36extern "C" SS_Vaddr n2_exe_fabss( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
37extern "C" SS_Vaddr n2_exe_fsqrts( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
38extern "C" SS_Vaddr n2_exe_fsmuld( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
39
40extern "C" SS_Vaddr n2_exe_fstoi( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
41extern "C" SS_Vaddr n2_exe_fstox( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
42extern "C" SS_Vaddr n2_exe_fstod( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
43extern "C" SS_Vaddr n2_exe_fitos( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
44extern "C" SS_Vaddr n2_exe_fitod( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
45
46extern "C" SS_Vaddr n2_exe_faddd( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
47extern "C" SS_Vaddr n2_exe_fsubd( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
48extern "C" SS_Vaddr n2_exe_fmuld( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
49extern "C" SS_Vaddr n2_exe_fdivd( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
50
51extern "C" SS_Vaddr n2_exe_fmovd( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
52extern "C" SS_Vaddr n2_exe_fnegd( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
53extern "C" SS_Vaddr n2_exe_fabsd( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
54extern "C" SS_Vaddr n2_exe_fsqrtd( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
55
56extern "C" SS_Vaddr n2_exe_fdtoi( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
57extern "C" SS_Vaddr n2_exe_fdtox( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
58extern "C" SS_Vaddr n2_exe_fdtos( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
59extern "C" SS_Vaddr n2_exe_fxtos( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
60extern "C" SS_Vaddr n2_exe_fxtod( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
61
62extern "C" SS_Vaddr n2_exe_fcmps( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
63extern "C" SS_Vaddr n2_exe_fcmpd( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
64extern "C" SS_Vaddr n2_exe_fcmpes( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
65extern "C" SS_Vaddr n2_exe_fcmped( SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
66
67class N2_Fpu : public SS_Fpu
68{
69 public:
70 N2_Fpu() : SS_Fpu() {}
71
72 enum Instr
73 {
74 FSTOI, FDTOI,
75 FSTOX, FDTOX,
76 FSTOD, FDTOS,
77 FITOS, FITOD,
78 FXTOS, FXTOD,
79 FMOVS, FMOVD,
80 FABSS, FABSD,
81 FNEGS, FNEGD,
82 FSQRTS, FSQRTD,
83 FADDS, FADDD,
84 FSUBS, FSUBD,
85 FMULS, FMULD,
86 FDIVS, FDIVD,
87 FSMULD,
88 FCMPS, FCMPD,
89 FCMPES, FCMPED
90 };
91
92 SS_Vaddr exe_off( Instr instr, SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
93 SS_Vaddr exe_fof( Instr instr, SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
94 SS_Vaddr exe_fff( Instr instr, SS_Vaddr pc, SS_Vaddr npc, SS_Strand* s, SS_Instr* i );
95
96 private:
97 static const int SP_BIAS = 127;
98 static const int SP_EMAX = 255;
99 static const int SP_EGUF = -25;
100
101 static const int DP_BIAS = 1023;
102 static const int DP_EMAX = 2047;
103 static const int DP_EGUF = -54;
104
105 enum Precision
106 {
107 SP_TYPE,
108 DP_TYPE,
109 UNKNOWN_TYPE
110 };
111 enum NumberType
112 {
113 FP_OP_NONE,
114 FP_OP_QNAN,
115 FP_OP_SNAN,
116 FP_OP_INF,
117 FP_OP_NSUBNORMAL,
118 FP_OP_PSUBNORMAL,
119 FP_OP_NZERO,
120 FP_OP_PZERO,
121 FP_OP_NORMAL
122 };
123
124 NumberType fpu_optype( uint32_t sp_value )/*{{{*/
125 {
126 if (is_nan_or_inf(sp_value))
127 {
128 if (is_inf(sp_value))
129 return FP_OP_INF;
130 else if (is_qnan(sp_value))
131 return FP_OP_QNAN;
132 else
133 return FP_OP_SNAN;
134 }
135 else if (is_sub_or_nil(sp_value))
136 {
137 if (is_sub(sp_value))
138 return to_sgn(sp_value) ? FP_OP_NSUBNORMAL : FP_OP_PSUBNORMAL;
139 else
140 return to_sgn(sp_value) ? FP_OP_NZERO : FP_OP_PZERO;
141 }
142 else
143 {
144 return FP_OP_NORMAL;
145 }
146 }
147 /*}}}*/
148 NumberType N2_Fpu::fpu_optype( uint64_t dp_value )/*{{{*/
149 {
150 if (is_nan_or_inf(dp_value))
151 {
152 if (is_inf(dp_value))
153 return FP_OP_INF;
154 else if (is_qnan(dp_value))
155 return FP_OP_QNAN;
156 else
157 return FP_OP_SNAN;
158 }
159 else if (is_sub_or_nil(dp_value))
160 {
161 if (is_sub(dp_value))
162 return to_sgn(dp_value) ? FP_OP_NSUBNORMAL : FP_OP_PSUBNORMAL;
163 else
164 return to_sgn(dp_value) ? FP_OP_NZERO : FP_OP_PZERO;
165 }
166 else
167 {
168 return FP_OP_NORMAL;
169 }
170 }
171 /*}}}*/
172
173 uint32_t nan_postprocess( uint32_t src1_sp_value, uint32_t src2_sp_value, uint32_t dest_sp_value )/*{{{*/
174 {
175 if (is_nan(src2_sp_value))
176 {
177 if (is_snan(src2_sp_value))
178 return to_qnan(src2_sp_value);
179 else if (is_snan(src1_sp_value))
180 return to_qnan(src1_sp_value);
181 else
182 return to_qnan(src2_sp_value);
183 }
184 else if (is_nan(src1_sp_value))
185 return to_qnan(src1_sp_value);
186 else
187 return dest_sp_value;
188 }
189 /*}}}*/
190 uint64_t nan_postprocess( uint64_t src1_dp_value, uint64_t src2_dp_value, uint64_t dest_dp_value )/*{{{*/
191 {
192 if (is_nan(src2_dp_value))
193 {
194 if (is_snan(src2_dp_value))
195 return to_qnan(src2_dp_value);
196 else if (is_snan(src1_dp_value))
197 return to_qnan(src1_dp_value);
198 else
199 return to_qnan(src2_dp_value);
200 }
201 else if (is_nan(src1_dp_value))
202 return to_qnan(src1_dp_value);
203 else
204 return dest_dp_value;
205 }
206 /*}}}*/
207 uint64_t nan_postprocess( uint32_t src1_sp_value, uint32_t src2_sp_value, uint64_t dest_dp_value )/*{{{*/
208 {
209 if (is_nan(src2_sp_value))
210 {
211 if (is_snan(src2_sp_value))
212 return to_qnan(to_nand(src2_sp_value));
213 else if (is_snan(src1_sp_value))
214 return to_qnan(to_nand(src1_sp_value));
215 else
216 return to_qnan(to_nand(src2_sp_value));
217 }
218 else if (is_nan(src1_sp_value))
219 return to_qnan(to_nand(src1_sp_value));
220 else
221 return dest_dp_value;
222 }
223 /*}}}*/
224
225 FloatTrapType fpu_postprocess( Instr instr, SS_Strand* s, NumberType src_fpop, NumberType src2_fpop, int Er, NumberType rd_fpop,
226 Precision dest_type, uint64_t *rd_dp_value, uint32_t *rd_sp_value );
227};
228
229#endif
230
231