root / target-ppc / op_helper.c @ 2e13d23a
History | View | Annotate | Download (76.5 kB)
1 | 9a64fbe4 | bellard | /*
|
---|---|---|---|
2 | 3fc6c082 | bellard | * PowerPC emulation helpers for qemu.
|
3 | 5fafdf24 | ths | *
|
4 | 76a66253 | j_mayer | * Copyright (c) 2003-2007 Jocelyn Mayer
|
5 | 9a64fbe4 | bellard | *
|
6 | 9a64fbe4 | bellard | * This library is free software; you can redistribute it and/or
|
7 | 9a64fbe4 | bellard | * modify it under the terms of the GNU Lesser General Public
|
8 | 9a64fbe4 | bellard | * License as published by the Free Software Foundation; either
|
9 | 9a64fbe4 | bellard | * version 2 of the License, or (at your option) any later version.
|
10 | 9a64fbe4 | bellard | *
|
11 | 9a64fbe4 | bellard | * This library is distributed in the hope that it will be useful,
|
12 | 9a64fbe4 | bellard | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 9a64fbe4 | bellard | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 9a64fbe4 | bellard | * Lesser General Public License for more details.
|
15 | 9a64fbe4 | bellard | *
|
16 | 9a64fbe4 | bellard | * You should have received a copy of the GNU Lesser General Public
|
17 | 9a64fbe4 | bellard | * License along with this library; if not, write to the Free Software
|
18 | 9a64fbe4 | bellard | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19 | 9a64fbe4 | bellard | */
|
20 | 9a64fbe4 | bellard | #include "exec.h" |
21 | 603fccce | j_mayer | #include "host-utils.h" |
22 | 9a64fbe4 | bellard | |
23 | 0411a972 | j_mayer | #include "helper_regs.h" |
24 | 0487d6a8 | j_mayer | #include "op_helper.h" |
25 | 0487d6a8 | j_mayer | |
26 | 9a64fbe4 | bellard | #define MEMSUFFIX _raw
|
27 | 0487d6a8 | j_mayer | #include "op_helper.h" |
28 | 9a64fbe4 | bellard | #include "op_helper_mem.h" |
29 | a541f297 | bellard | #if !defined(CONFIG_USER_ONLY)
|
30 | 9a64fbe4 | bellard | #define MEMSUFFIX _user
|
31 | 0487d6a8 | j_mayer | #include "op_helper.h" |
32 | 9a64fbe4 | bellard | #include "op_helper_mem.h" |
33 | 9a64fbe4 | bellard | #define MEMSUFFIX _kernel
|
34 | 0487d6a8 | j_mayer | #include "op_helper.h" |
35 | 9a64fbe4 | bellard | #include "op_helper_mem.h" |
36 | 1e42b8f0 | j_mayer | #if defined(TARGET_PPC64H)
|
37 | 1e42b8f0 | j_mayer | #define MEMSUFFIX _hypv
|
38 | 1e42b8f0 | j_mayer | #include "op_helper.h" |
39 | 1e42b8f0 | j_mayer | #include "op_helper_mem.h" |
40 | 1e42b8f0 | j_mayer | #endif
|
41 | 9a64fbe4 | bellard | #endif
|
42 | 9a64fbe4 | bellard | |
43 | fdabc366 | bellard | //#define DEBUG_OP
|
44 | fdabc366 | bellard | //#define DEBUG_EXCEPTIONS
|
45 | 76a66253 | j_mayer | //#define DEBUG_SOFTWARE_TLB
|
46 | fdabc366 | bellard | |
47 | 9a64fbe4 | bellard | /*****************************************************************************/
|
48 | 9a64fbe4 | bellard | /* Exceptions processing helpers */
|
49 | 9a64fbe4 | bellard | |
50 | 9fddaa0c | bellard | void do_raise_exception_err (uint32_t exception, int error_code) |
51 | 9a64fbe4 | bellard | { |
52 | 9fddaa0c | bellard | #if 0
|
53 | 9fddaa0c | bellard | printf("Raise exception %3x code : %d\n", exception, error_code);
|
54 | 9fddaa0c | bellard | #endif
|
55 | 9fddaa0c | bellard | env->exception_index = exception; |
56 | 9fddaa0c | bellard | env->error_code = error_code; |
57 | 76a66253 | j_mayer | cpu_loop_exit(); |
58 | 76a66253 | j_mayer | } |
59 | 9fddaa0c | bellard | |
60 | 9fddaa0c | bellard | void do_raise_exception (uint32_t exception)
|
61 | 9fddaa0c | bellard | { |
62 | 9fddaa0c | bellard | do_raise_exception_err(exception, 0);
|
63 | 9a64fbe4 | bellard | } |
64 | 9a64fbe4 | bellard | |
65 | a496775f | j_mayer | void cpu_dump_EA (target_ulong EA);
|
66 | a496775f | j_mayer | void do_print_mem_EA (target_ulong EA)
|
67 | a496775f | j_mayer | { |
68 | a496775f | j_mayer | cpu_dump_EA(EA); |
69 | a496775f | j_mayer | } |
70 | a496775f | j_mayer | |
71 | 9a64fbe4 | bellard | /*****************************************************************************/
|
72 | 76a66253 | j_mayer | /* Registers load and stores */
|
73 | 76a66253 | j_mayer | void do_load_cr (void) |
74 | 76a66253 | j_mayer | { |
75 | 76a66253 | j_mayer | T0 = (env->crf[0] << 28) | |
76 | 76a66253 | j_mayer | (env->crf[1] << 24) | |
77 | 76a66253 | j_mayer | (env->crf[2] << 20) | |
78 | 76a66253 | j_mayer | (env->crf[3] << 16) | |
79 | 76a66253 | j_mayer | (env->crf[4] << 12) | |
80 | 76a66253 | j_mayer | (env->crf[5] << 8) | |
81 | 76a66253 | j_mayer | (env->crf[6] << 4) | |
82 | 76a66253 | j_mayer | (env->crf[7] << 0); |
83 | 76a66253 | j_mayer | } |
84 | 76a66253 | j_mayer | |
85 | 76a66253 | j_mayer | void do_store_cr (uint32_t mask)
|
86 | 76a66253 | j_mayer | { |
87 | 76a66253 | j_mayer | int i, sh;
|
88 | 76a66253 | j_mayer | |
89 | 36081602 | j_mayer | for (i = 0, sh = 7; i < 8; i++, sh--) { |
90 | 76a66253 | j_mayer | if (mask & (1 << sh)) |
91 | 76a66253 | j_mayer | env->crf[i] = (T0 >> (sh * 4)) & 0xFUL; |
92 | 76a66253 | j_mayer | } |
93 | 76a66253 | j_mayer | } |
94 | 76a66253 | j_mayer | |
95 | c80f84e3 | j_mayer | #if defined(TARGET_PPC64)
|
96 | c80f84e3 | j_mayer | void do_store_pri (int prio) |
97 | c80f84e3 | j_mayer | { |
98 | c80f84e3 | j_mayer | env->spr[SPR_PPR] &= ~0x001C000000000000ULL;
|
99 | c80f84e3 | j_mayer | env->spr[SPR_PPR] |= ((uint64_t)prio & 0x7) << 50; |
100 | c80f84e3 | j_mayer | } |
101 | c80f84e3 | j_mayer | #endif
|
102 | c80f84e3 | j_mayer | |
103 | a496775f | j_mayer | target_ulong ppc_load_dump_spr (int sprn)
|
104 | a496775f | j_mayer | { |
105 | 6b80055d | j_mayer | if (loglevel != 0) { |
106 | a496775f | j_mayer | fprintf(logfile, "Read SPR %d %03x => " ADDRX "\n", |
107 | a496775f | j_mayer | sprn, sprn, env->spr[sprn]); |
108 | a496775f | j_mayer | } |
109 | a496775f | j_mayer | |
110 | a496775f | j_mayer | return env->spr[sprn];
|
111 | a496775f | j_mayer | } |
112 | a496775f | j_mayer | |
113 | a496775f | j_mayer | void ppc_store_dump_spr (int sprn, target_ulong val) |
114 | a496775f | j_mayer | { |
115 | 6b80055d | j_mayer | if (loglevel != 0) { |
116 | a496775f | j_mayer | fprintf(logfile, "Write SPR %d %03x => " ADDRX " <= " ADDRX "\n", |
117 | a496775f | j_mayer | sprn, sprn, env->spr[sprn], val); |
118 | a496775f | j_mayer | } |
119 | a496775f | j_mayer | env->spr[sprn] = val; |
120 | a496775f | j_mayer | } |
121 | a496775f | j_mayer | |
122 | 76a66253 | j_mayer | /*****************************************************************************/
|
123 | fdabc366 | bellard | /* Fixed point operations helpers */
|
124 | fdabc366 | bellard | void do_adde (void) |
125 | fdabc366 | bellard | { |
126 | fdabc366 | bellard | T2 = T0; |
127 | fdabc366 | bellard | T0 += T1 + xer_ca; |
128 | d9bce9d9 | j_mayer | if (likely(!((uint32_t)T0 < (uint32_t)T2 ||
|
129 | d9bce9d9 | j_mayer | (xer_ca == 1 && (uint32_t)T0 == (uint32_t)T2)))) {
|
130 | fdabc366 | bellard | xer_ca = 0;
|
131 | fdabc366 | bellard | } else {
|
132 | fdabc366 | bellard | xer_ca = 1;
|
133 | fdabc366 | bellard | } |
134 | fdabc366 | bellard | } |
135 | fdabc366 | bellard | |
136 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
137 | d9bce9d9 | j_mayer | void do_adde_64 (void) |
138 | fdabc366 | bellard | { |
139 | fdabc366 | bellard | T2 = T0; |
140 | fdabc366 | bellard | T0 += T1 + xer_ca; |
141 | d9bce9d9 | j_mayer | if (likely(!((uint64_t)T0 < (uint64_t)T2 ||
|
142 | d9bce9d9 | j_mayer | (xer_ca == 1 && (uint64_t)T0 == (uint64_t)T2)))) {
|
143 | fdabc366 | bellard | xer_ca = 0;
|
144 | fdabc366 | bellard | } else {
|
145 | fdabc366 | bellard | xer_ca = 1;
|
146 | fdabc366 | bellard | } |
147 | fdabc366 | bellard | } |
148 | d9bce9d9 | j_mayer | #endif
|
149 | fdabc366 | bellard | |
150 | fdabc366 | bellard | void do_addmeo (void) |
151 | fdabc366 | bellard | { |
152 | fdabc366 | bellard | T1 = T0; |
153 | fdabc366 | bellard | T0 += xer_ca + (-1);
|
154 | d9bce9d9 | j_mayer | if (likely(!((uint32_t)T1 &
|
155 | d9bce9d9 | j_mayer | ((uint32_t)T1 ^ (uint32_t)T0) & (1UL << 31)))) { |
156 | fdabc366 | bellard | xer_ov = 0;
|
157 | fdabc366 | bellard | } else {
|
158 | fdabc366 | bellard | xer_ov = 1;
|
159 | 966439a6 | j_mayer | xer_so = 1;
|
160 | fdabc366 | bellard | } |
161 | fdabc366 | bellard | if (likely(T1 != 0)) |
162 | fdabc366 | bellard | xer_ca = 1;
|
163 | fdabc366 | bellard | } |
164 | fdabc366 | bellard | |
165 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
166 | d9bce9d9 | j_mayer | void do_addmeo_64 (void) |
167 | fdabc366 | bellard | { |
168 | fdabc366 | bellard | T1 = T0; |
169 | d9bce9d9 | j_mayer | T0 += xer_ca + (-1);
|
170 | d9bce9d9 | j_mayer | if (likely(!((uint64_t)T1 &
|
171 | d9bce9d9 | j_mayer | ((uint64_t)T1 ^ (uint64_t)T0) & (1ULL << 63)))) { |
172 | fdabc366 | bellard | xer_ov = 0;
|
173 | fdabc366 | bellard | } else {
|
174 | fdabc366 | bellard | xer_ov = 1;
|
175 | 966439a6 | j_mayer | xer_so = 1;
|
176 | fdabc366 | bellard | } |
177 | d9bce9d9 | j_mayer | if (likely(T1 != 0)) |
178 | fdabc366 | bellard | xer_ca = 1;
|
179 | fdabc366 | bellard | } |
180 | d9bce9d9 | j_mayer | #endif
|
181 | fdabc366 | bellard | |
182 | fdabc366 | bellard | void do_divwo (void) |
183 | fdabc366 | bellard | { |
184 | d9bce9d9 | j_mayer | if (likely(!(((int32_t)T0 == INT32_MIN && (int32_t)T1 == -1) || |
185 | d9bce9d9 | j_mayer | (int32_t)T1 == 0))) {
|
186 | fdabc366 | bellard | xer_ov = 0;
|
187 | d9bce9d9 | j_mayer | T0 = (int32_t)T0 / (int32_t)T1; |
188 | fdabc366 | bellard | } else {
|
189 | fdabc366 | bellard | xer_ov = 1;
|
190 | 966439a6 | j_mayer | xer_so = 1;
|
191 | fdabc366 | bellard | T0 = (-1) * ((uint32_t)T0 >> 31); |
192 | fdabc366 | bellard | } |
193 | fdabc366 | bellard | } |
194 | fdabc366 | bellard | |
195 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
196 | d9bce9d9 | j_mayer | void do_divdo (void) |
197 | d9bce9d9 | j_mayer | { |
198 | d9bce9d9 | j_mayer | if (likely(!(((int64_t)T0 == INT64_MIN && (int64_t)T1 == -1ULL) || |
199 | d9bce9d9 | j_mayer | (int64_t)T1 == 0))) {
|
200 | d9bce9d9 | j_mayer | xer_ov = 0;
|
201 | d9bce9d9 | j_mayer | T0 = (int64_t)T0 / (int64_t)T1; |
202 | d9bce9d9 | j_mayer | } else {
|
203 | d9bce9d9 | j_mayer | xer_ov = 1;
|
204 | 966439a6 | j_mayer | xer_so = 1;
|
205 | d9bce9d9 | j_mayer | T0 = (-1ULL) * ((uint64_t)T0 >> 63); |
206 | d9bce9d9 | j_mayer | } |
207 | d9bce9d9 | j_mayer | } |
208 | d9bce9d9 | j_mayer | #endif
|
209 | d9bce9d9 | j_mayer | |
210 | fdabc366 | bellard | void do_divwuo (void) |
211 | fdabc366 | bellard | { |
212 | fdabc366 | bellard | if (likely((uint32_t)T1 != 0)) { |
213 | fdabc366 | bellard | xer_ov = 0;
|
214 | fdabc366 | bellard | T0 = (uint32_t)T0 / (uint32_t)T1; |
215 | fdabc366 | bellard | } else {
|
216 | fdabc366 | bellard | xer_ov = 1;
|
217 | 966439a6 | j_mayer | xer_so = 1;
|
218 | fdabc366 | bellard | T0 = 0;
|
219 | fdabc366 | bellard | } |
220 | fdabc366 | bellard | } |
221 | fdabc366 | bellard | |
222 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
223 | d9bce9d9 | j_mayer | void do_divduo (void) |
224 | d9bce9d9 | j_mayer | { |
225 | d9bce9d9 | j_mayer | if (likely((uint64_t)T1 != 0)) { |
226 | d9bce9d9 | j_mayer | xer_ov = 0;
|
227 | d9bce9d9 | j_mayer | T0 = (uint64_t)T0 / (uint64_t)T1; |
228 | d9bce9d9 | j_mayer | } else {
|
229 | d9bce9d9 | j_mayer | xer_ov = 1;
|
230 | 966439a6 | j_mayer | xer_so = 1;
|
231 | d9bce9d9 | j_mayer | T0 = 0;
|
232 | d9bce9d9 | j_mayer | } |
233 | d9bce9d9 | j_mayer | } |
234 | d9bce9d9 | j_mayer | #endif
|
235 | d9bce9d9 | j_mayer | |
236 | fdabc366 | bellard | void do_mullwo (void) |
237 | fdabc366 | bellard | { |
238 | d9bce9d9 | j_mayer | int64_t res = (int64_t)T0 * (int64_t)T1; |
239 | fdabc366 | bellard | |
240 | fdabc366 | bellard | if (likely((int32_t)res == res)) {
|
241 | fdabc366 | bellard | xer_ov = 0;
|
242 | fdabc366 | bellard | } else {
|
243 | fdabc366 | bellard | xer_ov = 1;
|
244 | fdabc366 | bellard | xer_so = 1;
|
245 | fdabc366 | bellard | } |
246 | fdabc366 | bellard | T0 = (int32_t)res; |
247 | fdabc366 | bellard | } |
248 | fdabc366 | bellard | |
249 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
250 | d9bce9d9 | j_mayer | void do_mulldo (void) |
251 | fdabc366 | bellard | { |
252 | d9bce9d9 | j_mayer | int64_t th; |
253 | d9bce9d9 | j_mayer | uint64_t tl; |
254 | d9bce9d9 | j_mayer | |
255 | 9d901a20 | j_mayer | muls64(&tl, &th, T0, T1); |
256 | 88ad920b | j_mayer | /* If th != 0 && th != -1, then we had an overflow */
|
257 | 88ad920b | j_mayer | if (likely((th + 1) <= 1)) { |
258 | fdabc366 | bellard | xer_ov = 0;
|
259 | fdabc366 | bellard | } else {
|
260 | fdabc366 | bellard | xer_ov = 1;
|
261 | fdabc366 | bellard | xer_so = 1;
|
262 | fdabc366 | bellard | } |
263 | d9bce9d9 | j_mayer | T0 = (int64_t)tl; |
264 | fdabc366 | bellard | } |
265 | d9bce9d9 | j_mayer | #endif
|
266 | fdabc366 | bellard | |
267 | d9bce9d9 | j_mayer | void do_nego (void) |
268 | fdabc366 | bellard | { |
269 | d9bce9d9 | j_mayer | if (likely((int32_t)T0 != INT32_MIN)) {
|
270 | fdabc366 | bellard | xer_ov = 0;
|
271 | d9bce9d9 | j_mayer | T0 = -(int32_t)T0; |
272 | fdabc366 | bellard | } else {
|
273 | fdabc366 | bellard | xer_ov = 1;
|
274 | d9bce9d9 | j_mayer | xer_so = 1;
|
275 | fdabc366 | bellard | } |
276 | fdabc366 | bellard | } |
277 | fdabc366 | bellard | |
278 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
279 | d9bce9d9 | j_mayer | void do_nego_64 (void) |
280 | fdabc366 | bellard | { |
281 | d9bce9d9 | j_mayer | if (likely((int64_t)T0 != INT64_MIN)) {
|
282 | fdabc366 | bellard | xer_ov = 0;
|
283 | d9bce9d9 | j_mayer | T0 = -(int64_t)T0; |
284 | fdabc366 | bellard | } else {
|
285 | fdabc366 | bellard | xer_ov = 1;
|
286 | d9bce9d9 | j_mayer | xer_so = 1;
|
287 | fdabc366 | bellard | } |
288 | fdabc366 | bellard | } |
289 | d9bce9d9 | j_mayer | #endif
|
290 | fdabc366 | bellard | |
291 | fdabc366 | bellard | void do_subfe (void) |
292 | fdabc366 | bellard | { |
293 | fdabc366 | bellard | T0 = T1 + ~T0 + xer_ca; |
294 | d9bce9d9 | j_mayer | if (likely((uint32_t)T0 >= (uint32_t)T1 &&
|
295 | d9bce9d9 | j_mayer | (xer_ca == 0 || (uint32_t)T0 != (uint32_t)T1))) {
|
296 | fdabc366 | bellard | xer_ca = 0;
|
297 | fdabc366 | bellard | } else {
|
298 | fdabc366 | bellard | xer_ca = 1;
|
299 | fdabc366 | bellard | } |
300 | fdabc366 | bellard | } |
301 | fdabc366 | bellard | |
302 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
303 | d9bce9d9 | j_mayer | void do_subfe_64 (void) |
304 | fdabc366 | bellard | { |
305 | fdabc366 | bellard | T0 = T1 + ~T0 + xer_ca; |
306 | d9bce9d9 | j_mayer | if (likely((uint64_t)T0 >= (uint64_t)T1 &&
|
307 | d9bce9d9 | j_mayer | (xer_ca == 0 || (uint64_t)T0 != (uint64_t)T1))) {
|
308 | d9bce9d9 | j_mayer | xer_ca = 0;
|
309 | d9bce9d9 | j_mayer | } else {
|
310 | d9bce9d9 | j_mayer | xer_ca = 1;
|
311 | d9bce9d9 | j_mayer | } |
312 | d9bce9d9 | j_mayer | } |
313 | d9bce9d9 | j_mayer | #endif
|
314 | d9bce9d9 | j_mayer | |
315 | d9bce9d9 | j_mayer | void do_subfmeo (void) |
316 | d9bce9d9 | j_mayer | { |
317 | d9bce9d9 | j_mayer | T1 = T0; |
318 | d9bce9d9 | j_mayer | T0 = ~T0 + xer_ca - 1;
|
319 | d9bce9d9 | j_mayer | if (likely(!((uint32_t)~T1 & ((uint32_t)~T1 ^ (uint32_t)T0) &
|
320 | d9bce9d9 | j_mayer | (1UL << 31)))) { |
321 | fdabc366 | bellard | xer_ov = 0;
|
322 | fdabc366 | bellard | } else {
|
323 | fdabc366 | bellard | xer_ov = 1;
|
324 | 966439a6 | j_mayer | xer_so = 1;
|
325 | fdabc366 | bellard | } |
326 | d9bce9d9 | j_mayer | if (likely((uint32_t)T1 != UINT32_MAX))
|
327 | fdabc366 | bellard | xer_ca = 1;
|
328 | fdabc366 | bellard | } |
329 | fdabc366 | bellard | |
330 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
331 | d9bce9d9 | j_mayer | void do_subfmeo_64 (void) |
332 | fdabc366 | bellard | { |
333 | fdabc366 | bellard | T1 = T0; |
334 | fdabc366 | bellard | T0 = ~T0 + xer_ca - 1;
|
335 | d9bce9d9 | j_mayer | if (likely(!((uint64_t)~T1 & ((uint64_t)~T1 ^ (uint64_t)T0) &
|
336 | d9bce9d9 | j_mayer | (1ULL << 63)))) { |
337 | fdabc366 | bellard | xer_ov = 0;
|
338 | fdabc366 | bellard | } else {
|
339 | fdabc366 | bellard | xer_ov = 1;
|
340 | 966439a6 | j_mayer | xer_so = 1;
|
341 | fdabc366 | bellard | } |
342 | d9bce9d9 | j_mayer | if (likely((uint64_t)T1 != UINT64_MAX))
|
343 | fdabc366 | bellard | xer_ca = 1;
|
344 | fdabc366 | bellard | } |
345 | d9bce9d9 | j_mayer | #endif
|
346 | fdabc366 | bellard | |
347 | fdabc366 | bellard | void do_subfzeo (void) |
348 | fdabc366 | bellard | { |
349 | fdabc366 | bellard | T1 = T0; |
350 | fdabc366 | bellard | T0 = ~T0 + xer_ca; |
351 | d9bce9d9 | j_mayer | if (likely(!(((uint32_t)~T1 ^ UINT32_MAX) &
|
352 | d9bce9d9 | j_mayer | ((uint32_t)(~T1) ^ (uint32_t)T0) & (1UL << 31)))) { |
353 | fdabc366 | bellard | xer_ov = 0;
|
354 | fdabc366 | bellard | } else {
|
355 | fdabc366 | bellard | xer_ov = 1;
|
356 | fdabc366 | bellard | xer_so = 1;
|
357 | fdabc366 | bellard | } |
358 | d9bce9d9 | j_mayer | if (likely((uint32_t)T0 >= (uint32_t)~T1)) {
|
359 | fdabc366 | bellard | xer_ca = 0;
|
360 | fdabc366 | bellard | } else {
|
361 | fdabc366 | bellard | xer_ca = 1;
|
362 | fdabc366 | bellard | } |
363 | fdabc366 | bellard | } |
364 | fdabc366 | bellard | |
365 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
366 | d9bce9d9 | j_mayer | void do_subfzeo_64 (void) |
367 | d9bce9d9 | j_mayer | { |
368 | d9bce9d9 | j_mayer | T1 = T0; |
369 | d9bce9d9 | j_mayer | T0 = ~T0 + xer_ca; |
370 | d9bce9d9 | j_mayer | if (likely(!(((uint64_t)~T1 ^ UINT64_MAX) &
|
371 | d9bce9d9 | j_mayer | ((uint64_t)(~T1) ^ (uint64_t)T0) & (1ULL << 63)))) { |
372 | d9bce9d9 | j_mayer | xer_ov = 0;
|
373 | d9bce9d9 | j_mayer | } else {
|
374 | d9bce9d9 | j_mayer | xer_ov = 1;
|
375 | d9bce9d9 | j_mayer | xer_so = 1;
|
376 | d9bce9d9 | j_mayer | } |
377 | d9bce9d9 | j_mayer | if (likely((uint64_t)T0 >= (uint64_t)~T1)) {
|
378 | d9bce9d9 | j_mayer | xer_ca = 0;
|
379 | d9bce9d9 | j_mayer | } else {
|
380 | d9bce9d9 | j_mayer | xer_ca = 1;
|
381 | d9bce9d9 | j_mayer | } |
382 | d9bce9d9 | j_mayer | } |
383 | d9bce9d9 | j_mayer | #endif
|
384 | d9bce9d9 | j_mayer | |
385 | 603fccce | j_mayer | void do_cntlzw (void) |
386 | 603fccce | j_mayer | { |
387 | 603fccce | j_mayer | T0 = clz32(T0); |
388 | 603fccce | j_mayer | } |
389 | 603fccce | j_mayer | |
390 | 603fccce | j_mayer | #if defined(TARGET_PPC64)
|
391 | 603fccce | j_mayer | void do_cntlzd (void) |
392 | 603fccce | j_mayer | { |
393 | 603fccce | j_mayer | T0 = clz64(T0); |
394 | 603fccce | j_mayer | } |
395 | 603fccce | j_mayer | #endif
|
396 | 603fccce | j_mayer | |
397 | 9a64fbe4 | bellard | /* shift right arithmetic helper */
|
398 | 9a64fbe4 | bellard | void do_sraw (void) |
399 | 9a64fbe4 | bellard | { |
400 | 9a64fbe4 | bellard | int32_t ret; |
401 | 9a64fbe4 | bellard | |
402 | fdabc366 | bellard | if (likely(!(T1 & 0x20UL))) { |
403 | d9bce9d9 | j_mayer | if (likely((uint32_t)T1 != 0)) { |
404 | fdabc366 | bellard | ret = (int32_t)T0 >> (T1 & 0x1fUL);
|
405 | fdabc366 | bellard | if (likely(ret >= 0 || ((int32_t)T0 & ((1 << T1) - 1)) == 0)) { |
406 | 76a66253 | j_mayer | xer_ca = 0;
|
407 | fdabc366 | bellard | } else {
|
408 | 76a66253 | j_mayer | xer_ca = 1;
|
409 | fdabc366 | bellard | } |
410 | fdabc366 | bellard | } else {
|
411 | 76a66253 | j_mayer | ret = T0; |
412 | fdabc366 | bellard | xer_ca = 0;
|
413 | fdabc366 | bellard | } |
414 | fdabc366 | bellard | } else {
|
415 | fdabc366 | bellard | ret = (-1) * ((uint32_t)T0 >> 31); |
416 | fdabc366 | bellard | if (likely(ret >= 0 || ((uint32_t)T0 & ~0x80000000UL) == 0)) { |
417 | fdabc366 | bellard | xer_ca = 0;
|
418 | 76a66253 | j_mayer | } else {
|
419 | 9a64fbe4 | bellard | xer_ca = 1;
|
420 | 76a66253 | j_mayer | } |
421 | fdabc366 | bellard | } |
422 | 4b3686fa | bellard | T0 = ret; |
423 | 9a64fbe4 | bellard | } |
424 | 9a64fbe4 | bellard | |
425 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
426 | d9bce9d9 | j_mayer | void do_srad (void) |
427 | d9bce9d9 | j_mayer | { |
428 | d9bce9d9 | j_mayer | int64_t ret; |
429 | d9bce9d9 | j_mayer | |
430 | d9bce9d9 | j_mayer | if (likely(!(T1 & 0x40UL))) { |
431 | d9bce9d9 | j_mayer | if (likely((uint64_t)T1 != 0)) { |
432 | d9bce9d9 | j_mayer | ret = (int64_t)T0 >> (T1 & 0x3FUL);
|
433 | d9bce9d9 | j_mayer | if (likely(ret >= 0 || ((int64_t)T0 & ((1 << T1) - 1)) == 0)) { |
434 | d9bce9d9 | j_mayer | xer_ca = 0;
|
435 | d9bce9d9 | j_mayer | } else {
|
436 | d9bce9d9 | j_mayer | xer_ca = 1;
|
437 | d9bce9d9 | j_mayer | } |
438 | d9bce9d9 | j_mayer | } else {
|
439 | d9bce9d9 | j_mayer | ret = T0; |
440 | d9bce9d9 | j_mayer | xer_ca = 0;
|
441 | d9bce9d9 | j_mayer | } |
442 | d9bce9d9 | j_mayer | } else {
|
443 | d9bce9d9 | j_mayer | ret = (-1) * ((uint64_t)T0 >> 63); |
444 | d9bce9d9 | j_mayer | if (likely(ret >= 0 || ((uint64_t)T0 & ~0x8000000000000000ULL) == 0)) { |
445 | d9bce9d9 | j_mayer | xer_ca = 0;
|
446 | d9bce9d9 | j_mayer | } else {
|
447 | d9bce9d9 | j_mayer | xer_ca = 1;
|
448 | d9bce9d9 | j_mayer | } |
449 | d9bce9d9 | j_mayer | } |
450 | d9bce9d9 | j_mayer | T0 = ret; |
451 | d9bce9d9 | j_mayer | } |
452 | d9bce9d9 | j_mayer | #endif
|
453 | d9bce9d9 | j_mayer | |
454 | d9bce9d9 | j_mayer | void do_popcntb (void) |
455 | d9bce9d9 | j_mayer | { |
456 | d9bce9d9 | j_mayer | uint32_t ret; |
457 | d9bce9d9 | j_mayer | int i;
|
458 | d9bce9d9 | j_mayer | |
459 | d9bce9d9 | j_mayer | ret = 0;
|
460 | d9bce9d9 | j_mayer | for (i = 0; i < 32; i += 8) |
461 | 603fccce | j_mayer | ret |= ctpop8((T0 >> i) & 0xFF) << i;
|
462 | d9bce9d9 | j_mayer | T0 = ret; |
463 | d9bce9d9 | j_mayer | } |
464 | d9bce9d9 | j_mayer | |
465 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
466 | d9bce9d9 | j_mayer | void do_popcntb_64 (void) |
467 | d9bce9d9 | j_mayer | { |
468 | d9bce9d9 | j_mayer | uint64_t ret; |
469 | d9bce9d9 | j_mayer | int i;
|
470 | d9bce9d9 | j_mayer | |
471 | d9bce9d9 | j_mayer | ret = 0;
|
472 | d9bce9d9 | j_mayer | for (i = 0; i < 64; i += 8) |
473 | 603fccce | j_mayer | ret |= ctpop8((T0 >> i) & 0xFF) << i;
|
474 | d9bce9d9 | j_mayer | T0 = ret; |
475 | d9bce9d9 | j_mayer | } |
476 | d9bce9d9 | j_mayer | #endif
|
477 | d9bce9d9 | j_mayer | |
478 | fdabc366 | bellard | /*****************************************************************************/
|
479 | 9a64fbe4 | bellard | /* Floating point operations helpers */
|
480 | a11b8151 | j_mayer | static always_inline int fpisneg (float64 f) |
481 | 7c58044c | j_mayer | { |
482 | 7c58044c | j_mayer | union {
|
483 | 7c58044c | j_mayer | float64 f; |
484 | 7c58044c | j_mayer | uint64_t u; |
485 | 7c58044c | j_mayer | } u; |
486 | 7c58044c | j_mayer | |
487 | 7c58044c | j_mayer | u.f = f; |
488 | 7c58044c | j_mayer | |
489 | 7c58044c | j_mayer | return u.u >> 63 != 0; |
490 | 7c58044c | j_mayer | } |
491 | 7c58044c | j_mayer | |
492 | a11b8151 | j_mayer | static always_inline int isden (float f) |
493 | 7c58044c | j_mayer | { |
494 | 7c58044c | j_mayer | union {
|
495 | 7c58044c | j_mayer | float64 f; |
496 | 7c58044c | j_mayer | uint64_t u; |
497 | 7c58044c | j_mayer | } u; |
498 | 7c58044c | j_mayer | |
499 | 7c58044c | j_mayer | u.f = f; |
500 | 7c58044c | j_mayer | |
501 | 7c58044c | j_mayer | return ((u.u >> 52) & 0x7FF) == 0; |
502 | 7c58044c | j_mayer | } |
503 | 7c58044c | j_mayer | |
504 | a11b8151 | j_mayer | static always_inline int iszero (float64 f) |
505 | 7c58044c | j_mayer | { |
506 | 7c58044c | j_mayer | union {
|
507 | 7c58044c | j_mayer | float64 f; |
508 | 7c58044c | j_mayer | uint64_t u; |
509 | 7c58044c | j_mayer | } u; |
510 | 7c58044c | j_mayer | |
511 | 7c58044c | j_mayer | u.f = f; |
512 | 7c58044c | j_mayer | |
513 | 7c58044c | j_mayer | return (u.u & ~0x8000000000000000ULL) == 0; |
514 | 7c58044c | j_mayer | } |
515 | 7c58044c | j_mayer | |
516 | a11b8151 | j_mayer | static always_inline int isinfinity (float64 f) |
517 | 7c58044c | j_mayer | { |
518 | 7c58044c | j_mayer | union {
|
519 | 7c58044c | j_mayer | float64 f; |
520 | 7c58044c | j_mayer | uint64_t u; |
521 | 7c58044c | j_mayer | } u; |
522 | 7c58044c | j_mayer | |
523 | 7c58044c | j_mayer | u.f = f; |
524 | 7c58044c | j_mayer | |
525 | 86c4a9f5 | j_mayer | return ((u.u >> 52) & 0x7FF) == 0x7FF && |
526 | 7c58044c | j_mayer | (u.u & 0x000FFFFFFFFFFFFFULL) == 0; |
527 | 7c58044c | j_mayer | } |
528 | 7c58044c | j_mayer | |
529 | 7c58044c | j_mayer | void do_compute_fprf (int set_fprf) |
530 | 7c58044c | j_mayer | { |
531 | 7c58044c | j_mayer | int isneg;
|
532 | 7c58044c | j_mayer | |
533 | 7c58044c | j_mayer | isneg = fpisneg(FT0); |
534 | 7c58044c | j_mayer | if (unlikely(float64_is_nan(FT0))) {
|
535 | 7c58044c | j_mayer | if (float64_is_signaling_nan(FT0)) {
|
536 | 7c58044c | j_mayer | /* Signaling NaN: flags are undefined */
|
537 | 7c58044c | j_mayer | T0 = 0x00;
|
538 | 7c58044c | j_mayer | } else {
|
539 | 7c58044c | j_mayer | /* Quiet NaN */
|
540 | 7c58044c | j_mayer | T0 = 0x11;
|
541 | 7c58044c | j_mayer | } |
542 | 7c58044c | j_mayer | } else if (unlikely(isinfinity(FT0))) { |
543 | 7c58044c | j_mayer | /* +/- infinity */
|
544 | 7c58044c | j_mayer | if (isneg)
|
545 | 7c58044c | j_mayer | T0 = 0x09;
|
546 | 7c58044c | j_mayer | else
|
547 | 7c58044c | j_mayer | T0 = 0x05;
|
548 | 7c58044c | j_mayer | } else {
|
549 | 7c58044c | j_mayer | if (iszero(FT0)) {
|
550 | 7c58044c | j_mayer | /* +/- zero */
|
551 | 7c58044c | j_mayer | if (isneg)
|
552 | 7c58044c | j_mayer | T0 = 0x12;
|
553 | 7c58044c | j_mayer | else
|
554 | 7c58044c | j_mayer | T0 = 0x02;
|
555 | 7c58044c | j_mayer | } else {
|
556 | 7c58044c | j_mayer | if (isden(FT0)) {
|
557 | 7c58044c | j_mayer | /* Denormalized numbers */
|
558 | 7c58044c | j_mayer | T0 = 0x10;
|
559 | 7c58044c | j_mayer | } else {
|
560 | 7c58044c | j_mayer | /* Normalized numbers */
|
561 | 7c58044c | j_mayer | T0 = 0x00;
|
562 | 7c58044c | j_mayer | } |
563 | 7c58044c | j_mayer | if (isneg) {
|
564 | 7c58044c | j_mayer | T0 |= 0x08;
|
565 | 7c58044c | j_mayer | } else {
|
566 | 7c58044c | j_mayer | T0 |= 0x04;
|
567 | 7c58044c | j_mayer | } |
568 | 7c58044c | j_mayer | } |
569 | 7c58044c | j_mayer | } |
570 | 7c58044c | j_mayer | if (set_fprf) {
|
571 | 7c58044c | j_mayer | /* We update FPSCR_FPRF */
|
572 | 7c58044c | j_mayer | env->fpscr &= ~(0x1F << FPSCR_FPRF);
|
573 | 7c58044c | j_mayer | env->fpscr |= T0 << FPSCR_FPRF; |
574 | 7c58044c | j_mayer | } |
575 | 7c58044c | j_mayer | /* We just need fpcc to update Rc1 */
|
576 | 7c58044c | j_mayer | T0 &= 0xF;
|
577 | 7c58044c | j_mayer | } |
578 | 7c58044c | j_mayer | |
579 | 7c58044c | j_mayer | /* Floating-point invalid operations exception */
|
580 | 7c58044c | j_mayer | static always_inline void fload_invalid_op_excp (int op) |
581 | 7c58044c | j_mayer | { |
582 | 7c58044c | j_mayer | int ve;
|
583 | 7c58044c | j_mayer | |
584 | 7c58044c | j_mayer | ve = fpscr_ve; |
585 | 7c58044c | j_mayer | if (op & POWERPC_EXCP_FP_VXSNAN) {
|
586 | 7c58044c | j_mayer | /* Operation on signaling NaN */
|
587 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_VXSNAN;
|
588 | 7c58044c | j_mayer | } |
589 | 7c58044c | j_mayer | if (op & POWERPC_EXCP_FP_VXSOFT) {
|
590 | 7c58044c | j_mayer | /* Software-defined condition */
|
591 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_VXSOFT;
|
592 | 7c58044c | j_mayer | } |
593 | 7c58044c | j_mayer | switch (op & ~(POWERPC_EXCP_FP_VXSOFT | POWERPC_EXCP_FP_VXSNAN)) {
|
594 | 7c58044c | j_mayer | case POWERPC_EXCP_FP_VXISI:
|
595 | 7c58044c | j_mayer | /* Magnitude subtraction of infinities */
|
596 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_VXISI;
|
597 | 7c58044c | j_mayer | goto update_arith;
|
598 | 7c58044c | j_mayer | case POWERPC_EXCP_FP_VXIDI:
|
599 | 7c58044c | j_mayer | /* Division of infinity by infinity */
|
600 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_VXIDI;
|
601 | 7c58044c | j_mayer | goto update_arith;
|
602 | 7c58044c | j_mayer | case POWERPC_EXCP_FP_VXZDZ:
|
603 | 7c58044c | j_mayer | /* Division of zero by zero */
|
604 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_VXZDZ;
|
605 | 7c58044c | j_mayer | goto update_arith;
|
606 | 7c58044c | j_mayer | case POWERPC_EXCP_FP_VXIMZ:
|
607 | 7c58044c | j_mayer | /* Multiplication of zero by infinity */
|
608 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_VXIMZ;
|
609 | 7c58044c | j_mayer | goto update_arith;
|
610 | 7c58044c | j_mayer | case POWERPC_EXCP_FP_VXVC:
|
611 | 7c58044c | j_mayer | /* Ordered comparison of NaN */
|
612 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_VXVC;
|
613 | 7c58044c | j_mayer | env->fpscr &= ~(0xF << FPSCR_FPCC);
|
614 | 7c58044c | j_mayer | env->fpscr |= 0x11 << FPSCR_FPCC;
|
615 | 7c58044c | j_mayer | /* We must update the target FPR before raising the exception */
|
616 | 7c58044c | j_mayer | if (ve != 0) { |
617 | 7c58044c | j_mayer | env->exception_index = POWERPC_EXCP_PROGRAM; |
618 | 7c58044c | j_mayer | env->error_code = POWERPC_EXCP_FP | POWERPC_EXCP_FP_VXVC; |
619 | 7c58044c | j_mayer | /* Update the floating-point enabled exception summary */
|
620 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_FEX;
|
621 | 7c58044c | j_mayer | /* Exception is differed */
|
622 | 7c58044c | j_mayer | ve = 0;
|
623 | 7c58044c | j_mayer | } |
624 | 7c58044c | j_mayer | break;
|
625 | 7c58044c | j_mayer | case POWERPC_EXCP_FP_VXSQRT:
|
626 | 7c58044c | j_mayer | /* Square root of a negative number */
|
627 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_VXSQRT;
|
628 | 7c58044c | j_mayer | update_arith:
|
629 | 7c58044c | j_mayer | env->fpscr &= ~((1 << FPSCR_FR) | (1 << FPSCR_FI)); |
630 | 7c58044c | j_mayer | if (ve == 0) { |
631 | 7c58044c | j_mayer | /* Set the result to quiet NaN */
|
632 | 7c58044c | j_mayer | FT0 = (uint64_t)-1;
|
633 | 7c58044c | j_mayer | env->fpscr &= ~(0xF << FPSCR_FPCC);
|
634 | 7c58044c | j_mayer | env->fpscr |= 0x11 << FPSCR_FPCC;
|
635 | 7c58044c | j_mayer | } |
636 | 7c58044c | j_mayer | break;
|
637 | 7c58044c | j_mayer | case POWERPC_EXCP_FP_VXCVI:
|
638 | 7c58044c | j_mayer | /* Invalid conversion */
|
639 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_VXCVI;
|
640 | 7c58044c | j_mayer | env->fpscr &= ~((1 << FPSCR_FR) | (1 << FPSCR_FI)); |
641 | 7c58044c | j_mayer | if (ve == 0) { |
642 | 7c58044c | j_mayer | /* Set the result to quiet NaN */
|
643 | 7c58044c | j_mayer | FT0 = (uint64_t)-1;
|
644 | 7c58044c | j_mayer | env->fpscr &= ~(0xF << FPSCR_FPCC);
|
645 | 7c58044c | j_mayer | env->fpscr |= 0x11 << FPSCR_FPCC;
|
646 | 7c58044c | j_mayer | } |
647 | 7c58044c | j_mayer | break;
|
648 | 7c58044c | j_mayer | } |
649 | 7c58044c | j_mayer | /* Update the floating-point invalid operation summary */
|
650 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_VX;
|
651 | 7c58044c | j_mayer | /* Update the floating-point exception summary */
|
652 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_FX;
|
653 | 7c58044c | j_mayer | if (ve != 0) { |
654 | 7c58044c | j_mayer | /* Update the floating-point enabled exception summary */
|
655 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_FEX;
|
656 | 7c58044c | j_mayer | if (msr_fe0 != 0 || msr_fe1 != 0) |
657 | 7c58044c | j_mayer | do_raise_exception_err(POWERPC_EXCP_PROGRAM, POWERPC_EXCP_FP | op); |
658 | 7c58044c | j_mayer | } |
659 | 7c58044c | j_mayer | } |
660 | 7c58044c | j_mayer | |
661 | 7c58044c | j_mayer | static always_inline void float_zero_divide_excp (void) |
662 | 7c58044c | j_mayer | { |
663 | 7c58044c | j_mayer | union {
|
664 | 7c58044c | j_mayer | float64 f; |
665 | 7c58044c | j_mayer | uint64_t u; |
666 | 7c58044c | j_mayer | } u0, u1; |
667 | 7c58044c | j_mayer | |
668 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_ZX;
|
669 | 7c58044c | j_mayer | env->fpscr &= ~((1 << FPSCR_FR) | (1 << FPSCR_FI)); |
670 | 7c58044c | j_mayer | /* Update the floating-point exception summary */
|
671 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_FX;
|
672 | 7c58044c | j_mayer | if (fpscr_ze != 0) { |
673 | 7c58044c | j_mayer | /* Update the floating-point enabled exception summary */
|
674 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_FEX;
|
675 | 7c58044c | j_mayer | if (msr_fe0 != 0 || msr_fe1 != 0) { |
676 | 7c58044c | j_mayer | do_raise_exception_err(POWERPC_EXCP_PROGRAM, |
677 | 7c58044c | j_mayer | POWERPC_EXCP_FP | POWERPC_EXCP_FP_ZX); |
678 | 7c58044c | j_mayer | } |
679 | 7c58044c | j_mayer | } else {
|
680 | 7c58044c | j_mayer | /* Set the result to infinity */
|
681 | 7c58044c | j_mayer | u0.f = FT0; |
682 | 7c58044c | j_mayer | u1.f = FT1; |
683 | 7c58044c | j_mayer | u0.u = ((u0.u ^ u1.u) & 0x8000000000000000ULL);
|
684 | 86c4a9f5 | j_mayer | u0.u |= 0x7FFULL << 52; |
685 | 7c58044c | j_mayer | FT0 = u0.f; |
686 | 7c58044c | j_mayer | } |
687 | 7c58044c | j_mayer | } |
688 | 7c58044c | j_mayer | |
689 | 7c58044c | j_mayer | static always_inline void float_overflow_excp (void) |
690 | 7c58044c | j_mayer | { |
691 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_OX;
|
692 | 7c58044c | j_mayer | /* Update the floating-point exception summary */
|
693 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_FX;
|
694 | 7c58044c | j_mayer | if (fpscr_oe != 0) { |
695 | 7c58044c | j_mayer | /* XXX: should adjust the result */
|
696 | 7c58044c | j_mayer | /* Update the floating-point enabled exception summary */
|
697 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_FEX;
|
698 | 7c58044c | j_mayer | /* We must update the target FPR before raising the exception */
|
699 | 7c58044c | j_mayer | env->exception_index = POWERPC_EXCP_PROGRAM; |
700 | 7c58044c | j_mayer | env->error_code = POWERPC_EXCP_FP | POWERPC_EXCP_FP_OX; |
701 | 7c58044c | j_mayer | } else {
|
702 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_XX;
|
703 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_FI;
|
704 | 7c58044c | j_mayer | } |
705 | 7c58044c | j_mayer | } |
706 | 7c58044c | j_mayer | |
707 | 7c58044c | j_mayer | static always_inline void float_underflow_excp (void) |
708 | 7c58044c | j_mayer | { |
709 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_UX;
|
710 | 7c58044c | j_mayer | /* Update the floating-point exception summary */
|
711 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_FX;
|
712 | 7c58044c | j_mayer | if (fpscr_ue != 0) { |
713 | 7c58044c | j_mayer | /* XXX: should adjust the result */
|
714 | 7c58044c | j_mayer | /* Update the floating-point enabled exception summary */
|
715 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_FEX;
|
716 | 7c58044c | j_mayer | /* We must update the target FPR before raising the exception */
|
717 | 7c58044c | j_mayer | env->exception_index = POWERPC_EXCP_PROGRAM; |
718 | 7c58044c | j_mayer | env->error_code = POWERPC_EXCP_FP | POWERPC_EXCP_FP_UX; |
719 | 7c58044c | j_mayer | } |
720 | 7c58044c | j_mayer | } |
721 | 7c58044c | j_mayer | |
722 | 7c58044c | j_mayer | static always_inline void float_inexact_excp (void) |
723 | 7c58044c | j_mayer | { |
724 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_XX;
|
725 | 7c58044c | j_mayer | /* Update the floating-point exception summary */
|
726 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_FX;
|
727 | 7c58044c | j_mayer | if (fpscr_xe != 0) { |
728 | 7c58044c | j_mayer | /* Update the floating-point enabled exception summary */
|
729 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_FEX;
|
730 | 7c58044c | j_mayer | /* We must update the target FPR before raising the exception */
|
731 | 7c58044c | j_mayer | env->exception_index = POWERPC_EXCP_PROGRAM; |
732 | 7c58044c | j_mayer | env->error_code = POWERPC_EXCP_FP | POWERPC_EXCP_FP_XX; |
733 | 7c58044c | j_mayer | } |
734 | 7c58044c | j_mayer | } |
735 | 7c58044c | j_mayer | |
736 | 7c58044c | j_mayer | static always_inline void fpscr_set_rounding_mode (void) |
737 | 7c58044c | j_mayer | { |
738 | 7c58044c | j_mayer | int rnd_type;
|
739 | 7c58044c | j_mayer | |
740 | 7c58044c | j_mayer | /* Set rounding mode */
|
741 | 7c58044c | j_mayer | switch (fpscr_rn) {
|
742 | 7c58044c | j_mayer | case 0: |
743 | 7c58044c | j_mayer | /* Best approximation (round to nearest) */
|
744 | 7c58044c | j_mayer | rnd_type = float_round_nearest_even; |
745 | 7c58044c | j_mayer | break;
|
746 | 7c58044c | j_mayer | case 1: |
747 | 7c58044c | j_mayer | /* Smaller magnitude (round toward zero) */
|
748 | 7c58044c | j_mayer | rnd_type = float_round_to_zero; |
749 | 7c58044c | j_mayer | break;
|
750 | 7c58044c | j_mayer | case 2: |
751 | 7c58044c | j_mayer | /* Round toward +infinite */
|
752 | 7c58044c | j_mayer | rnd_type = float_round_up; |
753 | 7c58044c | j_mayer | break;
|
754 | 7c58044c | j_mayer | default:
|
755 | 7c58044c | j_mayer | case 3: |
756 | 7c58044c | j_mayer | /* Round toward -infinite */
|
757 | 7c58044c | j_mayer | rnd_type = float_round_down; |
758 | 7c58044c | j_mayer | break;
|
759 | 7c58044c | j_mayer | } |
760 | 7c58044c | j_mayer | set_float_rounding_mode(rnd_type, &env->fp_status); |
761 | 7c58044c | j_mayer | } |
762 | 7c58044c | j_mayer | |
763 | 7c58044c | j_mayer | void do_fpscr_setbit (int bit) |
764 | 7c58044c | j_mayer | { |
765 | 7c58044c | j_mayer | int prev;
|
766 | 7c58044c | j_mayer | |
767 | 7c58044c | j_mayer | prev = (env->fpscr >> bit) & 1;
|
768 | 7c58044c | j_mayer | env->fpscr |= 1 << bit;
|
769 | 7c58044c | j_mayer | if (prev == 0) { |
770 | 7c58044c | j_mayer | switch (bit) {
|
771 | 7c58044c | j_mayer | case FPSCR_VX:
|
772 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_FX;
|
773 | 7c58044c | j_mayer | if (fpscr_ve)
|
774 | 7c58044c | j_mayer | goto raise_ve;
|
775 | 7c58044c | j_mayer | case FPSCR_OX:
|
776 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_FX;
|
777 | 7c58044c | j_mayer | if (fpscr_oe)
|
778 | 7c58044c | j_mayer | goto raise_oe;
|
779 | 7c58044c | j_mayer | break;
|
780 | 7c58044c | j_mayer | case FPSCR_UX:
|
781 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_FX;
|
782 | 7c58044c | j_mayer | if (fpscr_ue)
|
783 | 7c58044c | j_mayer | goto raise_ue;
|
784 | 7c58044c | j_mayer | break;
|
785 | 7c58044c | j_mayer | case FPSCR_ZX:
|
786 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_FX;
|
787 | 7c58044c | j_mayer | if (fpscr_ze)
|
788 | 7c58044c | j_mayer | goto raise_ze;
|
789 | 7c58044c | j_mayer | break;
|
790 | 7c58044c | j_mayer | case FPSCR_XX:
|
791 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_FX;
|
792 | 7c58044c | j_mayer | if (fpscr_xe)
|
793 | 7c58044c | j_mayer | goto raise_xe;
|
794 | 7c58044c | j_mayer | break;
|
795 | 7c58044c | j_mayer | case FPSCR_VXSNAN:
|
796 | 7c58044c | j_mayer | case FPSCR_VXISI:
|
797 | 7c58044c | j_mayer | case FPSCR_VXIDI:
|
798 | 7c58044c | j_mayer | case FPSCR_VXZDZ:
|
799 | 7c58044c | j_mayer | case FPSCR_VXIMZ:
|
800 | 7c58044c | j_mayer | case FPSCR_VXVC:
|
801 | 7c58044c | j_mayer | case FPSCR_VXSOFT:
|
802 | 7c58044c | j_mayer | case FPSCR_VXSQRT:
|
803 | 7c58044c | j_mayer | case FPSCR_VXCVI:
|
804 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_VX;
|
805 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_FX;
|
806 | 7c58044c | j_mayer | if (fpscr_ve != 0) |
807 | 7c58044c | j_mayer | goto raise_ve;
|
808 | 7c58044c | j_mayer | break;
|
809 | 7c58044c | j_mayer | case FPSCR_VE:
|
810 | 7c58044c | j_mayer | if (fpscr_vx != 0) { |
811 | 7c58044c | j_mayer | raise_ve:
|
812 | 7c58044c | j_mayer | env->error_code = POWERPC_EXCP_FP; |
813 | 7c58044c | j_mayer | if (fpscr_vxsnan)
|
814 | 7c58044c | j_mayer | env->error_code |= POWERPC_EXCP_FP_VXSNAN; |
815 | 7c58044c | j_mayer | if (fpscr_vxisi)
|
816 | 7c58044c | j_mayer | env->error_code |= POWERPC_EXCP_FP_VXISI; |
817 | 7c58044c | j_mayer | if (fpscr_vxidi)
|
818 | 7c58044c | j_mayer | env->error_code |= POWERPC_EXCP_FP_VXIDI; |
819 | 7c58044c | j_mayer | if (fpscr_vxzdz)
|
820 | 7c58044c | j_mayer | env->error_code |= POWERPC_EXCP_FP_VXZDZ; |
821 | 7c58044c | j_mayer | if (fpscr_vximz)
|
822 | 7c58044c | j_mayer | env->error_code |= POWERPC_EXCP_FP_VXIMZ; |
823 | 7c58044c | j_mayer | if (fpscr_vxvc)
|
824 | 7c58044c | j_mayer | env->error_code |= POWERPC_EXCP_FP_VXVC; |
825 | 7c58044c | j_mayer | if (fpscr_vxsoft)
|
826 | 7c58044c | j_mayer | env->error_code |= POWERPC_EXCP_FP_VXSOFT; |
827 | 7c58044c | j_mayer | if (fpscr_vxsqrt)
|
828 | 7c58044c | j_mayer | env->error_code |= POWERPC_EXCP_FP_VXSQRT; |
829 | 7c58044c | j_mayer | if (fpscr_vxcvi)
|
830 | 7c58044c | j_mayer | env->error_code |= POWERPC_EXCP_FP_VXCVI; |
831 | 7c58044c | j_mayer | goto raise_excp;
|
832 | 7c58044c | j_mayer | } |
833 | 7c58044c | j_mayer | break;
|
834 | 7c58044c | j_mayer | case FPSCR_OE:
|
835 | 7c58044c | j_mayer | if (fpscr_ox != 0) { |
836 | 7c58044c | j_mayer | raise_oe:
|
837 | 7c58044c | j_mayer | env->error_code = POWERPC_EXCP_FP | POWERPC_EXCP_FP_OX; |
838 | 7c58044c | j_mayer | goto raise_excp;
|
839 | 7c58044c | j_mayer | } |
840 | 7c58044c | j_mayer | break;
|
841 | 7c58044c | j_mayer | case FPSCR_UE:
|
842 | 7c58044c | j_mayer | if (fpscr_ux != 0) { |
843 | 7c58044c | j_mayer | raise_ue:
|
844 | 7c58044c | j_mayer | env->error_code = POWERPC_EXCP_FP | POWERPC_EXCP_FP_UX; |
845 | 7c58044c | j_mayer | goto raise_excp;
|
846 | 7c58044c | j_mayer | } |
847 | 7c58044c | j_mayer | break;
|
848 | 7c58044c | j_mayer | case FPSCR_ZE:
|
849 | 7c58044c | j_mayer | if (fpscr_zx != 0) { |
850 | 7c58044c | j_mayer | raise_ze:
|
851 | 7c58044c | j_mayer | env->error_code = POWERPC_EXCP_FP | POWERPC_EXCP_FP_ZX; |
852 | 7c58044c | j_mayer | goto raise_excp;
|
853 | 7c58044c | j_mayer | } |
854 | 7c58044c | j_mayer | break;
|
855 | 7c58044c | j_mayer | case FPSCR_XE:
|
856 | 7c58044c | j_mayer | if (fpscr_xx != 0) { |
857 | 7c58044c | j_mayer | raise_xe:
|
858 | 7c58044c | j_mayer | env->error_code = POWERPC_EXCP_FP | POWERPC_EXCP_FP_XX; |
859 | 7c58044c | j_mayer | goto raise_excp;
|
860 | 7c58044c | j_mayer | } |
861 | 7c58044c | j_mayer | break;
|
862 | 7c58044c | j_mayer | case FPSCR_RN1:
|
863 | 7c58044c | j_mayer | case FPSCR_RN:
|
864 | 7c58044c | j_mayer | fpscr_set_rounding_mode(); |
865 | 7c58044c | j_mayer | break;
|
866 | 7c58044c | j_mayer | default:
|
867 | 7c58044c | j_mayer | break;
|
868 | 7c58044c | j_mayer | raise_excp:
|
869 | 7c58044c | j_mayer | /* Update the floating-point enabled exception summary */
|
870 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_FEX;
|
871 | 7c58044c | j_mayer | /* We have to update Rc1 before raising the exception */
|
872 | 7c58044c | j_mayer | env->exception_index = POWERPC_EXCP_PROGRAM; |
873 | 7c58044c | j_mayer | break;
|
874 | 7c58044c | j_mayer | } |
875 | 7c58044c | j_mayer | } |
876 | 7c58044c | j_mayer | } |
877 | 7c58044c | j_mayer | |
878 | 7c58044c | j_mayer | #if defined(WORDS_BIGENDIAN)
|
879 | 7c58044c | j_mayer | #define WORD0 0 |
880 | 7c58044c | j_mayer | #define WORD1 1 |
881 | 7c58044c | j_mayer | #else
|
882 | 7c58044c | j_mayer | #define WORD0 1 |
883 | 7c58044c | j_mayer | #define WORD1 0 |
884 | 7c58044c | j_mayer | #endif
|
885 | 7c58044c | j_mayer | void do_store_fpscr (uint32_t mask)
|
886 | 7c58044c | j_mayer | { |
887 | 7c58044c | j_mayer | /*
|
888 | 7c58044c | j_mayer | * We use only the 32 LSB of the incoming fpr
|
889 | 7c58044c | j_mayer | */
|
890 | 7c58044c | j_mayer | union {
|
891 | 7c58044c | j_mayer | double d;
|
892 | 7c58044c | j_mayer | struct {
|
893 | 7c58044c | j_mayer | uint32_t u[2];
|
894 | 7c58044c | j_mayer | } s; |
895 | 7c58044c | j_mayer | } u; |
896 | 7c58044c | j_mayer | uint32_t prev, new; |
897 | 7c58044c | j_mayer | int i;
|
898 | 7c58044c | j_mayer | |
899 | 7c58044c | j_mayer | u.d = FT0; |
900 | 7c58044c | j_mayer | prev = env->fpscr; |
901 | 7c58044c | j_mayer | new = u.s.u[WORD1]; |
902 | 7c58044c | j_mayer | new &= ~0x90000000;
|
903 | 7c58044c | j_mayer | new |= prev & 0x90000000;
|
904 | 7c58044c | j_mayer | for (i = 0; i < 7; i++) { |
905 | 7c58044c | j_mayer | if (mask & (1 << i)) { |
906 | 7c58044c | j_mayer | env->fpscr &= ~(0xF << (4 * i)); |
907 | 7c58044c | j_mayer | env->fpscr |= new & (0xF << (4 * i)); |
908 | 7c58044c | j_mayer | } |
909 | 7c58044c | j_mayer | } |
910 | 7c58044c | j_mayer | /* Update VX and FEX */
|
911 | 7c58044c | j_mayer | if (fpscr_ix != 0) |
912 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_VX;
|
913 | 7c58044c | j_mayer | if ((fpscr_ex & fpscr_eex) != 0) { |
914 | 7c58044c | j_mayer | env->fpscr |= 1 << FPSCR_FEX;
|
915 | 7c58044c | j_mayer | env->exception_index = POWERPC_EXCP_PROGRAM; |
916 | 7c58044c | j_mayer | /* XXX: we should compute it properly */
|
917 | 7c58044c | j_mayer | env->error_code = POWERPC_EXCP_FP; |
918 | 7c58044c | j_mayer | } |
919 | 7c58044c | j_mayer | fpscr_set_rounding_mode(); |
920 | 7c58044c | j_mayer | } |
921 | 7c58044c | j_mayer | #undef WORD0
|
922 | 7c58044c | j_mayer | #undef WORD1
|
923 | 7c58044c | j_mayer | |
924 | 7c58044c | j_mayer | #ifdef CONFIG_SOFTFLOAT
|
925 | 7c58044c | j_mayer | void do_float_check_status (void) |
926 | 7c58044c | j_mayer | { |
927 | 7c58044c | j_mayer | if (env->exception_index == POWERPC_EXCP_PROGRAM &&
|
928 | 7c58044c | j_mayer | (env->error_code & POWERPC_EXCP_FP)) { |
929 | 7c58044c | j_mayer | /* Differred floating-point exception after target FPR update */
|
930 | 7c58044c | j_mayer | if (msr_fe0 != 0 || msr_fe1 != 0) |
931 | 7c58044c | j_mayer | do_raise_exception_err(env->exception_index, env->error_code); |
932 | 7c58044c | j_mayer | } else if (env->fp_status.float_exception_flags & float_flag_overflow) { |
933 | 7c58044c | j_mayer | float_overflow_excp(); |
934 | 7c58044c | j_mayer | } else if (env->fp_status.float_exception_flags & float_flag_underflow) { |
935 | 7c58044c | j_mayer | float_underflow_excp(); |
936 | 7c58044c | j_mayer | } else if (env->fp_status.float_exception_flags & float_flag_inexact) { |
937 | 7c58044c | j_mayer | float_inexact_excp(); |
938 | 7c58044c | j_mayer | } |
939 | 7c58044c | j_mayer | } |
940 | 7c58044c | j_mayer | #endif
|
941 | 7c58044c | j_mayer | |
942 | 7c58044c | j_mayer | #if USE_PRECISE_EMULATION
|
943 | 7c58044c | j_mayer | void do_fadd (void) |
944 | 7c58044c | j_mayer | { |
945 | 7c58044c | j_mayer | if (unlikely(float64_is_signaling_nan(FT0) ||
|
946 | 7c58044c | j_mayer | float64_is_signaling_nan(FT1))) { |
947 | 7c58044c | j_mayer | /* sNaN addition */
|
948 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN); |
949 | 7c58044c | j_mayer | } else if (likely(isfinite(FT0) || isfinite(FT1) || |
950 | 7c58044c | j_mayer | fpisneg(FT0) == fpisneg(FT1))) { |
951 | 7c58044c | j_mayer | FT0 = float64_add(FT0, FT1, &env->fp_status); |
952 | 7c58044c | j_mayer | } else {
|
953 | 7c58044c | j_mayer | /* Magnitude subtraction of infinities */
|
954 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXISI); |
955 | 7c58044c | j_mayer | } |
956 | 7c58044c | j_mayer | } |
957 | 7c58044c | j_mayer | |
958 | 7c58044c | j_mayer | void do_fsub (void) |
959 | 7c58044c | j_mayer | { |
960 | 7c58044c | j_mayer | if (unlikely(float64_is_signaling_nan(FT0) ||
|
961 | 7c58044c | j_mayer | float64_is_signaling_nan(FT1))) { |
962 | 7c58044c | j_mayer | /* sNaN subtraction */
|
963 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN); |
964 | 7c58044c | j_mayer | } else if (likely(isfinite(FT0) || isfinite(FT1) || |
965 | 7c58044c | j_mayer | fpisneg(FT0) != fpisneg(FT1))) { |
966 | 7c58044c | j_mayer | FT0 = float64_sub(FT0, FT1, &env->fp_status); |
967 | 7c58044c | j_mayer | } else {
|
968 | 7c58044c | j_mayer | /* Magnitude subtraction of infinities */
|
969 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXISI); |
970 | 7c58044c | j_mayer | } |
971 | 7c58044c | j_mayer | } |
972 | 7c58044c | j_mayer | |
973 | 7c58044c | j_mayer | void do_fmul (void) |
974 | 7c58044c | j_mayer | { |
975 | 7c58044c | j_mayer | if (unlikely(float64_is_signaling_nan(FT0) ||
|
976 | 7c58044c | j_mayer | float64_is_signaling_nan(FT1))) { |
977 | 7c58044c | j_mayer | /* sNaN multiplication */
|
978 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN); |
979 | 5bda2843 | j_mayer | } else if (unlikely((isinfinity(FT0) && iszero(FT1)) || |
980 | 5bda2843 | j_mayer | (iszero(FT0) && isinfinity(FT1)))) { |
981 | 7c58044c | j_mayer | /* Multiplication of zero by infinity */
|
982 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXIMZ); |
983 | 7c58044c | j_mayer | } else {
|
984 | 7c58044c | j_mayer | FT0 = float64_mul(FT0, FT1, &env->fp_status); |
985 | 7c58044c | j_mayer | } |
986 | 7c58044c | j_mayer | } |
987 | 7c58044c | j_mayer | |
988 | 7c58044c | j_mayer | void do_fdiv (void) |
989 | 7c58044c | j_mayer | { |
990 | 7c58044c | j_mayer | if (unlikely(float64_is_signaling_nan(FT0) ||
|
991 | 7c58044c | j_mayer | float64_is_signaling_nan(FT1))) { |
992 | 7c58044c | j_mayer | /* sNaN division */
|
993 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN); |
994 | 7c58044c | j_mayer | } else if (unlikely(isinfinity(FT0) && isinfinity(FT1))) { |
995 | 7c58044c | j_mayer | /* Division of infinity by infinity */
|
996 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXIDI); |
997 | 7c58044c | j_mayer | } else if (unlikely(iszero(FT1))) { |
998 | 7c58044c | j_mayer | if (iszero(FT0)) {
|
999 | 7c58044c | j_mayer | /* Division of zero by zero */
|
1000 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXZDZ); |
1001 | 7c58044c | j_mayer | } else {
|
1002 | 7c58044c | j_mayer | /* Division by zero */
|
1003 | 7c58044c | j_mayer | float_zero_divide_excp(); |
1004 | 7c58044c | j_mayer | } |
1005 | 7c58044c | j_mayer | } else {
|
1006 | 7c58044c | j_mayer | FT0 = float64_div(FT0, FT1, &env->fp_status); |
1007 | 7c58044c | j_mayer | } |
1008 | 7c58044c | j_mayer | } |
1009 | 7c58044c | j_mayer | #endif /* USE_PRECISE_EMULATION */ |
1010 | 7c58044c | j_mayer | |
1011 | 9a64fbe4 | bellard | void do_fctiw (void) |
1012 | 9a64fbe4 | bellard | { |
1013 | 9a64fbe4 | bellard | union {
|
1014 | 9a64fbe4 | bellard | double d;
|
1015 | 9a64fbe4 | bellard | uint64_t i; |
1016 | 4ecc3190 | bellard | } p; |
1017 | 9a64fbe4 | bellard | |
1018 | 7c58044c | j_mayer | if (unlikely(float64_is_signaling_nan(FT0))) {
|
1019 | 7c58044c | j_mayer | /* sNaN conversion */
|
1020 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN | POWERPC_EXCP_FP_VXCVI); |
1021 | 7c58044c | j_mayer | } else if (unlikely(float64_is_nan(FT0) || isinfinity(FT0))) { |
1022 | 7c58044c | j_mayer | /* qNan / infinity conversion */
|
1023 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI); |
1024 | 7c58044c | j_mayer | } else {
|
1025 | 7c58044c | j_mayer | p.i = float64_to_int32(FT0, &env->fp_status); |
1026 | e864cabd | j_mayer | #if USE_PRECISE_EMULATION
|
1027 | 7c58044c | j_mayer | /* XXX: higher bits are not supposed to be significant.
|
1028 | 7c58044c | j_mayer | * to make tests easier, return the same as a real PowerPC 750
|
1029 | 7c58044c | j_mayer | */
|
1030 | 7c58044c | j_mayer | p.i |= 0xFFF80000ULL << 32; |
1031 | e864cabd | j_mayer | #endif
|
1032 | 7c58044c | j_mayer | FT0 = p.d; |
1033 | 7c58044c | j_mayer | } |
1034 | 9a64fbe4 | bellard | } |
1035 | 9a64fbe4 | bellard | |
1036 | 9a64fbe4 | bellard | void do_fctiwz (void) |
1037 | 9a64fbe4 | bellard | { |
1038 | 9a64fbe4 | bellard | union {
|
1039 | 9a64fbe4 | bellard | double d;
|
1040 | 9a64fbe4 | bellard | uint64_t i; |
1041 | 4ecc3190 | bellard | } p; |
1042 | 4ecc3190 | bellard | |
1043 | 7c58044c | j_mayer | if (unlikely(float64_is_signaling_nan(FT0))) {
|
1044 | 7c58044c | j_mayer | /* sNaN conversion */
|
1045 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN | POWERPC_EXCP_FP_VXCVI); |
1046 | 7c58044c | j_mayer | } else if (unlikely(float64_is_nan(FT0) || isinfinity(FT0))) { |
1047 | 7c58044c | j_mayer | /* qNan / infinity conversion */
|
1048 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI); |
1049 | 7c58044c | j_mayer | } else {
|
1050 | 7c58044c | j_mayer | p.i = float64_to_int32_round_to_zero(FT0, &env->fp_status); |
1051 | e864cabd | j_mayer | #if USE_PRECISE_EMULATION
|
1052 | 7c58044c | j_mayer | /* XXX: higher bits are not supposed to be significant.
|
1053 | 7c58044c | j_mayer | * to make tests easier, return the same as a real PowerPC 750
|
1054 | 7c58044c | j_mayer | */
|
1055 | 7c58044c | j_mayer | p.i |= 0xFFF80000ULL << 32; |
1056 | e864cabd | j_mayer | #endif
|
1057 | 7c58044c | j_mayer | FT0 = p.d; |
1058 | 7c58044c | j_mayer | } |
1059 | 9a64fbe4 | bellard | } |
1060 | 9a64fbe4 | bellard | |
1061 | 426613db | j_mayer | #if defined(TARGET_PPC64)
|
1062 | 426613db | j_mayer | void do_fcfid (void) |
1063 | 426613db | j_mayer | { |
1064 | 426613db | j_mayer | union {
|
1065 | 426613db | j_mayer | double d;
|
1066 | 426613db | j_mayer | uint64_t i; |
1067 | 426613db | j_mayer | } p; |
1068 | 426613db | j_mayer | |
1069 | 426613db | j_mayer | p.d = FT0; |
1070 | 426613db | j_mayer | FT0 = int64_to_float64(p.i, &env->fp_status); |
1071 | 426613db | j_mayer | } |
1072 | 426613db | j_mayer | |
1073 | 426613db | j_mayer | void do_fctid (void) |
1074 | 426613db | j_mayer | { |
1075 | 426613db | j_mayer | union {
|
1076 | 426613db | j_mayer | double d;
|
1077 | 426613db | j_mayer | uint64_t i; |
1078 | 426613db | j_mayer | } p; |
1079 | 426613db | j_mayer | |
1080 | 7c58044c | j_mayer | if (unlikely(float64_is_signaling_nan(FT0))) {
|
1081 | 7c58044c | j_mayer | /* sNaN conversion */
|
1082 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN | POWERPC_EXCP_FP_VXCVI); |
1083 | 7c58044c | j_mayer | } else if (unlikely(float64_is_nan(FT0) || isinfinity(FT0))) { |
1084 | 7c58044c | j_mayer | /* qNan / infinity conversion */
|
1085 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI); |
1086 | 7c58044c | j_mayer | } else {
|
1087 | 7c58044c | j_mayer | p.i = float64_to_int64(FT0, &env->fp_status); |
1088 | 7c58044c | j_mayer | FT0 = p.d; |
1089 | 7c58044c | j_mayer | } |
1090 | 426613db | j_mayer | } |
1091 | 426613db | j_mayer | |
1092 | 426613db | j_mayer | void do_fctidz (void) |
1093 | 426613db | j_mayer | { |
1094 | 426613db | j_mayer | union {
|
1095 | 426613db | j_mayer | double d;
|
1096 | 426613db | j_mayer | uint64_t i; |
1097 | 426613db | j_mayer | } p; |
1098 | 426613db | j_mayer | |
1099 | 7c58044c | j_mayer | if (unlikely(float64_is_signaling_nan(FT0))) {
|
1100 | 7c58044c | j_mayer | /* sNaN conversion */
|
1101 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN | POWERPC_EXCP_FP_VXCVI); |
1102 | 7c58044c | j_mayer | } else if (unlikely(float64_is_nan(FT0) || isinfinity(FT0))) { |
1103 | 7c58044c | j_mayer | /* qNan / infinity conversion */
|
1104 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI); |
1105 | 7c58044c | j_mayer | } else {
|
1106 | 7c58044c | j_mayer | p.i = float64_to_int64_round_to_zero(FT0, &env->fp_status); |
1107 | 7c58044c | j_mayer | FT0 = p.d; |
1108 | 7c58044c | j_mayer | } |
1109 | 426613db | j_mayer | } |
1110 | 426613db | j_mayer | |
1111 | 426613db | j_mayer | #endif
|
1112 | 426613db | j_mayer | |
1113 | b068d6a7 | j_mayer | static always_inline void do_fri (int rounding_mode) |
1114 | d7e4b87e | j_mayer | { |
1115 | 7c58044c | j_mayer | if (unlikely(float64_is_signaling_nan(FT0))) {
|
1116 | 7c58044c | j_mayer | /* sNaN round */
|
1117 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN | POWERPC_EXCP_FP_VXCVI); |
1118 | 7c58044c | j_mayer | } else if (unlikely(float64_is_nan(FT0) || isinfinity(FT0))) { |
1119 | 7c58044c | j_mayer | /* qNan / infinity round */
|
1120 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXCVI); |
1121 | 7c58044c | j_mayer | } else {
|
1122 | 7c58044c | j_mayer | set_float_rounding_mode(rounding_mode, &env->fp_status); |
1123 | 7c58044c | j_mayer | FT0 = float64_round_to_int(FT0, &env->fp_status); |
1124 | 7c58044c | j_mayer | /* Restore rounding mode from FPSCR */
|
1125 | 7c58044c | j_mayer | fpscr_set_rounding_mode(); |
1126 | 7c58044c | j_mayer | } |
1127 | d7e4b87e | j_mayer | } |
1128 | d7e4b87e | j_mayer | |
1129 | d7e4b87e | j_mayer | void do_frin (void) |
1130 | d7e4b87e | j_mayer | { |
1131 | d7e4b87e | j_mayer | do_fri(float_round_nearest_even); |
1132 | d7e4b87e | j_mayer | } |
1133 | d7e4b87e | j_mayer | |
1134 | d7e4b87e | j_mayer | void do_friz (void) |
1135 | d7e4b87e | j_mayer | { |
1136 | d7e4b87e | j_mayer | do_fri(float_round_to_zero); |
1137 | d7e4b87e | j_mayer | } |
1138 | d7e4b87e | j_mayer | |
1139 | d7e4b87e | j_mayer | void do_frip (void) |
1140 | d7e4b87e | j_mayer | { |
1141 | d7e4b87e | j_mayer | do_fri(float_round_up); |
1142 | d7e4b87e | j_mayer | } |
1143 | d7e4b87e | j_mayer | |
1144 | d7e4b87e | j_mayer | void do_frim (void) |
1145 | d7e4b87e | j_mayer | { |
1146 | d7e4b87e | j_mayer | do_fri(float_round_down); |
1147 | d7e4b87e | j_mayer | } |
1148 | d7e4b87e | j_mayer | |
1149 | e864cabd | j_mayer | #if USE_PRECISE_EMULATION
|
1150 | e864cabd | j_mayer | void do_fmadd (void) |
1151 | e864cabd | j_mayer | { |
1152 | 7c58044c | j_mayer | if (unlikely(float64_is_signaling_nan(FT0) ||
|
1153 | 7c58044c | j_mayer | float64_is_signaling_nan(FT1) || |
1154 | 7c58044c | j_mayer | float64_is_signaling_nan(FT2))) { |
1155 | 7c58044c | j_mayer | /* sNaN operation */
|
1156 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN); |
1157 | 7c58044c | j_mayer | } else {
|
1158 | e864cabd | j_mayer | #ifdef FLOAT128
|
1159 | 7c58044c | j_mayer | /* This is the way the PowerPC specification defines it */
|
1160 | 7c58044c | j_mayer | float128 ft0_128, ft1_128; |
1161 | 7c58044c | j_mayer | |
1162 | 7c58044c | j_mayer | ft0_128 = float64_to_float128(FT0, &env->fp_status); |
1163 | 7c58044c | j_mayer | ft1_128 = float64_to_float128(FT1, &env->fp_status); |
1164 | 7c58044c | j_mayer | ft0_128 = float128_mul(ft0_128, ft1_128, &env->fp_status); |
1165 | 7c58044c | j_mayer | ft1_128 = float64_to_float128(FT2, &env->fp_status); |
1166 | 7c58044c | j_mayer | ft0_128 = float128_add(ft0_128, ft1_128, &env->fp_status); |
1167 | 7c58044c | j_mayer | FT0 = float128_to_float64(ft0_128, &env->fp_status); |
1168 | e864cabd | j_mayer | #else
|
1169 | 7c58044c | j_mayer | /* This is OK on x86 hosts */
|
1170 | 7c58044c | j_mayer | FT0 = (FT0 * FT1) + FT2; |
1171 | e864cabd | j_mayer | #endif
|
1172 | 7c58044c | j_mayer | } |
1173 | e864cabd | j_mayer | } |
1174 | e864cabd | j_mayer | |
1175 | e864cabd | j_mayer | void do_fmsub (void) |
1176 | e864cabd | j_mayer | { |
1177 | 7c58044c | j_mayer | if (unlikely(float64_is_signaling_nan(FT0) ||
|
1178 | 7c58044c | j_mayer | float64_is_signaling_nan(FT1) || |
1179 | 7c58044c | j_mayer | float64_is_signaling_nan(FT2))) { |
1180 | 7c58044c | j_mayer | /* sNaN operation */
|
1181 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN); |
1182 | 7c58044c | j_mayer | } else {
|
1183 | e864cabd | j_mayer | #ifdef FLOAT128
|
1184 | 7c58044c | j_mayer | /* This is the way the PowerPC specification defines it */
|
1185 | 7c58044c | j_mayer | float128 ft0_128, ft1_128; |
1186 | 7c58044c | j_mayer | |
1187 | 7c58044c | j_mayer | ft0_128 = float64_to_float128(FT0, &env->fp_status); |
1188 | 7c58044c | j_mayer | ft1_128 = float64_to_float128(FT1, &env->fp_status); |
1189 | 7c58044c | j_mayer | ft0_128 = float128_mul(ft0_128, ft1_128, &env->fp_status); |
1190 | 7c58044c | j_mayer | ft1_128 = float64_to_float128(FT2, &env->fp_status); |
1191 | 7c58044c | j_mayer | ft0_128 = float128_sub(ft0_128, ft1_128, &env->fp_status); |
1192 | 7c58044c | j_mayer | FT0 = float128_to_float64(ft0_128, &env->fp_status); |
1193 | e864cabd | j_mayer | #else
|
1194 | 7c58044c | j_mayer | /* This is OK on x86 hosts */
|
1195 | 7c58044c | j_mayer | FT0 = (FT0 * FT1) - FT2; |
1196 | e864cabd | j_mayer | #endif
|
1197 | 7c58044c | j_mayer | } |
1198 | e864cabd | j_mayer | } |
1199 | e864cabd | j_mayer | #endif /* USE_PRECISE_EMULATION */ |
1200 | e864cabd | j_mayer | |
1201 | 4b3686fa | bellard | void do_fnmadd (void) |
1202 | 4b3686fa | bellard | { |
1203 | 7c58044c | j_mayer | if (unlikely(float64_is_signaling_nan(FT0) ||
|
1204 | 7c58044c | j_mayer | float64_is_signaling_nan(FT1) || |
1205 | 7c58044c | j_mayer | float64_is_signaling_nan(FT2))) { |
1206 | 7c58044c | j_mayer | /* sNaN operation */
|
1207 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN); |
1208 | 7c58044c | j_mayer | } else {
|
1209 | e864cabd | j_mayer | #if USE_PRECISE_EMULATION
|
1210 | e864cabd | j_mayer | #ifdef FLOAT128
|
1211 | 7c58044c | j_mayer | /* This is the way the PowerPC specification defines it */
|
1212 | 7c58044c | j_mayer | float128 ft0_128, ft1_128; |
1213 | 7c58044c | j_mayer | |
1214 | 7c58044c | j_mayer | ft0_128 = float64_to_float128(FT0, &env->fp_status); |
1215 | 7c58044c | j_mayer | ft1_128 = float64_to_float128(FT1, &env->fp_status); |
1216 | 7c58044c | j_mayer | ft0_128 = float128_mul(ft0_128, ft1_128, &env->fp_status); |
1217 | 7c58044c | j_mayer | ft1_128 = float64_to_float128(FT2, &env->fp_status); |
1218 | 7c58044c | j_mayer | ft0_128 = float128_add(ft0_128, ft1_128, &env->fp_status); |
1219 | 7c58044c | j_mayer | FT0 = float128_to_float64(ft0_128, &env->fp_status); |
1220 | e864cabd | j_mayer | #else
|
1221 | 7c58044c | j_mayer | /* This is OK on x86 hosts */
|
1222 | 7c58044c | j_mayer | FT0 = (FT0 * FT1) + FT2; |
1223 | e864cabd | j_mayer | #endif
|
1224 | e864cabd | j_mayer | #else
|
1225 | 7c58044c | j_mayer | FT0 = float64_mul(FT0, FT1, &env->fp_status); |
1226 | 7c58044c | j_mayer | FT0 = float64_add(FT0, FT2, &env->fp_status); |
1227 | e864cabd | j_mayer | #endif
|
1228 | 7c58044c | j_mayer | if (likely(!isnan(FT0)))
|
1229 | 7c58044c | j_mayer | FT0 = float64_chs(FT0); |
1230 | 7c58044c | j_mayer | } |
1231 | 4b3686fa | bellard | } |
1232 | 4b3686fa | bellard | |
1233 | 4b3686fa | bellard | void do_fnmsub (void) |
1234 | 4b3686fa | bellard | { |
1235 | 7c58044c | j_mayer | if (unlikely(float64_is_signaling_nan(FT0) ||
|
1236 | 7c58044c | j_mayer | float64_is_signaling_nan(FT1) || |
1237 | 7c58044c | j_mayer | float64_is_signaling_nan(FT2))) { |
1238 | 7c58044c | j_mayer | /* sNaN operation */
|
1239 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN); |
1240 | 7c58044c | j_mayer | } else {
|
1241 | e864cabd | j_mayer | #if USE_PRECISE_EMULATION
|
1242 | e864cabd | j_mayer | #ifdef FLOAT128
|
1243 | 7c58044c | j_mayer | /* This is the way the PowerPC specification defines it */
|
1244 | 7c58044c | j_mayer | float128 ft0_128, ft1_128; |
1245 | 7c58044c | j_mayer | |
1246 | 7c58044c | j_mayer | ft0_128 = float64_to_float128(FT0, &env->fp_status); |
1247 | 7c58044c | j_mayer | ft1_128 = float64_to_float128(FT1, &env->fp_status); |
1248 | 7c58044c | j_mayer | ft0_128 = float128_mul(ft0_128, ft1_128, &env->fp_status); |
1249 | 7c58044c | j_mayer | ft1_128 = float64_to_float128(FT2, &env->fp_status); |
1250 | 7c58044c | j_mayer | ft0_128 = float128_sub(ft0_128, ft1_128, &env->fp_status); |
1251 | 7c58044c | j_mayer | FT0 = float128_to_float64(ft0_128, &env->fp_status); |
1252 | e864cabd | j_mayer | #else
|
1253 | 7c58044c | j_mayer | /* This is OK on x86 hosts */
|
1254 | 7c58044c | j_mayer | FT0 = (FT0 * FT1) - FT2; |
1255 | e864cabd | j_mayer | #endif
|
1256 | e864cabd | j_mayer | #else
|
1257 | 7c58044c | j_mayer | FT0 = float64_mul(FT0, FT1, &env->fp_status); |
1258 | 7c58044c | j_mayer | FT0 = float64_sub(FT0, FT2, &env->fp_status); |
1259 | e864cabd | j_mayer | #endif
|
1260 | 7c58044c | j_mayer | if (likely(!isnan(FT0)))
|
1261 | 7c58044c | j_mayer | FT0 = float64_chs(FT0); |
1262 | 7c58044c | j_mayer | } |
1263 | 1ef59d0a | bellard | } |
1264 | 1ef59d0a | bellard | |
1265 | 7c58044c | j_mayer | #if USE_PRECISE_EMULATION
|
1266 | 7c58044c | j_mayer | void do_frsp (void) |
1267 | 7c58044c | j_mayer | { |
1268 | 7c58044c | j_mayer | if (unlikely(float64_is_signaling_nan(FT0))) {
|
1269 | 7c58044c | j_mayer | /* sNaN square root */
|
1270 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN); |
1271 | 7c58044c | j_mayer | } else {
|
1272 | 7c58044c | j_mayer | FT0 = float64_to_float32(FT0, &env->fp_status); |
1273 | 7c58044c | j_mayer | } |
1274 | 7c58044c | j_mayer | } |
1275 | 7c58044c | j_mayer | #endif /* USE_PRECISE_EMULATION */ |
1276 | 7c58044c | j_mayer | |
1277 | 9a64fbe4 | bellard | void do_fsqrt (void) |
1278 | 9a64fbe4 | bellard | { |
1279 | 7c58044c | j_mayer | if (unlikely(float64_is_signaling_nan(FT0))) {
|
1280 | 7c58044c | j_mayer | /* sNaN square root */
|
1281 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN); |
1282 | 7c58044c | j_mayer | } else if (unlikely(fpisneg(FT0) && !iszero(FT0))) { |
1283 | 7c58044c | j_mayer | /* Square root of a negative nonzero number */
|
1284 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXSQRT); |
1285 | 7c58044c | j_mayer | } else {
|
1286 | 7c58044c | j_mayer | FT0 = float64_sqrt(FT0, &env->fp_status); |
1287 | 7c58044c | j_mayer | } |
1288 | 9a64fbe4 | bellard | } |
1289 | 9a64fbe4 | bellard | |
1290 | d7e4b87e | j_mayer | void do_fre (void) |
1291 | d7e4b87e | j_mayer | { |
1292 | d7e4b87e | j_mayer | union {
|
1293 | d7e4b87e | j_mayer | double d;
|
1294 | d7e4b87e | j_mayer | uint64_t i; |
1295 | d7e4b87e | j_mayer | } p; |
1296 | d7e4b87e | j_mayer | |
1297 | 7c58044c | j_mayer | if (unlikely(float64_is_signaling_nan(FT0))) {
|
1298 | 7c58044c | j_mayer | /* sNaN reciprocal */
|
1299 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN); |
1300 | 7c58044c | j_mayer | } else if (unlikely(iszero(FT0))) { |
1301 | 7c58044c | j_mayer | /* Zero reciprocal */
|
1302 | 7c58044c | j_mayer | float_zero_divide_excp(); |
1303 | 7c58044c | j_mayer | } else if (likely(isnormal(FT0))) { |
1304 | d7e4b87e | j_mayer | FT0 = float64_div(1.0, FT0, &env->fp_status); |
1305 | d7e4b87e | j_mayer | } else {
|
1306 | d7e4b87e | j_mayer | p.d = FT0; |
1307 | d7e4b87e | j_mayer | if (p.i == 0x8000000000000000ULL) { |
1308 | d7e4b87e | j_mayer | p.i = 0xFFF0000000000000ULL;
|
1309 | d7e4b87e | j_mayer | } else if (p.i == 0x0000000000000000ULL) { |
1310 | d7e4b87e | j_mayer | p.i = 0x7FF0000000000000ULL;
|
1311 | d7e4b87e | j_mayer | } else if (isnan(FT0)) { |
1312 | d7e4b87e | j_mayer | p.i = 0x7FF8000000000000ULL;
|
1313 | 7c58044c | j_mayer | } else if (fpisneg(FT0)) { |
1314 | d7e4b87e | j_mayer | p.i = 0x8000000000000000ULL;
|
1315 | d7e4b87e | j_mayer | } else {
|
1316 | d7e4b87e | j_mayer | p.i = 0x0000000000000000ULL;
|
1317 | d7e4b87e | j_mayer | } |
1318 | d7e4b87e | j_mayer | FT0 = p.d; |
1319 | d7e4b87e | j_mayer | } |
1320 | d7e4b87e | j_mayer | } |
1321 | d7e4b87e | j_mayer | |
1322 | 9a64fbe4 | bellard | void do_fres (void) |
1323 | 9a64fbe4 | bellard | { |
1324 | 4ecc3190 | bellard | union {
|
1325 | 4ecc3190 | bellard | double d;
|
1326 | 4ecc3190 | bellard | uint64_t i; |
1327 | 4ecc3190 | bellard | } p; |
1328 | 4ecc3190 | bellard | |
1329 | 7c58044c | j_mayer | if (unlikely(float64_is_signaling_nan(FT0))) {
|
1330 | 7c58044c | j_mayer | /* sNaN reciprocal */
|
1331 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN); |
1332 | 7c58044c | j_mayer | } else if (unlikely(iszero(FT0))) { |
1333 | 7c58044c | j_mayer | /* Zero reciprocal */
|
1334 | 7c58044c | j_mayer | float_zero_divide_excp(); |
1335 | 7c58044c | j_mayer | } else if (likely(isnormal(FT0))) { |
1336 | e864cabd | j_mayer | #if USE_PRECISE_EMULATION
|
1337 | e864cabd | j_mayer | FT0 = float64_div(1.0, FT0, &env->fp_status); |
1338 | e864cabd | j_mayer | FT0 = float64_to_float32(FT0, &env->fp_status); |
1339 | e864cabd | j_mayer | #else
|
1340 | 76a66253 | j_mayer | FT0 = float32_div(1.0, FT0, &env->fp_status); |
1341 | e864cabd | j_mayer | #endif
|
1342 | 4ecc3190 | bellard | } else {
|
1343 | 4ecc3190 | bellard | p.d = FT0; |
1344 | 4ecc3190 | bellard | if (p.i == 0x8000000000000000ULL) { |
1345 | 4ecc3190 | bellard | p.i = 0xFFF0000000000000ULL;
|
1346 | 4ecc3190 | bellard | } else if (p.i == 0x0000000000000000ULL) { |
1347 | 4ecc3190 | bellard | p.i = 0x7FF0000000000000ULL;
|
1348 | 4ecc3190 | bellard | } else if (isnan(FT0)) { |
1349 | 4ecc3190 | bellard | p.i = 0x7FF8000000000000ULL;
|
1350 | 7c58044c | j_mayer | } else if (fpisneg(FT0)) { |
1351 | 4ecc3190 | bellard | p.i = 0x8000000000000000ULL;
|
1352 | 4ecc3190 | bellard | } else {
|
1353 | 4ecc3190 | bellard | p.i = 0x0000000000000000ULL;
|
1354 | 4ecc3190 | bellard | } |
1355 | 4ecc3190 | bellard | FT0 = p.d; |
1356 | 4ecc3190 | bellard | } |
1357 | 9a64fbe4 | bellard | } |
1358 | 9a64fbe4 | bellard | |
1359 | 4ecc3190 | bellard | void do_frsqrte (void) |
1360 | 9a64fbe4 | bellard | { |
1361 | 4ecc3190 | bellard | union {
|
1362 | 4ecc3190 | bellard | double d;
|
1363 | 4ecc3190 | bellard | uint64_t i; |
1364 | 4ecc3190 | bellard | } p; |
1365 | 4ecc3190 | bellard | |
1366 | 7c58044c | j_mayer | if (unlikely(float64_is_signaling_nan(FT0))) {
|
1367 | 7c58044c | j_mayer | /* sNaN reciprocal square root */
|
1368 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN); |
1369 | 7c58044c | j_mayer | } else if (unlikely(fpisneg(FT0) && !iszero(FT0))) { |
1370 | 7c58044c | j_mayer | /* Reciprocal square root of a negative nonzero number */
|
1371 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXSQRT); |
1372 | 7c58044c | j_mayer | } else if (likely(isnormal(FT0))) { |
1373 | fdabc366 | bellard | FT0 = float64_sqrt(FT0, &env->fp_status); |
1374 | fdabc366 | bellard | FT0 = float32_div(1.0, FT0, &env->fp_status); |
1375 | 4ecc3190 | bellard | } else {
|
1376 | 4ecc3190 | bellard | p.d = FT0; |
1377 | 4ecc3190 | bellard | if (p.i == 0x8000000000000000ULL) { |
1378 | 4ecc3190 | bellard | p.i = 0xFFF0000000000000ULL;
|
1379 | 4ecc3190 | bellard | } else if (p.i == 0x0000000000000000ULL) { |
1380 | 4ecc3190 | bellard | p.i = 0x7FF0000000000000ULL;
|
1381 | 4ecc3190 | bellard | } else if (isnan(FT0)) { |
1382 | 7c58044c | j_mayer | p.i |= 0x000FFFFFFFFFFFFFULL;
|
1383 | 7c58044c | j_mayer | } else if (fpisneg(FT0)) { |
1384 | 4ecc3190 | bellard | p.i = 0x7FF8000000000000ULL;
|
1385 | 4ecc3190 | bellard | } else {
|
1386 | 4ecc3190 | bellard | p.i = 0x0000000000000000ULL;
|
1387 | 4ecc3190 | bellard | } |
1388 | 4ecc3190 | bellard | FT0 = p.d; |
1389 | 4ecc3190 | bellard | } |
1390 | 9a64fbe4 | bellard | } |
1391 | 9a64fbe4 | bellard | |
1392 | 9a64fbe4 | bellard | void do_fsel (void) |
1393 | 9a64fbe4 | bellard | { |
1394 | 7c58044c | j_mayer | if (!fpisneg(FT0) || iszero(FT0))
|
1395 | 9a64fbe4 | bellard | FT0 = FT1; |
1396 | 4ecc3190 | bellard | else
|
1397 | 4ecc3190 | bellard | FT0 = FT2; |
1398 | 9a64fbe4 | bellard | } |
1399 | 9a64fbe4 | bellard | |
1400 | 9a64fbe4 | bellard | void do_fcmpu (void) |
1401 | 9a64fbe4 | bellard | { |
1402 | 7c58044c | j_mayer | if (unlikely(float64_is_signaling_nan(FT0) ||
|
1403 | 7c58044c | j_mayer | float64_is_signaling_nan(FT1))) { |
1404 | 7c58044c | j_mayer | /* sNaN comparison */
|
1405 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN); |
1406 | 7c58044c | j_mayer | } else {
|
1407 | fdabc366 | bellard | if (float64_lt(FT0, FT1, &env->fp_status)) {
|
1408 | fdabc366 | bellard | T0 = 0x08UL;
|
1409 | fdabc366 | bellard | } else if (!float64_le(FT0, FT1, &env->fp_status)) { |
1410 | fdabc366 | bellard | T0 = 0x04UL;
|
1411 | fdabc366 | bellard | } else {
|
1412 | fdabc366 | bellard | T0 = 0x02UL;
|
1413 | fdabc366 | bellard | } |
1414 | 9a64fbe4 | bellard | } |
1415 | 7c58044c | j_mayer | env->fpscr &= ~(0x0F << FPSCR_FPRF);
|
1416 | 7c58044c | j_mayer | env->fpscr |= T0 << FPSCR_FPRF; |
1417 | 9a64fbe4 | bellard | } |
1418 | 9a64fbe4 | bellard | |
1419 | 9a64fbe4 | bellard | void do_fcmpo (void) |
1420 | 9a64fbe4 | bellard | { |
1421 | 7c58044c | j_mayer | if (unlikely(float64_is_nan(FT0) ||
|
1422 | 7c58044c | j_mayer | float64_is_nan(FT1))) { |
1423 | 7c58044c | j_mayer | if (float64_is_signaling_nan(FT0) ||
|
1424 | 7c58044c | j_mayer | float64_is_signaling_nan(FT1)) { |
1425 | 7c58044c | j_mayer | /* sNaN comparison */
|
1426 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXSNAN | |
1427 | 7c58044c | j_mayer | POWERPC_EXCP_FP_VXVC); |
1428 | 7c58044c | j_mayer | } else {
|
1429 | 7c58044c | j_mayer | /* qNaN comparison */
|
1430 | 7c58044c | j_mayer | fload_invalid_op_excp(POWERPC_EXCP_FP_VXVC); |
1431 | 7c58044c | j_mayer | } |
1432 | 7c58044c | j_mayer | } else {
|
1433 | fdabc366 | bellard | if (float64_lt(FT0, FT1, &env->fp_status)) {
|
1434 | fdabc366 | bellard | T0 = 0x08UL;
|
1435 | fdabc366 | bellard | } else if (!float64_le(FT0, FT1, &env->fp_status)) { |
1436 | fdabc366 | bellard | T0 = 0x04UL;
|
1437 | fdabc366 | bellard | } else {
|
1438 | fdabc366 | bellard | T0 = 0x02UL;
|
1439 | fdabc366 | bellard | } |
1440 | 9a64fbe4 | bellard | } |
1441 | 7c58044c | j_mayer | env->fpscr &= ~(0x0F << FPSCR_FPRF);
|
1442 | 7c58044c | j_mayer | env->fpscr |= T0 << FPSCR_FPRF; |
1443 | 9a64fbe4 | bellard | } |
1444 | 9a64fbe4 | bellard | |
1445 | 76a66253 | j_mayer | #if !defined (CONFIG_USER_ONLY)
|
1446 | 6b80055d | j_mayer | void cpu_dump_rfi (target_ulong RA, target_ulong msr);
|
1447 | 0411a972 | j_mayer | |
1448 | 0411a972 | j_mayer | void do_store_msr (void) |
1449 | 0411a972 | j_mayer | { |
1450 | 0411a972 | j_mayer | T0 = hreg_store_msr(env, T0); |
1451 | 0411a972 | j_mayer | if (T0 != 0) { |
1452 | 0411a972 | j_mayer | env->interrupt_request |= CPU_INTERRUPT_EXITTB; |
1453 | 0411a972 | j_mayer | do_raise_exception(T0); |
1454 | 0411a972 | j_mayer | } |
1455 | 0411a972 | j_mayer | } |
1456 | 0411a972 | j_mayer | |
1457 | 0411a972 | j_mayer | static always_inline void __do_rfi (target_ulong nip, target_ulong msr, |
1458 | 0411a972 | j_mayer | target_ulong msrm, int keep_msrh)
|
1459 | 9a64fbe4 | bellard | { |
1460 | 426613db | j_mayer | #if defined(TARGET_PPC64)
|
1461 | 0411a972 | j_mayer | if (msr & (1ULL << MSR_SF)) { |
1462 | 0411a972 | j_mayer | nip = (uint64_t)nip; |
1463 | 0411a972 | j_mayer | msr &= (uint64_t)msrm; |
1464 | a42bd6cc | j_mayer | } else {
|
1465 | 0411a972 | j_mayer | nip = (uint32_t)nip; |
1466 | 0411a972 | j_mayer | msr = (uint32_t)(msr & msrm); |
1467 | 0411a972 | j_mayer | if (keep_msrh)
|
1468 | 0411a972 | j_mayer | msr |= env->msr & ~((uint64_t)0xFFFFFFFF);
|
1469 | a42bd6cc | j_mayer | } |
1470 | 426613db | j_mayer | #else
|
1471 | 0411a972 | j_mayer | nip = (uint32_t)nip; |
1472 | 0411a972 | j_mayer | msr &= (uint32_t)msrm; |
1473 | 426613db | j_mayer | #endif
|
1474 | 0411a972 | j_mayer | /* XXX: beware: this is false if VLE is supported */
|
1475 | 0411a972 | j_mayer | env->nip = nip & ~((target_ulong)0x00000003);
|
1476 | 0411a972 | j_mayer | hreg_store_msr(env, msr); |
1477 | fdabc366 | bellard | #if defined (DEBUG_OP)
|
1478 | 0411a972 | j_mayer | cpu_dump_rfi(env->nip, env->msr); |
1479 | fdabc366 | bellard | #endif
|
1480 | 0411a972 | j_mayer | /* No need to raise an exception here,
|
1481 | 0411a972 | j_mayer | * as rfi is always the last insn of a TB
|
1482 | 0411a972 | j_mayer | */
|
1483 | fdabc366 | bellard | env->interrupt_request |= CPU_INTERRUPT_EXITTB; |
1484 | 9a64fbe4 | bellard | } |
1485 | d9bce9d9 | j_mayer | |
1486 | 0411a972 | j_mayer | void do_rfi (void) |
1487 | 0411a972 | j_mayer | { |
1488 | 0411a972 | j_mayer | __do_rfi(env->spr[SPR_SRR0], env->spr[SPR_SRR1], |
1489 | 0411a972 | j_mayer | ~((target_ulong)0xFFFF0000), 1); |
1490 | 0411a972 | j_mayer | } |
1491 | 0411a972 | j_mayer | |
1492 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
1493 | 426613db | j_mayer | void do_rfid (void) |
1494 | 426613db | j_mayer | { |
1495 | 0411a972 | j_mayer | __do_rfi(env->spr[SPR_SRR0], env->spr[SPR_SRR1], |
1496 | 0411a972 | j_mayer | ~((target_ulong)0xFFFF0000), 0); |
1497 | d9bce9d9 | j_mayer | } |
1498 | d9bce9d9 | j_mayer | #endif
|
1499 | be147d08 | j_mayer | #if defined(TARGET_PPC64H)
|
1500 | be147d08 | j_mayer | void do_hrfid (void) |
1501 | be147d08 | j_mayer | { |
1502 | 0411a972 | j_mayer | __do_rfi(env->spr[SPR_HSRR0], env->spr[SPR_HSRR1], |
1503 | 0411a972 | j_mayer | ~((target_ulong)0xFFFF0000), 0); |
1504 | be147d08 | j_mayer | } |
1505 | be147d08 | j_mayer | #endif
|
1506 | 76a66253 | j_mayer | #endif
|
1507 | 9a64fbe4 | bellard | |
1508 | 76a66253 | j_mayer | void do_tw (int flags) |
1509 | 9a64fbe4 | bellard | { |
1510 | d9bce9d9 | j_mayer | if (!likely(!(((int32_t)T0 < (int32_t)T1 && (flags & 0x10)) || |
1511 | d9bce9d9 | j_mayer | ((int32_t)T0 > (int32_t)T1 && (flags & 0x08)) ||
|
1512 | d9bce9d9 | j_mayer | ((int32_t)T0 == (int32_t)T1 && (flags & 0x04)) ||
|
1513 | d9bce9d9 | j_mayer | ((uint32_t)T0 < (uint32_t)T1 && (flags & 0x02)) ||
|
1514 | a42bd6cc | j_mayer | ((uint32_t)T0 > (uint32_t)T1 && (flags & 0x01))))) {
|
1515 | e1833e1f | j_mayer | do_raise_exception_err(POWERPC_EXCP_PROGRAM, POWERPC_EXCP_TRAP); |
1516 | a42bd6cc | j_mayer | } |
1517 | 9a64fbe4 | bellard | } |
1518 | 9a64fbe4 | bellard | |
1519 | d9bce9d9 | j_mayer | #if defined(TARGET_PPC64)
|
1520 | d9bce9d9 | j_mayer | void do_td (int flags) |
1521 | d9bce9d9 | j_mayer | { |
1522 | d9bce9d9 | j_mayer | if (!likely(!(((int64_t)T0 < (int64_t)T1 && (flags & 0x10)) || |
1523 | d9bce9d9 | j_mayer | ((int64_t)T0 > (int64_t)T1 && (flags & 0x08)) ||
|
1524 | d9bce9d9 | j_mayer | ((int64_t)T0 == (int64_t)T1 && (flags & 0x04)) ||
|
1525 | d9bce9d9 | j_mayer | ((uint64_t)T0 < (uint64_t)T1 && (flags & 0x02)) ||
|
1526 | d9bce9d9 | j_mayer | ((uint64_t)T0 > (uint64_t)T1 && (flags & 0x01)))))
|
1527 | e1833e1f | j_mayer | do_raise_exception_err(POWERPC_EXCP_PROGRAM, POWERPC_EXCP_TRAP); |
1528 | d9bce9d9 | j_mayer | } |
1529 | d9bce9d9 | j_mayer | #endif
|
1530 | d9bce9d9 | j_mayer | |
1531 | fdabc366 | bellard | /*****************************************************************************/
|
1532 | 76a66253 | j_mayer | /* PowerPC 601 specific instructions (POWER bridge) */
|
1533 | 76a66253 | j_mayer | void do_POWER_abso (void) |
1534 | 9a64fbe4 | bellard | { |
1535 | d9bce9d9 | j_mayer | if ((uint32_t)T0 == INT32_MIN) {
|
1536 | 76a66253 | j_mayer | T0 = INT32_MAX; |
1537 | 76a66253 | j_mayer | xer_ov = 1;
|
1538 | 76a66253 | j_mayer | xer_so = 1;
|
1539 | 76a66253 | j_mayer | } else {
|
1540 | 76a66253 | j_mayer | T0 = -T0; |
1541 | 76a66253 | j_mayer | xer_ov = 0;
|
1542 | 76a66253 | j_mayer | } |
1543 | 9a64fbe4 | bellard | } |
1544 | 9a64fbe4 | bellard | |
1545 | 76a66253 | j_mayer | void do_POWER_clcs (void) |
1546 | 9a64fbe4 | bellard | { |
1547 | 76a66253 | j_mayer | switch (T0) {
|
1548 | 76a66253 | j_mayer | case 0x0CUL: |
1549 | 76a66253 | j_mayer | /* Instruction cache line size */
|
1550 | d63001d1 | j_mayer | T0 = env->icache_line_size; |
1551 | 76a66253 | j_mayer | break;
|
1552 | 76a66253 | j_mayer | case 0x0DUL: |
1553 | 76a66253 | j_mayer | /* Data cache line size */
|
1554 | d63001d1 | j_mayer | T0 = env->dcache_line_size; |
1555 | 76a66253 | j_mayer | break;
|
1556 | 76a66253 | j_mayer | case 0x0EUL: |
1557 | 76a66253 | j_mayer | /* Minimum cache line size */
|
1558 | d63001d1 | j_mayer | T0 = env->icache_line_size < env->dcache_line_size ? |
1559 | d63001d1 | j_mayer | env->icache_line_size : env->dcache_line_size; |
1560 | 76a66253 | j_mayer | break;
|
1561 | 76a66253 | j_mayer | case 0x0FUL: |
1562 | 76a66253 | j_mayer | /* Maximum cache line size */
|
1563 | d63001d1 | j_mayer | T0 = env->icache_line_size > env->dcache_line_size ? |
1564 | d63001d1 | j_mayer | env->icache_line_size : env->dcache_line_size; |
1565 | 76a66253 | j_mayer | break;
|
1566 | 76a66253 | j_mayer | default:
|
1567 | 76a66253 | j_mayer | /* Undefined */
|
1568 | 76a66253 | j_mayer | break;
|
1569 | 76a66253 | j_mayer | } |
1570 | 76a66253 | j_mayer | } |
1571 | 76a66253 | j_mayer | |
1572 | 76a66253 | j_mayer | void do_POWER_div (void) |
1573 | 76a66253 | j_mayer | { |
1574 | 76a66253 | j_mayer | uint64_t tmp; |
1575 | 76a66253 | j_mayer | |
1576 | d9bce9d9 | j_mayer | if (((int32_t)T0 == INT32_MIN && (int32_t)T1 == -1) || (int32_t)T1 == 0) { |
1577 | 76a66253 | j_mayer | T0 = (long)((-1) * (T0 >> 31)); |
1578 | 76a66253 | j_mayer | env->spr[SPR_MQ] = 0;
|
1579 | 76a66253 | j_mayer | } else {
|
1580 | 76a66253 | j_mayer | tmp = ((uint64_t)T0 << 32) | env->spr[SPR_MQ];
|
1581 | 76a66253 | j_mayer | env->spr[SPR_MQ] = tmp % T1; |
1582 | d9bce9d9 | j_mayer | T0 = tmp / (int32_t)T1; |
1583 | 76a66253 | j_mayer | } |
1584 | 76a66253 | j_mayer | } |
1585 | 76a66253 | j_mayer | |
1586 | 76a66253 | j_mayer | void do_POWER_divo (void) |
1587 | 76a66253 | j_mayer | { |
1588 | 76a66253 | j_mayer | int64_t tmp; |
1589 | 76a66253 | j_mayer | |
1590 | d9bce9d9 | j_mayer | if (((int32_t)T0 == INT32_MIN && (int32_t)T1 == -1) || (int32_t)T1 == 0) { |
1591 | 76a66253 | j_mayer | T0 = (long)((-1) * (T0 >> 31)); |
1592 | 76a66253 | j_mayer | env->spr[SPR_MQ] = 0;
|
1593 | 76a66253 | j_mayer | xer_ov = 1;
|
1594 | 76a66253 | j_mayer | xer_so = 1;
|
1595 | 76a66253 | j_mayer | } else {
|
1596 | 76a66253 | j_mayer | tmp = ((uint64_t)T0 << 32) | env->spr[SPR_MQ];
|
1597 | 76a66253 | j_mayer | env->spr[SPR_MQ] = tmp % T1; |
1598 | d9bce9d9 | j_mayer | tmp /= (int32_t)T1; |
1599 | 76a66253 | j_mayer | if (tmp > (int64_t)INT32_MAX || tmp < (int64_t)INT32_MIN) {
|
1600 | 76a66253 | j_mayer | xer_ov = 1;
|
1601 | 76a66253 | j_mayer | xer_so = 1;
|
1602 | 76a66253 | j_mayer | } else {
|
1603 | 76a66253 | j_mayer | xer_ov = 0;
|
1604 | 76a66253 | j_mayer | } |
1605 | 76a66253 | j_mayer | T0 = tmp; |
1606 | 76a66253 | j_mayer | } |
1607 | 76a66253 | j_mayer | } |
1608 | 76a66253 | j_mayer | |
1609 | 76a66253 | j_mayer | void do_POWER_divs (void) |
1610 | 76a66253 | j_mayer | { |
1611 | d9bce9d9 | j_mayer | if (((int32_t)T0 == INT32_MIN && (int32_t)T1 == -1) || (int32_t)T1 == 0) { |
1612 | 76a66253 | j_mayer | T0 = (long)((-1) * (T0 >> 31)); |
1613 | 76a66253 | j_mayer | env->spr[SPR_MQ] = 0;
|
1614 | 76a66253 | j_mayer | } else {
|
1615 | 76a66253 | j_mayer | env->spr[SPR_MQ] = T0 % T1; |
1616 | d9bce9d9 | j_mayer | T0 = (int32_t)T0 / (int32_t)T1; |
1617 | 76a66253 | j_mayer | } |
1618 | 76a66253 | j_mayer | } |
1619 | 76a66253 | j_mayer | |
1620 | 76a66253 | j_mayer | void do_POWER_divso (void) |
1621 | 76a66253 | j_mayer | { |
1622 | d9bce9d9 | j_mayer | if (((int32_t)T0 == INT32_MIN && (int32_t)T1 == -1) || (int32_t)T1 == 0) { |
1623 | 76a66253 | j_mayer | T0 = (long)((-1) * (T0 >> 31)); |
1624 | 76a66253 | j_mayer | env->spr[SPR_MQ] = 0;
|
1625 | 76a66253 | j_mayer | xer_ov = 1;
|
1626 | 76a66253 | j_mayer | xer_so = 1;
|
1627 | 76a66253 | j_mayer | } else {
|
1628 | d9bce9d9 | j_mayer | T0 = (int32_t)T0 / (int32_t)T1; |
1629 | d9bce9d9 | j_mayer | env->spr[SPR_MQ] = (int32_t)T0 % (int32_t)T1; |
1630 | 76a66253 | j_mayer | xer_ov = 0;
|
1631 | 76a66253 | j_mayer | } |
1632 | 76a66253 | j_mayer | } |
1633 | 76a66253 | j_mayer | |
1634 | 76a66253 | j_mayer | void do_POWER_dozo (void) |
1635 | 76a66253 | j_mayer | { |
1636 | d9bce9d9 | j_mayer | if ((int32_t)T1 > (int32_t)T0) {
|
1637 | 76a66253 | j_mayer | T2 = T0; |
1638 | 76a66253 | j_mayer | T0 = T1 - T0; |
1639 | d9bce9d9 | j_mayer | if (((uint32_t)(~T2) ^ (uint32_t)T1 ^ UINT32_MAX) &
|
1640 | d9bce9d9 | j_mayer | ((uint32_t)(~T2) ^ (uint32_t)T0) & (1UL << 31)) { |
1641 | 76a66253 | j_mayer | xer_ov = 1;
|
1642 | 966439a6 | j_mayer | xer_so = 1;
|
1643 | 76a66253 | j_mayer | } else {
|
1644 | 76a66253 | j_mayer | xer_ov = 0;
|
1645 | 76a66253 | j_mayer | } |
1646 | 76a66253 | j_mayer | } else {
|
1647 | 76a66253 | j_mayer | T0 = 0;
|
1648 | 76a66253 | j_mayer | xer_ov = 0;
|
1649 | 76a66253 | j_mayer | } |
1650 | 76a66253 | j_mayer | } |
1651 | 76a66253 | j_mayer | |
1652 | 76a66253 | j_mayer | void do_POWER_maskg (void) |
1653 | 76a66253 | j_mayer | { |
1654 | 76a66253 | j_mayer | uint32_t ret; |
1655 | 76a66253 | j_mayer | |
1656 | d9bce9d9 | j_mayer | if ((uint32_t)T0 == (uint32_t)(T1 + 1)) { |
1657 | 76a66253 | j_mayer | ret = -1;
|
1658 | 76a66253 | j_mayer | } else {
|
1659 | d9bce9d9 | j_mayer | ret = (((uint32_t)(-1)) >> ((uint32_t)T0)) ^
|
1660 | d9bce9d9 | j_mayer | (((uint32_t)(-1) >> ((uint32_t)T1)) >> 1); |
1661 | d9bce9d9 | j_mayer | if ((uint32_t)T0 > (uint32_t)T1)
|
1662 | 76a66253 | j_mayer | ret = ~ret; |
1663 | 76a66253 | j_mayer | } |
1664 | 76a66253 | j_mayer | T0 = ret; |
1665 | 76a66253 | j_mayer | } |
1666 | 76a66253 | j_mayer | |
1667 | 76a66253 | j_mayer | void do_POWER_mulo (void) |
1668 | 76a66253 | j_mayer | { |
1669 | 76a66253 | j_mayer | uint64_t tmp; |
1670 | 76a66253 | j_mayer | |
1671 | 76a66253 | j_mayer | tmp = (uint64_t)T0 * (uint64_t)T1; |
1672 | 76a66253 | j_mayer | env->spr[SPR_MQ] = tmp >> 32;
|
1673 | 76a66253 | j_mayer | T0 = tmp; |
1674 | 76a66253 | j_mayer | if (tmp >> 32 != ((uint64_t)T0 >> 16) * ((uint64_t)T1 >> 16)) { |
1675 | 76a66253 | j_mayer | xer_ov = 1;
|
1676 | 76a66253 | j_mayer | xer_so = 1;
|
1677 | 76a66253 | j_mayer | } else {
|
1678 | 76a66253 | j_mayer | xer_ov = 0;
|
1679 | 76a66253 | j_mayer | } |
1680 | 76a66253 | j_mayer | } |
1681 | 76a66253 | j_mayer | |
1682 | 76a66253 | j_mayer | #if !defined (CONFIG_USER_ONLY)
|
1683 | 76a66253 | j_mayer | void do_POWER_rac (void) |
1684 | 76a66253 | j_mayer | { |
1685 | 76a66253 | j_mayer | mmu_ctx_t ctx; |
1686 | faadf50e | j_mayer | int nb_BATs;
|
1687 | 76a66253 | j_mayer | |
1688 | 76a66253 | j_mayer | /* We don't have to generate many instances of this instruction,
|
1689 | 76a66253 | j_mayer | * as rac is supervisor only.
|
1690 | 76a66253 | j_mayer | */
|
1691 | faadf50e | j_mayer | /* XXX: FIX THIS: Pretend we have no BAT */
|
1692 | faadf50e | j_mayer | nb_BATs = env->nb_BATs; |
1693 | faadf50e | j_mayer | env->nb_BATs = 0;
|
1694 | faadf50e | j_mayer | if (get_physical_address(env, &ctx, T0, 0, ACCESS_INT) == 0) |
1695 | 76a66253 | j_mayer | T0 = ctx.raddr; |
1696 | faadf50e | j_mayer | env->nb_BATs = nb_BATs; |
1697 | 76a66253 | j_mayer | } |
1698 | 76a66253 | j_mayer | |
1699 | 76a66253 | j_mayer | void do_POWER_rfsvc (void) |
1700 | 76a66253 | j_mayer | { |
1701 | 0411a972 | j_mayer | __do_rfi(env->lr, env->ctr, 0x0000FFFF, 0); |
1702 | 76a66253 | j_mayer | } |
1703 | 76a66253 | j_mayer | |
1704 | 76a66253 | j_mayer | /* PowerPC 601 BAT management helper */
|
1705 | 76a66253 | j_mayer | void do_store_601_batu (int nr) |
1706 | 76a66253 | j_mayer | { |
1707 | d9bce9d9 | j_mayer | do_store_ibatu(env, nr, (uint32_t)T0); |
1708 | 76a66253 | j_mayer | env->DBAT[0][nr] = env->IBAT[0][nr]; |
1709 | 76a66253 | j_mayer | env->DBAT[1][nr] = env->IBAT[1][nr]; |
1710 | 76a66253 | j_mayer | } |
1711 | 76a66253 | j_mayer | #endif
|
1712 | 76a66253 | j_mayer | |
1713 | 76a66253 | j_mayer | /*****************************************************************************/
|
1714 | 76a66253 | j_mayer | /* 602 specific instructions */
|
1715 | 76a66253 | j_mayer | /* mfrom is the most crazy instruction ever seen, imho ! */
|
1716 | 76a66253 | j_mayer | /* Real implementation uses a ROM table. Do the same */
|
1717 | 76a66253 | j_mayer | #define USE_MFROM_ROM_TABLE
|
1718 | 76a66253 | j_mayer | void do_op_602_mfrom (void) |
1719 | 76a66253 | j_mayer | { |
1720 | 76a66253 | j_mayer | if (likely(T0 < 602)) { |
1721 | d9bce9d9 | j_mayer | #if defined(USE_MFROM_ROM_TABLE)
|
1722 | 76a66253 | j_mayer | #include "mfrom_table.c" |
1723 | 76a66253 | j_mayer | T0 = mfrom_ROM_table[T0]; |
1724 | fdabc366 | bellard | #else
|
1725 | 76a66253 | j_mayer | double d;
|
1726 | 76a66253 | j_mayer | /* Extremly decomposed:
|
1727 | 76a66253 | j_mayer | * -T0 / 256
|
1728 | 76a66253 | j_mayer | * T0 = 256 * log10(10 + 1.0) + 0.5
|
1729 | 76a66253 | j_mayer | */
|
1730 | 76a66253 | j_mayer | d = T0; |
1731 | 76a66253 | j_mayer | d = float64_div(d, 256, &env->fp_status);
|
1732 | 76a66253 | j_mayer | d = float64_chs(d); |
1733 | 76a66253 | j_mayer | d = exp10(d); // XXX: use float emulation function
|
1734 | 76a66253 | j_mayer | d = float64_add(d, 1.0, &env->fp_status); |
1735 | 76a66253 | j_mayer | d = log10(d); // XXX: use float emulation function
|
1736 | 76a66253 | j_mayer | d = float64_mul(d, 256, &env->fp_status);
|
1737 | 76a66253 | j_mayer | d = float64_add(d, 0.5, &env->fp_status); |
1738 | 76a66253 | j_mayer | T0 = float64_round_to_int(d, &env->fp_status); |
1739 | fdabc366 | bellard | #endif
|
1740 | 76a66253 | j_mayer | } else {
|
1741 | 76a66253 | j_mayer | T0 = 0;
|
1742 | 76a66253 | j_mayer | } |
1743 | 76a66253 | j_mayer | } |
1744 | 76a66253 | j_mayer | |
1745 | 76a66253 | j_mayer | /*****************************************************************************/
|
1746 | 76a66253 | j_mayer | /* Embedded PowerPC specific helpers */
|
1747 | 76a66253 | j_mayer | void do_405_check_ov (void) |
1748 | 76a66253 | j_mayer | { |
1749 | d9bce9d9 | j_mayer | if (likely((((uint32_t)T1 ^ (uint32_t)T2) >> 31) || |
1750 | d9bce9d9 | j_mayer | !(((uint32_t)T0 ^ (uint32_t)T2) >> 31))) {
|
1751 | 76a66253 | j_mayer | xer_ov = 0;
|
1752 | 76a66253 | j_mayer | } else {
|
1753 | 76a66253 | j_mayer | xer_ov = 1;
|
1754 | 76a66253 | j_mayer | xer_so = 1;
|
1755 | 76a66253 | j_mayer | } |
1756 | 76a66253 | j_mayer | } |
1757 | 76a66253 | j_mayer | |
1758 | 76a66253 | j_mayer | void do_405_check_sat (void) |
1759 | 76a66253 | j_mayer | { |
1760 | d9bce9d9 | j_mayer | if (!likely((((uint32_t)T1 ^ (uint32_t)T2) >> 31) || |
1761 | d9bce9d9 | j_mayer | !(((uint32_t)T0 ^ (uint32_t)T2) >> 31))) {
|
1762 | 76a66253 | j_mayer | /* Saturate result */
|
1763 | 76a66253 | j_mayer | if (T2 >> 31) { |
1764 | 76a66253 | j_mayer | T0 = INT32_MIN; |
1765 | 76a66253 | j_mayer | } else {
|
1766 | 76a66253 | j_mayer | T0 = INT32_MAX; |
1767 | 76a66253 | j_mayer | } |
1768 | 76a66253 | j_mayer | } |
1769 | 76a66253 | j_mayer | } |
1770 | 76a66253 | j_mayer | |
1771 | a750fc0b | j_mayer | /* XXX: to be improved to check access rights when in user-mode */
|
1772 | a750fc0b | j_mayer | void do_load_dcr (void) |
1773 | a750fc0b | j_mayer | { |
1774 | a750fc0b | j_mayer | target_ulong val; |
1775 | a750fc0b | j_mayer | |
1776 | a750fc0b | j_mayer | if (unlikely(env->dcr_env == NULL)) { |
1777 | a750fc0b | j_mayer | if (loglevel != 0) { |
1778 | a750fc0b | j_mayer | fprintf(logfile, "No DCR environment\n");
|
1779 | a750fc0b | j_mayer | } |
1780 | e1833e1f | j_mayer | do_raise_exception_err(POWERPC_EXCP_PROGRAM, |
1781 | e1833e1f | j_mayer | POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_INVAL); |
1782 | a750fc0b | j_mayer | } else if (unlikely(ppc_dcr_read(env->dcr_env, T0, &val) != 0)) { |
1783 | a750fc0b | j_mayer | if (loglevel != 0) { |
1784 | a750fc0b | j_mayer | fprintf(logfile, "DCR read error %d %03x\n", (int)T0, (int)T0); |
1785 | a750fc0b | j_mayer | } |
1786 | e1833e1f | j_mayer | do_raise_exception_err(POWERPC_EXCP_PROGRAM, |
1787 | e1833e1f | j_mayer | POWERPC_EXCP_INVAL | POWERPC_EXCP_PRIV_REG); |
1788 | a750fc0b | j_mayer | } else {
|
1789 | a750fc0b | j_mayer | T0 = val; |
1790 | a750fc0b | j_mayer | } |
1791 | a750fc0b | j_mayer | } |
1792 | a750fc0b | j_mayer | |
1793 | a750fc0b | j_mayer | void do_store_dcr (void) |
1794 | a750fc0b | j_mayer | { |
1795 | a750fc0b | j_mayer | if (unlikely(env->dcr_env == NULL)) { |
1796 | a750fc0b | j_mayer | if (loglevel != 0) { |
1797 | a750fc0b | j_mayer | fprintf(logfile, "No DCR environment\n");
|
1798 | a750fc0b | j_mayer | } |
1799 | e1833e1f | j_mayer | do_raise_exception_err(POWERPC_EXCP_PROGRAM, |
1800 | e1833e1f | j_mayer | POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_INVAL); |
1801 | a750fc0b | j_mayer | } else if (unlikely(ppc_dcr_write(env->dcr_env, T0, T1) != 0)) { |
1802 | a750fc0b | j_mayer | if (loglevel != 0) { |
1803 | a750fc0b | j_mayer | fprintf(logfile, "DCR write error %d %03x\n", (int)T0, (int)T0); |
1804 | a750fc0b | j_mayer | } |
1805 | e1833e1f | j_mayer | do_raise_exception_err(POWERPC_EXCP_PROGRAM, |
1806 | e1833e1f | j_mayer | POWERPC_EXCP_INVAL | POWERPC_EXCP_PRIV_REG); |
1807 | a750fc0b | j_mayer | } |
1808 | a750fc0b | j_mayer | } |
1809 | a750fc0b | j_mayer | |
1810 | 76a66253 | j_mayer | #if !defined(CONFIG_USER_ONLY)
|
1811 | a42bd6cc | j_mayer | void do_40x_rfci (void) |
1812 | 76a66253 | j_mayer | { |
1813 | 0411a972 | j_mayer | __do_rfi(env->spr[SPR_40x_SRR2], env->spr[SPR_40x_SRR3], |
1814 | 0411a972 | j_mayer | ~((target_ulong)0xFFFF0000), 0); |
1815 | a42bd6cc | j_mayer | } |
1816 | a42bd6cc | j_mayer | |
1817 | a42bd6cc | j_mayer | void do_rfci (void) |
1818 | a42bd6cc | j_mayer | { |
1819 | 0411a972 | j_mayer | __do_rfi(env->spr[SPR_BOOKE_CSRR0], SPR_BOOKE_CSRR1, |
1820 | 0411a972 | j_mayer | ~((target_ulong)0x3FFF0000), 0); |
1821 | a42bd6cc | j_mayer | } |
1822 | a42bd6cc | j_mayer | |
1823 | a42bd6cc | j_mayer | void do_rfdi (void) |
1824 | a42bd6cc | j_mayer | { |
1825 | 0411a972 | j_mayer | __do_rfi(env->spr[SPR_BOOKE_DSRR0], SPR_BOOKE_DSRR1, |
1826 | 0411a972 | j_mayer | ~((target_ulong)0x3FFF0000), 0); |
1827 | a42bd6cc | j_mayer | } |
1828 | a42bd6cc | j_mayer | |
1829 | a42bd6cc | j_mayer | void do_rfmci (void) |
1830 | a42bd6cc | j_mayer | { |
1831 | 0411a972 | j_mayer | __do_rfi(env->spr[SPR_BOOKE_MCSRR0], SPR_BOOKE_MCSRR1, |
1832 | 0411a972 | j_mayer | ~((target_ulong)0x3FFF0000), 0); |
1833 | 76a66253 | j_mayer | } |
1834 | 76a66253 | j_mayer | |
1835 | 76a66253 | j_mayer | void do_load_403_pb (int num) |
1836 | 76a66253 | j_mayer | { |
1837 | 76a66253 | j_mayer | T0 = env->pb[num]; |
1838 | 76a66253 | j_mayer | } |
1839 | 76a66253 | j_mayer | |
1840 | 76a66253 | j_mayer | void do_store_403_pb (int num) |
1841 | 76a66253 | j_mayer | { |
1842 | 76a66253 | j_mayer | if (likely(env->pb[num] != T0)) {
|
1843 | 76a66253 | j_mayer | env->pb[num] = T0; |
1844 | 76a66253 | j_mayer | /* Should be optimized */
|
1845 | 76a66253 | j_mayer | tlb_flush(env, 1);
|
1846 | 76a66253 | j_mayer | } |
1847 | 76a66253 | j_mayer | } |
1848 | 76a66253 | j_mayer | #endif
|
1849 | 76a66253 | j_mayer | |
1850 | 76a66253 | j_mayer | /* 440 specific */
|
1851 | 76a66253 | j_mayer | void do_440_dlmzb (void) |
1852 | 76a66253 | j_mayer | { |
1853 | 76a66253 | j_mayer | target_ulong mask; |
1854 | 76a66253 | j_mayer | int i;
|
1855 | 76a66253 | j_mayer | |
1856 | 76a66253 | j_mayer | i = 1;
|
1857 | 76a66253 | j_mayer | for (mask = 0xFF000000; mask != 0; mask = mask >> 8) { |
1858 | 76a66253 | j_mayer | if ((T0 & mask) == 0) |
1859 | 76a66253 | j_mayer | goto done;
|
1860 | 76a66253 | j_mayer | i++; |
1861 | 76a66253 | j_mayer | } |
1862 | 76a66253 | j_mayer | for (mask = 0xFF000000; mask != 0; mask = mask >> 8) { |
1863 | 76a66253 | j_mayer | if ((T1 & mask) == 0) |
1864 | 76a66253 | j_mayer | break;
|
1865 | 76a66253 | j_mayer | i++; |
1866 | 76a66253 | j_mayer | } |
1867 | 76a66253 | j_mayer | done:
|
1868 | 76a66253 | j_mayer | T0 = i; |
1869 | fdabc366 | bellard | } |
1870 | fdabc366 | bellard | |
1871 | 35cdaad6 | j_mayer | #if defined(TARGET_PPCEMB)
|
1872 | 0487d6a8 | j_mayer | /* SPE extension helpers */
|
1873 | 0487d6a8 | j_mayer | /* Use a table to make this quicker */
|
1874 | 0487d6a8 | j_mayer | static uint8_t hbrev[16] = { |
1875 | 0487d6a8 | j_mayer | 0x0, 0x8, 0x4, 0xC, 0x2, 0xA, 0x6, 0xE, |
1876 | 0487d6a8 | j_mayer | 0x1, 0x9, 0x5, 0xD, 0x3, 0xB, 0x7, 0xF, |
1877 | 0487d6a8 | j_mayer | }; |
1878 | 0487d6a8 | j_mayer | |
1879 | b068d6a7 | j_mayer | static always_inline uint8_t byte_reverse (uint8_t val)
|
1880 | 0487d6a8 | j_mayer | { |
1881 | 0487d6a8 | j_mayer | return hbrev[val >> 4] | (hbrev[val & 0xF] << 4); |
1882 | 0487d6a8 | j_mayer | } |
1883 | 0487d6a8 | j_mayer | |
1884 | b068d6a7 | j_mayer | static always_inline uint32_t word_reverse (uint32_t val)
|
1885 | 0487d6a8 | j_mayer | { |
1886 | 0487d6a8 | j_mayer | return byte_reverse(val >> 24) | (byte_reverse(val >> 16) << 8) | |
1887 | 0487d6a8 | j_mayer | (byte_reverse(val >> 8) << 16) | (byte_reverse(val) << 24); |
1888 | 0487d6a8 | j_mayer | } |
1889 | 0487d6a8 | j_mayer | |
1890 | 0487d6a8 | j_mayer | #define MASKBITS 16 // Random value - to be fixed |
1891 | 0487d6a8 | j_mayer | void do_brinc (void) |
1892 | 0487d6a8 | j_mayer | { |
1893 | 0487d6a8 | j_mayer | uint32_t a, b, d, mask; |
1894 | 0487d6a8 | j_mayer | |
1895 | 0487d6a8 | j_mayer | mask = (uint32_t)(-1UL) >> MASKBITS;
|
1896 | 0487d6a8 | j_mayer | b = T1_64 & mask; |
1897 | 0487d6a8 | j_mayer | a = T0_64 & mask; |
1898 | 0487d6a8 | j_mayer | d = word_reverse(1 + word_reverse(a | ~mask));
|
1899 | 0487d6a8 | j_mayer | T0_64 = (T0_64 & ~mask) | (d & mask); |
1900 | 0487d6a8 | j_mayer | } |
1901 | 0487d6a8 | j_mayer | |
1902 | 0487d6a8 | j_mayer | #define DO_SPE_OP2(name) \
|
1903 | 0487d6a8 | j_mayer | void do_ev##name (void) \ |
1904 | 0487d6a8 | j_mayer | { \ |
1905 | 0487d6a8 | j_mayer | T0_64 = ((uint64_t)_do_e##name(T0_64 >> 32, T1_64 >> 32) << 32) | \ |
1906 | 0487d6a8 | j_mayer | (uint64_t)_do_e##name(T0_64, T1_64); \ |
1907 | 0487d6a8 | j_mayer | } |
1908 | 0487d6a8 | j_mayer | |
1909 | 0487d6a8 | j_mayer | #define DO_SPE_OP1(name) \
|
1910 | 0487d6a8 | j_mayer | void do_ev##name (void) \ |
1911 | 0487d6a8 | j_mayer | { \ |
1912 | 0487d6a8 | j_mayer | T0_64 = ((uint64_t)_do_e##name(T0_64 >> 32) << 32) | \ |
1913 | 0487d6a8 | j_mayer | (uint64_t)_do_e##name(T0_64); \ |
1914 | 0487d6a8 | j_mayer | } |
1915 | 0487d6a8 | j_mayer | |
1916 | 0487d6a8 | j_mayer | /* Fixed-point vector arithmetic */
|
1917 | b068d6a7 | j_mayer | static always_inline uint32_t _do_eabs (uint32_t val)
|
1918 | 0487d6a8 | j_mayer | { |
1919 | 0487d6a8 | j_mayer | if (val != 0x80000000) |
1920 | 0487d6a8 | j_mayer | val &= ~0x80000000;
|
1921 | 0487d6a8 | j_mayer | |
1922 | 0487d6a8 | j_mayer | return val;
|
1923 | 0487d6a8 | j_mayer | } |
1924 | 0487d6a8 | j_mayer | |
1925 | b068d6a7 | j_mayer | static always_inline uint32_t _do_eaddw (uint32_t op1, uint32_t op2)
|
1926 | 0487d6a8 | j_mayer | { |
1927 | 0487d6a8 | j_mayer | return op1 + op2;
|
1928 | 0487d6a8 | j_mayer | } |
1929 | 0487d6a8 | j_mayer | |
1930 | b068d6a7 | j_mayer | static always_inline int _do_ecntlsw (uint32_t val) |
1931 | 0487d6a8 | j_mayer | { |
1932 | 0487d6a8 | j_mayer | if (val & 0x80000000) |
1933 | 603fccce | j_mayer | return clz32(~val);
|
1934 | 0487d6a8 | j_mayer | else
|
1935 | 603fccce | j_mayer | return clz32(val);
|
1936 | 0487d6a8 | j_mayer | } |
1937 | 0487d6a8 | j_mayer | |
1938 | b068d6a7 | j_mayer | static always_inline int _do_ecntlzw (uint32_t val) |
1939 | 0487d6a8 | j_mayer | { |
1940 | 603fccce | j_mayer | return clz32(val);
|
1941 | 0487d6a8 | j_mayer | } |
1942 | 0487d6a8 | j_mayer | |
1943 | b068d6a7 | j_mayer | static always_inline uint32_t _do_eneg (uint32_t val)
|
1944 | 0487d6a8 | j_mayer | { |
1945 | 0487d6a8 | j_mayer | if (val != 0x80000000) |
1946 | 0487d6a8 | j_mayer | val ^= 0x80000000;
|
1947 | 0487d6a8 | j_mayer | |
1948 | 0487d6a8 | j_mayer | return val;
|
1949 | 0487d6a8 | j_mayer | } |
1950 | 0487d6a8 | j_mayer | |
1951 | b068d6a7 | j_mayer | static always_inline uint32_t _do_erlw (uint32_t op1, uint32_t op2)
|
1952 | 0487d6a8 | j_mayer | { |
1953 | 0487d6a8 | j_mayer | return rotl32(op1, op2);
|
1954 | 0487d6a8 | j_mayer | } |
1955 | 0487d6a8 | j_mayer | |
1956 | b068d6a7 | j_mayer | static always_inline uint32_t _do_erndw (uint32_t val)
|
1957 | 0487d6a8 | j_mayer | { |
1958 | 0487d6a8 | j_mayer | return (val + 0x000080000000) & 0xFFFF0000; |
1959 | 0487d6a8 | j_mayer | } |
1960 | 0487d6a8 | j_mayer | |
1961 | b068d6a7 | j_mayer | static always_inline uint32_t _do_eslw (uint32_t op1, uint32_t op2)
|
1962 | 0487d6a8 | j_mayer | { |
1963 | 0487d6a8 | j_mayer | /* No error here: 6 bits are used */
|
1964 | 0487d6a8 | j_mayer | return op1 << (op2 & 0x3F); |
1965 | 0487d6a8 | j_mayer | } |
1966 | 0487d6a8 | j_mayer | |
1967 | b068d6a7 | j_mayer | static always_inline int32_t _do_esrws (int32_t op1, uint32_t op2)
|
1968 | 0487d6a8 | j_mayer | { |
1969 | 0487d6a8 | j_mayer | /* No error here: 6 bits are used */
|
1970 | 0487d6a8 | j_mayer | return op1 >> (op2 & 0x3F); |
1971 | 0487d6a8 | j_mayer | } |
1972 | 0487d6a8 | j_mayer | |
1973 | b068d6a7 | j_mayer | static always_inline uint32_t _do_esrwu (uint32_t op1, uint32_t op2)
|
1974 | 0487d6a8 | j_mayer | { |
1975 | 0487d6a8 | j_mayer | /* No error here: 6 bits are used */
|
1976 | 0487d6a8 | j_mayer | return op1 >> (op2 & 0x3F); |
1977 | 0487d6a8 | j_mayer | } |
1978 | 0487d6a8 | j_mayer | |
1979 | b068d6a7 | j_mayer | static always_inline uint32_t _do_esubfw (uint32_t op1, uint32_t op2)
|
1980 | 0487d6a8 | j_mayer | { |
1981 | 0487d6a8 | j_mayer | return op2 - op1;
|
1982 | 0487d6a8 | j_mayer | } |
1983 | 0487d6a8 | j_mayer | |
1984 | 0487d6a8 | j_mayer | /* evabs */
|
1985 | 0487d6a8 | j_mayer | DO_SPE_OP1(abs); |
1986 | 0487d6a8 | j_mayer | /* evaddw */
|
1987 | 0487d6a8 | j_mayer | DO_SPE_OP2(addw); |
1988 | 0487d6a8 | j_mayer | /* evcntlsw */
|
1989 | 0487d6a8 | j_mayer | DO_SPE_OP1(cntlsw); |
1990 | 0487d6a8 | j_mayer | /* evcntlzw */
|
1991 | 0487d6a8 | j_mayer | DO_SPE_OP1(cntlzw); |
1992 | 0487d6a8 | j_mayer | /* evneg */
|
1993 | 0487d6a8 | j_mayer | DO_SPE_OP1(neg); |
1994 | 0487d6a8 | j_mayer | /* evrlw */
|
1995 | 0487d6a8 | j_mayer | DO_SPE_OP2(rlw); |
1996 | 0487d6a8 | j_mayer | /* evrnd */
|
1997 | 0487d6a8 | j_mayer | DO_SPE_OP1(rndw); |
1998 | 0487d6a8 | j_mayer | /* evslw */
|
1999 | 0487d6a8 | j_mayer | DO_SPE_OP2(slw); |
2000 | 0487d6a8 | j_mayer | /* evsrws */
|
2001 | 0487d6a8 | j_mayer | DO_SPE_OP2(srws); |
2002 | 0487d6a8 | j_mayer | /* evsrwu */
|
2003 | 0487d6a8 | j_mayer | DO_SPE_OP2(srwu); |
2004 | 0487d6a8 | j_mayer | /* evsubfw */
|
2005 | 0487d6a8 | j_mayer | DO_SPE_OP2(subfw); |
2006 | 0487d6a8 | j_mayer | |
2007 | 0487d6a8 | j_mayer | /* evsel is a little bit more complicated... */
|
2008 | b068d6a7 | j_mayer | static always_inline uint32_t _do_esel (uint32_t op1, uint32_t op2, int n) |
2009 | 0487d6a8 | j_mayer | { |
2010 | 0487d6a8 | j_mayer | if (n)
|
2011 | 0487d6a8 | j_mayer | return op1;
|
2012 | 0487d6a8 | j_mayer | else
|
2013 | 0487d6a8 | j_mayer | return op2;
|
2014 | 0487d6a8 | j_mayer | } |
2015 | 0487d6a8 | j_mayer | |
2016 | 0487d6a8 | j_mayer | void do_evsel (void) |
2017 | 0487d6a8 | j_mayer | { |
2018 | 0487d6a8 | j_mayer | T0_64 = ((uint64_t)_do_esel(T0_64 >> 32, T1_64 >> 32, T0 >> 3) << 32) | |
2019 | 0487d6a8 | j_mayer | (uint64_t)_do_esel(T0_64, T1_64, (T0 >> 2) & 1); |
2020 | 0487d6a8 | j_mayer | } |
2021 | 0487d6a8 | j_mayer | |
2022 | 0487d6a8 | j_mayer | /* Fixed-point vector comparisons */
|
2023 | 0487d6a8 | j_mayer | #define DO_SPE_CMP(name) \
|
2024 | 0487d6a8 | j_mayer | void do_ev##name (void) \ |
2025 | 0487d6a8 | j_mayer | { \ |
2026 | 0487d6a8 | j_mayer | T0 = _do_evcmp_merge((uint64_t)_do_e##name(T0_64 >> 32, \ |
2027 | 0487d6a8 | j_mayer | T1_64 >> 32) << 32, \ |
2028 | 0487d6a8 | j_mayer | _do_e##name(T0_64, T1_64)); \ |
2029 | 0487d6a8 | j_mayer | } |
2030 | 0487d6a8 | j_mayer | |
2031 | b068d6a7 | j_mayer | static always_inline uint32_t _do_evcmp_merge (int t0, int t1) |
2032 | 0487d6a8 | j_mayer | { |
2033 | 0487d6a8 | j_mayer | return (t0 << 3) | (t1 << 2) | ((t0 | t1) << 1) | (t0 & t1); |
2034 | 0487d6a8 | j_mayer | } |
2035 | b068d6a7 | j_mayer | static always_inline int _do_ecmpeq (uint32_t op1, uint32_t op2) |
2036 | 0487d6a8 | j_mayer | { |
2037 | 0487d6a8 | j_mayer | return op1 == op2 ? 1 : 0; |
2038 | 0487d6a8 | j_mayer | } |
2039 | 0487d6a8 | j_mayer | |
2040 | b068d6a7 | j_mayer | static always_inline int _do_ecmpgts (int32_t op1, int32_t op2) |
2041 | 0487d6a8 | j_mayer | { |
2042 | 0487d6a8 | j_mayer | return op1 > op2 ? 1 : 0; |
2043 | 0487d6a8 | j_mayer | } |
2044 | 0487d6a8 | j_mayer | |
2045 | b068d6a7 | j_mayer | static always_inline int _do_ecmpgtu (uint32_t op1, uint32_t op2) |
2046 | 0487d6a8 | j_mayer | { |
2047 | 0487d6a8 | j_mayer | return op1 > op2 ? 1 : 0; |
2048 | 0487d6a8 | j_mayer | } |
2049 | 0487d6a8 | j_mayer | |
2050 | b068d6a7 | j_mayer | static always_inline int _do_ecmplts (int32_t op1, int32_t op2) |
2051 | 0487d6a8 | j_mayer | { |
2052 | 0487d6a8 | j_mayer | return op1 < op2 ? 1 : 0; |
2053 | 0487d6a8 | j_mayer | } |
2054 | 0487d6a8 | j_mayer | |
2055 | b068d6a7 | j_mayer | static always_inline int _do_ecmpltu (uint32_t op1, uint32_t op2) |
2056 | 0487d6a8 | j_mayer | { |
2057 | 0487d6a8 | j_mayer | return op1 < op2 ? 1 : 0; |
2058 | 0487d6a8 | j_mayer | } |
2059 | 0487d6a8 | j_mayer | |
2060 | 0487d6a8 | j_mayer | /* evcmpeq */
|
2061 | 0487d6a8 | j_mayer | DO_SPE_CMP(cmpeq); |
2062 | 0487d6a8 | j_mayer | /* evcmpgts */
|
2063 | 0487d6a8 | j_mayer | DO_SPE_CMP(cmpgts); |
2064 | 0487d6a8 | j_mayer | /* evcmpgtu */
|
2065 | 0487d6a8 | j_mayer | DO_SPE_CMP(cmpgtu); |
2066 | 0487d6a8 | j_mayer | /* evcmplts */
|
2067 | 0487d6a8 | j_mayer | DO_SPE_CMP(cmplts); |
2068 | 0487d6a8 | j_mayer | /* evcmpltu */
|
2069 | 0487d6a8 | j_mayer | DO_SPE_CMP(cmpltu); |
2070 | 0487d6a8 | j_mayer | |
2071 | 0487d6a8 | j_mayer | /* Single precision floating-point conversions from/to integer */
|
2072 | b068d6a7 | j_mayer | static always_inline uint32_t _do_efscfsi (int32_t val)
|
2073 | 0487d6a8 | j_mayer | { |
2074 | 0487d6a8 | j_mayer | union {
|
2075 | 0487d6a8 | j_mayer | uint32_t u; |
2076 | 0487d6a8 | j_mayer | float32 f; |
2077 | 0487d6a8 | j_mayer | } u; |
2078 | 0487d6a8 | j_mayer | |
2079 | 0487d6a8 | j_mayer | u.f = int32_to_float32(val, &env->spe_status); |
2080 | 0487d6a8 | j_mayer | |
2081 | 0487d6a8 | j_mayer | return u.u;
|
2082 | 0487d6a8 | j_mayer | } |
2083 | 0487d6a8 | j_mayer | |
2084 | b068d6a7 | j_mayer | static always_inline uint32_t _do_efscfui (uint32_t val)
|
2085 | 0487d6a8 | j_mayer | { |
2086 | 0487d6a8 | j_mayer | union {
|
2087 | 0487d6a8 | j_mayer | uint32_t u; |
2088 | 0487d6a8 | j_mayer | float32 f; |
2089 | 0487d6a8 | j_mayer | } u; |
2090 | 0487d6a8 | j_mayer | |
2091 | 0487d6a8 | j_mayer | u.f = uint32_to_float32(val, &env->spe_status); |
2092 | 0487d6a8 | j_mayer | |
2093 | 0487d6a8 | j_mayer | return u.u;
|
2094 | 0487d6a8 | j_mayer | } |
2095 | 0487d6a8 | j_mayer | |
2096 | b068d6a7 | j_mayer | static always_inline int32_t _do_efsctsi (uint32_t val)
|
2097 | 0487d6a8 | j_mayer | { |
2098 | 0487d6a8 | j_mayer | union {
|
2099 | 0487d6a8 | j_mayer | int32_t u; |
2100 | 0487d6a8 | j_mayer | float32 f; |
2101 | 0487d6a8 | j_mayer | } u; |
2102 | 0487d6a8 | j_mayer | |
2103 | 0487d6a8 | j_mayer | u.u = val; |
2104 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
2105 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
2106 | 0487d6a8 | j_mayer | return 0; |
2107 | 0487d6a8 | j_mayer | |
2108 | 0487d6a8 | j_mayer | return float32_to_int32(u.f, &env->spe_status);
|
2109 | 0487d6a8 | j_mayer | } |
2110 | 0487d6a8 | j_mayer | |
2111 | b068d6a7 | j_mayer | static always_inline uint32_t _do_efsctui (uint32_t val)
|
2112 | 0487d6a8 | j_mayer | { |
2113 | 0487d6a8 | j_mayer | union {
|
2114 | 0487d6a8 | j_mayer | int32_t u; |
2115 | 0487d6a8 | j_mayer | float32 f; |
2116 | 0487d6a8 | j_mayer | } u; |
2117 | 0487d6a8 | j_mayer | |
2118 | 0487d6a8 | j_mayer | u.u = val; |
2119 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
2120 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
2121 | 0487d6a8 | j_mayer | return 0; |
2122 | 0487d6a8 | j_mayer | |
2123 | 0487d6a8 | j_mayer | return float32_to_uint32(u.f, &env->spe_status);
|
2124 | 0487d6a8 | j_mayer | } |
2125 | 0487d6a8 | j_mayer | |
2126 | b068d6a7 | j_mayer | static always_inline int32_t _do_efsctsiz (uint32_t val)
|
2127 | 0487d6a8 | j_mayer | { |
2128 | 0487d6a8 | j_mayer | union {
|
2129 | 0487d6a8 | j_mayer | int32_t u; |
2130 | 0487d6a8 | j_mayer | float32 f; |
2131 | 0487d6a8 | j_mayer | } u; |
2132 | 0487d6a8 | j_mayer | |
2133 | 0487d6a8 | j_mayer | u.u = val; |
2134 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
2135 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
2136 | 0487d6a8 | j_mayer | return 0; |
2137 | 0487d6a8 | j_mayer | |
2138 | 0487d6a8 | j_mayer | return float32_to_int32_round_to_zero(u.f, &env->spe_status);
|
2139 | 0487d6a8 | j_mayer | } |
2140 | 0487d6a8 | j_mayer | |
2141 | b068d6a7 | j_mayer | static always_inline uint32_t _do_efsctuiz (uint32_t val)
|
2142 | 0487d6a8 | j_mayer | { |
2143 | 0487d6a8 | j_mayer | union {
|
2144 | 0487d6a8 | j_mayer | int32_t u; |
2145 | 0487d6a8 | j_mayer | float32 f; |
2146 | 0487d6a8 | j_mayer | } u; |
2147 | 0487d6a8 | j_mayer | |
2148 | 0487d6a8 | j_mayer | u.u = val; |
2149 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
2150 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
2151 | 0487d6a8 | j_mayer | return 0; |
2152 | 0487d6a8 | j_mayer | |
2153 | 0487d6a8 | j_mayer | return float32_to_uint32_round_to_zero(u.f, &env->spe_status);
|
2154 | 0487d6a8 | j_mayer | } |
2155 | 0487d6a8 | j_mayer | |
2156 | 0487d6a8 | j_mayer | void do_efscfsi (void) |
2157 | 0487d6a8 | j_mayer | { |
2158 | 0487d6a8 | j_mayer | T0_64 = _do_efscfsi(T0_64); |
2159 | 0487d6a8 | j_mayer | } |
2160 | 0487d6a8 | j_mayer | |
2161 | 0487d6a8 | j_mayer | void do_efscfui (void) |
2162 | 0487d6a8 | j_mayer | { |
2163 | 0487d6a8 | j_mayer | T0_64 = _do_efscfui(T0_64); |
2164 | 0487d6a8 | j_mayer | } |
2165 | 0487d6a8 | j_mayer | |
2166 | 0487d6a8 | j_mayer | void do_efsctsi (void) |
2167 | 0487d6a8 | j_mayer | { |
2168 | 0487d6a8 | j_mayer | T0_64 = _do_efsctsi(T0_64); |
2169 | 0487d6a8 | j_mayer | } |
2170 | 0487d6a8 | j_mayer | |
2171 | 0487d6a8 | j_mayer | void do_efsctui (void) |
2172 | 0487d6a8 | j_mayer | { |
2173 | 0487d6a8 | j_mayer | T0_64 = _do_efsctui(T0_64); |
2174 | 0487d6a8 | j_mayer | } |
2175 | 0487d6a8 | j_mayer | |
2176 | 0487d6a8 | j_mayer | void do_efsctsiz (void) |
2177 | 0487d6a8 | j_mayer | { |
2178 | 0487d6a8 | j_mayer | T0_64 = _do_efsctsiz(T0_64); |
2179 | 0487d6a8 | j_mayer | } |
2180 | 0487d6a8 | j_mayer | |
2181 | 0487d6a8 | j_mayer | void do_efsctuiz (void) |
2182 | 0487d6a8 | j_mayer | { |
2183 | 0487d6a8 | j_mayer | T0_64 = _do_efsctuiz(T0_64); |
2184 | 0487d6a8 | j_mayer | } |
2185 | 0487d6a8 | j_mayer | |
2186 | 0487d6a8 | j_mayer | /* Single precision floating-point conversion to/from fractional */
|
2187 | b068d6a7 | j_mayer | static always_inline uint32_t _do_efscfsf (uint32_t val)
|
2188 | 0487d6a8 | j_mayer | { |
2189 | 0487d6a8 | j_mayer | union {
|
2190 | 0487d6a8 | j_mayer | uint32_t u; |
2191 | 0487d6a8 | j_mayer | float32 f; |
2192 | 0487d6a8 | j_mayer | } u; |
2193 | 0487d6a8 | j_mayer | float32 tmp; |
2194 | 0487d6a8 | j_mayer | |
2195 | 0487d6a8 | j_mayer | u.f = int32_to_float32(val, &env->spe_status); |
2196 | 0487d6a8 | j_mayer | tmp = int64_to_float32(1ULL << 32, &env->spe_status); |
2197 | 0487d6a8 | j_mayer | u.f = float32_div(u.f, tmp, &env->spe_status); |
2198 | 0487d6a8 | j_mayer | |
2199 | 0487d6a8 | j_mayer | return u.u;
|
2200 | 0487d6a8 | j_mayer | } |
2201 | 0487d6a8 | j_mayer | |
2202 | b068d6a7 | j_mayer | static always_inline uint32_t _do_efscfuf (uint32_t val)
|
2203 | 0487d6a8 | j_mayer | { |
2204 | 0487d6a8 | j_mayer | union {
|
2205 | 0487d6a8 | j_mayer | uint32_t u; |
2206 | 0487d6a8 | j_mayer | float32 f; |
2207 | 0487d6a8 | j_mayer | } u; |
2208 | 0487d6a8 | j_mayer | float32 tmp; |
2209 | 0487d6a8 | j_mayer | |
2210 | 0487d6a8 | j_mayer | u.f = uint32_to_float32(val, &env->spe_status); |
2211 | 0487d6a8 | j_mayer | tmp = uint64_to_float32(1ULL << 32, &env->spe_status); |
2212 | 0487d6a8 | j_mayer | u.f = float32_div(u.f, tmp, &env->spe_status); |
2213 | 0487d6a8 | j_mayer | |
2214 | 0487d6a8 | j_mayer | return u.u;
|
2215 | 0487d6a8 | j_mayer | } |
2216 | 0487d6a8 | j_mayer | |
2217 | b068d6a7 | j_mayer | static always_inline int32_t _do_efsctsf (uint32_t val)
|
2218 | 0487d6a8 | j_mayer | { |
2219 | 0487d6a8 | j_mayer | union {
|
2220 | 0487d6a8 | j_mayer | int32_t u; |
2221 | 0487d6a8 | j_mayer | float32 f; |
2222 | 0487d6a8 | j_mayer | } u; |
2223 | 0487d6a8 | j_mayer | float32 tmp; |
2224 | 0487d6a8 | j_mayer | |
2225 | 0487d6a8 | j_mayer | u.u = val; |
2226 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
2227 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
2228 | 0487d6a8 | j_mayer | return 0; |
2229 | 0487d6a8 | j_mayer | tmp = uint64_to_float32(1ULL << 32, &env->spe_status); |
2230 | 0487d6a8 | j_mayer | u.f = float32_mul(u.f, tmp, &env->spe_status); |
2231 | 0487d6a8 | j_mayer | |
2232 | 0487d6a8 | j_mayer | return float32_to_int32(u.f, &env->spe_status);
|
2233 | 0487d6a8 | j_mayer | } |
2234 | 0487d6a8 | j_mayer | |
2235 | b068d6a7 | j_mayer | static always_inline uint32_t _do_efsctuf (uint32_t val)
|
2236 | 0487d6a8 | j_mayer | { |
2237 | 0487d6a8 | j_mayer | union {
|
2238 | 0487d6a8 | j_mayer | int32_t u; |
2239 | 0487d6a8 | j_mayer | float32 f; |
2240 | 0487d6a8 | j_mayer | } u; |
2241 | 0487d6a8 | j_mayer | float32 tmp; |
2242 | 0487d6a8 | j_mayer | |
2243 | 0487d6a8 | j_mayer | u.u = val; |
2244 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
2245 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
2246 | 0487d6a8 | j_mayer | return 0; |
2247 | 0487d6a8 | j_mayer | tmp = uint64_to_float32(1ULL << 32, &env->spe_status); |
2248 | 0487d6a8 | j_mayer | u.f = float32_mul(u.f, tmp, &env->spe_status); |
2249 | 0487d6a8 | j_mayer | |
2250 | 0487d6a8 | j_mayer | return float32_to_uint32(u.f, &env->spe_status);
|
2251 | 0487d6a8 | j_mayer | } |
2252 | 0487d6a8 | j_mayer | |
2253 | b068d6a7 | j_mayer | static always_inline int32_t _do_efsctsfz (uint32_t val)
|
2254 | 0487d6a8 | j_mayer | { |
2255 | 0487d6a8 | j_mayer | union {
|
2256 | 0487d6a8 | j_mayer | int32_t u; |
2257 | 0487d6a8 | j_mayer | float32 f; |
2258 | 0487d6a8 | j_mayer | } u; |
2259 | 0487d6a8 | j_mayer | float32 tmp; |
2260 | 0487d6a8 | j_mayer | |
2261 | 0487d6a8 | j_mayer | u.u = val; |
2262 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
2263 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
2264 | 0487d6a8 | j_mayer | return 0; |
2265 | 0487d6a8 | j_mayer | tmp = uint64_to_float32(1ULL << 32, &env->spe_status); |
2266 | 0487d6a8 | j_mayer | u.f = float32_mul(u.f, tmp, &env->spe_status); |
2267 | 0487d6a8 | j_mayer | |
2268 | 0487d6a8 | j_mayer | return float32_to_int32_round_to_zero(u.f, &env->spe_status);
|
2269 | 0487d6a8 | j_mayer | } |
2270 | 0487d6a8 | j_mayer | |
2271 | b068d6a7 | j_mayer | static always_inline uint32_t _do_efsctufz (uint32_t val)
|
2272 | 0487d6a8 | j_mayer | { |
2273 | 0487d6a8 | j_mayer | union {
|
2274 | 0487d6a8 | j_mayer | int32_t u; |
2275 | 0487d6a8 | j_mayer | float32 f; |
2276 | 0487d6a8 | j_mayer | } u; |
2277 | 0487d6a8 | j_mayer | float32 tmp; |
2278 | 0487d6a8 | j_mayer | |
2279 | 0487d6a8 | j_mayer | u.u = val; |
2280 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
2281 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
2282 | 0487d6a8 | j_mayer | return 0; |
2283 | 0487d6a8 | j_mayer | tmp = uint64_to_float32(1ULL << 32, &env->spe_status); |
2284 | 0487d6a8 | j_mayer | u.f = float32_mul(u.f, tmp, &env->spe_status); |
2285 | 0487d6a8 | j_mayer | |
2286 | 0487d6a8 | j_mayer | return float32_to_uint32_round_to_zero(u.f, &env->spe_status);
|
2287 | 0487d6a8 | j_mayer | } |
2288 | 0487d6a8 | j_mayer | |
2289 | 0487d6a8 | j_mayer | void do_efscfsf (void) |
2290 | 0487d6a8 | j_mayer | { |
2291 | 0487d6a8 | j_mayer | T0_64 = _do_efscfsf(T0_64); |
2292 | 0487d6a8 | j_mayer | } |
2293 | 0487d6a8 | j_mayer | |
2294 | 0487d6a8 | j_mayer | void do_efscfuf (void) |
2295 | 0487d6a8 | j_mayer | { |
2296 | 0487d6a8 | j_mayer | T0_64 = _do_efscfuf(T0_64); |
2297 | 0487d6a8 | j_mayer | } |
2298 | 0487d6a8 | j_mayer | |
2299 | 0487d6a8 | j_mayer | void do_efsctsf (void) |
2300 | 0487d6a8 | j_mayer | { |
2301 | 0487d6a8 | j_mayer | T0_64 = _do_efsctsf(T0_64); |
2302 | 0487d6a8 | j_mayer | } |
2303 | 0487d6a8 | j_mayer | |
2304 | 0487d6a8 | j_mayer | void do_efsctuf (void) |
2305 | 0487d6a8 | j_mayer | { |
2306 | 0487d6a8 | j_mayer | T0_64 = _do_efsctuf(T0_64); |
2307 | 0487d6a8 | j_mayer | } |
2308 | 0487d6a8 | j_mayer | |
2309 | 0487d6a8 | j_mayer | void do_efsctsfz (void) |
2310 | 0487d6a8 | j_mayer | { |
2311 | 0487d6a8 | j_mayer | T0_64 = _do_efsctsfz(T0_64); |
2312 | 0487d6a8 | j_mayer | } |
2313 | 0487d6a8 | j_mayer | |
2314 | 0487d6a8 | j_mayer | void do_efsctufz (void) |
2315 | 0487d6a8 | j_mayer | { |
2316 | 0487d6a8 | j_mayer | T0_64 = _do_efsctufz(T0_64); |
2317 | 0487d6a8 | j_mayer | } |
2318 | 0487d6a8 | j_mayer | |
2319 | 0487d6a8 | j_mayer | /* Double precision floating point helpers */
|
2320 | b068d6a7 | j_mayer | static always_inline int _do_efdcmplt (uint64_t op1, uint64_t op2) |
2321 | 0487d6a8 | j_mayer | { |
2322 | 0487d6a8 | j_mayer | /* XXX: TODO: test special values (NaN, infinites, ...) */
|
2323 | 0487d6a8 | j_mayer | return _do_efdtstlt(op1, op2);
|
2324 | 0487d6a8 | j_mayer | } |
2325 | 0487d6a8 | j_mayer | |
2326 | b068d6a7 | j_mayer | static always_inline int _do_efdcmpgt (uint64_t op1, uint64_t op2) |
2327 | 0487d6a8 | j_mayer | { |
2328 | 0487d6a8 | j_mayer | /* XXX: TODO: test special values (NaN, infinites, ...) */
|
2329 | 0487d6a8 | j_mayer | return _do_efdtstgt(op1, op2);
|
2330 | 0487d6a8 | j_mayer | } |
2331 | 0487d6a8 | j_mayer | |
2332 | b068d6a7 | j_mayer | static always_inline int _do_efdcmpeq (uint64_t op1, uint64_t op2) |
2333 | 0487d6a8 | j_mayer | { |
2334 | 0487d6a8 | j_mayer | /* XXX: TODO: test special values (NaN, infinites, ...) */
|
2335 | 0487d6a8 | j_mayer | return _do_efdtsteq(op1, op2);
|
2336 | 0487d6a8 | j_mayer | } |
2337 | 0487d6a8 | j_mayer | |
2338 | 0487d6a8 | j_mayer | void do_efdcmplt (void) |
2339 | 0487d6a8 | j_mayer | { |
2340 | 0487d6a8 | j_mayer | T0 = _do_efdcmplt(T0_64, T1_64); |
2341 | 0487d6a8 | j_mayer | } |
2342 | 0487d6a8 | j_mayer | |
2343 | 0487d6a8 | j_mayer | void do_efdcmpgt (void) |
2344 | 0487d6a8 | j_mayer | { |
2345 | 0487d6a8 | j_mayer | T0 = _do_efdcmpgt(T0_64, T1_64); |
2346 | 0487d6a8 | j_mayer | } |
2347 | 0487d6a8 | j_mayer | |
2348 | 0487d6a8 | j_mayer | void do_efdcmpeq (void) |
2349 | 0487d6a8 | j_mayer | { |
2350 | 0487d6a8 | j_mayer | T0 = _do_efdcmpeq(T0_64, T1_64); |
2351 | 0487d6a8 | j_mayer | } |
2352 | 0487d6a8 | j_mayer | |
2353 | 0487d6a8 | j_mayer | /* Double precision floating-point conversion to/from integer */
|
2354 | b068d6a7 | j_mayer | static always_inline uint64_t _do_efdcfsi (int64_t val)
|
2355 | 0487d6a8 | j_mayer | { |
2356 | 0487d6a8 | j_mayer | union {
|
2357 | 0487d6a8 | j_mayer | uint64_t u; |
2358 | 0487d6a8 | j_mayer | float64 f; |
2359 | 0487d6a8 | j_mayer | } u; |
2360 | 0487d6a8 | j_mayer | |
2361 | 0487d6a8 | j_mayer | u.f = int64_to_float64(val, &env->spe_status); |
2362 | 0487d6a8 | j_mayer | |
2363 | 0487d6a8 | j_mayer | return u.u;
|
2364 | 0487d6a8 | j_mayer | } |
2365 | 0487d6a8 | j_mayer | |
2366 | b068d6a7 | j_mayer | static always_inline uint64_t _do_efdcfui (uint64_t val)
|
2367 | 0487d6a8 | j_mayer | { |
2368 | 0487d6a8 | j_mayer | union {
|
2369 | 0487d6a8 | j_mayer | uint64_t u; |
2370 | 0487d6a8 | j_mayer | float64 f; |
2371 | 0487d6a8 | j_mayer | } u; |
2372 | 0487d6a8 | j_mayer | |
2373 | 0487d6a8 | j_mayer | u.f = uint64_to_float64(val, &env->spe_status); |
2374 | 0487d6a8 | j_mayer | |
2375 | 0487d6a8 | j_mayer | return u.u;
|
2376 | 0487d6a8 | j_mayer | } |
2377 | 0487d6a8 | j_mayer | |
2378 | b068d6a7 | j_mayer | static always_inline int64_t _do_efdctsi (uint64_t val)
|
2379 | 0487d6a8 | j_mayer | { |
2380 | 0487d6a8 | j_mayer | union {
|
2381 | 0487d6a8 | j_mayer | int64_t u; |
2382 | 0487d6a8 | j_mayer | float64 f; |
2383 | 0487d6a8 | j_mayer | } u; |
2384 | 0487d6a8 | j_mayer | |
2385 | 0487d6a8 | j_mayer | u.u = val; |
2386 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
2387 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
2388 | 0487d6a8 | j_mayer | return 0; |
2389 | 0487d6a8 | j_mayer | |
2390 | 0487d6a8 | j_mayer | return float64_to_int64(u.f, &env->spe_status);
|
2391 | 0487d6a8 | j_mayer | } |
2392 | 0487d6a8 | j_mayer | |
2393 | b068d6a7 | j_mayer | static always_inline uint64_t _do_efdctui (uint64_t val)
|
2394 | 0487d6a8 | j_mayer | { |
2395 | 0487d6a8 | j_mayer | union {
|
2396 | 0487d6a8 | j_mayer | int64_t u; |
2397 | 0487d6a8 | j_mayer | float64 f; |
2398 | 0487d6a8 | j_mayer | } u; |
2399 | 0487d6a8 | j_mayer | |
2400 | 0487d6a8 | j_mayer | u.u = val; |
2401 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
2402 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
2403 | 0487d6a8 | j_mayer | return 0; |
2404 | 0487d6a8 | j_mayer | |
2405 | 0487d6a8 | j_mayer | return float64_to_uint64(u.f, &env->spe_status);
|
2406 | 0487d6a8 | j_mayer | } |
2407 | 0487d6a8 | j_mayer | |
2408 | b068d6a7 | j_mayer | static always_inline int64_t _do_efdctsiz (uint64_t val)
|
2409 | 0487d6a8 | j_mayer | { |
2410 | 0487d6a8 | j_mayer | union {
|
2411 | 0487d6a8 | j_mayer | int64_t u; |
2412 | 0487d6a8 | j_mayer | float64 f; |
2413 | 0487d6a8 | j_mayer | } u; |
2414 | 0487d6a8 | j_mayer | |
2415 | 0487d6a8 | j_mayer | u.u = val; |
2416 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
2417 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
2418 | 0487d6a8 | j_mayer | return 0; |
2419 | 0487d6a8 | j_mayer | |
2420 | 0487d6a8 | j_mayer | return float64_to_int64_round_to_zero(u.f, &env->spe_status);
|
2421 | 0487d6a8 | j_mayer | } |
2422 | 0487d6a8 | j_mayer | |
2423 | b068d6a7 | j_mayer | static always_inline uint64_t _do_efdctuiz (uint64_t val)
|
2424 | 0487d6a8 | j_mayer | { |
2425 | 0487d6a8 | j_mayer | union {
|
2426 | 0487d6a8 | j_mayer | int64_t u; |
2427 | 0487d6a8 | j_mayer | float64 f; |
2428 | 0487d6a8 | j_mayer | } u; |
2429 | 0487d6a8 | j_mayer | |
2430 | 0487d6a8 | j_mayer | u.u = val; |
2431 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
2432 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
2433 | 0487d6a8 | j_mayer | return 0; |
2434 | 0487d6a8 | j_mayer | |
2435 | 0487d6a8 | j_mayer | return float64_to_uint64_round_to_zero(u.f, &env->spe_status);
|
2436 | 0487d6a8 | j_mayer | } |
2437 | 0487d6a8 | j_mayer | |
2438 | 0487d6a8 | j_mayer | void do_efdcfsi (void) |
2439 | 0487d6a8 | j_mayer | { |
2440 | 0487d6a8 | j_mayer | T0_64 = _do_efdcfsi(T0_64); |
2441 | 0487d6a8 | j_mayer | } |
2442 | 0487d6a8 | j_mayer | |
2443 | 0487d6a8 | j_mayer | void do_efdcfui (void) |
2444 | 0487d6a8 | j_mayer | { |
2445 | 0487d6a8 | j_mayer | T0_64 = _do_efdcfui(T0_64); |
2446 | 0487d6a8 | j_mayer | } |
2447 | 0487d6a8 | j_mayer | |
2448 | 0487d6a8 | j_mayer | void do_efdctsi (void) |
2449 | 0487d6a8 | j_mayer | { |
2450 | 0487d6a8 | j_mayer | T0_64 = _do_efdctsi(T0_64); |
2451 | 0487d6a8 | j_mayer | } |
2452 | 0487d6a8 | j_mayer | |
2453 | 0487d6a8 | j_mayer | void do_efdctui (void) |
2454 | 0487d6a8 | j_mayer | { |
2455 | 0487d6a8 | j_mayer | T0_64 = _do_efdctui(T0_64); |
2456 | 0487d6a8 | j_mayer | } |
2457 | 0487d6a8 | j_mayer | |
2458 | 0487d6a8 | j_mayer | void do_efdctsiz (void) |
2459 | 0487d6a8 | j_mayer | { |
2460 | 0487d6a8 | j_mayer | T0_64 = _do_efdctsiz(T0_64); |
2461 | 0487d6a8 | j_mayer | } |
2462 | 0487d6a8 | j_mayer | |
2463 | 0487d6a8 | j_mayer | void do_efdctuiz (void) |
2464 | 0487d6a8 | j_mayer | { |
2465 | 0487d6a8 | j_mayer | T0_64 = _do_efdctuiz(T0_64); |
2466 | 0487d6a8 | j_mayer | } |
2467 | 0487d6a8 | j_mayer | |
2468 | 0487d6a8 | j_mayer | /* Double precision floating-point conversion to/from fractional */
|
2469 | b068d6a7 | j_mayer | static always_inline uint64_t _do_efdcfsf (int64_t val)
|
2470 | 0487d6a8 | j_mayer | { |
2471 | 0487d6a8 | j_mayer | union {
|
2472 | 0487d6a8 | j_mayer | uint64_t u; |
2473 | 0487d6a8 | j_mayer | float64 f; |
2474 | 0487d6a8 | j_mayer | } u; |
2475 | 0487d6a8 | j_mayer | float64 tmp; |
2476 | 0487d6a8 | j_mayer | |
2477 | 0487d6a8 | j_mayer | u.f = int32_to_float64(val, &env->spe_status); |
2478 | 0487d6a8 | j_mayer | tmp = int64_to_float64(1ULL << 32, &env->spe_status); |
2479 | 0487d6a8 | j_mayer | u.f = float64_div(u.f, tmp, &env->spe_status); |
2480 | 0487d6a8 | j_mayer | |
2481 | 0487d6a8 | j_mayer | return u.u;
|
2482 | 0487d6a8 | j_mayer | } |
2483 | 0487d6a8 | j_mayer | |
2484 | b068d6a7 | j_mayer | static always_inline uint64_t _do_efdcfuf (uint64_t val)
|
2485 | 0487d6a8 | j_mayer | { |
2486 | 0487d6a8 | j_mayer | union {
|
2487 | 0487d6a8 | j_mayer | uint64_t u; |
2488 | 0487d6a8 | j_mayer | float64 f; |
2489 | 0487d6a8 | j_mayer | } u; |
2490 | 0487d6a8 | j_mayer | float64 tmp; |
2491 | 0487d6a8 | j_mayer | |
2492 | 0487d6a8 | j_mayer | u.f = uint32_to_float64(val, &env->spe_status); |
2493 | 0487d6a8 | j_mayer | tmp = int64_to_float64(1ULL << 32, &env->spe_status); |
2494 | 0487d6a8 | j_mayer | u.f = float64_div(u.f, tmp, &env->spe_status); |
2495 | 0487d6a8 | j_mayer | |
2496 | 0487d6a8 | j_mayer | return u.u;
|
2497 | 0487d6a8 | j_mayer | } |
2498 | 0487d6a8 | j_mayer | |
2499 | b068d6a7 | j_mayer | static always_inline int64_t _do_efdctsf (uint64_t val)
|
2500 | 0487d6a8 | j_mayer | { |
2501 | 0487d6a8 | j_mayer | union {
|
2502 | 0487d6a8 | j_mayer | int64_t u; |
2503 | 0487d6a8 | j_mayer | float64 f; |
2504 | 0487d6a8 | j_mayer | } u; |
2505 | 0487d6a8 | j_mayer | float64 tmp; |
2506 | 0487d6a8 | j_mayer | |
2507 | 0487d6a8 | j_mayer | u.u = val; |
2508 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
2509 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
2510 | 0487d6a8 | j_mayer | return 0; |
2511 | 0487d6a8 | j_mayer | tmp = uint64_to_float64(1ULL << 32, &env->spe_status); |
2512 | 0487d6a8 | j_mayer | u.f = float64_mul(u.f, tmp, &env->spe_status); |
2513 | 0487d6a8 | j_mayer | |
2514 | 0487d6a8 | j_mayer | return float64_to_int32(u.f, &env->spe_status);
|
2515 | 0487d6a8 | j_mayer | } |
2516 | 0487d6a8 | j_mayer | |
2517 | b068d6a7 | j_mayer | static always_inline uint64_t _do_efdctuf (uint64_t val)
|
2518 | 0487d6a8 | j_mayer | { |
2519 | 0487d6a8 | j_mayer | union {
|
2520 | 0487d6a8 | j_mayer | int64_t u; |
2521 | 0487d6a8 | j_mayer | float64 f; |
2522 | 0487d6a8 | j_mayer | } u; |
2523 | 0487d6a8 | j_mayer | float64 tmp; |
2524 | 0487d6a8 | j_mayer | |
2525 | 0487d6a8 | j_mayer | u.u = val; |
2526 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
2527 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
2528 | 0487d6a8 | j_mayer | return 0; |
2529 | 0487d6a8 | j_mayer | tmp = uint64_to_float64(1ULL << 32, &env->spe_status); |
2530 | 0487d6a8 | j_mayer | u.f = float64_mul(u.f, tmp, &env->spe_status); |
2531 | 0487d6a8 | j_mayer | |
2532 | 0487d6a8 | j_mayer | return float64_to_uint32(u.f, &env->spe_status);
|
2533 | 0487d6a8 | j_mayer | } |
2534 | 0487d6a8 | j_mayer | |
2535 | b068d6a7 | j_mayer | static always_inline int64_t _do_efdctsfz (uint64_t val)
|
2536 | 0487d6a8 | j_mayer | { |
2537 | 0487d6a8 | j_mayer | union {
|
2538 | 0487d6a8 | j_mayer | int64_t u; |
2539 | 0487d6a8 | j_mayer | float64 f; |
2540 | 0487d6a8 | j_mayer | } u; |
2541 | 0487d6a8 | j_mayer | float64 tmp; |
2542 | 0487d6a8 | j_mayer | |
2543 | 0487d6a8 | j_mayer | u.u = val; |
2544 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
2545 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
2546 | 0487d6a8 | j_mayer | return 0; |
2547 | 0487d6a8 | j_mayer | tmp = uint64_to_float64(1ULL << 32, &env->spe_status); |
2548 | 0487d6a8 | j_mayer | u.f = float64_mul(u.f, tmp, &env->spe_status); |
2549 | 0487d6a8 | j_mayer | |
2550 | 0487d6a8 | j_mayer | return float64_to_int32_round_to_zero(u.f, &env->spe_status);
|
2551 | 0487d6a8 | j_mayer | } |
2552 | 0487d6a8 | j_mayer | |
2553 | b068d6a7 | j_mayer | static always_inline uint64_t _do_efdctufz (uint64_t val)
|
2554 | 0487d6a8 | j_mayer | { |
2555 | 0487d6a8 | j_mayer | union {
|
2556 | 0487d6a8 | j_mayer | int64_t u; |
2557 | 0487d6a8 | j_mayer | float64 f; |
2558 | 0487d6a8 | j_mayer | } u; |
2559 | 0487d6a8 | j_mayer | float64 tmp; |
2560 | 0487d6a8 | j_mayer | |
2561 | 0487d6a8 | j_mayer | u.u = val; |
2562 | 0487d6a8 | j_mayer | /* NaN are not treated the same way IEEE 754 does */
|
2563 | 0487d6a8 | j_mayer | if (unlikely(isnan(u.f)))
|
2564 | 0487d6a8 | j_mayer | return 0; |
2565 | 0487d6a8 | j_mayer | tmp = uint64_to_float64(1ULL << 32, &env->spe_status); |
2566 | 0487d6a8 | j_mayer | u.f = float64_mul(u.f, tmp, &env->spe_status); |
2567 | 0487d6a8 | j_mayer | |
2568 | 0487d6a8 | j_mayer | return float64_to_uint32_round_to_zero(u.f, &env->spe_status);
|
2569 | 0487d6a8 | j_mayer | } |
2570 | 0487d6a8 | j_mayer | |
2571 | 0487d6a8 | j_mayer | void do_efdcfsf (void) |
2572 | 0487d6a8 | j_mayer | { |
2573 | 0487d6a8 | j_mayer | T0_64 = _do_efdcfsf(T0_64); |
2574 | 0487d6a8 | j_mayer | } |
2575 | 0487d6a8 | j_mayer | |
2576 | 0487d6a8 | j_mayer | void do_efdcfuf (void) |
2577 | 0487d6a8 | j_mayer | { |
2578 | 0487d6a8 | j_mayer | T0_64 = _do_efdcfuf(T0_64); |
2579 | 0487d6a8 | j_mayer | } |
2580 | 0487d6a8 | j_mayer | |
2581 | 0487d6a8 | j_mayer | void do_efdctsf (void) |
2582 | 0487d6a8 | j_mayer | { |
2583 | 0487d6a8 | j_mayer | T0_64 = _do_efdctsf(T0_64); |
2584 | 0487d6a8 | j_mayer | } |
2585 | 0487d6a8 | j_mayer | |
2586 | 0487d6a8 | j_mayer | void do_efdctuf (void) |
2587 | 0487d6a8 | j_mayer | { |
2588 | 0487d6a8 | j_mayer | T0_64 = _do_efdctuf(T0_64); |
2589 | 0487d6a8 | j_mayer | } |
2590 | 0487d6a8 | j_mayer | |
2591 | 0487d6a8 | j_mayer | void do_efdctsfz (void) |
2592 | 0487d6a8 | j_mayer | { |
2593 | 0487d6a8 | j_mayer | T0_64 = _do_efdctsfz(T0_64); |
2594 | 0487d6a8 | j_mayer | } |
2595 | 0487d6a8 | j_mayer | |
2596 | 0487d6a8 | j_mayer | void do_efdctufz (void) |
2597 | 0487d6a8 | j_mayer | { |
2598 | 0487d6a8 | j_mayer | T0_64 = _do_efdctufz(T0_64); |
2599 | 0487d6a8 | j_mayer | } |
2600 | 0487d6a8 | j_mayer | |
2601 | 0487d6a8 | j_mayer | /* Floating point conversion between single and double precision */
|
2602 | b068d6a7 | j_mayer | static always_inline uint32_t _do_efscfd (uint64_t val)
|
2603 | 0487d6a8 | j_mayer | { |
2604 | 0487d6a8 | j_mayer | union {
|
2605 | 0487d6a8 | j_mayer | uint64_t u; |
2606 | 0487d6a8 | j_mayer | float64 f; |
2607 | 0487d6a8 | j_mayer | } u1; |
2608 | 0487d6a8 | j_mayer | union {
|
2609 | 0487d6a8 | j_mayer | uint32_t u; |
2610 | 0487d6a8 | j_mayer | float32 f; |
2611 | 0487d6a8 | j_mayer | } u2; |
2612 | 0487d6a8 | j_mayer | |
2613 | 0487d6a8 | j_mayer | u1.u = val; |
2614 | 0487d6a8 | j_mayer | u2.f = float64_to_float32(u1.f, &env->spe_status); |
2615 | 0487d6a8 | j_mayer | |
2616 | 0487d6a8 | j_mayer | return u2.u;
|
2617 | 0487d6a8 | j_mayer | } |
2618 | 0487d6a8 | j_mayer | |
2619 | b068d6a7 | j_mayer | static always_inline uint64_t _do_efdcfs (uint32_t val)
|
2620 | 0487d6a8 | j_mayer | { |
2621 | 0487d6a8 | j_mayer | union {
|
2622 | 0487d6a8 | j_mayer | uint64_t u; |
2623 | 0487d6a8 | j_mayer | float64 f; |
2624 | 0487d6a8 | j_mayer | } u2; |
2625 | 0487d6a8 | j_mayer | union {
|
2626 | 0487d6a8 | j_mayer | uint32_t u; |
2627 | 0487d6a8 | j_mayer | float32 f; |
2628 | 0487d6a8 | j_mayer | } u1; |
2629 | 0487d6a8 | j_mayer | |
2630 | 0487d6a8 | j_mayer | u1.u = val; |
2631 | 0487d6a8 | j_mayer | u2.f = float32_to_float64(u1.f, &env->spe_status); |
2632 | 0487d6a8 | j_mayer | |
2633 | 0487d6a8 | j_mayer | return u2.u;
|
2634 | 0487d6a8 | j_mayer | } |
2635 | 0487d6a8 | j_mayer | |
2636 | 0487d6a8 | j_mayer | void do_efscfd (void) |
2637 | 0487d6a8 | j_mayer | { |
2638 | 0487d6a8 | j_mayer | T0_64 = _do_efscfd(T0_64); |
2639 | 0487d6a8 | j_mayer | } |
2640 | 0487d6a8 | j_mayer | |
2641 | 0487d6a8 | j_mayer | void do_efdcfs (void) |
2642 | 0487d6a8 | j_mayer | { |
2643 | 0487d6a8 | j_mayer | T0_64 = _do_efdcfs(T0_64); |
2644 | 0487d6a8 | j_mayer | } |
2645 | 0487d6a8 | j_mayer | |
2646 | 0487d6a8 | j_mayer | /* Single precision fixed-point vector arithmetic */
|
2647 | 0487d6a8 | j_mayer | /* evfsabs */
|
2648 | 0487d6a8 | j_mayer | DO_SPE_OP1(fsabs); |
2649 | 0487d6a8 | j_mayer | /* evfsnabs */
|
2650 | 0487d6a8 | j_mayer | DO_SPE_OP1(fsnabs); |
2651 | 0487d6a8 | j_mayer | /* evfsneg */
|
2652 | 0487d6a8 | j_mayer | DO_SPE_OP1(fsneg); |
2653 | 0487d6a8 | j_mayer | /* evfsadd */
|
2654 | 0487d6a8 | j_mayer | DO_SPE_OP2(fsadd); |
2655 | 0487d6a8 | j_mayer | /* evfssub */
|
2656 | 0487d6a8 | j_mayer | DO_SPE_OP2(fssub); |
2657 | 0487d6a8 | j_mayer | /* evfsmul */
|
2658 | 0487d6a8 | j_mayer | DO_SPE_OP2(fsmul); |
2659 | 0487d6a8 | j_mayer | /* evfsdiv */
|
2660 | 0487d6a8 | j_mayer | DO_SPE_OP2(fsdiv); |
2661 | 0487d6a8 | j_mayer | |
2662 | 0487d6a8 | j_mayer | /* Single-precision floating-point comparisons */
|
2663 | b068d6a7 | j_mayer | static always_inline int _do_efscmplt (uint32_t op1, uint32_t op2) |
2664 | 0487d6a8 | j_mayer | { |
2665 | 0487d6a8 | j_mayer | /* XXX: TODO: test special values (NaN, infinites, ...) */
|
2666 | 0487d6a8 | j_mayer | return _do_efststlt(op1, op2);
|
2667 | 0487d6a8 | j_mayer | } |
2668 | 0487d6a8 | j_mayer | |
2669 | b068d6a7 | j_mayer | static always_inline int _do_efscmpgt (uint32_t op1, uint32_t op2) |
2670 | 0487d6a8 | j_mayer | { |
2671 | 0487d6a8 | j_mayer | /* XXX: TODO: test special values (NaN, infinites, ...) */
|
2672 | 0487d6a8 | j_mayer | return _do_efststgt(op1, op2);
|
2673 | 0487d6a8 | j_mayer | } |
2674 | 0487d6a8 | j_mayer | |
2675 | b068d6a7 | j_mayer | static always_inline int _do_efscmpeq (uint32_t op1, uint32_t op2) |
2676 | 0487d6a8 | j_mayer | { |
2677 | 0487d6a8 | j_mayer | /* XXX: TODO: test special values (NaN, infinites, ...) */
|
2678 | 0487d6a8 | j_mayer | return _do_efststeq(op1, op2);
|
2679 | 0487d6a8 | j_mayer | } |
2680 | 0487d6a8 | j_mayer | |
2681 | 0487d6a8 | j_mayer | void do_efscmplt (void) |
2682 | 0487d6a8 | j_mayer | { |
2683 | 0487d6a8 | j_mayer | T0 = _do_efscmplt(T0_64, T1_64); |
2684 | 0487d6a8 | j_mayer | } |
2685 | 0487d6a8 | j_mayer | |
2686 | 0487d6a8 | j_mayer | void do_efscmpgt (void) |
2687 | 0487d6a8 | j_mayer | { |
2688 | 0487d6a8 | j_mayer | T0 = _do_efscmpgt(T0_64, T1_64); |
2689 | 0487d6a8 | j_mayer | } |
2690 | 0487d6a8 | j_mayer | |
2691 | 0487d6a8 | j_mayer | void do_efscmpeq (void) |
2692 | 0487d6a8 | j_mayer | { |
2693 | 0487d6a8 | j_mayer | T0 = _do_efscmpeq(T0_64, T1_64); |
2694 | 0487d6a8 | j_mayer | } |
2695 | 0487d6a8 | j_mayer | |
2696 | 0487d6a8 | j_mayer | /* Single-precision floating-point vector comparisons */
|
2697 | 0487d6a8 | j_mayer | /* evfscmplt */
|
2698 | 0487d6a8 | j_mayer | DO_SPE_CMP(fscmplt); |
2699 | 0487d6a8 | j_mayer | /* evfscmpgt */
|
2700 | 0487d6a8 | j_mayer | DO_SPE_CMP(fscmpgt); |
2701 | 0487d6a8 | j_mayer | /* evfscmpeq */
|
2702 | 0487d6a8 | j_mayer | DO_SPE_CMP(fscmpeq); |
2703 | 0487d6a8 | j_mayer | /* evfststlt */
|
2704 | 0487d6a8 | j_mayer | DO_SPE_CMP(fststlt); |
2705 | 0487d6a8 | j_mayer | /* evfststgt */
|
2706 | 0487d6a8 | j_mayer | DO_SPE_CMP(fststgt); |
2707 | 0487d6a8 | j_mayer | /* evfststeq */
|
2708 | 0487d6a8 | j_mayer | DO_SPE_CMP(fststeq); |
2709 | 0487d6a8 | j_mayer | |
2710 | 0487d6a8 | j_mayer | /* Single-precision floating-point vector conversions */
|
2711 | 0487d6a8 | j_mayer | /* evfscfsi */
|
2712 | 0487d6a8 | j_mayer | DO_SPE_OP1(fscfsi); |
2713 | 0487d6a8 | j_mayer | /* evfscfui */
|
2714 | 0487d6a8 | j_mayer | DO_SPE_OP1(fscfui); |
2715 | 0487d6a8 | j_mayer | /* evfscfuf */
|
2716 | 0487d6a8 | j_mayer | DO_SPE_OP1(fscfuf); |
2717 | 0487d6a8 | j_mayer | /* evfscfsf */
|
2718 | 0487d6a8 | j_mayer | DO_SPE_OP1(fscfsf); |
2719 | 0487d6a8 | j_mayer | /* evfsctsi */
|
2720 | 0487d6a8 | j_mayer | DO_SPE_OP1(fsctsi); |
2721 | 0487d6a8 | j_mayer | /* evfsctui */
|
2722 | 0487d6a8 | j_mayer | DO_SPE_OP1(fsctui); |
2723 | 0487d6a8 | j_mayer | /* evfsctsiz */
|
2724 | 0487d6a8 | j_mayer | DO_SPE_OP1(fsctsiz); |
2725 | 0487d6a8 | j_mayer | /* evfsctuiz */
|
2726 | 0487d6a8 | j_mayer | DO_SPE_OP1(fsctuiz); |
2727 | 0487d6a8 | j_mayer | /* evfsctsf */
|
2728 | 0487d6a8 | j_mayer | DO_SPE_OP1(fsctsf); |
2729 | 0487d6a8 | j_mayer | /* evfsctuf */
|
2730 | 0487d6a8 | j_mayer | DO_SPE_OP1(fsctuf); |
2731 | 35cdaad6 | j_mayer | #endif /* defined(TARGET_PPCEMB) */ |
2732 | 0487d6a8 | j_mayer | |
2733 | fdabc366 | bellard | /*****************************************************************************/
|
2734 | fdabc366 | bellard | /* Softmmu support */
|
2735 | fdabc366 | bellard | #if !defined (CONFIG_USER_ONLY)
|
2736 | fdabc366 | bellard | |
2737 | fdabc366 | bellard | #define MMUSUFFIX _mmu
|
2738 | 273af660 | ths | #ifdef __s390__
|
2739 | 273af660 | ths | # define GETPC() ((void*)((unsigned long)__builtin_return_address(0) & 0x7fffffffUL)) |
2740 | 273af660 | ths | #else
|
2741 | 273af660 | ths | # define GETPC() (__builtin_return_address(0)) |
2742 | 273af660 | ths | #endif
|
2743 | fdabc366 | bellard | |
2744 | fdabc366 | bellard | #define SHIFT 0 |
2745 | fdabc366 | bellard | #include "softmmu_template.h" |
2746 | fdabc366 | bellard | |
2747 | fdabc366 | bellard | #define SHIFT 1 |
2748 | fdabc366 | bellard | #include "softmmu_template.h" |
2749 | fdabc366 | bellard | |
2750 | fdabc366 | bellard | #define SHIFT 2 |
2751 | fdabc366 | bellard | #include "softmmu_template.h" |
2752 | fdabc366 | bellard | |
2753 | fdabc366 | bellard | #define SHIFT 3 |
2754 | fdabc366 | bellard | #include "softmmu_template.h" |
2755 | fdabc366 | bellard | |
2756 | fdabc366 | bellard | /* try to fill the TLB and return an exception if error. If retaddr is
|
2757 | fdabc366 | bellard | NULL, it means that the function was called in C code (i.e. not
|
2758 | fdabc366 | bellard | from generated code or from helper.c) */
|
2759 | fdabc366 | bellard | /* XXX: fix it to restore all registers */
|
2760 | 6ebbf390 | j_mayer | void tlb_fill (target_ulong addr, int is_write, int mmu_idx, void *retaddr) |
2761 | fdabc366 | bellard | { |
2762 | fdabc366 | bellard | TranslationBlock *tb; |
2763 | fdabc366 | bellard | CPUState *saved_env; |
2764 | fdabc366 | bellard | target_phys_addr_t pc; |
2765 | fdabc366 | bellard | int ret;
|
2766 | fdabc366 | bellard | |
2767 | fdabc366 | bellard | /* XXX: hack to restore env in all cases, even if not called from
|
2768 | fdabc366 | bellard | generated code */
|
2769 | fdabc366 | bellard | saved_env = env; |
2770 | fdabc366 | bellard | env = cpu_single_env; |
2771 | 6ebbf390 | j_mayer | ret = cpu_ppc_handle_mmu_fault(env, addr, is_write, mmu_idx, 1);
|
2772 | 76a66253 | j_mayer | if (unlikely(ret != 0)) { |
2773 | fdabc366 | bellard | if (likely(retaddr)) {
|
2774 | fdabc366 | bellard | /* now we have a real cpu fault */
|
2775 | a750fc0b | j_mayer | pc = (target_phys_addr_t)(unsigned long)retaddr; |
2776 | fdabc366 | bellard | tb = tb_find_pc(pc); |
2777 | fdabc366 | bellard | if (likely(tb)) {
|
2778 | fdabc366 | bellard | /* the PC is inside the translated code. It means that we have
|
2779 | fdabc366 | bellard | a virtual CPU fault */
|
2780 | fdabc366 | bellard | cpu_restore_state(tb, env, pc, NULL);
|
2781 | 76a66253 | j_mayer | } |
2782 | fdabc366 | bellard | } |
2783 | fdabc366 | bellard | do_raise_exception_err(env->exception_index, env->error_code); |
2784 | fdabc366 | bellard | } |
2785 | fdabc366 | bellard | env = saved_env; |
2786 | 9a64fbe4 | bellard | } |
2787 | 9a64fbe4 | bellard | |
2788 | 76a66253 | j_mayer | /* Software driven TLBs management */
|
2789 | 76a66253 | j_mayer | /* PowerPC 602/603 software TLB load instructions helpers */
|
2790 | 76a66253 | j_mayer | void do_load_6xx_tlb (int is_code) |
2791 | 76a66253 | j_mayer | { |
2792 | 76a66253 | j_mayer | target_ulong RPN, CMP, EPN; |
2793 | 76a66253 | j_mayer | int way;
|
2794 | d9bce9d9 | j_mayer | |
2795 | 76a66253 | j_mayer | RPN = env->spr[SPR_RPA]; |
2796 | 76a66253 | j_mayer | if (is_code) {
|
2797 | 76a66253 | j_mayer | CMP = env->spr[SPR_ICMP]; |
2798 | 76a66253 | j_mayer | EPN = env->spr[SPR_IMISS]; |
2799 | 76a66253 | j_mayer | } else {
|
2800 | 76a66253 | j_mayer | CMP = env->spr[SPR_DCMP]; |
2801 | 76a66253 | j_mayer | EPN = env->spr[SPR_DMISS]; |
2802 | 76a66253 | j_mayer | } |
2803 | 76a66253 | j_mayer | way = (env->spr[SPR_SRR1] >> 17) & 1; |
2804 | 76a66253 | j_mayer | #if defined (DEBUG_SOFTWARE_TLB)
|
2805 | 76a66253 | j_mayer | if (loglevel != 0) { |
2806 | 76a66253 | j_mayer | fprintf(logfile, "%s: EPN %08lx %08lx PTE0 %08lx PTE1 %08lx way %d\n",
|
2807 | 76a66253 | j_mayer | __func__, (unsigned long)T0, (unsigned long)EPN, |
2808 | 76a66253 | j_mayer | (unsigned long)CMP, (unsigned long)RPN, way); |
2809 | 76a66253 | j_mayer | } |
2810 | 76a66253 | j_mayer | #endif
|
2811 | 76a66253 | j_mayer | /* Store this TLB */
|
2812 | d9bce9d9 | j_mayer | ppc6xx_tlb_store(env, (uint32_t)(T0 & TARGET_PAGE_MASK), |
2813 | d9bce9d9 | j_mayer | way, is_code, CMP, RPN); |
2814 | 76a66253 | j_mayer | } |
2815 | 76a66253 | j_mayer | |
2816 | 7dbe11ac | j_mayer | void do_load_74xx_tlb (int is_code) |
2817 | 7dbe11ac | j_mayer | { |
2818 | 7dbe11ac | j_mayer | target_ulong RPN, CMP, EPN; |
2819 | 7dbe11ac | j_mayer | int way;
|
2820 | 7dbe11ac | j_mayer | |
2821 | 7dbe11ac | j_mayer | RPN = env->spr[SPR_PTELO]; |
2822 | 7dbe11ac | j_mayer | CMP = env->spr[SPR_PTEHI]; |
2823 | 7dbe11ac | j_mayer | EPN = env->spr[SPR_TLBMISS] & ~0x3;
|
2824 | 7dbe11ac | j_mayer | way = env->spr[SPR_TLBMISS] & 0x3;
|
2825 | 7dbe11ac | j_mayer | #if defined (DEBUG_SOFTWARE_TLB)
|
2826 | 7dbe11ac | j_mayer | if (loglevel != 0) { |
2827 | 7dbe11ac | j_mayer | fprintf(logfile, "%s: EPN %08lx %08lx PTE0 %08lx PTE1 %08lx way %d\n",
|
2828 | 7dbe11ac | j_mayer | __func__, (unsigned long)T0, (unsigned long)EPN, |
2829 | 7dbe11ac | j_mayer | (unsigned long)CMP, (unsigned long)RPN, way); |
2830 | 7dbe11ac | j_mayer | } |
2831 | 7dbe11ac | j_mayer | #endif
|
2832 | 7dbe11ac | j_mayer | /* Store this TLB */
|
2833 | 7dbe11ac | j_mayer | ppc6xx_tlb_store(env, (uint32_t)(T0 & TARGET_PAGE_MASK), |
2834 | 7dbe11ac | j_mayer | way, is_code, CMP, RPN); |
2835 | 7dbe11ac | j_mayer | } |
2836 | 7dbe11ac | j_mayer | |
2837 | a11b8151 | j_mayer | static always_inline target_ulong booke_tlb_to_page_size (int size) |
2838 | a8dea12f | j_mayer | { |
2839 | a8dea12f | j_mayer | return 1024 << (2 * size); |
2840 | a8dea12f | j_mayer | } |
2841 | a8dea12f | j_mayer | |
2842 | a11b8151 | j_mayer | static always_inline int booke_page_size_to_tlb (target_ulong page_size) |
2843 | a8dea12f | j_mayer | { |
2844 | a8dea12f | j_mayer | int size;
|
2845 | a8dea12f | j_mayer | |
2846 | a8dea12f | j_mayer | switch (page_size) {
|
2847 | a8dea12f | j_mayer | case 0x00000400UL: |
2848 | a8dea12f | j_mayer | size = 0x0;
|
2849 | a8dea12f | j_mayer | break;
|
2850 | a8dea12f | j_mayer | case 0x00001000UL: |
2851 | a8dea12f | j_mayer | size = 0x1;
|
2852 | a8dea12f | j_mayer | break;
|
2853 | a8dea12f | j_mayer | case 0x00004000UL: |
2854 | a8dea12f | j_mayer | size = 0x2;
|
2855 | a8dea12f | j_mayer | break;
|
2856 | a8dea12f | j_mayer | case 0x00010000UL: |
2857 | a8dea12f | j_mayer | size = 0x3;
|
2858 | a8dea12f | j_mayer | break;
|
2859 | a8dea12f | j_mayer | case 0x00040000UL: |
2860 | a8dea12f | j_mayer | size = 0x4;
|
2861 | a8dea12f | j_mayer | break;
|
2862 | a8dea12f | j_mayer | case 0x00100000UL: |
2863 | a8dea12f | j_mayer | size = 0x5;
|
2864 | a8dea12f | j_mayer | break;
|
2865 | a8dea12f | j_mayer | case 0x00400000UL: |
2866 | a8dea12f | j_mayer | size = 0x6;
|
2867 | a8dea12f | j_mayer | break;
|
2868 | a8dea12f | j_mayer | case 0x01000000UL: |
2869 | a8dea12f | j_mayer | size = 0x7;
|
2870 | a8dea12f | j_mayer | break;
|
2871 | a8dea12f | j_mayer | case 0x04000000UL: |
2872 | a8dea12f | j_mayer | size = 0x8;
|
2873 | a8dea12f | j_mayer | break;
|
2874 | a8dea12f | j_mayer | case 0x10000000UL: |
2875 | a8dea12f | j_mayer | size = 0x9;
|
2876 | a8dea12f | j_mayer | break;
|
2877 | a8dea12f | j_mayer | case 0x40000000UL: |
2878 | a8dea12f | j_mayer | size = 0xA;
|
2879 | a8dea12f | j_mayer | break;
|
2880 | a8dea12f | j_mayer | #if defined (TARGET_PPC64)
|
2881 | a8dea12f | j_mayer | case 0x000100000000ULL: |
2882 | a8dea12f | j_mayer | size = 0xB;
|
2883 | a8dea12f | j_mayer | break;
|
2884 | a8dea12f | j_mayer | case 0x000400000000ULL: |
2885 | a8dea12f | j_mayer | size = 0xC;
|
2886 | a8dea12f | j_mayer | break;
|
2887 | a8dea12f | j_mayer | case 0x001000000000ULL: |
2888 | a8dea12f | j_mayer | size = 0xD;
|
2889 | a8dea12f | j_mayer | break;
|
2890 | a8dea12f | j_mayer | case 0x004000000000ULL: |
2891 | a8dea12f | j_mayer | size = 0xE;
|
2892 | a8dea12f | j_mayer | break;
|
2893 | a8dea12f | j_mayer | case 0x010000000000ULL: |
2894 | a8dea12f | j_mayer | size = 0xF;
|
2895 | a8dea12f | j_mayer | break;
|
2896 | a8dea12f | j_mayer | #endif
|
2897 | a8dea12f | j_mayer | default:
|
2898 | a8dea12f | j_mayer | size = -1;
|
2899 | a8dea12f | j_mayer | break;
|
2900 | a8dea12f | j_mayer | } |
2901 | a8dea12f | j_mayer | |
2902 | a8dea12f | j_mayer | return size;
|
2903 | a8dea12f | j_mayer | } |
2904 | a8dea12f | j_mayer | |
2905 | 76a66253 | j_mayer | /* Helpers for 4xx TLB management */
|
2906 | 76a66253 | j_mayer | void do_4xx_tlbre_lo (void) |
2907 | 76a66253 | j_mayer | { |
2908 | a8dea12f | j_mayer | ppcemb_tlb_t *tlb; |
2909 | a8dea12f | j_mayer | int size;
|
2910 | 76a66253 | j_mayer | |
2911 | 76a66253 | j_mayer | T0 &= 0x3F;
|
2912 | a8dea12f | j_mayer | tlb = &env->tlb[T0].tlbe; |
2913 | a8dea12f | j_mayer | T0 = tlb->EPN; |
2914 | a8dea12f | j_mayer | if (tlb->prot & PAGE_VALID)
|
2915 | a8dea12f | j_mayer | T0 |= 0x400;
|
2916 | a8dea12f | j_mayer | size = booke_page_size_to_tlb(tlb->size); |
2917 | a8dea12f | j_mayer | if (size < 0 || size > 0x7) |
2918 | a8dea12f | j_mayer | size = 1;
|
2919 | a8dea12f | j_mayer | T0 |= size << 7;
|
2920 | a8dea12f | j_mayer | env->spr[SPR_40x_PID] = tlb->PID; |
2921 | 76a66253 | j_mayer | } |
2922 | 76a66253 | j_mayer | |
2923 | 76a66253 | j_mayer | void do_4xx_tlbre_hi (void) |
2924 | 76a66253 | j_mayer | { |
2925 | a8dea12f | j_mayer | ppcemb_tlb_t *tlb; |
2926 | 76a66253 | j_mayer | |
2927 | 76a66253 | j_mayer | T0 &= 0x3F;
|
2928 | a8dea12f | j_mayer | tlb = &env->tlb[T0].tlbe; |
2929 | a8dea12f | j_mayer | T0 = tlb->RPN; |
2930 | a8dea12f | j_mayer | if (tlb->prot & PAGE_EXEC)
|
2931 | a8dea12f | j_mayer | T0 |= 0x200;
|
2932 | a8dea12f | j_mayer | if (tlb->prot & PAGE_WRITE)
|
2933 | a8dea12f | j_mayer | T0 |= 0x100;
|
2934 | 76a66253 | j_mayer | } |
2935 | 76a66253 | j_mayer | |
2936 | c55e9aef | j_mayer | void do_4xx_tlbwe_hi (void) |
2937 | 76a66253 | j_mayer | { |
2938 | a8dea12f | j_mayer | ppcemb_tlb_t *tlb; |
2939 | 76a66253 | j_mayer | target_ulong page, end; |
2940 | 76a66253 | j_mayer | |
2941 | c55e9aef | j_mayer | #if defined (DEBUG_SOFTWARE_TLB)
|
2942 | 6b80055d | j_mayer | if (loglevel != 0) { |
2943 | c55e9aef | j_mayer | fprintf(logfile, "%s T0 " REGX " T1 " REGX "\n", __func__, T0, T1); |
2944 | c55e9aef | j_mayer | } |
2945 | c55e9aef | j_mayer | #endif
|
2946 | 76a66253 | j_mayer | T0 &= 0x3F;
|
2947 | a8dea12f | j_mayer | tlb = &env->tlb[T0].tlbe; |
2948 | 76a66253 | j_mayer | /* Invalidate previous TLB (if it's valid) */
|
2949 | 76a66253 | j_mayer | if (tlb->prot & PAGE_VALID) {
|
2950 | 76a66253 | j_mayer | end = tlb->EPN + tlb->size; |
2951 | c55e9aef | j_mayer | #if defined (DEBUG_SOFTWARE_TLB)
|
2952 | 6b80055d | j_mayer | if (loglevel != 0) { |
2953 | c55e9aef | j_mayer | fprintf(logfile, "%s: invalidate old TLB %d start " ADDRX
|
2954 | c55e9aef | j_mayer | " end " ADDRX "\n", __func__, (int)T0, tlb->EPN, end); |
2955 | c55e9aef | j_mayer | } |
2956 | c55e9aef | j_mayer | #endif
|
2957 | 76a66253 | j_mayer | for (page = tlb->EPN; page < end; page += TARGET_PAGE_SIZE)
|
2958 | 76a66253 | j_mayer | tlb_flush_page(env, page); |
2959 | 76a66253 | j_mayer | } |
2960 | a8dea12f | j_mayer | tlb->size = booke_tlb_to_page_size((T1 >> 7) & 0x7); |
2961 | c294fc58 | j_mayer | /* We cannot handle TLB size < TARGET_PAGE_SIZE.
|
2962 | c294fc58 | j_mayer | * If this ever occurs, one should use the ppcemb target instead
|
2963 | c294fc58 | j_mayer | * of the ppc or ppc64 one
|
2964 | c294fc58 | j_mayer | */
|
2965 | c294fc58 | j_mayer | if ((T1 & 0x40) && tlb->size < TARGET_PAGE_SIZE) { |
2966 | 71c8b8fd | j_mayer | cpu_abort(env, "TLB size " TARGET_FMT_lu " < %u " |
2967 | 71c8b8fd | j_mayer | "are not supported (%d)\n",
|
2968 | c294fc58 | j_mayer | tlb->size, TARGET_PAGE_SIZE, (int)((T1 >> 7) & 0x7)); |
2969 | c294fc58 | j_mayer | } |
2970 | a750fc0b | j_mayer | tlb->EPN = T1 & ~(tlb->size - 1);
|
2971 | c55e9aef | j_mayer | if (T1 & 0x40) |
2972 | 76a66253 | j_mayer | tlb->prot |= PAGE_VALID; |
2973 | 76a66253 | j_mayer | else
|
2974 | 76a66253 | j_mayer | tlb->prot &= ~PAGE_VALID; |
2975 | c294fc58 | j_mayer | if (T1 & 0x20) { |
2976 | c294fc58 | j_mayer | /* XXX: TO BE FIXED */
|
2977 | c294fc58 | j_mayer | cpu_abort(env, "Little-endian TLB entries are not supported by now\n");
|
2978 | c294fc58 | j_mayer | } |
2979 | c55e9aef | j_mayer | tlb->PID = env->spr[SPR_40x_PID]; /* PID */
|
2980 | a8dea12f | j_mayer | tlb->attr = T1 & 0xFF;
|
2981 | c55e9aef | j_mayer | #if defined (DEBUG_SOFTWARE_TLB)
|
2982 | c294fc58 | j_mayer | if (loglevel != 0) { |
2983 | c294fc58 | j_mayer | fprintf(logfile, "%s: set up TLB %d RPN " PADDRX " EPN " ADDRX |
2984 | c55e9aef | j_mayer | " size " ADDRX " prot %c%c%c%c PID %d\n", __func__, |
2985 | 5fafdf24 | ths | (int)T0, tlb->RPN, tlb->EPN, tlb->size,
|
2986 | c55e9aef | j_mayer | tlb->prot & PAGE_READ ? 'r' : '-', |
2987 | c55e9aef | j_mayer | tlb->prot & PAGE_WRITE ? 'w' : '-', |
2988 | c55e9aef | j_mayer | tlb->prot & PAGE_EXEC ? 'x' : '-', |
2989 | c55e9aef | j_mayer | tlb->prot & PAGE_VALID ? 'v' : '-', (int)tlb->PID); |
2990 | c55e9aef | j_mayer | } |
2991 | c55e9aef | j_mayer | #endif
|
2992 | 76a66253 | j_mayer | /* Invalidate new TLB (if valid) */
|
2993 | 76a66253 | j_mayer | if (tlb->prot & PAGE_VALID) {
|
2994 | 76a66253 | j_mayer | end = tlb->EPN + tlb->size; |
2995 | c55e9aef | j_mayer | #if defined (DEBUG_SOFTWARE_TLB)
|
2996 | 6b80055d | j_mayer | if (loglevel != 0) { |
2997 | c55e9aef | j_mayer | fprintf(logfile, "%s: invalidate TLB %d start " ADDRX
|
2998 | c55e9aef | j_mayer | " end " ADDRX "\n", __func__, (int)T0, tlb->EPN, end); |
2999 | c55e9aef | j_mayer | } |
3000 | c55e9aef | j_mayer | #endif
|
3001 | 76a66253 | j_mayer | for (page = tlb->EPN; page < end; page += TARGET_PAGE_SIZE)
|
3002 | 76a66253 | j_mayer | tlb_flush_page(env, page); |
3003 | 76a66253 | j_mayer | } |
3004 | 76a66253 | j_mayer | } |
3005 | 76a66253 | j_mayer | |
3006 | c55e9aef | j_mayer | void do_4xx_tlbwe_lo (void) |
3007 | 76a66253 | j_mayer | { |
3008 | a8dea12f | j_mayer | ppcemb_tlb_t *tlb; |
3009 | 76a66253 | j_mayer | |
3010 | c55e9aef | j_mayer | #if defined (DEBUG_SOFTWARE_TLB)
|
3011 | 6b80055d | j_mayer | if (loglevel != 0) { |
3012 | c55e9aef | j_mayer | fprintf(logfile, "%s T0 " REGX " T1 " REGX "\n", __func__, T0, T1); |
3013 | c55e9aef | j_mayer | } |
3014 | c55e9aef | j_mayer | #endif
|
3015 | 76a66253 | j_mayer | T0 &= 0x3F;
|
3016 | a8dea12f | j_mayer | tlb = &env->tlb[T0].tlbe; |
3017 | 76a66253 | j_mayer | tlb->RPN = T1 & 0xFFFFFC00;
|
3018 | 76a66253 | j_mayer | tlb->prot = PAGE_READ; |
3019 | 76a66253 | j_mayer | if (T1 & 0x200) |
3020 | 76a66253 | j_mayer | tlb->prot |= PAGE_EXEC; |
3021 | 76a66253 | j_mayer | if (T1 & 0x100) |
3022 | 76a66253 | j_mayer | tlb->prot |= PAGE_WRITE; |
3023 | c55e9aef | j_mayer | #if defined (DEBUG_SOFTWARE_TLB)
|
3024 | 6b80055d | j_mayer | if (loglevel != 0) { |
3025 | 6b80055d | j_mayer | fprintf(logfile, "%s: set up TLB %d RPN " PADDRX " EPN " ADDRX |
3026 | c55e9aef | j_mayer | " size " ADDRX " prot %c%c%c%c PID %d\n", __func__, |
3027 | 5fafdf24 | ths | (int)T0, tlb->RPN, tlb->EPN, tlb->size,
|
3028 | c55e9aef | j_mayer | tlb->prot & PAGE_READ ? 'r' : '-', |
3029 | c55e9aef | j_mayer | tlb->prot & PAGE_WRITE ? 'w' : '-', |
3030 | c55e9aef | j_mayer | tlb->prot & PAGE_EXEC ? 'x' : '-', |
3031 | c55e9aef | j_mayer | tlb->prot & PAGE_VALID ? 'v' : '-', (int)tlb->PID); |
3032 | c55e9aef | j_mayer | } |
3033 | c55e9aef | j_mayer | #endif
|
3034 | 76a66253 | j_mayer | } |
3035 | 5eb7995e | j_mayer | |
3036 | a4bb6c3e | j_mayer | /* PowerPC 440 TLB management */
|
3037 | a4bb6c3e | j_mayer | void do_440_tlbwe (int word) |
3038 | 5eb7995e | j_mayer | { |
3039 | 5eb7995e | j_mayer | ppcemb_tlb_t *tlb; |
3040 | a4bb6c3e | j_mayer | target_ulong EPN, RPN, size; |
3041 | 5eb7995e | j_mayer | int do_flush_tlbs;
|
3042 | 5eb7995e | j_mayer | |
3043 | 5eb7995e | j_mayer | #if defined (DEBUG_SOFTWARE_TLB)
|
3044 | 5eb7995e | j_mayer | if (loglevel != 0) { |
3045 | a4bb6c3e | j_mayer | fprintf(logfile, "%s word %d T0 " REGX " T1 " REGX "\n", |
3046 | a4bb6c3e | j_mayer | __func__, word, T0, T1); |
3047 | 5eb7995e | j_mayer | } |
3048 | 5eb7995e | j_mayer | #endif
|
3049 | 5eb7995e | j_mayer | do_flush_tlbs = 0;
|
3050 | 5eb7995e | j_mayer | T0 &= 0x3F;
|
3051 | 5eb7995e | j_mayer | tlb = &env->tlb[T0].tlbe; |
3052 | a4bb6c3e | j_mayer | switch (word) {
|
3053 | a4bb6c3e | j_mayer | default:
|
3054 | a4bb6c3e | j_mayer | /* Just here to please gcc */
|
3055 | a4bb6c3e | j_mayer | case 0: |
3056 | a4bb6c3e | j_mayer | EPN = T1 & 0xFFFFFC00;
|
3057 | a4bb6c3e | j_mayer | if ((tlb->prot & PAGE_VALID) && EPN != tlb->EPN)
|
3058 | 5eb7995e | j_mayer | do_flush_tlbs = 1;
|
3059 | a4bb6c3e | j_mayer | tlb->EPN = EPN; |
3060 | a4bb6c3e | j_mayer | size = booke_tlb_to_page_size((T1 >> 4) & 0xF); |
3061 | a4bb6c3e | j_mayer | if ((tlb->prot & PAGE_VALID) && tlb->size < size)
|
3062 | a4bb6c3e | j_mayer | do_flush_tlbs = 1;
|
3063 | a4bb6c3e | j_mayer | tlb->size = size; |
3064 | a4bb6c3e | j_mayer | tlb->attr &= ~0x1;
|
3065 | a4bb6c3e | j_mayer | tlb->attr |= (T1 >> 8) & 1; |
3066 | a4bb6c3e | j_mayer | if (T1 & 0x200) { |
3067 | a4bb6c3e | j_mayer | tlb->prot |= PAGE_VALID; |
3068 | a4bb6c3e | j_mayer | } else {
|
3069 | a4bb6c3e | j_mayer | if (tlb->prot & PAGE_VALID) {
|
3070 | a4bb6c3e | j_mayer | tlb->prot &= ~PAGE_VALID; |
3071 | a4bb6c3e | j_mayer | do_flush_tlbs = 1;
|
3072 | a4bb6c3e | j_mayer | } |
3073 | 5eb7995e | j_mayer | } |
3074 | a4bb6c3e | j_mayer | tlb->PID = env->spr[SPR_440_MMUCR] & 0x000000FF;
|
3075 | a4bb6c3e | j_mayer | if (do_flush_tlbs)
|
3076 | a4bb6c3e | j_mayer | tlb_flush(env, 1);
|
3077 | a4bb6c3e | j_mayer | break;
|
3078 | a4bb6c3e | j_mayer | case 1: |
3079 | a4bb6c3e | j_mayer | RPN = T1 & 0xFFFFFC0F;
|
3080 | a4bb6c3e | j_mayer | if ((tlb->prot & PAGE_VALID) && tlb->RPN != RPN)
|
3081 | a4bb6c3e | j_mayer | tlb_flush(env, 1);
|
3082 | a4bb6c3e | j_mayer | tlb->RPN = RPN; |
3083 | a4bb6c3e | j_mayer | break;
|
3084 | a4bb6c3e | j_mayer | case 2: |
3085 | a4bb6c3e | j_mayer | tlb->attr = (tlb->attr & 0x1) | (T1 & 0x0000FF00); |
3086 | a4bb6c3e | j_mayer | tlb->prot = tlb->prot & PAGE_VALID; |
3087 | a4bb6c3e | j_mayer | if (T1 & 0x1) |
3088 | a4bb6c3e | j_mayer | tlb->prot |= PAGE_READ << 4;
|
3089 | a4bb6c3e | j_mayer | if (T1 & 0x2) |
3090 | a4bb6c3e | j_mayer | tlb->prot |= PAGE_WRITE << 4;
|
3091 | a4bb6c3e | j_mayer | if (T1 & 0x4) |
3092 | a4bb6c3e | j_mayer | tlb->prot |= PAGE_EXEC << 4;
|
3093 | a4bb6c3e | j_mayer | if (T1 & 0x8) |
3094 | a4bb6c3e | j_mayer | tlb->prot |= PAGE_READ; |
3095 | a4bb6c3e | j_mayer | if (T1 & 0x10) |
3096 | a4bb6c3e | j_mayer | tlb->prot |= PAGE_WRITE; |
3097 | a4bb6c3e | j_mayer | if (T1 & 0x20) |
3098 | a4bb6c3e | j_mayer | tlb->prot |= PAGE_EXEC; |
3099 | a4bb6c3e | j_mayer | break;
|
3100 | 5eb7995e | j_mayer | } |
3101 | 5eb7995e | j_mayer | } |
3102 | 5eb7995e | j_mayer | |
3103 | a4bb6c3e | j_mayer | void do_440_tlbre (int word) |
3104 | 5eb7995e | j_mayer | { |
3105 | 5eb7995e | j_mayer | ppcemb_tlb_t *tlb; |
3106 | 5eb7995e | j_mayer | int size;
|
3107 | 5eb7995e | j_mayer | |
3108 | 5eb7995e | j_mayer | T0 &= 0x3F;
|
3109 | 5eb7995e | j_mayer | tlb = &env->tlb[T0].tlbe; |
3110 | a4bb6c3e | j_mayer | switch (word) {
|
3111 | a4bb6c3e | j_mayer | default:
|
3112 | a4bb6c3e | j_mayer | /* Just here to please gcc */
|
3113 | a4bb6c3e | j_mayer | case 0: |
3114 | a4bb6c3e | j_mayer | T0 = tlb->EPN; |
3115 | a4bb6c3e | j_mayer | size = booke_page_size_to_tlb(tlb->size); |
3116 | a4bb6c3e | j_mayer | if (size < 0 || size > 0xF) |
3117 | a4bb6c3e | j_mayer | size = 1;
|
3118 | a4bb6c3e | j_mayer | T0 |= size << 4;
|
3119 | a4bb6c3e | j_mayer | if (tlb->attr & 0x1) |
3120 | a4bb6c3e | j_mayer | T0 |= 0x100;
|
3121 | a4bb6c3e | j_mayer | if (tlb->prot & PAGE_VALID)
|
3122 | a4bb6c3e | j_mayer | T0 |= 0x200;
|
3123 | a4bb6c3e | j_mayer | env->spr[SPR_440_MMUCR] &= ~0x000000FF;
|
3124 | a4bb6c3e | j_mayer | env->spr[SPR_440_MMUCR] |= tlb->PID; |
3125 | a4bb6c3e | j_mayer | break;
|
3126 | a4bb6c3e | j_mayer | case 1: |
3127 | a4bb6c3e | j_mayer | T0 = tlb->RPN; |
3128 | a4bb6c3e | j_mayer | break;
|
3129 | a4bb6c3e | j_mayer | case 2: |
3130 | a4bb6c3e | j_mayer | T0 = tlb->attr & ~0x1;
|
3131 | a4bb6c3e | j_mayer | if (tlb->prot & (PAGE_READ << 4)) |
3132 | a4bb6c3e | j_mayer | T0 |= 0x1;
|
3133 | a4bb6c3e | j_mayer | if (tlb->prot & (PAGE_WRITE << 4)) |
3134 | a4bb6c3e | j_mayer | T0 |= 0x2;
|
3135 | a4bb6c3e | j_mayer | if (tlb->prot & (PAGE_EXEC << 4)) |
3136 | a4bb6c3e | j_mayer | T0 |= 0x4;
|
3137 | a4bb6c3e | j_mayer | if (tlb->prot & PAGE_READ)
|
3138 | a4bb6c3e | j_mayer | T0 |= 0x8;
|
3139 | a4bb6c3e | j_mayer | if (tlb->prot & PAGE_WRITE)
|
3140 | a4bb6c3e | j_mayer | T0 |= 0x10;
|
3141 | a4bb6c3e | j_mayer | if (tlb->prot & PAGE_EXEC)
|
3142 | a4bb6c3e | j_mayer | T0 |= 0x20;
|
3143 | a4bb6c3e | j_mayer | break;
|
3144 | a4bb6c3e | j_mayer | } |
3145 | 5eb7995e | j_mayer | } |
3146 | 76a66253 | j_mayer | #endif /* !CONFIG_USER_ONLY */ |