Add copyright notices
[qemu-kvm/fedora.git] / target-sparc / op.c
blob52b824cc7bc74deaca273d99d8cdbf82e67cbb26
1 /*
2 SPARC micro operations
4 Copyright (C) 2003 Thomas M. Ogrisegg <tom@fnord.at>
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "exec.h"
23 /*XXX*/
24 #define REGNAME g0
25 #define REG (env->gregs[0])
26 #include "op_template.h"
27 #define REGNAME g1
28 #define REG (env->gregs[1])
29 #include "op_template.h"
30 #define REGNAME g2
31 #define REG (env->gregs[2])
32 #include "op_template.h"
33 #define REGNAME g3
34 #define REG (env->gregs[3])
35 #include "op_template.h"
36 #define REGNAME g4
37 #define REG (env->gregs[4])
38 #include "op_template.h"
39 #define REGNAME g5
40 #define REG (env->gregs[5])
41 #include "op_template.h"
42 #define REGNAME g6
43 #define REG (env->gregs[6])
44 #include "op_template.h"
45 #define REGNAME g7
46 #define REG (env->gregs[7])
47 #include "op_template.h"
48 #define REGNAME i0
49 #define REG (REGWPTR[16])
50 #include "op_template.h"
51 #define REGNAME i1
52 #define REG (REGWPTR[17])
53 #include "op_template.h"
54 #define REGNAME i2
55 #define REG (REGWPTR[18])
56 #include "op_template.h"
57 #define REGNAME i3
58 #define REG (REGWPTR[19])
59 #include "op_template.h"
60 #define REGNAME i4
61 #define REG (REGWPTR[20])
62 #include "op_template.h"
63 #define REGNAME i5
64 #define REG (REGWPTR[21])
65 #include "op_template.h"
66 #define REGNAME i6
67 #define REG (REGWPTR[22])
68 #include "op_template.h"
69 #define REGNAME i7
70 #define REG (REGWPTR[23])
71 #include "op_template.h"
72 #define REGNAME l0
73 #define REG (REGWPTR[8])
74 #include "op_template.h"
75 #define REGNAME l1
76 #define REG (REGWPTR[9])
77 #include "op_template.h"
78 #define REGNAME l2
79 #define REG (REGWPTR[10])
80 #include "op_template.h"
81 #define REGNAME l3
82 #define REG (REGWPTR[11])
83 #include "op_template.h"
84 #define REGNAME l4
85 #define REG (REGWPTR[12])
86 #include "op_template.h"
87 #define REGNAME l5
88 #define REG (REGWPTR[13])
89 #include "op_template.h"
90 #define REGNAME l6
91 #define REG (REGWPTR[14])
92 #include "op_template.h"
93 #define REGNAME l7
94 #define REG (REGWPTR[15])
95 #include "op_template.h"
96 #define REGNAME o0
97 #define REG (REGWPTR[0])
98 #include "op_template.h"
99 #define REGNAME o1
100 #define REG (REGWPTR[1])
101 #include "op_template.h"
102 #define REGNAME o2
103 #define REG (REGWPTR[2])
104 #include "op_template.h"
105 #define REGNAME o3
106 #define REG (REGWPTR[3])
107 #include "op_template.h"
108 #define REGNAME o4
109 #define REG (REGWPTR[4])
110 #include "op_template.h"
111 #define REGNAME o5
112 #define REG (REGWPTR[5])
113 #include "op_template.h"
114 #define REGNAME o6
115 #define REG (REGWPTR[6])
116 #include "op_template.h"
117 #define REGNAME o7
118 #define REG (REGWPTR[7])
119 #include "op_template.h"
121 #define REGNAME f0
122 #define REG (env->fpr[0])
123 #include "fop_template.h"
124 #define REGNAME f1
125 #define REG (env->fpr[1])
126 #include "fop_template.h"
127 #define REGNAME f2
128 #define REG (env->fpr[2])
129 #include "fop_template.h"
130 #define REGNAME f3
131 #define REG (env->fpr[3])
132 #include "fop_template.h"
133 #define REGNAME f4
134 #define REG (env->fpr[4])
135 #include "fop_template.h"
136 #define REGNAME f5
137 #define REG (env->fpr[5])
138 #include "fop_template.h"
139 #define REGNAME f6
140 #define REG (env->fpr[6])
141 #include "fop_template.h"
142 #define REGNAME f7
143 #define REG (env->fpr[7])
144 #include "fop_template.h"
145 #define REGNAME f8
146 #define REG (env->fpr[8])
147 #include "fop_template.h"
148 #define REGNAME f9
149 #define REG (env->fpr[9])
150 #include "fop_template.h"
151 #define REGNAME f10
152 #define REG (env->fpr[10])
153 #include "fop_template.h"
154 #define REGNAME f11
155 #define REG (env->fpr[11])
156 #include "fop_template.h"
157 #define REGNAME f12
158 #define REG (env->fpr[12])
159 #include "fop_template.h"
160 #define REGNAME f13
161 #define REG (env->fpr[13])
162 #include "fop_template.h"
163 #define REGNAME f14
164 #define REG (env->fpr[14])
165 #include "fop_template.h"
166 #define REGNAME f15
167 #define REG (env->fpr[15])
168 #include "fop_template.h"
169 #define REGNAME f16
170 #define REG (env->fpr[16])
171 #include "fop_template.h"
172 #define REGNAME f17
173 #define REG (env->fpr[17])
174 #include "fop_template.h"
175 #define REGNAME f18
176 #define REG (env->fpr[18])
177 #include "fop_template.h"
178 #define REGNAME f19
179 #define REG (env->fpr[19])
180 #include "fop_template.h"
181 #define REGNAME f20
182 #define REG (env->fpr[20])
183 #include "fop_template.h"
184 #define REGNAME f21
185 #define REG (env->fpr[21])
186 #include "fop_template.h"
187 #define REGNAME f22
188 #define REG (env->fpr[22])
189 #include "fop_template.h"
190 #define REGNAME f23
191 #define REG (env->fpr[23])
192 #include "fop_template.h"
193 #define REGNAME f24
194 #define REG (env->fpr[24])
195 #include "fop_template.h"
196 #define REGNAME f25
197 #define REG (env->fpr[25])
198 #include "fop_template.h"
199 #define REGNAME f26
200 #define REG (env->fpr[26])
201 #include "fop_template.h"
202 #define REGNAME f27
203 #define REG (env->fpr[27])
204 #include "fop_template.h"
205 #define REGNAME f28
206 #define REG (env->fpr[28])
207 #include "fop_template.h"
208 #define REGNAME f29
209 #define REG (env->fpr[29])
210 #include "fop_template.h"
211 #define REGNAME f30
212 #define REG (env->fpr[30])
213 #include "fop_template.h"
214 #define REGNAME f31
215 #define REG (env->fpr[31])
216 #include "fop_template.h"
218 #ifdef TARGET_SPARC64
219 #define REGNAME f32
220 #define REG (env->fpr[32])
221 #include "fop_template.h"
222 #define REGNAME f34
223 #define REG (env->fpr[34])
224 #include "fop_template.h"
225 #define REGNAME f36
226 #define REG (env->fpr[36])
227 #include "fop_template.h"
228 #define REGNAME f38
229 #define REG (env->fpr[38])
230 #include "fop_template.h"
231 #define REGNAME f40
232 #define REG (env->fpr[40])
233 #include "fop_template.h"
234 #define REGNAME f42
235 #define REG (env->fpr[42])
236 #include "fop_template.h"
237 #define REGNAME f44
238 #define REG (env->fpr[44])
239 #include "fop_template.h"
240 #define REGNAME f46
241 #define REG (env->fpr[46])
242 #include "fop_template.h"
243 #define REGNAME f48
244 #define REG (env->fpr[47])
245 #include "fop_template.h"
246 #define REGNAME f50
247 #define REG (env->fpr[50])
248 #include "fop_template.h"
249 #define REGNAME f52
250 #define REG (env->fpr[52])
251 #include "fop_template.h"
252 #define REGNAME f54
253 #define REG (env->fpr[54])
254 #include "fop_template.h"
255 #define REGNAME f56
256 #define REG (env->fpr[56])
257 #include "fop_template.h"
258 #define REGNAME f58
259 #define REG (env->fpr[58])
260 #include "fop_template.h"
261 #define REGNAME f60
262 #define REG (env->fpr[60])
263 #include "fop_template.h"
264 #define REGNAME f62
265 #define REG (env->fpr[62])
266 #include "fop_template.h"
267 #endif
269 #ifdef TARGET_SPARC64
270 #ifdef WORDS_BIGENDIAN
271 typedef union UREG64 {
272 struct { uint16_t v3, v2, v1, v0; } w;
273 struct { uint32_t v1, v0; } l;
274 uint64_t q;
275 } UREG64;
276 #else
277 typedef union UREG64 {
278 struct { uint16_t v0, v1, v2, v3; } w;
279 struct { uint32_t v0, v1; } l;
280 uint64_t q;
281 } UREG64;
282 #endif
284 #define PARAMQ1 \
286 UREG64 __p;\
287 __p.l.v1 = PARAM1;\
288 __p.l.v0 = PARAM2;\
289 __p.q;\
292 void OPPROTO op_movq_T0_im64(void)
294 T0 = PARAMQ1;
297 void OPPROTO op_movq_T1_im64(void)
299 T1 = PARAMQ1;
302 #define XFLAG_SET(x) ((env->xcc&x)?1:0)
304 #else
305 #define EIP (env->pc)
306 #endif
308 #define FLAG_SET(x) ((env->psr&x)?1:0)
310 void OPPROTO op_movl_T0_0(void)
312 T0 = 0;
315 void OPPROTO op_movl_T0_im(void)
317 T0 = (uint32_t)PARAM1;
320 void OPPROTO op_movl_T1_im(void)
322 T1 = (uint32_t)PARAM1;
325 void OPPROTO op_movl_T2_im(void)
327 T2 = (uint32_t)PARAM1;
330 void OPPROTO op_movl_T0_sim(void)
332 T0 = (int32_t)PARAM1;
335 void OPPROTO op_movl_T1_sim(void)
337 T1 = (int32_t)PARAM1;
340 void OPPROTO op_movl_T2_sim(void)
342 T2 = (int32_t)PARAM1;
345 void OPPROTO op_movl_T0_env(void)
347 T0 = *(uint32_t *)((char *)env + PARAM1);
350 void OPPROTO op_movl_env_T0(void)
352 *(uint32_t *)((char *)env + PARAM1) = T0;
355 void OPPROTO op_movtl_T0_env(void)
357 T0 = *(target_ulong *)((char *)env + PARAM1);
360 void OPPROTO op_movtl_env_T0(void)
362 *(target_ulong *)((char *)env + PARAM1) = T0;
365 void OPPROTO op_add_T1_T0(void)
367 T0 += T1;
370 void OPPROTO op_add_T1_T0_cc(void)
372 target_ulong src1;
374 src1 = T0;
375 T0 += T1;
376 env->psr = 0;
377 #ifdef TARGET_SPARC64
378 if (!(T0 & 0xffffffff))
379 env->psr |= PSR_ZERO;
380 if ((int32_t) T0 < 0)
381 env->psr |= PSR_NEG;
382 if ((T0 & 0xffffffff) < (src1 & 0xffffffff))
383 env->psr |= PSR_CARRY;
384 if ((((src1 & 0xffffffff) ^ (T1 & 0xffffffff) ^ -1) &
385 ((src1 & 0xffffffff) ^ (T0 & 0xffffffff))) & (1 << 31))
386 env->psr |= PSR_OVF;
388 env->xcc = 0;
389 if (!T0)
390 env->xcc |= PSR_ZERO;
391 if ((int64_t) T0 < 0)
392 env->xcc |= PSR_NEG;
393 if (T0 < src1)
394 env->xcc |= PSR_CARRY;
395 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1ULL << 63))
396 env->xcc |= PSR_OVF;
397 #else
398 if (!T0)
399 env->psr |= PSR_ZERO;
400 if ((int32_t) T0 < 0)
401 env->psr |= PSR_NEG;
402 if (T0 < src1)
403 env->psr |= PSR_CARRY;
404 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31))
405 env->psr |= PSR_OVF;
406 #endif
407 FORCE_RET();
410 void OPPROTO op_addx_T1_T0(void)
412 T0 += T1 + FLAG_SET(PSR_CARRY);
415 void OPPROTO op_addx_T1_T0_cc(void)
417 target_ulong src1;
418 src1 = T0;
419 if (FLAG_SET(PSR_CARRY))
421 T0 += T1 + 1;
422 env->psr = 0;
423 #ifdef TARGET_SPARC64
424 if ((T0 & 0xffffffff) <= (src1 & 0xffffffff))
425 env->psr |= PSR_CARRY;
426 env->xcc = 0;
427 if (T0 <= src1)
428 env->xcc |= PSR_CARRY;
429 #else
430 if (T0 <= src1)
431 env->psr |= PSR_CARRY;
432 #endif
434 else
436 T0 += T1;
437 env->psr = 0;
438 #ifdef TARGET_SPARC64
439 if ((T0 & 0xffffffff) < (src1 & 0xffffffff))
440 env->psr |= PSR_CARRY;
441 env->xcc = 0;
442 if (T0 < src1)
443 env->xcc |= PSR_CARRY;
444 #else
445 if (T0 < src1)
446 env->psr |= PSR_CARRY;
447 #endif
449 #ifdef TARGET_SPARC64
450 if (!(T0 & 0xffffffff))
451 env->psr |= PSR_ZERO;
452 if ((int32_t) T0 < 0)
453 env->psr |= PSR_NEG;
454 if ((((src1 & 0xffffffff) ^ (T1 & 0xffffffff) ^ -1) &
455 ((src1 & 0xffffffff) ^ (T0 & 0xffffffff))) & (1 << 31))
456 env->psr |= PSR_OVF;
458 if (!T0)
459 env->xcc |= PSR_ZERO;
460 if ((int64_t) T0 < 0)
461 env->xcc |= PSR_NEG;
462 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1ULL << 63))
463 env->xcc |= PSR_OVF;
464 #else
465 if (!T0)
466 env->psr |= PSR_ZERO;
467 if ((int32_t) T0 < 0)
468 env->psr |= PSR_NEG;
469 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31))
470 env->psr |= PSR_OVF;
471 #endif
472 FORCE_RET();
475 void OPPROTO op_tadd_T1_T0_cc(void)
477 target_ulong src1;
479 src1 = T0;
480 T0 += T1;
481 env->psr = 0;
482 #ifdef TARGET_SPARC64
483 if (!(T0 & 0xffffffff))
484 env->psr |= PSR_ZERO;
485 if ((int32_t) T0 < 0)
486 env->psr |= PSR_NEG;
487 if ((T0 & 0xffffffff) < (src1 & 0xffffffff))
488 env->psr |= PSR_CARRY;
489 if ((((src1 & 0xffffffff) ^ (T1 & 0xffffffff) ^ -1) &
490 ((src1 & 0xffffffff) ^ (T0 & 0xffffffff))) & (1 << 31))
491 env->psr |= PSR_OVF;
492 if ((src1 & 0x03) || (T1 & 0x03))
493 env->psr |= PSR_OVF;
495 env->xcc = 0;
496 if (!T0)
497 env->xcc |= PSR_ZERO;
498 if ((int64_t) T0 < 0)
499 env->xcc |= PSR_NEG;
500 if (T0 < src1)
501 env->xcc |= PSR_CARRY;
502 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1ULL << 63))
503 env->xcc |= PSR_OVF;
504 #else
505 if (!T0)
506 env->psr |= PSR_ZERO;
507 if ((int32_t) T0 < 0)
508 env->psr |= PSR_NEG;
509 if (T0 < src1)
510 env->psr |= PSR_CARRY;
511 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31))
512 env->psr |= PSR_OVF;
513 if ((src1 & 0x03) || (T1 & 0x03))
514 env->psr |= PSR_OVF;
515 #endif
516 FORCE_RET();
519 void OPPROTO op_tadd_T1_T0_ccTV(void)
521 target_ulong src1;
523 if ((T0 & 0x03) || (T1 & 0x03)) {
524 raise_exception(TT_TOVF);
525 FORCE_RET();
526 return;
529 src1 = T0;
530 T0 += T1;
532 #ifdef TARGET_SPARC64
533 if ((((src1 & 0xffffffff) ^ (T1 & 0xffffffff) ^ -1) &
534 ((src1 & 0xffffffff) ^ (T0 & 0xffffffff))) & (1 << 31))
535 raise_exception(TT_TOVF);
536 #else
537 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31))
538 raise_exception(TT_TOVF);
539 #endif
541 env->psr = 0;
542 #ifdef TARGET_SPARC64
543 if (!(T0 & 0xffffffff))
544 env->psr |= PSR_ZERO;
545 if ((int32_t) T0 < 0)
546 env->psr |= PSR_NEG;
547 if ((T0 & 0xffffffff) < (src1 & 0xffffffff))
548 env->psr |= PSR_CARRY;
550 env->xcc = 0;
551 if (!T0)
552 env->xcc |= PSR_ZERO;
553 if ((int64_t) T0 < 0)
554 env->xcc |= PSR_NEG;
555 if (T0 < src1)
556 env->xcc |= PSR_CARRY;
557 #else
558 if (!T0)
559 env->psr |= PSR_ZERO;
560 if ((int32_t) T0 < 0)
561 env->psr |= PSR_NEG;
562 if (T0 < src1)
563 env->psr |= PSR_CARRY;
564 #endif
565 FORCE_RET();
568 void OPPROTO op_sub_T1_T0(void)
570 T0 -= T1;
573 void OPPROTO op_sub_T1_T0_cc(void)
575 target_ulong src1;
577 src1 = T0;
578 T0 -= T1;
579 env->psr = 0;
580 #ifdef TARGET_SPARC64
581 if (!(T0 & 0xffffffff))
582 env->psr |= PSR_ZERO;
583 if ((int32_t) T0 < 0)
584 env->psr |= PSR_NEG;
585 if ((src1 & 0xffffffff) < (T1 & 0xffffffff))
586 env->psr |= PSR_CARRY;
587 if ((((src1 & 0xffffffff) ^ (T1 & 0xffffffff)) &
588 ((src1 & 0xffffffff) ^ (T0 & 0xffffffff))) & (1 << 31))
589 env->psr |= PSR_OVF;
591 env->xcc = 0;
592 if (!T0)
593 env->xcc |= PSR_ZERO;
594 if ((int64_t) T0 < 0)
595 env->xcc |= PSR_NEG;
596 if (src1 < T1)
597 env->xcc |= PSR_CARRY;
598 if (((src1 ^ T1) & (src1 ^ T0)) & (1ULL << 63))
599 env->xcc |= PSR_OVF;
600 #else
601 if (!T0)
602 env->psr |= PSR_ZERO;
603 if ((int32_t) T0 < 0)
604 env->psr |= PSR_NEG;
605 if (src1 < T1)
606 env->psr |= PSR_CARRY;
607 if (((src1 ^ T1) & (src1 ^ T0)) & (1 << 31))
608 env->psr |= PSR_OVF;
609 #endif
610 FORCE_RET();
613 void OPPROTO op_subx_T1_T0(void)
615 T0 -= T1 + FLAG_SET(PSR_CARRY);
618 void OPPROTO op_subx_T1_T0_cc(void)
620 target_ulong src1;
621 src1 = T0;
622 if (FLAG_SET(PSR_CARRY))
624 T0 -= T1 + 1;
625 env->psr = 0;
626 #ifdef TARGET_SPARC64
627 if ((src1 & 0xffffffff) <= (T1 & 0xffffffff))
628 env->psr |= PSR_CARRY;
629 env->xcc = 0;
630 if (src1 <= T1)
631 env->xcc |= PSR_CARRY;
632 #else
633 if (src1 <= T1)
634 env->psr |= PSR_CARRY;
635 #endif
637 else
639 T0 -= T1;
640 env->psr = 0;
641 #ifdef TARGET_SPARC64
642 if ((src1 & 0xffffffff) < (T1 & 0xffffffff))
643 env->psr |= PSR_CARRY;
644 env->xcc = 0;
645 if (src1 < T1)
646 env->xcc |= PSR_CARRY;
647 #else
648 if (src1 < T1)
649 env->psr |= PSR_CARRY;
650 #endif
652 #ifdef TARGET_SPARC64
653 if (!(T0 & 0xffffffff))
654 env->psr |= PSR_ZERO;
655 if ((int32_t) T0 < 0)
656 env->psr |= PSR_NEG;
657 if ((((src1 & 0xffffffff) ^ (T1 & 0xffffffff)) &
658 ((src1 & 0xffffffff) ^ (T0 & 0xffffffff))) & (1 << 31))
659 env->psr |= PSR_OVF;
661 if (!T0)
662 env->xcc |= PSR_ZERO;
663 if ((int64_t) T0 < 0)
664 env->xcc |= PSR_NEG;
665 if (((src1 ^ T1) & (src1 ^ T0)) & (1ULL << 63))
666 env->xcc |= PSR_OVF;
667 #else
668 if (!T0)
669 env->psr |= PSR_ZERO;
670 if ((int32_t) T0 < 0)
671 env->psr |= PSR_NEG;
672 if (((src1 ^ T1) & (src1 ^ T0)) & (1 << 31))
673 env->psr |= PSR_OVF;
674 #endif
675 FORCE_RET();
678 void OPPROTO op_tsub_T1_T0_cc(void)
680 target_ulong src1;
682 src1 = T0;
683 T0 -= T1;
684 env->psr = 0;
685 #ifdef TARGET_SPARC64
686 if (!(T0 & 0xffffffff))
687 env->psr |= PSR_ZERO;
688 if ((int32_t) T0 < 0)
689 env->psr |= PSR_NEG;
690 if ((src1 & 0xffffffff) < (T1 & 0xffffffff))
691 env->psr |= PSR_CARRY;
692 if ((((src1 & 0xffffffff) ^ (T1 & 0xffffffff)) &
693 ((src1 & 0xffffffff) ^ (T0 & 0xffffffff))) & (1 << 31))
694 env->psr |= PSR_OVF;
695 if ((src1 & 0x03) || (T1 & 0x03))
696 env->psr |= PSR_OVF;
698 env->xcc = 0;
699 if (!T0)
700 env->xcc |= PSR_ZERO;
701 if ((int64_t) T0 < 0)
702 env->xcc |= PSR_NEG;
703 if (src1 < T1)
704 env->xcc |= PSR_CARRY;
705 if (((src1 ^ T1) & (src1 ^ T0)) & (1ULL << 63))
706 env->xcc |= PSR_OVF;
707 #else
708 if (!T0)
709 env->psr |= PSR_ZERO;
710 if ((int32_t) T0 < 0)
711 env->psr |= PSR_NEG;
712 if (src1 < T1)
713 env->psr |= PSR_CARRY;
714 if (((src1 ^ T1) & (src1 ^ T0)) & (1 << 31))
715 env->psr |= PSR_OVF;
716 if ((src1 & 0x03) || (T1 & 0x03))
717 env->psr |= PSR_OVF;
718 #endif
719 FORCE_RET();
722 void OPPROTO op_tsub_T1_T0_ccTV(void)
724 target_ulong src1;
726 if ((T0 & 0x03) || (T1 & 0x03))
727 raise_exception(TT_TOVF);
729 src1 = T0;
730 T0 -= T1;
732 #ifdef TARGET_SPARC64
733 if ((((src1 & 0xffffffff) ^ (T1 & 0xffffffff)) &
734 ((src1 & 0xffffffff) ^ (T0 & 0xffffffff))) & (1 << 31))
735 raise_exception(TT_TOVF);
736 #else
737 if (((src1 ^ T1) & (src1 ^ T0)) & (1 << 31))
738 raise_exception(TT_TOVF);
739 #endif
741 env->psr = 0;
742 #ifdef TARGET_SPARC64
743 if (!(T0 & 0xffffffff))
744 env->psr |= PSR_ZERO;
745 if ((int32_t) T0 < 0)
746 env->psr |= PSR_NEG;
747 if ((src1 & 0xffffffff) < (T1 & 0xffffffff))
748 env->psr |= PSR_CARRY;
750 env->xcc = 0;
751 if (!T0)
752 env->xcc |= PSR_ZERO;
753 if ((int64_t) T0 < 0)
754 env->xcc |= PSR_NEG;
755 if (src1 < T1)
756 env->xcc |= PSR_CARRY;
757 #else
758 if (!T0)
759 env->psr |= PSR_ZERO;
760 if ((int32_t) T0 < 0)
761 env->psr |= PSR_NEG;
762 if (src1 < T1)
763 env->psr |= PSR_CARRY;
764 #endif
765 FORCE_RET();
768 void OPPROTO op_and_T1_T0(void)
770 T0 &= T1;
773 void OPPROTO op_or_T1_T0(void)
775 T0 |= T1;
778 void OPPROTO op_xor_T1_T0(void)
780 T0 ^= T1;
783 void OPPROTO op_andn_T1_T0(void)
785 T0 &= ~T1;
788 void OPPROTO op_orn_T1_T0(void)
790 T0 |= ~T1;
793 void OPPROTO op_xnor_T1_T0(void)
795 T0 ^= ~T1;
798 void OPPROTO op_umul_T1_T0(void)
800 uint64_t res;
801 res = (uint64_t) T0 * (uint64_t) T1;
802 #ifdef TARGET_SPARC64
803 T0 = res;
804 #else
805 T0 = res & 0xffffffff;
806 #endif
807 env->y = res >> 32;
810 void OPPROTO op_smul_T1_T0(void)
812 uint64_t res;
813 res = (int64_t) ((int32_t) T0) * (int64_t) ((int32_t) T1);
814 #ifdef TARGET_SPARC64
815 T0 = res;
816 #else
817 T0 = res & 0xffffffff;
818 #endif
819 env->y = res >> 32;
822 void OPPROTO op_mulscc_T1_T0(void)
824 unsigned int b1, N, V, b2;
825 target_ulong src1;
827 N = FLAG_SET(PSR_NEG);
828 V = FLAG_SET(PSR_OVF);
829 b1 = N ^ V;
830 b2 = T0 & 1;
831 T0 = (b1 << 31) | (T0 >> 1);
832 if (!(env->y & 1))
833 T1 = 0;
834 /* do addition and update flags */
835 src1 = T0;
836 T0 += T1;
837 env->psr = 0;
838 if (!T0)
839 env->psr |= PSR_ZERO;
840 if ((int32_t) T0 < 0)
841 env->psr |= PSR_NEG;
842 if (T0 < src1)
843 env->psr |= PSR_CARRY;
844 if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31))
845 env->psr |= PSR_OVF;
846 env->y = (b2 << 31) | (env->y >> 1);
847 FORCE_RET();
850 void OPPROTO op_udiv_T1_T0(void)
852 uint64_t x0;
853 uint32_t x1;
855 x0 = T0 | ((uint64_t) (env->y) << 32);
856 x1 = T1;
858 if (x1 == 0) {
859 raise_exception(TT_DIV_ZERO);
862 x0 = x0 / x1;
863 if (x0 > 0xffffffff) {
864 T0 = 0xffffffff;
865 T1 = 1;
866 } else {
867 T0 = x0;
868 T1 = 0;
870 FORCE_RET();
873 void OPPROTO op_sdiv_T1_T0(void)
875 int64_t x0;
876 int32_t x1;
878 x0 = T0 | ((int64_t) (env->y) << 32);
879 x1 = T1;
881 if (x1 == 0) {
882 raise_exception(TT_DIV_ZERO);
885 x0 = x0 / x1;
886 if ((int32_t) x0 != x0) {
887 T0 = x0 < 0? 0x80000000: 0x7fffffff;
888 T1 = 1;
889 } else {
890 T0 = x0;
891 T1 = 0;
893 FORCE_RET();
896 void OPPROTO op_div_cc(void)
898 env->psr = 0;
899 #ifdef TARGET_SPARC64
900 if (!T0)
901 env->psr |= PSR_ZERO;
902 if ((int32_t) T0 < 0)
903 env->psr |= PSR_NEG;
904 if (T1)
905 env->psr |= PSR_OVF;
907 env->xcc = 0;
908 if (!T0)
909 env->xcc |= PSR_ZERO;
910 if ((int64_t) T0 < 0)
911 env->xcc |= PSR_NEG;
912 #else
913 if (!T0)
914 env->psr |= PSR_ZERO;
915 if ((int32_t) T0 < 0)
916 env->psr |= PSR_NEG;
917 if (T1)
918 env->psr |= PSR_OVF;
919 #endif
920 FORCE_RET();
923 #ifdef TARGET_SPARC64
924 void OPPROTO op_mulx_T1_T0(void)
926 T0 *= T1;
927 FORCE_RET();
930 void OPPROTO op_udivx_T1_T0(void)
932 if (T1 == 0) {
933 raise_exception(TT_DIV_ZERO);
935 T0 /= T1;
936 FORCE_RET();
939 void OPPROTO op_sdivx_T1_T0(void)
941 if (T1 == 0) {
942 raise_exception(TT_DIV_ZERO);
944 if (T0 == INT64_MIN && T1 == -1)
945 T0 = INT64_MIN;
946 else
947 T0 /= (target_long) T1;
948 FORCE_RET();
950 #endif
952 void OPPROTO op_logic_T0_cc(void)
954 env->psr = 0;
955 #ifdef TARGET_SPARC64
956 if (!(T0 & 0xffffffff))
957 env->psr |= PSR_ZERO;
958 if ((int32_t) T0 < 0)
959 env->psr |= PSR_NEG;
961 env->xcc = 0;
962 if (!T0)
963 env->xcc |= PSR_ZERO;
964 if ((int64_t) T0 < 0)
965 env->xcc |= PSR_NEG;
966 #else
967 if (!T0)
968 env->psr |= PSR_ZERO;
969 if ((int32_t) T0 < 0)
970 env->psr |= PSR_NEG;
971 #endif
972 FORCE_RET();
975 void OPPROTO op_sll(void)
977 T0 <<= (T1 & 0x1f);
980 #ifdef TARGET_SPARC64
981 void OPPROTO op_sllx(void)
983 T0 <<= (T1 & 0x3f);
986 void OPPROTO op_srl(void)
988 T0 = (T0 & 0xffffffff) >> (T1 & 0x1f);
991 void OPPROTO op_srlx(void)
993 T0 >>= (T1 & 0x3f);
996 void OPPROTO op_sra(void)
998 T0 = ((int32_t) (T0 & 0xffffffff)) >> (T1 & 0x1f);
1001 void OPPROTO op_srax(void)
1003 T0 = ((int64_t) T0) >> (T1 & 0x3f);
1005 #else
1006 void OPPROTO op_srl(void)
1008 T0 >>= (T1 & 0x1f);
1011 void OPPROTO op_sra(void)
1013 T0 = ((int32_t) T0) >> (T1 & 0x1f);
1015 #endif
1017 /* Load and store */
1018 #define MEMSUFFIX _raw
1019 #include "op_mem.h"
1020 #if !defined(CONFIG_USER_ONLY)
1021 #define MEMSUFFIX _user
1022 #include "op_mem.h"
1024 #define MEMSUFFIX _kernel
1025 #include "op_mem.h"
1027 #ifdef TARGET_SPARC64
1028 #define MEMSUFFIX _hypv
1029 #include "op_mem.h"
1030 #endif
1031 #endif
1033 void OPPROTO op_ldfsr(void)
1035 PUT_FSR32(env, *((uint32_t *) &FT0));
1036 helper_ldfsr();
1039 void OPPROTO op_stfsr(void)
1041 *((uint32_t *) &FT0) = GET_FSR32(env);
1044 #ifndef TARGET_SPARC64
1045 void OPPROTO op_rdpsr(void)
1047 do_rdpsr();
1050 void OPPROTO op_wrpsr(void)
1052 do_wrpsr();
1053 FORCE_RET();
1056 void OPPROTO op_wrwim(void)
1058 #if NWINDOWS == 32
1059 env->wim = T0;
1060 #else
1061 env->wim = T0 & ((1 << NWINDOWS) - 1);
1062 #endif
1065 void OPPROTO op_rett(void)
1067 helper_rett();
1068 FORCE_RET();
1071 /* XXX: use another pointer for %iN registers to avoid slow wrapping
1072 handling ? */
1073 void OPPROTO op_save(void)
1075 uint32_t cwp;
1076 cwp = (env->cwp - 1) & (NWINDOWS - 1);
1077 if (env->wim & (1 << cwp)) {
1078 raise_exception(TT_WIN_OVF);
1080 set_cwp(cwp);
1081 FORCE_RET();
1084 void OPPROTO op_restore(void)
1086 uint32_t cwp;
1087 cwp = (env->cwp + 1) & (NWINDOWS - 1);
1088 if (env->wim & (1 << cwp)) {
1089 raise_exception(TT_WIN_UNF);
1091 set_cwp(cwp);
1092 FORCE_RET();
1094 #else
1095 void OPPROTO op_rdccr(void)
1097 T0 = GET_CCR(env);
1100 void OPPROTO op_wrccr(void)
1102 PUT_CCR(env, T0);
1105 void OPPROTO op_rdtick(void)
1107 T0 = do_tick_get_count(env->tick);
1110 void OPPROTO op_wrtick(void)
1112 do_tick_set_count(env->tick, T0);
1115 void OPPROTO op_wrtick_cmpr(void)
1117 do_tick_set_limit(env->tick, T0);
1120 void OPPROTO op_rdstick(void)
1122 T0 = do_tick_get_count(env->stick);
1125 void OPPROTO op_wrstick(void)
1127 do_tick_set_count(env->stick, T0);
1128 do_tick_set_count(env->hstick, T0);
1131 void OPPROTO op_wrstick_cmpr(void)
1133 do_tick_set_limit(env->stick, T0);
1136 void OPPROTO op_wrhstick_cmpr(void)
1138 do_tick_set_limit(env->hstick, T0);
1141 void OPPROTO op_rdtpc(void)
1143 T0 = env->tpc[env->tl];
1146 void OPPROTO op_wrtpc(void)
1148 env->tpc[env->tl] = T0;
1151 void OPPROTO op_rdtnpc(void)
1153 T0 = env->tnpc[env->tl];
1156 void OPPROTO op_wrtnpc(void)
1158 env->tnpc[env->tl] = T0;
1161 void OPPROTO op_rdtstate(void)
1163 T0 = env->tstate[env->tl];
1166 void OPPROTO op_wrtstate(void)
1168 env->tstate[env->tl] = T0;
1171 void OPPROTO op_rdtt(void)
1173 T0 = env->tt[env->tl];
1176 void OPPROTO op_wrtt(void)
1178 env->tt[env->tl] = T0;
1181 void OPPROTO op_rdpstate(void)
1183 T0 = env->pstate;
1186 void OPPROTO op_wrpstate(void)
1188 do_wrpstate();
1191 // CWP handling is reversed in V9, but we still use the V8 register
1192 // order.
1193 void OPPROTO op_rdcwp(void)
1195 T0 = GET_CWP64(env);
1198 void OPPROTO op_wrcwp(void)
1200 PUT_CWP64(env, T0);
1203 /* XXX: use another pointer for %iN registers to avoid slow wrapping
1204 handling ? */
1205 void OPPROTO op_save(void)
1207 uint32_t cwp;
1208 cwp = (env->cwp - 1) & (NWINDOWS - 1);
1209 if (env->cansave == 0) {
1210 raise_exception(TT_SPILL | (env->otherwin != 0 ?
1211 (TT_WOTHER | ((env->wstate & 0x38) >> 1)):
1212 ((env->wstate & 0x7) << 2)));
1213 } else {
1214 if (env->cleanwin - env->canrestore == 0) {
1215 // XXX Clean windows without trap
1216 raise_exception(TT_CLRWIN);
1217 } else {
1218 env->cansave--;
1219 env->canrestore++;
1220 set_cwp(cwp);
1223 FORCE_RET();
1226 void OPPROTO op_restore(void)
1228 uint32_t cwp;
1229 cwp = (env->cwp + 1) & (NWINDOWS - 1);
1230 if (env->canrestore == 0) {
1231 raise_exception(TT_FILL | (env->otherwin != 0 ?
1232 (TT_WOTHER | ((env->wstate & 0x38) >> 1)):
1233 ((env->wstate & 0x7) << 2)));
1234 } else {
1235 env->cansave++;
1236 env->canrestore--;
1237 set_cwp(cwp);
1239 FORCE_RET();
1241 #endif
1243 void OPPROTO op_exception(void)
1245 env->exception_index = PARAM1;
1246 cpu_loop_exit();
1247 FORCE_RET();
1250 void OPPROTO op_trap_T0(void)
1252 env->exception_index = TT_TRAP + (T0 & 0x7f);
1253 cpu_loop_exit();
1254 FORCE_RET();
1257 void OPPROTO op_trapcc_T0(void)
1259 if (T2) {
1260 env->exception_index = TT_TRAP + (T0 & 0x7f);
1261 cpu_loop_exit();
1263 FORCE_RET();
1266 void OPPROTO op_fpexception_im(void)
1268 env->exception_index = TT_FP_EXCP;
1269 env->fsr &= ~FSR_FTT_MASK;
1270 env->fsr |= PARAM1;
1271 cpu_loop_exit();
1272 FORCE_RET();
1275 void OPPROTO op_debug(void)
1277 helper_debug();
1280 void OPPROTO op_exit_tb(void)
1282 EXIT_TB();
1285 void OPPROTO op_eval_ba(void)
1287 T2 = 1;
1290 void OPPROTO op_eval_be(void)
1292 T2 = FLAG_SET(PSR_ZERO);
1295 void OPPROTO op_eval_ble(void)
1297 target_ulong Z = FLAG_SET(PSR_ZERO), N = FLAG_SET(PSR_NEG), V = FLAG_SET(PSR_OVF);
1299 T2 = Z | (N ^ V);
1302 void OPPROTO op_eval_bl(void)
1304 target_ulong N = FLAG_SET(PSR_NEG), V = FLAG_SET(PSR_OVF);
1306 T2 = N ^ V;
1309 void OPPROTO op_eval_bleu(void)
1311 target_ulong Z = FLAG_SET(PSR_ZERO), C = FLAG_SET(PSR_CARRY);
1313 T2 = C | Z;
1316 void OPPROTO op_eval_bcs(void)
1318 T2 = FLAG_SET(PSR_CARRY);
1321 void OPPROTO op_eval_bvs(void)
1323 T2 = FLAG_SET(PSR_OVF);
1326 void OPPROTO op_eval_bn(void)
1328 T2 = 0;
1331 void OPPROTO op_eval_bneg(void)
1333 T2 = FLAG_SET(PSR_NEG);
1336 void OPPROTO op_eval_bne(void)
1338 T2 = !FLAG_SET(PSR_ZERO);
1341 void OPPROTO op_eval_bg(void)
1343 target_ulong Z = FLAG_SET(PSR_ZERO), N = FLAG_SET(PSR_NEG), V = FLAG_SET(PSR_OVF);
1345 T2 = !(Z | (N ^ V));
1348 void OPPROTO op_eval_bge(void)
1350 target_ulong N = FLAG_SET(PSR_NEG), V = FLAG_SET(PSR_OVF);
1352 T2 = !(N ^ V);
1355 void OPPROTO op_eval_bgu(void)
1357 target_ulong Z = FLAG_SET(PSR_ZERO), C = FLAG_SET(PSR_CARRY);
1359 T2 = !(C | Z);
1362 void OPPROTO op_eval_bcc(void)
1364 T2 = !FLAG_SET(PSR_CARRY);
1367 void OPPROTO op_eval_bpos(void)
1369 T2 = !FLAG_SET(PSR_NEG);
1372 void OPPROTO op_eval_bvc(void)
1374 T2 = !FLAG_SET(PSR_OVF);
1377 #ifdef TARGET_SPARC64
1378 void OPPROTO op_eval_xbe(void)
1380 T2 = XFLAG_SET(PSR_ZERO);
1383 void OPPROTO op_eval_xble(void)
1385 target_ulong Z = XFLAG_SET(PSR_ZERO), N = XFLAG_SET(PSR_NEG), V = XFLAG_SET(PSR_OVF);
1387 T2 = Z | (N ^ V);
1390 void OPPROTO op_eval_xbl(void)
1392 target_ulong N = XFLAG_SET(PSR_NEG), V = XFLAG_SET(PSR_OVF);
1394 T2 = N ^ V;
1397 void OPPROTO op_eval_xbleu(void)
1399 target_ulong Z = XFLAG_SET(PSR_ZERO), C = XFLAG_SET(PSR_CARRY);
1401 T2 = C | Z;
1404 void OPPROTO op_eval_xbcs(void)
1406 T2 = XFLAG_SET(PSR_CARRY);
1409 void OPPROTO op_eval_xbvs(void)
1411 T2 = XFLAG_SET(PSR_OVF);
1414 void OPPROTO op_eval_xbneg(void)
1416 T2 = XFLAG_SET(PSR_NEG);
1419 void OPPROTO op_eval_xbne(void)
1421 T2 = !XFLAG_SET(PSR_ZERO);
1424 void OPPROTO op_eval_xbg(void)
1426 target_ulong Z = XFLAG_SET(PSR_ZERO), N = XFLAG_SET(PSR_NEG), V = XFLAG_SET(PSR_OVF);
1428 T2 = !(Z | (N ^ V));
1431 void OPPROTO op_eval_xbge(void)
1433 target_ulong N = XFLAG_SET(PSR_NEG), V = XFLAG_SET(PSR_OVF);
1435 T2 = !(N ^ V);
1438 void OPPROTO op_eval_xbgu(void)
1440 target_ulong Z = XFLAG_SET(PSR_ZERO), C = XFLAG_SET(PSR_CARRY);
1442 T2 = !(C | Z);
1445 void OPPROTO op_eval_xbcc(void)
1447 T2 = !XFLAG_SET(PSR_CARRY);
1450 void OPPROTO op_eval_xbpos(void)
1452 T2 = !XFLAG_SET(PSR_NEG);
1455 void OPPROTO op_eval_xbvc(void)
1457 T2 = !XFLAG_SET(PSR_OVF);
1459 #endif
1461 #define FCC
1462 #define FFLAG_SET(x) (env->fsr & x? 1: 0)
1463 #include "fbranch_template.h"
1465 #ifdef TARGET_SPARC64
1466 #define FCC _fcc1
1467 #define FFLAG_SET(x) ((env->fsr & ((uint64_t)x >> 32))? 1: 0)
1468 #include "fbranch_template.h"
1469 #define FCC _fcc2
1470 #define FFLAG_SET(x) ((env->fsr & ((uint64_t)x >> 34))? 1: 0)
1471 #include "fbranch_template.h"
1472 #define FCC _fcc3
1473 #define FFLAG_SET(x) ((env->fsr & ((uint64_t)x >> 36))? 1: 0)
1474 #include "fbranch_template.h"
1475 #endif
1477 #ifdef TARGET_SPARC64
1478 void OPPROTO op_eval_brz(void)
1480 T2 = (T0 == 0);
1483 void OPPROTO op_eval_brnz(void)
1485 T2 = (T0 != 0);
1488 void OPPROTO op_eval_brlz(void)
1490 T2 = ((int64_t)T0 < 0);
1493 void OPPROTO op_eval_brlez(void)
1495 T2 = ((int64_t)T0 <= 0);
1498 void OPPROTO op_eval_brgz(void)
1500 T2 = ((int64_t)T0 > 0);
1503 void OPPROTO op_eval_brgez(void)
1505 T2 = ((int64_t)T0 >= 0);
1508 void OPPROTO op_jmp_im64(void)
1510 env->pc = PARAMQ1;
1513 void OPPROTO op_movq_npc_im64(void)
1515 env->npc = PARAMQ1;
1517 #endif
1519 void OPPROTO op_jmp_im(void)
1521 env->pc = (uint32_t)PARAM1;
1524 void OPPROTO op_movl_npc_im(void)
1526 env->npc = (uint32_t)PARAM1;
1529 void OPPROTO op_movl_npc_T0(void)
1531 env->npc = T0;
1534 void OPPROTO op_mov_pc_npc(void)
1536 env->pc = env->npc;
1539 void OPPROTO op_next_insn(void)
1541 env->pc = env->npc;
1542 env->npc = env->npc + 4;
1545 void OPPROTO op_goto_tb0(void)
1547 GOTO_TB(op_goto_tb0, PARAM1, 0);
1550 void OPPROTO op_goto_tb1(void)
1552 GOTO_TB(op_goto_tb1, PARAM1, 1);
1555 void OPPROTO op_jmp_label(void)
1557 GOTO_LABEL_PARAM(1);
1560 void OPPROTO op_jnz_T2_label(void)
1562 if (T2)
1563 GOTO_LABEL_PARAM(1);
1564 FORCE_RET();
1567 void OPPROTO op_jz_T2_label(void)
1569 if (!T2)
1570 GOTO_LABEL_PARAM(1);
1571 FORCE_RET();
1574 void OPPROTO op_flush_T0(void)
1576 helper_flush(T0);
1579 void OPPROTO op_clear_ieee_excp_and_FTT(void)
1581 env->fsr &= ~(FSR_FTT_MASK | FSR_CEXC_MASK);;
1584 #define F_OP(name, p) void OPPROTO op_f##name##p(void)
1586 #if defined(CONFIG_USER_ONLY)
1587 #define F_BINOP(name) \
1588 F_OP(name, s) \
1590 set_float_exception_flags(0, &env->fp_status); \
1591 FT0 = float32_ ## name (FT0, FT1, &env->fp_status); \
1592 check_ieee_exceptions(); \
1594 F_OP(name, d) \
1596 set_float_exception_flags(0, &env->fp_status); \
1597 DT0 = float64_ ## name (DT0, DT1, &env->fp_status); \
1598 check_ieee_exceptions(); \
1600 F_OP(name, q) \
1602 set_float_exception_flags(0, &env->fp_status); \
1603 QT0 = float128_ ## name (QT0, QT1, &env->fp_status); \
1604 check_ieee_exceptions(); \
1606 #else
1607 #define F_BINOP(name) \
1608 F_OP(name, s) \
1610 set_float_exception_flags(0, &env->fp_status); \
1611 FT0 = float32_ ## name (FT0, FT1, &env->fp_status); \
1612 check_ieee_exceptions(); \
1614 F_OP(name, d) \
1616 set_float_exception_flags(0, &env->fp_status); \
1617 DT0 = float64_ ## name (DT0, DT1, &env->fp_status); \
1618 check_ieee_exceptions(); \
1620 #endif
1622 F_BINOP(add);
1623 F_BINOP(sub);
1624 F_BINOP(mul);
1625 F_BINOP(div);
1626 #undef F_BINOP
1628 void OPPROTO op_fsmuld(void)
1630 set_float_exception_flags(0, &env->fp_status);
1631 DT0 = float64_mul(float32_to_float64(FT0, &env->fp_status),
1632 float32_to_float64(FT1, &env->fp_status),
1633 &env->fp_status);
1634 check_ieee_exceptions();
1637 #if defined(CONFIG_USER_ONLY)
1638 void OPPROTO op_fdmulq(void)
1640 set_float_exception_flags(0, &env->fp_status);
1641 QT0 = float128_mul(float64_to_float128(DT0, &env->fp_status),
1642 float64_to_float128(DT1, &env->fp_status),
1643 &env->fp_status);
1644 check_ieee_exceptions();
1646 #endif
1648 #if defined(CONFIG_USER_ONLY)
1649 #define F_HELPER(name) \
1650 F_OP(name, s) \
1652 do_f##name##s(); \
1654 F_OP(name, d) \
1656 do_f##name##d(); \
1658 F_OP(name, q) \
1660 do_f##name##q(); \
1662 #else
1663 #define F_HELPER(name) \
1664 F_OP(name, s) \
1666 do_f##name##s(); \
1668 F_OP(name, d) \
1670 do_f##name##d(); \
1672 #endif
1674 F_HELPER(sqrt);
1676 F_OP(neg, s)
1678 FT0 = float32_chs(FT1);
1681 F_OP(abs, s)
1683 do_fabss();
1686 F_HELPER(cmp);
1687 F_HELPER(cmpe);
1689 #ifdef TARGET_SPARC64
1690 F_OP(neg, d)
1692 DT0 = float64_chs(DT1);
1695 F_OP(abs, d)
1697 do_fabsd();
1700 #if defined(CONFIG_USER_ONLY)
1701 F_OP(neg, q)
1703 QT0 = float128_chs(QT1);
1706 F_OP(abs, q)
1708 do_fabsd();
1710 #endif
1712 void OPPROTO op_fcmps_fcc1(void)
1714 do_fcmps_fcc1();
1717 void OPPROTO op_fcmpd_fcc1(void)
1719 do_fcmpd_fcc1();
1722 void OPPROTO op_fcmps_fcc2(void)
1724 do_fcmps_fcc2();
1727 void OPPROTO op_fcmpd_fcc2(void)
1729 do_fcmpd_fcc2();
1732 void OPPROTO op_fcmps_fcc3(void)
1734 do_fcmps_fcc3();
1737 void OPPROTO op_fcmpd_fcc3(void)
1739 do_fcmpd_fcc3();
1742 void OPPROTO op_fcmpes_fcc1(void)
1744 do_fcmpes_fcc1();
1747 void OPPROTO op_fcmped_fcc1(void)
1749 do_fcmped_fcc1();
1752 void OPPROTO op_fcmpes_fcc2(void)
1754 do_fcmpes_fcc2();
1757 void OPPROTO op_fcmped_fcc2(void)
1759 do_fcmped_fcc2();
1762 void OPPROTO op_fcmpes_fcc3(void)
1764 do_fcmpes_fcc3();
1767 void OPPROTO op_fcmped_fcc3(void)
1769 do_fcmped_fcc3();
1772 #if defined(CONFIG_USER_ONLY)
1773 void OPPROTO op_fcmpq_fcc1(void)
1775 do_fcmpq_fcc1();
1778 void OPPROTO op_fcmpq_fcc2(void)
1780 do_fcmpq_fcc2();
1783 void OPPROTO op_fcmpq_fcc3(void)
1785 do_fcmpq_fcc3();
1788 void OPPROTO op_fcmpeq_fcc1(void)
1790 do_fcmpeq_fcc1();
1793 void OPPROTO op_fcmpeq_fcc2(void)
1795 do_fcmpeq_fcc2();
1798 void OPPROTO op_fcmpeq_fcc3(void)
1800 do_fcmpeq_fcc3();
1802 #endif
1804 #endif
1806 /* Integer to float conversion. */
1807 #ifdef USE_INT_TO_FLOAT_HELPERS
1808 F_HELPER(ito);
1809 #ifdef TARGET_SPARC64
1810 F_HELPER(xto);
1811 #endif
1812 #else
1813 F_OP(ito, s)
1815 set_float_exception_flags(0, &env->fp_status);
1816 FT0 = int32_to_float32(*((int32_t *)&FT1), &env->fp_status);
1817 check_ieee_exceptions();
1820 F_OP(ito, d)
1822 set_float_exception_flags(0, &env->fp_status);
1823 DT0 = int32_to_float64(*((int32_t *)&FT1), &env->fp_status);
1824 check_ieee_exceptions();
1827 #if defined(CONFIG_USER_ONLY)
1828 F_OP(ito, q)
1830 set_float_exception_flags(0, &env->fp_status);
1831 QT0 = int32_to_float128(*((int32_t *)&FT1), &env->fp_status);
1832 check_ieee_exceptions();
1834 #endif
1836 #ifdef TARGET_SPARC64
1837 F_OP(xto, s)
1839 set_float_exception_flags(0, &env->fp_status);
1840 FT0 = int64_to_float32(*((int64_t *)&DT1), &env->fp_status);
1841 check_ieee_exceptions();
1844 F_OP(xto, d)
1846 set_float_exception_flags(0, &env->fp_status);
1847 DT0 = int64_to_float64(*((int64_t *)&DT1), &env->fp_status);
1848 check_ieee_exceptions();
1850 #if defined(CONFIG_USER_ONLY)
1851 F_OP(xto, q)
1853 set_float_exception_flags(0, &env->fp_status);
1854 QT0 = int64_to_float128(*((int64_t *)&DT1), &env->fp_status);
1855 check_ieee_exceptions();
1857 #endif
1858 #endif
1859 #endif
1860 #undef F_HELPER
1862 /* floating point conversion */
1863 void OPPROTO op_fdtos(void)
1865 set_float_exception_flags(0, &env->fp_status);
1866 FT0 = float64_to_float32(DT1, &env->fp_status);
1867 check_ieee_exceptions();
1870 void OPPROTO op_fstod(void)
1872 set_float_exception_flags(0, &env->fp_status);
1873 DT0 = float32_to_float64(FT1, &env->fp_status);
1874 check_ieee_exceptions();
1877 #if defined(CONFIG_USER_ONLY)
1878 void OPPROTO op_fqtos(void)
1880 set_float_exception_flags(0, &env->fp_status);
1881 FT0 = float128_to_float32(QT1, &env->fp_status);
1882 check_ieee_exceptions();
1885 void OPPROTO op_fstoq(void)
1887 set_float_exception_flags(0, &env->fp_status);
1888 QT0 = float32_to_float128(FT1, &env->fp_status);
1889 check_ieee_exceptions();
1892 void OPPROTO op_fqtod(void)
1894 set_float_exception_flags(0, &env->fp_status);
1895 DT0 = float128_to_float64(QT1, &env->fp_status);
1896 check_ieee_exceptions();
1899 void OPPROTO op_fdtoq(void)
1901 set_float_exception_flags(0, &env->fp_status);
1902 QT0 = float64_to_float128(DT1, &env->fp_status);
1903 check_ieee_exceptions();
1905 #endif
1907 /* Float to integer conversion. */
1908 void OPPROTO op_fstoi(void)
1910 set_float_exception_flags(0, &env->fp_status);
1911 *((int32_t *)&FT0) = float32_to_int32_round_to_zero(FT1, &env->fp_status);
1912 check_ieee_exceptions();
1915 void OPPROTO op_fdtoi(void)
1917 set_float_exception_flags(0, &env->fp_status);
1918 *((int32_t *)&FT0) = float64_to_int32_round_to_zero(DT1, &env->fp_status);
1919 check_ieee_exceptions();
1922 #if defined(CONFIG_USER_ONLY)
1923 void OPPROTO op_fqtoi(void)
1925 set_float_exception_flags(0, &env->fp_status);
1926 *((int32_t *)&FT0) = float128_to_int32_round_to_zero(QT1, &env->fp_status);
1927 check_ieee_exceptions();
1929 #endif
1931 #ifdef TARGET_SPARC64
1932 void OPPROTO op_fstox(void)
1934 set_float_exception_flags(0, &env->fp_status);
1935 *((int64_t *)&DT0) = float32_to_int64_round_to_zero(FT1, &env->fp_status);
1936 check_ieee_exceptions();
1939 void OPPROTO op_fdtox(void)
1941 set_float_exception_flags(0, &env->fp_status);
1942 *((int64_t *)&DT0) = float64_to_int64_round_to_zero(DT1, &env->fp_status);
1943 check_ieee_exceptions();
1946 #if defined(CONFIG_USER_ONLY)
1947 void OPPROTO op_fqtox(void)
1949 set_float_exception_flags(0, &env->fp_status);
1950 *((int64_t *)&DT0) = float128_to_int64_round_to_zero(QT1, &env->fp_status);
1951 check_ieee_exceptions();
1953 #endif
1955 void OPPROTO op_fmovs_cc(void)
1957 if (T2)
1958 FT0 = FT1;
1961 void OPPROTO op_fmovd_cc(void)
1963 if (T2)
1964 DT0 = DT1;
1967 #if defined(CONFIG_USER_ONLY)
1968 void OPPROTO op_fmovq_cc(void)
1970 if (T2)
1971 QT0 = QT1;
1973 #endif
1975 void OPPROTO op_mov_cc(void)
1977 if (T2)
1978 T0 = T1;
1981 void OPPROTO op_flushw(void)
1983 if (env->cansave != NWINDOWS - 2) {
1984 raise_exception(TT_SPILL | (env->otherwin != 0 ?
1985 (TT_WOTHER | ((env->wstate & 0x38) >> 1)):
1986 ((env->wstate & 0x7) << 2)));
1990 void OPPROTO op_saved(void)
1992 env->cansave++;
1993 if (env->otherwin == 0)
1994 env->canrestore--;
1995 else
1996 env->otherwin--;
1997 FORCE_RET();
2000 void OPPROTO op_restored(void)
2002 env->canrestore++;
2003 if (env->cleanwin < NWINDOWS - 1)
2004 env->cleanwin++;
2005 if (env->otherwin == 0)
2006 env->cansave--;
2007 else
2008 env->otherwin--;
2009 FORCE_RET();
2012 void OPPROTO op_popc(void)
2014 do_popc();
2017 void OPPROTO op_done(void)
2019 do_done();
2022 void OPPROTO op_retry(void)
2024 do_retry();
2027 void OPPROTO op_sir(void)
2029 T0 = 0; // XXX
2032 void OPPROTO op_ld_asi_reg()
2034 T0 += PARAM1;
2035 helper_ld_asi(env->asi, PARAM2, PARAM3);
2038 void OPPROTO op_st_asi_reg()
2040 T0 += PARAM1;
2041 helper_st_asi(env->asi, PARAM2);
2044 void OPPROTO op_ldf_asi_reg()
2046 T0 += PARAM1;
2047 helper_ldf_asi(env->asi, PARAM2, PARAM3);
2050 void OPPROTO op_stf_asi_reg()
2052 T0 += PARAM1;
2053 helper_stf_asi(env->asi, PARAM2, PARAM3);
2056 void OPPROTO op_ldf_asi()
2058 helper_ldf_asi(PARAM1, PARAM2, PARAM3);
2061 void OPPROTO op_stf_asi()
2063 helper_stf_asi(PARAM1, PARAM2, PARAM3);
2066 void OPPROTO op_ldstub_asi_reg() /* XXX: should be atomically */
2068 target_ulong tmp;
2070 T0 += PARAM1;
2071 helper_ld_asi(env->asi, 1, 0);
2072 tmp = T1;
2073 T1 = 0xff;
2074 helper_st_asi(env->asi, 1);
2075 T1 = tmp;
2078 void OPPROTO op_swap_asi_reg() /* XXX: should be atomically */
2080 target_ulong tmp1, tmp2;
2082 T0 += PARAM1;
2083 tmp1 = T1;
2084 helper_ld_asi(env->asi, 4, 0);
2085 tmp2 = T1;
2086 T1 = tmp1;
2087 helper_st_asi(env->asi, 4);
2088 T1 = tmp2;
2091 void OPPROTO op_ldda_asi()
2093 helper_ld_asi(PARAM1, 8, 0);
2094 T0 = T1 & 0xffffffffUL;
2095 T1 >>= 32;
2098 void OPPROTO op_ldda_asi_reg()
2100 T0 += PARAM1;
2101 helper_ld_asi(env->asi, 8, 0);
2102 T0 = T1 & 0xffffffffUL;
2103 T1 >>= 32;
2106 void OPPROTO op_stda_asi()
2108 T1 <<= 32;
2109 T1 += T2 & 0xffffffffUL;
2110 helper_st_asi(PARAM1, 8);
2113 void OPPROTO op_stda_asi_reg()
2115 T0 += PARAM1;
2116 T1 <<= 32;
2117 T1 += T2 & 0xffffffffUL;
2118 helper_st_asi(env->asi, 8);
2121 void OPPROTO op_cas_asi() /* XXX: should be atomically */
2123 target_ulong tmp;
2125 tmp = T1 & 0xffffffffUL;
2126 helper_ld_asi(PARAM1, 4, 0);
2127 if (tmp == T1) {
2128 tmp = T1;
2129 T1 = T2 & 0xffffffffUL;
2130 helper_st_asi(PARAM1, 4);
2131 T1 = tmp;
2133 T1 &= 0xffffffffUL;
2136 void OPPROTO op_cas_asi_reg() /* XXX: should be atomically */
2138 target_ulong tmp;
2140 T0 += PARAM1;
2141 tmp = T1 & 0xffffffffUL;
2142 helper_ld_asi(env->asi, 4, 0);
2143 if (tmp == T1) {
2144 tmp = T1;
2145 T1 = T2 & 0xffffffffUL;
2146 helper_st_asi(env->asi, 4);
2147 T1 = tmp;
2149 T1 &= 0xffffffffUL;
2152 void OPPROTO op_casx_asi() /* XXX: should be atomically */
2154 target_ulong tmp;
2156 tmp = T1;
2157 helper_ld_asi(PARAM1, 8, 0);
2158 if (tmp == T1) {
2159 tmp = T1;
2160 T1 = T2;
2161 helper_st_asi(PARAM1, 8);
2162 T1 = tmp;
2166 void OPPROTO op_casx_asi_reg() /* XXX: should be atomically */
2168 target_ulong tmp;
2170 T0 += PARAM1;
2171 tmp = T1;
2172 helper_ld_asi(env->asi, 8, 0);
2173 if (tmp == T1) {
2174 tmp = T1;
2175 T1 = T2;
2176 helper_st_asi(env->asi, 8);
2177 T1 = tmp;
2180 #endif
2182 #if !defined(CONFIG_USER_ONLY) || defined(TARGET_SPARC64)
2183 void OPPROTO op_ld_asi()
2185 helper_ld_asi(PARAM1, PARAM2, PARAM3);
2188 void OPPROTO op_st_asi()
2190 helper_st_asi(PARAM1, PARAM2);
2193 void OPPROTO op_ldstub_asi() /* XXX: should be atomically */
2195 target_ulong tmp;
2197 helper_ld_asi(PARAM1, 1, 0);
2198 tmp = T1;
2199 T1 = 0xff;
2200 helper_st_asi(PARAM1, 1);
2201 T1 = tmp;
2204 void OPPROTO op_swap_asi() /* XXX: should be atomically */
2206 target_ulong tmp1, tmp2;
2208 tmp1 = T1;
2209 helper_ld_asi(PARAM1, 4, 0);
2210 tmp2 = T1;
2211 T1 = tmp1;
2212 helper_st_asi(PARAM1, 4);
2213 T1 = tmp2;
2215 #endif
2217 #ifdef TARGET_SPARC64
2218 // This function uses non-native bit order
2219 #define GET_FIELD(X, FROM, TO) \
2220 ((X) >> (63 - (TO)) & ((1ULL << ((TO) - (FROM) + 1)) - 1))
2222 // This function uses the order in the manuals, i.e. bit 0 is 2^0
2223 #define GET_FIELD_SP(X, FROM, TO) \
2224 GET_FIELD(X, 63 - (TO), 63 - (FROM))
2226 void OPPROTO op_array8()
2228 T0 = (GET_FIELD_SP(T0, 60, 63) << (17 + 2 * T1)) |
2229 (GET_FIELD_SP(T0, 39, 39 + T1 - 1) << (17 + T1)) |
2230 (GET_FIELD_SP(T0, 17 + T1 - 1, 17) << 17) |
2231 (GET_FIELD_SP(T0, 56, 59) << 13) | (GET_FIELD_SP(T0, 35, 38) << 9) |
2232 (GET_FIELD_SP(T0, 13, 16) << 5) | (((T0 >> 55) & 1) << 4) |
2233 (GET_FIELD_SP(T0, 33, 34) << 2) | GET_FIELD_SP(T0, 11, 12);
2236 void OPPROTO op_array16()
2238 T0 = ((GET_FIELD_SP(T0, 60, 63) << (17 + 2 * T1)) |
2239 (GET_FIELD_SP(T0, 39, 39 + T1 - 1) << (17 + T1)) |
2240 (GET_FIELD_SP(T0, 17 + T1 - 1, 17) << 17) |
2241 (GET_FIELD_SP(T0, 56, 59) << 13) | (GET_FIELD_SP(T0, 35, 38) << 9) |
2242 (GET_FIELD_SP(T0, 13, 16) << 5) | (((T0 >> 55) & 1) << 4) |
2243 (GET_FIELD_SP(T0, 33, 34) << 2) | GET_FIELD_SP(T0, 11, 12)) << 1;
2246 void OPPROTO op_array32()
2248 T0 = ((GET_FIELD_SP(T0, 60, 63) << (17 + 2 * T1)) |
2249 (GET_FIELD_SP(T0, 39, 39 + T1 - 1) << (17 + T1)) |
2250 (GET_FIELD_SP(T0, 17 + T1 - 1, 17) << 17) |
2251 (GET_FIELD_SP(T0, 56, 59) << 13) | (GET_FIELD_SP(T0, 35, 38) << 9) |
2252 (GET_FIELD_SP(T0, 13, 16) << 5) | (((T0 >> 55) & 1) << 4) |
2253 (GET_FIELD_SP(T0, 33, 34) << 2) | GET_FIELD_SP(T0, 11, 12)) << 2;
2256 void OPPROTO op_alignaddr()
2258 uint64_t tmp;
2260 tmp = T0 + T1;
2261 env->gsr &= ~7ULL;
2262 env->gsr |= tmp & 7ULL;
2263 T0 = tmp & ~7ULL;
2266 void OPPROTO op_faligndata()
2268 uint64_t tmp;
2270 tmp = (*((uint64_t *)&DT0)) << ((env->gsr & 7) * 8);
2271 tmp |= (*((uint64_t *)&DT1)) >> (64 - (env->gsr & 7) * 8);
2272 *((uint64_t *)&DT0) = tmp;
2275 void OPPROTO op_movl_FT0_0(void)
2277 *((uint32_t *)&FT0) = 0;
2280 void OPPROTO op_movl_DT0_0(void)
2282 *((uint64_t *)&DT0) = 0;
2285 void OPPROTO op_movl_FT0_1(void)
2287 *((uint32_t *)&FT0) = 0xffffffff;
2290 void OPPROTO op_movl_DT0_1(void)
2292 *((uint64_t *)&DT0) = 0xffffffffffffffffULL;
2295 void OPPROTO op_fnot(void)
2297 *(uint64_t *)&DT0 = ~*(uint64_t *)&DT1;
2300 void OPPROTO op_fnots(void)
2302 *(uint32_t *)&FT0 = ~*(uint32_t *)&FT1;
2305 void OPPROTO op_fnor(void)
2307 *(uint64_t *)&DT0 = ~(*(uint64_t *)&DT0 | *(uint64_t *)&DT1);
2310 void OPPROTO op_fnors(void)
2312 *(uint32_t *)&FT0 = ~(*(uint32_t *)&FT0 | *(uint32_t *)&FT1);
2315 void OPPROTO op_for(void)
2317 *(uint64_t *)&DT0 |= *(uint64_t *)&DT1;
2320 void OPPROTO op_fors(void)
2322 *(uint32_t *)&FT0 |= *(uint32_t *)&FT1;
2325 void OPPROTO op_fxor(void)
2327 *(uint64_t *)&DT0 ^= *(uint64_t *)&DT1;
2330 void OPPROTO op_fxors(void)
2332 *(uint32_t *)&FT0 ^= *(uint32_t *)&FT1;
2335 void OPPROTO op_fand(void)
2337 *(uint64_t *)&DT0 &= *(uint64_t *)&DT1;
2340 void OPPROTO op_fands(void)
2342 *(uint32_t *)&FT0 &= *(uint32_t *)&FT1;
2345 void OPPROTO op_fornot(void)
2347 *(uint64_t *)&DT0 = *(uint64_t *)&DT0 | ~*(uint64_t *)&DT1;
2350 void OPPROTO op_fornots(void)
2352 *(uint32_t *)&FT0 = *(uint32_t *)&FT0 | ~*(uint32_t *)&FT1;
2355 void OPPROTO op_fandnot(void)
2357 *(uint64_t *)&DT0 = *(uint64_t *)&DT0 & ~*(uint64_t *)&DT1;
2360 void OPPROTO op_fandnots(void)
2362 *(uint32_t *)&FT0 = *(uint32_t *)&FT0 & ~*(uint32_t *)&FT1;
2365 void OPPROTO op_fnand(void)
2367 *(uint64_t *)&DT0 = ~(*(uint64_t *)&DT0 & *(uint64_t *)&DT1);
2370 void OPPROTO op_fnands(void)
2372 *(uint32_t *)&FT0 = ~(*(uint32_t *)&FT0 & *(uint32_t *)&FT1);
2375 void OPPROTO op_fxnor(void)
2377 *(uint64_t *)&DT0 ^= ~*(uint64_t *)&DT1;
2380 void OPPROTO op_fxnors(void)
2382 *(uint32_t *)&FT0 ^= ~*(uint32_t *)&FT1;
2385 #ifdef WORDS_BIGENDIAN
2386 #define VIS_B64(n) b[7 - (n)]
2387 #define VIS_W64(n) w[3 - (n)]
2388 #define VIS_SW64(n) sw[3 - (n)]
2389 #define VIS_L64(n) l[1 - (n)]
2390 #define VIS_B32(n) b[3 - (n)]
2391 #define VIS_W32(n) w[1 - (n)]
2392 #else
2393 #define VIS_B64(n) b[n]
2394 #define VIS_W64(n) w[n]
2395 #define VIS_SW64(n) sw[n]
2396 #define VIS_L64(n) l[n]
2397 #define VIS_B32(n) b[n]
2398 #define VIS_W32(n) w[n]
2399 #endif
2401 typedef union {
2402 uint8_t b[8];
2403 uint16_t w[4];
2404 int16_t sw[4];
2405 uint32_t l[2];
2406 float64 d;
2407 } vis64;
2409 typedef union {
2410 uint8_t b[4];
2411 uint16_t w[2];
2412 uint32_t l;
2413 float32 f;
2414 } vis32;
2416 void OPPROTO op_fpmerge(void)
2418 vis64 s, d;
2420 s.d = DT0;
2421 d.d = DT1;
2423 // Reverse calculation order to handle overlap
2424 d.VIS_B64(7) = s.VIS_B64(3);
2425 d.VIS_B64(6) = d.VIS_B64(3);
2426 d.VIS_B64(5) = s.VIS_B64(2);
2427 d.VIS_B64(4) = d.VIS_B64(2);
2428 d.VIS_B64(3) = s.VIS_B64(1);
2429 d.VIS_B64(2) = d.VIS_B64(1);
2430 d.VIS_B64(1) = s.VIS_B64(0);
2431 //d.VIS_B64(0) = d.VIS_B64(0);
2433 DT0 = d.d;
2436 void OPPROTO op_fmul8x16(void)
2438 vis64 s, d;
2439 uint32_t tmp;
2441 s.d = DT0;
2442 d.d = DT1;
2444 #define PMUL(r) \
2445 tmp = (int32_t)d.VIS_SW64(r) * (int32_t)s.VIS_B64(r); \
2446 if ((tmp & 0xff) > 0x7f) \
2447 tmp += 0x100; \
2448 d.VIS_W64(r) = tmp >> 8;
2450 PMUL(0);
2451 PMUL(1);
2452 PMUL(2);
2453 PMUL(3);
2454 #undef PMUL
2456 DT0 = d.d;
2459 void OPPROTO op_fmul8x16al(void)
2461 vis64 s, d;
2462 uint32_t tmp;
2464 s.d = DT0;
2465 d.d = DT1;
2467 #define PMUL(r) \
2468 tmp = (int32_t)d.VIS_SW64(1) * (int32_t)s.VIS_B64(r); \
2469 if ((tmp & 0xff) > 0x7f) \
2470 tmp += 0x100; \
2471 d.VIS_W64(r) = tmp >> 8;
2473 PMUL(0);
2474 PMUL(1);
2475 PMUL(2);
2476 PMUL(3);
2477 #undef PMUL
2479 DT0 = d.d;
2482 void OPPROTO op_fmul8x16au(void)
2484 vis64 s, d;
2485 uint32_t tmp;
2487 s.d = DT0;
2488 d.d = DT1;
2490 #define PMUL(r) \
2491 tmp = (int32_t)d.VIS_SW64(0) * (int32_t)s.VIS_B64(r); \
2492 if ((tmp & 0xff) > 0x7f) \
2493 tmp += 0x100; \
2494 d.VIS_W64(r) = tmp >> 8;
2496 PMUL(0);
2497 PMUL(1);
2498 PMUL(2);
2499 PMUL(3);
2500 #undef PMUL
2502 DT0 = d.d;
2505 void OPPROTO op_fmul8sux16(void)
2507 vis64 s, d;
2508 uint32_t tmp;
2510 s.d = DT0;
2511 d.d = DT1;
2513 #define PMUL(r) \
2514 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
2515 if ((tmp & 0xff) > 0x7f) \
2516 tmp += 0x100; \
2517 d.VIS_W64(r) = tmp >> 8;
2519 PMUL(0);
2520 PMUL(1);
2521 PMUL(2);
2522 PMUL(3);
2523 #undef PMUL
2525 DT0 = d.d;
2528 void OPPROTO op_fmul8ulx16(void)
2530 vis64 s, d;
2531 uint32_t tmp;
2533 s.d = DT0;
2534 d.d = DT1;
2536 #define PMUL(r) \
2537 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
2538 if ((tmp & 0xff) > 0x7f) \
2539 tmp += 0x100; \
2540 d.VIS_W64(r) = tmp >> 8;
2542 PMUL(0);
2543 PMUL(1);
2544 PMUL(2);
2545 PMUL(3);
2546 #undef PMUL
2548 DT0 = d.d;
2551 void OPPROTO op_fmuld8sux16(void)
2553 vis64 s, d;
2554 uint32_t tmp;
2556 s.d = DT0;
2557 d.d = DT1;
2559 #define PMUL(r) \
2560 tmp = (int32_t)d.VIS_SW64(r) * ((int32_t)s.VIS_SW64(r) >> 8); \
2561 if ((tmp & 0xff) > 0x7f) \
2562 tmp += 0x100; \
2563 d.VIS_L64(r) = tmp;
2565 // Reverse calculation order to handle overlap
2566 PMUL(1);
2567 PMUL(0);
2568 #undef PMUL
2570 DT0 = d.d;
2573 void OPPROTO op_fmuld8ulx16(void)
2575 vis64 s, d;
2576 uint32_t tmp;
2578 s.d = DT0;
2579 d.d = DT1;
2581 #define PMUL(r) \
2582 tmp = (int32_t)d.VIS_SW64(r) * ((uint32_t)s.VIS_B64(r * 2)); \
2583 if ((tmp & 0xff) > 0x7f) \
2584 tmp += 0x100; \
2585 d.VIS_L64(r) = tmp;
2587 // Reverse calculation order to handle overlap
2588 PMUL(1);
2589 PMUL(0);
2590 #undef PMUL
2592 DT0 = d.d;
2595 void OPPROTO op_fexpand(void)
2597 vis32 s;
2598 vis64 d;
2600 s.l = (uint32_t)(*(uint64_t *)&DT0 & 0xffffffff);
2601 d.d = DT1;
2602 d.VIS_L64(0) = s.VIS_W32(0) << 4;
2603 d.VIS_L64(1) = s.VIS_W32(1) << 4;
2604 d.VIS_L64(2) = s.VIS_W32(2) << 4;
2605 d.VIS_L64(3) = s.VIS_W32(3) << 4;
2607 DT0 = d.d;
2610 #define VIS_OP(name, F) \
2611 void OPPROTO name##16(void) \
2613 vis64 s, d; \
2615 s.d = DT0; \
2616 d.d = DT1; \
2618 d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0)); \
2619 d.VIS_W64(1) = F(d.VIS_W64(1), s.VIS_W64(1)); \
2620 d.VIS_W64(2) = F(d.VIS_W64(2), s.VIS_W64(2)); \
2621 d.VIS_W64(3) = F(d.VIS_W64(3), s.VIS_W64(3)); \
2623 DT0 = d.d; \
2626 void OPPROTO name##16s(void) \
2628 vis32 s, d; \
2630 s.f = FT0; \
2631 d.f = FT1; \
2633 d.VIS_W32(0) = F(d.VIS_W32(0), s.VIS_W32(0)); \
2634 d.VIS_W32(1) = F(d.VIS_W32(1), s.VIS_W32(1)); \
2636 FT0 = d.f; \
2639 void OPPROTO name##32(void) \
2641 vis64 s, d; \
2643 s.d = DT0; \
2644 d.d = DT1; \
2646 d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0)); \
2647 d.VIS_L64(1) = F(d.VIS_L64(1), s.VIS_L64(1)); \
2649 DT0 = d.d; \
2652 void OPPROTO name##32s(void) \
2654 vis32 s, d; \
2656 s.f = FT0; \
2657 d.f = FT1; \
2659 d.l = F(d.l, s.l); \
2661 FT0 = d.f; \
2664 #define FADD(a, b) ((a) + (b))
2665 #define FSUB(a, b) ((a) - (b))
2666 VIS_OP(op_fpadd, FADD)
2667 VIS_OP(op_fpsub, FSUB)
2669 #define VIS_CMPOP(name, F) \
2670 void OPPROTO name##16(void) \
2672 vis64 s, d; \
2674 s.d = DT0; \
2675 d.d = DT1; \
2677 d.VIS_W64(0) = F(d.VIS_W64(0), s.VIS_W64(0))? 1: 0; \
2678 d.VIS_W64(0) |= F(d.VIS_W64(1), s.VIS_W64(1))? 2: 0; \
2679 d.VIS_W64(0) |= F(d.VIS_W64(2), s.VIS_W64(2))? 4: 0; \
2680 d.VIS_W64(0) |= F(d.VIS_W64(3), s.VIS_W64(3))? 8: 0; \
2682 DT0 = d.d; \
2685 void OPPROTO name##32(void) \
2687 vis64 s, d; \
2689 s.d = DT0; \
2690 d.d = DT1; \
2692 d.VIS_L64(0) = F(d.VIS_L64(0), s.VIS_L64(0))? 1: 0; \
2693 d.VIS_L64(0) |= F(d.VIS_L64(1), s.VIS_L64(1))? 2: 0; \
2695 DT0 = d.d; \
2698 #define FCMPGT(a, b) ((a) > (b))
2699 #define FCMPEQ(a, b) ((a) == (b))
2700 #define FCMPLE(a, b) ((a) <= (b))
2701 #define FCMPNE(a, b) ((a) != (b))
2703 VIS_CMPOP(op_fcmpgt, FCMPGT)
2704 VIS_CMPOP(op_fcmpeq, FCMPEQ)
2705 VIS_CMPOP(op_fcmple, FCMPLE)
2706 VIS_CMPOP(op_fcmpne, FCMPNE)
2708 #endif
2710 #define CHECK_ALIGN_OP(align) \
2711 void OPPROTO op_check_align_T0_ ## align (void) \
2713 if (T0 & align) \
2714 raise_exception(TT_UNALIGNED); \
2715 FORCE_RET(); \
2718 CHECK_ALIGN_OP(1)
2719 CHECK_ALIGN_OP(3)
2720 CHECK_ALIGN_OP(7)