2 * Copyright (c) 2012-2014 Bastian Koppelmann C-Lab/University Paderborn
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 #include "qemu/host-utils.h"
20 #include "exec/helper-proto.h"
21 #include "exec/cpu_ldst.h"
22 #include <zlib.h> /* for crc32 */
24 /* Addressing mode helper */
26 static uint16_t reverse16(uint16_t val
)
28 uint8_t high
= (uint8_t)(val
>> 8);
29 uint8_t low
= (uint8_t)(val
& 0xff);
33 rl
= (uint16_t)((high
* 0x0202020202ULL
& 0x010884422010ULL
) % 1023);
34 rh
= (uint16_t)((low
* 0x0202020202ULL
& 0x010884422010ULL
) % 1023);
36 return (rh
<< 8) | rl
;
39 uint32_t helper_br_update(uint32_t reg
)
41 uint32_t index
= reg
& 0xffff;
42 uint32_t incr
= reg
>> 16;
43 uint32_t new_index
= reverse16(reverse16(index
) + reverse16(incr
));
44 return reg
- index
+ new_index
;
47 uint32_t helper_circ_update(uint32_t reg
, uint32_t off
)
49 uint32_t index
= reg
& 0xffff;
50 uint32_t length
= reg
>> 16;
51 int32_t new_index
= index
+ off
;
57 return reg
- index
+ new_index
;
60 static uint32_t ssov32(CPUTriCoreState
*env
, int64_t arg
)
63 int64_t max_pos
= INT32_MAX
;
64 int64_t max_neg
= INT32_MIN
;
66 env
->PSW_USB_V
= (1 << 31);
67 env
->PSW_USB_SV
= (1 << 31);
68 ret
= (target_ulong
)max_pos
;
71 env
->PSW_USB_V
= (1 << 31);
72 env
->PSW_USB_SV
= (1 << 31);
73 ret
= (target_ulong
)max_neg
;
76 ret
= (target_ulong
)arg
;
79 env
->PSW_USB_AV
= arg
^ arg
* 2u;
80 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
84 static uint32_t suov32_pos(CPUTriCoreState
*env
, uint64_t arg
)
87 uint64_t max_pos
= UINT32_MAX
;
89 env
->PSW_USB_V
= (1 << 31);
90 env
->PSW_USB_SV
= (1 << 31);
91 ret
= (target_ulong
)max_pos
;
94 ret
= (target_ulong
)arg
;
96 env
->PSW_USB_AV
= arg
^ arg
* 2u;
97 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
101 static uint32_t suov32_neg(CPUTriCoreState
*env
, int64_t arg
)
106 env
->PSW_USB_V
= (1 << 31);
107 env
->PSW_USB_SV
= (1 << 31);
111 ret
= (target_ulong
)arg
;
113 env
->PSW_USB_AV
= arg
^ arg
* 2u;
114 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
118 static uint32_t ssov16(CPUTriCoreState
*env
, int32_t hw0
, int32_t hw1
)
120 int32_t max_pos
= INT16_MAX
;
121 int32_t max_neg
= INT16_MIN
;
125 av0
= hw0
^ hw0
* 2u;
127 env
->PSW_USB_V
= (1 << 31);
129 } else if (hw0
< max_neg
) {
130 env
->PSW_USB_V
= (1 << 31);
134 av1
= hw1
^ hw1
* 2u;
136 env
->PSW_USB_V
= (1 << 31);
138 } else if (hw1
< max_neg
) {
139 env
->PSW_USB_V
= (1 << 31);
143 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
144 env
->PSW_USB_AV
= (av0
| av1
) << 16;
145 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
146 return (hw0
& 0xffff) | (hw1
<< 16);
149 static uint32_t suov16(CPUTriCoreState
*env
, int32_t hw0
, int32_t hw1
)
151 int32_t max_pos
= UINT16_MAX
;
155 av0
= hw0
^ hw0
* 2u;
157 env
->PSW_USB_V
= (1 << 31);
159 } else if (hw0
< 0) {
160 env
->PSW_USB_V
= (1 << 31);
164 av1
= hw1
^ hw1
* 2u;
166 env
->PSW_USB_V
= (1 << 31);
168 } else if (hw1
< 0) {
169 env
->PSW_USB_V
= (1 << 31);
173 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
174 env
->PSW_USB_AV
= (av0
| av1
) << 16;
175 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
176 return (hw0
& 0xffff) | (hw1
<< 16);
179 target_ulong
helper_add_ssov(CPUTriCoreState
*env
, target_ulong r1
,
182 int64_t t1
= sextract64(r1
, 0, 32);
183 int64_t t2
= sextract64(r2
, 0, 32);
184 int64_t result
= t1
+ t2
;
185 return ssov32(env
, result
);
188 uint64_t helper_add64_ssov(CPUTriCoreState
*env
, uint64_t r1
, uint64_t r2
)
194 ovf
= (result
^ r1
) & ~(r1
^ r2
);
195 env
->PSW_USB_AV
= (result
^ result
* 2u) >> 32;
196 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
198 env
->PSW_USB_V
= (1 << 31);
199 env
->PSW_USB_SV
= (1 << 31);
200 /* ext_ret > MAX_INT */
201 if ((int64_t)r1
>= 0) {
203 /* ext_ret < MIN_INT */
213 target_ulong
helper_add_h_ssov(CPUTriCoreState
*env
, target_ulong r1
,
216 int32_t ret_hw0
, ret_hw1
;
218 ret_hw0
= sextract32(r1
, 0, 16) + sextract32(r2
, 0, 16);
219 ret_hw1
= sextract32(r1
, 16, 16) + sextract32(r2
, 16, 16);
220 return ssov16(env
, ret_hw0
, ret_hw1
);
223 uint32_t helper_addr_h_ssov(CPUTriCoreState
*env
, uint64_t r1
, uint32_t r2_l
,
226 int64_t mul_res0
= sextract64(r1
, 0, 32);
227 int64_t mul_res1
= sextract64(r1
, 32, 32);
228 int64_t r2_low
= sextract64(r2_l
, 0, 32);
229 int64_t r2_high
= sextract64(r2_h
, 0, 32);
230 int64_t result0
, result1
;
236 result0
= r2_low
+ mul_res0
+ 0x8000;
237 result1
= r2_high
+ mul_res1
+ 0x8000;
240 avf0
= result0
^ avf0
;
242 avf1
= result1
^ avf1
;
244 if (result0
> INT32_MAX
) {
247 } else if (result0
< INT32_MIN
) {
252 if (result1
> INT32_MAX
) {
255 } else if (result1
< INT32_MIN
) {
260 env
->PSW_USB_V
= ovf0
| ovf1
;
261 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
263 env
->PSW_USB_AV
= avf0
| avf1
;
264 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
266 return (result1
& 0xffff0000ULL
) | ((result0
>> 16) & 0xffffULL
);
269 uint32_t helper_addsur_h_ssov(CPUTriCoreState
*env
, uint64_t r1
, uint32_t r2_l
,
272 int64_t mul_res0
= sextract64(r1
, 0, 32);
273 int64_t mul_res1
= sextract64(r1
, 32, 32);
274 int64_t r2_low
= sextract64(r2_l
, 0, 32);
275 int64_t r2_high
= sextract64(r2_h
, 0, 32);
276 int64_t result0
, result1
;
282 result0
= r2_low
- mul_res0
+ 0x8000;
283 result1
= r2_high
+ mul_res1
+ 0x8000;
286 avf0
= result0
^ avf0
;
288 avf1
= result1
^ avf1
;
290 if (result0
> INT32_MAX
) {
293 } else if (result0
< INT32_MIN
) {
298 if (result1
> INT32_MAX
) {
301 } else if (result1
< INT32_MIN
) {
306 env
->PSW_USB_V
= ovf0
| ovf1
;
307 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
309 env
->PSW_USB_AV
= avf0
| avf1
;
310 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
312 return (result1
& 0xffff0000ULL
) | ((result0
>> 16) & 0xffffULL
);
316 target_ulong
helper_add_suov(CPUTriCoreState
*env
, target_ulong r1
,
319 int64_t t1
= extract64(r1
, 0, 32);
320 int64_t t2
= extract64(r2
, 0, 32);
321 int64_t result
= t1
+ t2
;
322 return suov32_pos(env
, result
);
325 target_ulong
helper_add_h_suov(CPUTriCoreState
*env
, target_ulong r1
,
328 int32_t ret_hw0
, ret_hw1
;
330 ret_hw0
= extract32(r1
, 0, 16) + extract32(r2
, 0, 16);
331 ret_hw1
= extract32(r1
, 16, 16) + extract32(r2
, 16, 16);
332 return suov16(env
, ret_hw0
, ret_hw1
);
335 target_ulong
helper_sub_ssov(CPUTriCoreState
*env
, target_ulong r1
,
338 int64_t t1
= sextract64(r1
, 0, 32);
339 int64_t t2
= sextract64(r2
, 0, 32);
340 int64_t result
= t1
- t2
;
341 return ssov32(env
, result
);
344 uint64_t helper_sub64_ssov(CPUTriCoreState
*env
, uint64_t r1
, uint64_t r2
)
350 ovf
= (result
^ r1
) & (r1
^ r2
);
351 env
->PSW_USB_AV
= (result
^ result
* 2u) >> 32;
352 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
354 env
->PSW_USB_V
= (1 << 31);
355 env
->PSW_USB_SV
= (1 << 31);
356 /* ext_ret > MAX_INT */
357 if ((int64_t)r1
>= 0) {
359 /* ext_ret < MIN_INT */
369 target_ulong
helper_sub_h_ssov(CPUTriCoreState
*env
, target_ulong r1
,
372 int32_t ret_hw0
, ret_hw1
;
374 ret_hw0
= sextract32(r1
, 0, 16) - sextract32(r2
, 0, 16);
375 ret_hw1
= sextract32(r1
, 16, 16) - sextract32(r2
, 16, 16);
376 return ssov16(env
, ret_hw0
, ret_hw1
);
379 uint32_t helper_subr_h_ssov(CPUTriCoreState
*env
, uint64_t r1
, uint32_t r2_l
,
382 int64_t mul_res0
= sextract64(r1
, 0, 32);
383 int64_t mul_res1
= sextract64(r1
, 32, 32);
384 int64_t r2_low
= sextract64(r2_l
, 0, 32);
385 int64_t r2_high
= sextract64(r2_h
, 0, 32);
386 int64_t result0
, result1
;
392 result0
= r2_low
- mul_res0
+ 0x8000;
393 result1
= r2_high
- mul_res1
+ 0x8000;
396 avf0
= result0
^ avf0
;
398 avf1
= result1
^ avf1
;
400 if (result0
> INT32_MAX
) {
403 } else if (result0
< INT32_MIN
) {
408 if (result1
> INT32_MAX
) {
411 } else if (result1
< INT32_MIN
) {
416 env
->PSW_USB_V
= ovf0
| ovf1
;
417 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
419 env
->PSW_USB_AV
= avf0
| avf1
;
420 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
422 return (result1
& 0xffff0000ULL
) | ((result0
>> 16) & 0xffffULL
);
425 uint32_t helper_subadr_h_ssov(CPUTriCoreState
*env
, uint64_t r1
, uint32_t r2_l
,
428 int64_t mul_res0
= sextract64(r1
, 0, 32);
429 int64_t mul_res1
= sextract64(r1
, 32, 32);
430 int64_t r2_low
= sextract64(r2_l
, 0, 32);
431 int64_t r2_high
= sextract64(r2_h
, 0, 32);
432 int64_t result0
, result1
;
438 result0
= r2_low
+ mul_res0
+ 0x8000;
439 result1
= r2_high
- mul_res1
+ 0x8000;
442 avf0
= result0
^ avf0
;
444 avf1
= result1
^ avf1
;
446 if (result0
> INT32_MAX
) {
449 } else if (result0
< INT32_MIN
) {
454 if (result1
> INT32_MAX
) {
457 } else if (result1
< INT32_MIN
) {
462 env
->PSW_USB_V
= ovf0
| ovf1
;
463 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
465 env
->PSW_USB_AV
= avf0
| avf1
;
466 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
468 return (result1
& 0xffff0000ULL
) | ((result0
>> 16) & 0xffffULL
);
471 target_ulong
helper_sub_suov(CPUTriCoreState
*env
, target_ulong r1
,
474 int64_t t1
= extract64(r1
, 0, 32);
475 int64_t t2
= extract64(r2
, 0, 32);
476 int64_t result
= t1
- t2
;
477 return suov32_neg(env
, result
);
480 target_ulong
helper_sub_h_suov(CPUTriCoreState
*env
, target_ulong r1
,
483 int32_t ret_hw0
, ret_hw1
;
485 ret_hw0
= extract32(r1
, 0, 16) - extract32(r2
, 0, 16);
486 ret_hw1
= extract32(r1
, 16, 16) - extract32(r2
, 16, 16);
487 return suov16(env
, ret_hw0
, ret_hw1
);
490 target_ulong
helper_mul_ssov(CPUTriCoreState
*env
, target_ulong r1
,
493 int64_t t1
= sextract64(r1
, 0, 32);
494 int64_t t2
= sextract64(r2
, 0, 32);
495 int64_t result
= t1
* t2
;
496 return ssov32(env
, result
);
499 target_ulong
helper_mul_suov(CPUTriCoreState
*env
, target_ulong r1
,
502 int64_t t1
= extract64(r1
, 0, 32);
503 int64_t t2
= extract64(r2
, 0, 32);
504 int64_t result
= t1
* t2
;
506 return suov32_pos(env
, result
);
509 target_ulong
helper_sha_ssov(CPUTriCoreState
*env
, target_ulong r1
,
512 int64_t t1
= sextract64(r1
, 0, 32);
513 int32_t t2
= sextract64(r2
, 0, 6);
522 return ssov32(env
, result
);
525 uint32_t helper_abs_ssov(CPUTriCoreState
*env
, target_ulong r1
)
528 result
= ((int32_t)r1
>= 0) ? r1
: (0 - r1
);
529 return ssov32(env
, result
);
532 uint32_t helper_abs_h_ssov(CPUTriCoreState
*env
, target_ulong r1
)
534 int32_t ret_h0
, ret_h1
;
536 ret_h0
= sextract32(r1
, 0, 16);
537 ret_h0
= (ret_h0
>= 0) ? ret_h0
: (0 - ret_h0
);
539 ret_h1
= sextract32(r1
, 16, 16);
540 ret_h1
= (ret_h1
>= 0) ? ret_h1
: (0 - ret_h1
);
542 return ssov16(env
, ret_h0
, ret_h1
);
545 target_ulong
helper_absdif_ssov(CPUTriCoreState
*env
, target_ulong r1
,
548 int64_t t1
= sextract64(r1
, 0, 32);
549 int64_t t2
= sextract64(r2
, 0, 32);
557 return ssov32(env
, result
);
560 uint32_t helper_absdif_h_ssov(CPUTriCoreState
*env
, target_ulong r1
,
564 int32_t ret_h0
, ret_h1
;
566 t1
= sextract32(r1
, 0, 16);
567 t2
= sextract32(r2
, 0, 16);
574 t1
= sextract32(r1
, 16, 16);
575 t2
= sextract32(r2
, 16, 16);
582 return ssov16(env
, ret_h0
, ret_h1
);
585 target_ulong
helper_madd32_ssov(CPUTriCoreState
*env
, target_ulong r1
,
586 target_ulong r2
, target_ulong r3
)
588 int64_t t1
= sextract64(r1
, 0, 32);
589 int64_t t2
= sextract64(r2
, 0, 32);
590 int64_t t3
= sextract64(r3
, 0, 32);
593 result
= t2
+ (t1
* t3
);
594 return ssov32(env
, result
);
597 target_ulong
helper_madd32_suov(CPUTriCoreState
*env
, target_ulong r1
,
598 target_ulong r2
, target_ulong r3
)
600 uint64_t t1
= extract64(r1
, 0, 32);
601 uint64_t t2
= extract64(r2
, 0, 32);
602 uint64_t t3
= extract64(r3
, 0, 32);
605 result
= t2
+ (t1
* t3
);
606 return suov32_pos(env
, result
);
609 uint64_t helper_madd64_ssov(CPUTriCoreState
*env
, target_ulong r1
,
610 uint64_t r2
, target_ulong r3
)
613 int64_t t1
= sextract64(r1
, 0, 32);
614 int64_t t3
= sextract64(r3
, 0, 32);
619 ovf
= (ret
^ mul
) & ~(mul
^ r2
);
622 env
->PSW_USB_AV
= t1
^ t1
* 2u;
623 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
625 if ((int64_t)ovf
< 0) {
626 env
->PSW_USB_V
= (1 << 31);
627 env
->PSW_USB_SV
= (1 << 31);
628 /* ext_ret > MAX_INT */
631 /* ext_ret < MIN_INT */
643 helper_madd32_q_add_ssov(CPUTriCoreState
*env
, uint64_t r1
, uint64_t r2
)
649 env
->PSW_USB_AV
= (result
^ result
* 2u);
650 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
652 /* we do the saturation by hand, since we produce an overflow on the host
653 if the mul before was (0x80000000 * 0x80000000) << 1). If this is the
654 case, we flip the saturated value. */
655 if (r2
== 0x8000000000000000LL
) {
656 if (result
> 0x7fffffffLL
) {
657 env
->PSW_USB_V
= (1 << 31);
658 env
->PSW_USB_SV
= (1 << 31);
660 } else if (result
< -0x80000000LL
) {
661 env
->PSW_USB_V
= (1 << 31);
662 env
->PSW_USB_SV
= (1 << 31);
668 if (result
> 0x7fffffffLL
) {
669 env
->PSW_USB_V
= (1 << 31);
670 env
->PSW_USB_SV
= (1 << 31);
672 } else if (result
< -0x80000000LL
) {
673 env
->PSW_USB_V
= (1 << 31);
674 env
->PSW_USB_SV
= (1 << 31);
680 return (uint32_t)result
;
683 uint64_t helper_madd64_q_ssov(CPUTriCoreState
*env
, uint64_t r1
, uint32_t r2
,
684 uint32_t r3
, uint32_t n
)
686 int64_t t1
= (int64_t)r1
;
687 int64_t t2
= sextract64(r2
, 0, 32);
688 int64_t t3
= sextract64(r3
, 0, 32);
692 mul
= (t2
* t3
) << n
;
695 env
->PSW_USB_AV
= (result
^ result
* 2u) >> 32;
696 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
698 ovf
= (result
^ mul
) & ~(mul
^ t1
);
699 /* we do the saturation by hand, since we produce an overflow on the host
700 if the mul was (0x80000000 * 0x80000000) << 1). If this is the
701 case, we flip the saturated value. */
702 if ((r2
== 0x80000000) && (r3
== 0x80000000) && (n
== 1)) {
704 env
->PSW_USB_V
= (1 << 31);
705 env
->PSW_USB_SV
= (1 << 31);
706 /* ext_ret > MAX_INT */
709 /* ext_ret < MIN_INT */
718 env
->PSW_USB_V
= (1 << 31);
719 env
->PSW_USB_SV
= (1 << 31);
720 /* ext_ret > MAX_INT */
723 /* ext_ret < MIN_INT */
731 return (uint64_t)result
;
734 uint32_t helper_maddr_q_ssov(CPUTriCoreState
*env
, uint32_t r1
, uint32_t r2
,
735 uint32_t r3
, uint32_t n
)
737 int64_t t1
= sextract64(r1
, 0, 32);
738 int64_t t2
= sextract64(r2
, 0, 32);
739 int64_t t3
= sextract64(r3
, 0, 32);
742 if ((t2
== -0x8000ll
) && (t3
== -0x8000ll
) && (n
== 1)) {
745 mul
= (t2
* t3
) << n
;
748 ret
= t1
+ mul
+ 0x8000;
750 env
->PSW_USB_AV
= ret
^ ret
* 2u;
751 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
753 if (ret
> 0x7fffffffll
) {
754 env
->PSW_USB_V
= (1 << 31);
755 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
757 } else if (ret
< -0x80000000ll
) {
758 env
->PSW_USB_V
= (1 << 31);
759 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
764 return ret
& 0xffff0000ll
;
767 uint64_t helper_madd64_suov(CPUTriCoreState
*env
, target_ulong r1
,
768 uint64_t r2
, target_ulong r3
)
771 uint64_t t1
= extract64(r1
, 0, 32);
772 uint64_t t3
= extract64(r3
, 0, 32);
778 env
->PSW_USB_AV
= t1
^ t1
* 2u;
779 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
782 env
->PSW_USB_V
= (1 << 31);
783 env
->PSW_USB_SV
= (1 << 31);
792 target_ulong
helper_msub32_ssov(CPUTriCoreState
*env
, target_ulong r1
,
793 target_ulong r2
, target_ulong r3
)
795 int64_t t1
= sextract64(r1
, 0, 32);
796 int64_t t2
= sextract64(r2
, 0, 32);
797 int64_t t3
= sextract64(r3
, 0, 32);
800 result
= t2
- (t1
* t3
);
801 return ssov32(env
, result
);
804 target_ulong
helper_msub32_suov(CPUTriCoreState
*env
, target_ulong r1
,
805 target_ulong r2
, target_ulong r3
)
807 uint64_t t1
= extract64(r1
, 0, 32);
808 uint64_t t2
= extract64(r2
, 0, 32);
809 uint64_t t3
= extract64(r3
, 0, 32);
816 env
->PSW_USB_AV
= result
^ result
* 2u;
817 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
818 /* we calculate ovf by hand here, because the multiplication can overflow on
819 the host, which would give false results if we compare to less than
822 env
->PSW_USB_V
= (1 << 31);
823 env
->PSW_USB_SV
= (1 << 31);
831 uint64_t helper_msub64_ssov(CPUTriCoreState
*env
, target_ulong r1
,
832 uint64_t r2
, target_ulong r3
)
835 int64_t t1
= sextract64(r1
, 0, 32);
836 int64_t t3
= sextract64(r3
, 0, 32);
841 ovf
= (ret
^ r2
) & (mul
^ r2
);
844 env
->PSW_USB_AV
= t1
^ t1
* 2u;
845 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
847 if ((int64_t)ovf
< 0) {
848 env
->PSW_USB_V
= (1 << 31);
849 env
->PSW_USB_SV
= (1 << 31);
850 /* ext_ret > MAX_INT */
853 /* ext_ret < MIN_INT */
863 uint64_t helper_msub64_suov(CPUTriCoreState
*env
, target_ulong r1
,
864 uint64_t r2
, target_ulong r3
)
867 uint64_t t1
= extract64(r1
, 0, 32);
868 uint64_t t3
= extract64(r3
, 0, 32);
874 env
->PSW_USB_AV
= t1
^ t1
* 2u;
875 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
878 env
->PSW_USB_V
= (1 << 31);
879 env
->PSW_USB_SV
= (1 << 31);
889 helper_msub32_q_sub_ssov(CPUTriCoreState
*env
, uint64_t r1
, uint64_t r2
)
892 int64_t t1
= (int64_t)r1
;
893 int64_t t2
= (int64_t)r2
;
897 env
->PSW_USB_AV
= (result
^ result
* 2u);
898 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
900 /* we do the saturation by hand, since we produce an overflow on the host
901 if the mul before was (0x80000000 * 0x80000000) << 1). If this is the
902 case, we flip the saturated value. */
903 if (r2
== 0x8000000000000000LL
) {
904 if (result
> 0x7fffffffLL
) {
905 env
->PSW_USB_V
= (1 << 31);
906 env
->PSW_USB_SV
= (1 << 31);
908 } else if (result
< -0x80000000LL
) {
909 env
->PSW_USB_V
= (1 << 31);
910 env
->PSW_USB_SV
= (1 << 31);
916 if (result
> 0x7fffffffLL
) {
917 env
->PSW_USB_V
= (1 << 31);
918 env
->PSW_USB_SV
= (1 << 31);
920 } else if (result
< -0x80000000LL
) {
921 env
->PSW_USB_V
= (1 << 31);
922 env
->PSW_USB_SV
= (1 << 31);
928 return (uint32_t)result
;
931 uint64_t helper_msub64_q_ssov(CPUTriCoreState
*env
, uint64_t r1
, uint32_t r2
,
932 uint32_t r3
, uint32_t n
)
934 int64_t t1
= (int64_t)r1
;
935 int64_t t2
= sextract64(r2
, 0, 32);
936 int64_t t3
= sextract64(r3
, 0, 32);
940 mul
= (t2
* t3
) << n
;
943 env
->PSW_USB_AV
= (result
^ result
* 2u) >> 32;
944 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
946 ovf
= (result
^ t1
) & (t1
^ mul
);
947 /* we do the saturation by hand, since we produce an overflow on the host
948 if the mul before was (0x80000000 * 0x80000000) << 1). If this is the
949 case, we flip the saturated value. */
950 if (mul
== 0x8000000000000000LL
) {
952 env
->PSW_USB_V
= (1 << 31);
953 env
->PSW_USB_SV
= (1 << 31);
954 /* ext_ret > MAX_INT */
957 /* ext_ret < MIN_INT */
964 env
->PSW_USB_V
= (1 << 31);
965 env
->PSW_USB_SV
= (1 << 31);
966 /* ext_ret > MAX_INT */
969 /* ext_ret < MIN_INT */
978 return (uint64_t)result
;
981 uint32_t helper_msubr_q_ssov(CPUTriCoreState
*env
, uint32_t r1
, uint32_t r2
,
982 uint32_t r3
, uint32_t n
)
984 int64_t t1
= sextract64(r1
, 0, 32);
985 int64_t t2
= sextract64(r2
, 0, 32);
986 int64_t t3
= sextract64(r3
, 0, 32);
989 if ((t2
== -0x8000ll
) && (t3
== -0x8000ll
) && (n
== 1)) {
992 mul
= (t2
* t3
) << n
;
995 ret
= t1
- mul
+ 0x8000;
997 env
->PSW_USB_AV
= ret
^ ret
* 2u;
998 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1000 if (ret
> 0x7fffffffll
) {
1001 env
->PSW_USB_V
= (1 << 31);
1002 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1004 } else if (ret
< -0x80000000ll
) {
1005 env
->PSW_USB_V
= (1 << 31);
1006 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1011 return ret
& 0xffff0000ll
;
1014 uint32_t helper_abs_b(CPUTriCoreState
*env
, target_ulong arg
)
1021 for (i
= 0; i
< 4; i
++) {
1022 b
= sextract32(arg
, i
* 8, 8);
1023 b
= (b
>= 0) ? b
: (0 - b
);
1024 ovf
|= (b
> 0x7F) || (b
< -0x80);
1026 ret
|= (b
& 0xff) << (i
* 8);
1029 env
->PSW_USB_V
= ovf
<< 31;
1030 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1031 env
->PSW_USB_AV
= avf
<< 24;
1032 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1037 uint32_t helper_abs_h(CPUTriCoreState
*env
, target_ulong arg
)
1044 for (i
= 0; i
< 2; i
++) {
1045 h
= sextract32(arg
, i
* 16, 16);
1046 h
= (h
>= 0) ? h
: (0 - h
);
1047 ovf
|= (h
> 0x7FFF) || (h
< -0x8000);
1049 ret
|= (h
& 0xffff) << (i
* 16);
1052 env
->PSW_USB_V
= ovf
<< 31;
1053 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1054 env
->PSW_USB_AV
= avf
<< 16;
1055 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1060 uint32_t helper_absdif_b(CPUTriCoreState
*env
, target_ulong r1
, target_ulong r2
)
1068 for (i
= 0; i
< 4; i
++) {
1069 extr_r2
= sextract32(r2
, i
* 8, 8);
1070 b
= sextract32(r1
, i
* 8, 8);
1071 b
= (b
> extr_r2
) ? (b
- extr_r2
) : (extr_r2
- b
);
1072 ovf
|= (b
> 0x7F) || (b
< -0x80);
1074 ret
|= (b
& 0xff) << (i
* 8);
1077 env
->PSW_USB_V
= ovf
<< 31;
1078 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1079 env
->PSW_USB_AV
= avf
<< 24;
1080 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1084 uint32_t helper_absdif_h(CPUTriCoreState
*env
, target_ulong r1
, target_ulong r2
)
1092 for (i
= 0; i
< 2; i
++) {
1093 extr_r2
= sextract32(r2
, i
* 16, 16);
1094 h
= sextract32(r1
, i
* 16, 16);
1095 h
= (h
> extr_r2
) ? (h
- extr_r2
) : (extr_r2
- h
);
1096 ovf
|= (h
> 0x7FFF) || (h
< -0x8000);
1098 ret
|= (h
& 0xffff) << (i
* 16);
1101 env
->PSW_USB_V
= ovf
<< 31;
1102 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1103 env
->PSW_USB_AV
= avf
<< 16;
1104 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1109 uint32_t helper_addr_h(CPUTriCoreState
*env
, uint64_t r1
, uint32_t r2_l
,
1112 int64_t mul_res0
= sextract64(r1
, 0, 32);
1113 int64_t mul_res1
= sextract64(r1
, 32, 32);
1114 int64_t r2_low
= sextract64(r2_l
, 0, 32);
1115 int64_t r2_high
= sextract64(r2_h
, 0, 32);
1116 int64_t result0
, result1
;
1117 uint32_t ovf0
, ovf1
;
1118 uint32_t avf0
, avf1
;
1122 result0
= r2_low
+ mul_res0
+ 0x8000;
1123 result1
= r2_high
+ mul_res1
+ 0x8000;
1125 if ((result0
> INT32_MAX
) || (result0
< INT32_MIN
)) {
1129 if ((result1
> INT32_MAX
) || (result1
< INT32_MIN
)) {
1133 env
->PSW_USB_V
= ovf0
| ovf1
;
1134 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1136 avf0
= result0
* 2u;
1137 avf0
= result0
^ avf0
;
1138 avf1
= result1
* 2u;
1139 avf1
= result1
^ avf1
;
1141 env
->PSW_USB_AV
= avf0
| avf1
;
1142 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1144 return (result1
& 0xffff0000ULL
) | ((result0
>> 16) & 0xffffULL
);
1147 uint32_t helper_addsur_h(CPUTriCoreState
*env
, uint64_t r1
, uint32_t r2_l
,
1150 int64_t mul_res0
= sextract64(r1
, 0, 32);
1151 int64_t mul_res1
= sextract64(r1
, 32, 32);
1152 int64_t r2_low
= sextract64(r2_l
, 0, 32);
1153 int64_t r2_high
= sextract64(r2_h
, 0, 32);
1154 int64_t result0
, result1
;
1155 uint32_t ovf0
, ovf1
;
1156 uint32_t avf0
, avf1
;
1160 result0
= r2_low
- mul_res0
+ 0x8000;
1161 result1
= r2_high
+ mul_res1
+ 0x8000;
1163 if ((result0
> INT32_MAX
) || (result0
< INT32_MIN
)) {
1167 if ((result1
> INT32_MAX
) || (result1
< INT32_MIN
)) {
1171 env
->PSW_USB_V
= ovf0
| ovf1
;
1172 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1174 avf0
= result0
* 2u;
1175 avf0
= result0
^ avf0
;
1176 avf1
= result1
* 2u;
1177 avf1
= result1
^ avf1
;
1179 env
->PSW_USB_AV
= avf0
| avf1
;
1180 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1182 return (result1
& 0xffff0000ULL
) | ((result0
>> 16) & 0xffffULL
);
1185 uint32_t helper_maddr_q(CPUTriCoreState
*env
, uint32_t r1
, uint32_t r2
,
1186 uint32_t r3
, uint32_t n
)
1188 int64_t t1
= sextract64(r1
, 0, 32);
1189 int64_t t2
= sextract64(r2
, 0, 32);
1190 int64_t t3
= sextract64(r3
, 0, 32);
1193 if ((t2
== -0x8000ll
) && (t3
== -0x8000ll
) && (n
== 1)) {
1196 mul
= (t2
* t3
) << n
;
1199 ret
= t1
+ mul
+ 0x8000;
1201 if ((ret
> 0x7fffffffll
) || (ret
< -0x80000000ll
)) {
1202 env
->PSW_USB_V
= (1 << 31);
1203 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1207 env
->PSW_USB_AV
= ret
^ ret
* 2u;
1208 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1210 return ret
& 0xffff0000ll
;
1213 uint32_t helper_add_b(CPUTriCoreState
*env
, target_ulong r1
, target_ulong r2
)
1216 int32_t extr_r1
, extr_r2
;
1221 for (i
= 0; i
< 4; i
++) {
1222 extr_r1
= sextract32(r1
, i
* 8, 8);
1223 extr_r2
= sextract32(r2
, i
* 8, 8);
1225 b
= extr_r1
+ extr_r2
;
1226 ovf
|= ((b
> 0x7f) || (b
< -0x80));
1228 ret
|= ((b
& 0xff) << (i
*8));
1231 env
->PSW_USB_V
= (ovf
<< 31);
1232 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1233 env
->PSW_USB_AV
= avf
<< 24;
1234 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1239 uint32_t helper_add_h(CPUTriCoreState
*env
, target_ulong r1
, target_ulong r2
)
1242 int32_t extr_r1
, extr_r2
;
1247 for (i
= 0; i
< 2; i
++) {
1248 extr_r1
= sextract32(r1
, i
* 16, 16);
1249 extr_r2
= sextract32(r2
, i
* 16, 16);
1250 h
= extr_r1
+ extr_r2
;
1251 ovf
|= ((h
> 0x7fff) || (h
< -0x8000));
1253 ret
|= (h
& 0xffff) << (i
* 16);
1256 env
->PSW_USB_V
= (ovf
<< 31);
1257 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1258 env
->PSW_USB_AV
= (avf
<< 16);
1259 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1264 uint32_t helper_subr_h(CPUTriCoreState
*env
, uint64_t r1
, uint32_t r2_l
,
1267 int64_t mul_res0
= sextract64(r1
, 0, 32);
1268 int64_t mul_res1
= sextract64(r1
, 32, 32);
1269 int64_t r2_low
= sextract64(r2_l
, 0, 32);
1270 int64_t r2_high
= sextract64(r2_h
, 0, 32);
1271 int64_t result0
, result1
;
1272 uint32_t ovf0
, ovf1
;
1273 uint32_t avf0
, avf1
;
1277 result0
= r2_low
- mul_res0
+ 0x8000;
1278 result1
= r2_high
- mul_res1
+ 0x8000;
1280 if ((result0
> INT32_MAX
) || (result0
< INT32_MIN
)) {
1284 if ((result1
> INT32_MAX
) || (result1
< INT32_MIN
)) {
1288 env
->PSW_USB_V
= ovf0
| ovf1
;
1289 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1291 avf0
= result0
* 2u;
1292 avf0
= result0
^ avf0
;
1293 avf1
= result1
* 2u;
1294 avf1
= result1
^ avf1
;
1296 env
->PSW_USB_AV
= avf0
| avf1
;
1297 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1299 return (result1
& 0xffff0000ULL
) | ((result0
>> 16) & 0xffffULL
);
1302 uint32_t helper_subadr_h(CPUTriCoreState
*env
, uint64_t r1
, uint32_t r2_l
,
1305 int64_t mul_res0
= sextract64(r1
, 0, 32);
1306 int64_t mul_res1
= sextract64(r1
, 32, 32);
1307 int64_t r2_low
= sextract64(r2_l
, 0, 32);
1308 int64_t r2_high
= sextract64(r2_h
, 0, 32);
1309 int64_t result0
, result1
;
1310 uint32_t ovf0
, ovf1
;
1311 uint32_t avf0
, avf1
;
1315 result0
= r2_low
+ mul_res0
+ 0x8000;
1316 result1
= r2_high
- mul_res1
+ 0x8000;
1318 if ((result0
> INT32_MAX
) || (result0
< INT32_MIN
)) {
1322 if ((result1
> INT32_MAX
) || (result1
< INT32_MIN
)) {
1326 env
->PSW_USB_V
= ovf0
| ovf1
;
1327 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1329 avf0
= result0
* 2u;
1330 avf0
= result0
^ avf0
;
1331 avf1
= result1
* 2u;
1332 avf1
= result1
^ avf1
;
1334 env
->PSW_USB_AV
= avf0
| avf1
;
1335 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1337 return (result1
& 0xffff0000ULL
) | ((result0
>> 16) & 0xffffULL
);
1340 uint32_t helper_msubr_q(CPUTriCoreState
*env
, uint32_t r1
, uint32_t r2
,
1341 uint32_t r3
, uint32_t n
)
1343 int64_t t1
= sextract64(r1
, 0, 32);
1344 int64_t t2
= sextract64(r2
, 0, 32);
1345 int64_t t3
= sextract64(r3
, 0, 32);
1348 if ((t2
== -0x8000ll
) && (t3
== -0x8000ll
) && (n
== 1)) {
1351 mul
= (t2
* t3
) << n
;
1354 ret
= t1
- mul
+ 0x8000;
1356 if ((ret
> 0x7fffffffll
) || (ret
< -0x80000000ll
)) {
1357 env
->PSW_USB_V
= (1 << 31);
1358 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1362 env
->PSW_USB_AV
= ret
^ ret
* 2u;
1363 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1365 return ret
& 0xffff0000ll
;
1368 uint32_t helper_sub_b(CPUTriCoreState
*env
, target_ulong r1
, target_ulong r2
)
1371 int32_t extr_r1
, extr_r2
;
1376 for (i
= 0; i
< 4; i
++) {
1377 extr_r1
= sextract32(r1
, i
* 8, 8);
1378 extr_r2
= sextract32(r2
, i
* 8, 8);
1380 b
= extr_r1
- extr_r2
;
1381 ovf
|= ((b
> 0x7f) || (b
< -0x80));
1383 ret
|= ((b
& 0xff) << (i
*8));
1386 env
->PSW_USB_V
= (ovf
<< 31);
1387 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1388 env
->PSW_USB_AV
= avf
<< 24;
1389 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1394 uint32_t helper_sub_h(CPUTriCoreState
*env
, target_ulong r1
, target_ulong r2
)
1397 int32_t extr_r1
, extr_r2
;
1402 for (i
= 0; i
< 2; i
++) {
1403 extr_r1
= sextract32(r1
, i
* 16, 16);
1404 extr_r2
= sextract32(r2
, i
* 16, 16);
1405 h
= extr_r1
- extr_r2
;
1406 ovf
|= ((h
> 0x7fff) || (h
< -0x8000));
1408 ret
|= (h
& 0xffff) << (i
* 16);
1411 env
->PSW_USB_V
= (ovf
<< 31);
1412 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1413 env
->PSW_USB_AV
= avf
<< 16;
1414 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1419 uint32_t helper_eq_b(target_ulong r1
, target_ulong r2
)
1426 for (i
= 0; i
< 4; i
++) {
1427 if ((r1
& msk
) == (r2
& msk
)) {
1436 uint32_t helper_eq_h(target_ulong r1
, target_ulong r2
)
1440 if ((r1
& 0xffff) == (r2
& 0xffff)) {
1444 if ((r1
& 0xffff0000) == (r2
& 0xffff0000)) {
1451 uint32_t helper_eqany_b(target_ulong r1
, target_ulong r2
)
1456 for (i
= 0; i
< 4; i
++) {
1457 ret
|= (sextract32(r1
, i
* 8, 8) == sextract32(r2
, i
* 8, 8));
1463 uint32_t helper_eqany_h(target_ulong r1
, target_ulong r2
)
1467 ret
= (sextract32(r1
, 0, 16) == sextract32(r2
, 0, 16));
1468 ret
|= (sextract32(r1
, 16, 16) == sextract32(r2
, 16, 16));
1473 uint32_t helper_lt_b(target_ulong r1
, target_ulong r2
)
1478 for (i
= 0; i
< 4; i
++) {
1479 if (sextract32(r1
, i
* 8, 8) < sextract32(r2
, i
* 8, 8)) {
1480 ret
|= (0xff << (i
* 8));
1487 uint32_t helper_lt_bu(target_ulong r1
, target_ulong r2
)
1492 for (i
= 0; i
< 4; i
++) {
1493 if (extract32(r1
, i
* 8, 8) < extract32(r2
, i
* 8, 8)) {
1494 ret
|= (0xff << (i
* 8));
1501 uint32_t helper_lt_h(target_ulong r1
, target_ulong r2
)
1505 if (sextract32(r1
, 0, 16) < sextract32(r2
, 0, 16)) {
1509 if (sextract32(r1
, 16, 16) < sextract32(r2
, 16, 16)) {
1516 uint32_t helper_lt_hu(target_ulong r1
, target_ulong r2
)
1520 if (extract32(r1
, 0, 16) < extract32(r2
, 0, 16)) {
1524 if (extract32(r1
, 16, 16) < extract32(r2
, 16, 16)) {
1531 #define EXTREMA_H_B(name, op) \
1532 uint32_t helper_##name ##_b(target_ulong r1, target_ulong r2) \
1534 int32_t i, extr_r1, extr_r2; \
1537 for (i = 0; i < 4; i++) { \
1538 extr_r1 = sextract32(r1, i * 8, 8); \
1539 extr_r2 = sextract32(r2, i * 8, 8); \
1540 extr_r1 = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
1541 ret |= (extr_r1 & 0xff) << (i * 8); \
1546 uint32_t helper_##name ##_bu(target_ulong r1, target_ulong r2)\
1549 uint32_t extr_r1, extr_r2; \
1552 for (i = 0; i < 4; i++) { \
1553 extr_r1 = extract32(r1, i * 8, 8); \
1554 extr_r2 = extract32(r2, i * 8, 8); \
1555 extr_r1 = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
1556 ret |= (extr_r1 & 0xff) << (i * 8); \
1561 uint32_t helper_##name ##_h(target_ulong r1, target_ulong r2) \
1563 int32_t extr_r1, extr_r2; \
1566 extr_r1 = sextract32(r1, 0, 16); \
1567 extr_r2 = sextract32(r2, 0, 16); \
1568 ret = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
1569 ret = ret & 0xffff; \
1571 extr_r1 = sextract32(r1, 16, 16); \
1572 extr_r2 = sextract32(r2, 16, 16); \
1573 extr_r1 = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
1574 ret |= extr_r1 << 16; \
1579 uint32_t helper_##name ##_hu(target_ulong r1, target_ulong r2)\
1581 uint32_t extr_r1, extr_r2; \
1584 extr_r1 = extract32(r1, 0, 16); \
1585 extr_r2 = extract32(r2, 0, 16); \
1586 ret = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
1587 ret = ret & 0xffff; \
1589 extr_r1 = extract32(r1, 16, 16); \
1590 extr_r2 = extract32(r2, 16, 16); \
1591 extr_r1 = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
1592 ret |= extr_r1 << (16); \
1597 uint64_t helper_ix##name(uint64_t r1, uint32_t r2) \
1599 int64_t r2l, r2h, r1hl; \
1602 ret = ((r1 + 2) & 0xffff); \
1603 r2l = sextract64(r2, 0, 16); \
1604 r2h = sextract64(r2, 16, 16); \
1605 r1hl = sextract64(r1, 32, 16); \
1607 if ((r2l op ## = r2h) && (r2l op r1hl)) { \
1608 ret |= (r2l & 0xffff) << 32; \
1609 ret |= extract64(r1, 0, 16) << 16; \
1610 } else if ((r2h op r2l) && (r2h op r1hl)) { \
1611 ret |= extract64(r2, 16, 16) << 32; \
1612 ret |= extract64(r1 + 1, 0, 16) << 16; \
1614 ret |= r1 & 0xffffffff0000ull; \
1619 uint64_t helper_ix##name ##_u(uint64_t r1, uint32_t r2) \
1621 int64_t r2l, r2h, r1hl; \
1624 ret = ((r1 + 2) & 0xffff); \
1625 r2l = extract64(r2, 0, 16); \
1626 r2h = extract64(r2, 16, 16); \
1627 r1hl = extract64(r1, 32, 16); \
1629 if ((r2l op ## = r2h) && (r2l op r1hl)) { \
1630 ret |= (r2l & 0xffff) << 32; \
1631 ret |= extract64(r1, 0, 16) << 16; \
1632 } else if ((r2h op r2l) && (r2h op r1hl)) { \
1633 ret |= extract64(r2, 16, 16) << 32; \
1634 ret |= extract64(r1 + 1, 0, 16) << 16; \
1636 ret |= r1 & 0xffffffff0000ull; \
1646 uint32_t helper_clo(target_ulong r1
)
1651 uint32_t helper_clo_h(target_ulong r1
)
1653 uint32_t ret_hw0
= extract32(r1
, 0, 16);
1654 uint32_t ret_hw1
= extract32(r1
, 16, 16);
1656 ret_hw0
= clo32(ret_hw0
<< 16);
1657 ret_hw1
= clo32(ret_hw1
<< 16);
1666 return ret_hw0
| (ret_hw1
<< 16);
1669 uint32_t helper_clz(target_ulong r1
)
1674 uint32_t helper_clz_h(target_ulong r1
)
1676 uint32_t ret_hw0
= extract32(r1
, 0, 16);
1677 uint32_t ret_hw1
= extract32(r1
, 16, 16);
1679 ret_hw0
= clz32(ret_hw0
<< 16);
1680 ret_hw1
= clz32(ret_hw1
<< 16);
1689 return ret_hw0
| (ret_hw1
<< 16);
1692 uint32_t helper_cls(target_ulong r1
)
1697 uint32_t helper_cls_h(target_ulong r1
)
1699 uint32_t ret_hw0
= extract32(r1
, 0, 16);
1700 uint32_t ret_hw1
= extract32(r1
, 16, 16);
1702 ret_hw0
= clrsb32(ret_hw0
<< 16);
1703 ret_hw1
= clrsb32(ret_hw1
<< 16);
1712 return ret_hw0
| (ret_hw1
<< 16);
1715 uint32_t helper_sh(target_ulong r1
, target_ulong r2
)
1717 int32_t shift_count
= sextract32(r2
, 0, 6);
1719 if (shift_count
== -32) {
1721 } else if (shift_count
< 0) {
1722 return r1
>> -shift_count
;
1724 return r1
<< shift_count
;
1728 uint32_t helper_sh_h(target_ulong r1
, target_ulong r2
)
1730 int32_t ret_hw0
, ret_hw1
;
1731 int32_t shift_count
;
1733 shift_count
= sextract32(r2
, 0, 5);
1735 if (shift_count
== -16) {
1737 } else if (shift_count
< 0) {
1738 ret_hw0
= extract32(r1
, 0, 16) >> -shift_count
;
1739 ret_hw1
= extract32(r1
, 16, 16) >> -shift_count
;
1740 return (ret_hw0
& 0xffff) | (ret_hw1
<< 16);
1742 ret_hw0
= extract32(r1
, 0, 16) << shift_count
;
1743 ret_hw1
= extract32(r1
, 16, 16) << shift_count
;
1744 return (ret_hw0
& 0xffff) | (ret_hw1
<< 16);
1748 uint32_t helper_sha(CPUTriCoreState
*env
, target_ulong r1
, target_ulong r2
)
1750 int32_t shift_count
;
1754 shift_count
= sextract32(r2
, 0, 6);
1755 t1
= sextract32(r1
, 0, 32);
1757 if (shift_count
== 0) {
1758 env
->PSW_USB_C
= env
->PSW_USB_V
= 0;
1760 } else if (shift_count
== -32) {
1761 env
->PSW_USB_C
= r1
;
1764 } else if (shift_count
> 0) {
1765 result
= t1
<< shift_count
;
1767 env
->PSW_USB_C
= ((result
& 0xffffffff00000000ULL
) != 0);
1769 env
->PSW_USB_V
= (((result
> 0x7fffffffLL
) ||
1770 (result
< -0x80000000LL
)) << 31);
1772 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1773 ret
= (uint32_t)result
;
1776 env
->PSW_USB_C
= (r1
& ((1 << -shift_count
) - 1));
1777 ret
= t1
>> -shift_count
;
1780 env
->PSW_USB_AV
= ret
^ ret
* 2u;
1781 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1786 uint32_t helper_sha_h(target_ulong r1
, target_ulong r2
)
1788 int32_t shift_count
;
1789 int32_t ret_hw0
, ret_hw1
;
1791 shift_count
= sextract32(r2
, 0, 5);
1793 if (shift_count
== 0) {
1795 } else if (shift_count
< 0) {
1796 ret_hw0
= sextract32(r1
, 0, 16) >> -shift_count
;
1797 ret_hw1
= sextract32(r1
, 16, 16) >> -shift_count
;
1798 return (ret_hw0
& 0xffff) | (ret_hw1
<< 16);
1800 ret_hw0
= sextract32(r1
, 0, 16) << shift_count
;
1801 ret_hw1
= sextract32(r1
, 16, 16) << shift_count
;
1802 return (ret_hw0
& 0xffff) | (ret_hw1
<< 16);
1806 uint32_t helper_bmerge(target_ulong r1
, target_ulong r2
)
1811 for (i
= 0; i
< 16; i
++) {
1812 ret
|= (r1
& 1) << (2 * i
+ 1);
1813 ret
|= (r2
& 1) << (2 * i
);
1820 uint64_t helper_bsplit(uint32_t r1
)
1826 for (i
= 0; i
< 32; i
= i
+ 2) {
1828 ret
|= (r1
& 1) << (i
/2);
1831 ret
|= (uint64_t)(r1
& 1) << (i
/2 + 32);
1837 uint32_t helper_parity(target_ulong r1
)
1844 for (i
= 0; i
< 8; i
++) {
1850 for (i
= 0; i
< 8; i
++) {
1857 for (i
= 0; i
< 8; i
++) {
1864 for (i
= 0; i
< 8; i
++) {
1873 uint32_t helper_pack(uint32_t carry
, uint32_t r1_low
, uint32_t r1_high
,
1877 int32_t fp_exp
, fp_frac
, temp_exp
, fp_exp_frac
;
1878 int32_t int_exp
= r1_high
;
1879 int32_t int_mant
= r1_low
;
1880 uint32_t flag_rnd
= (int_mant
& (1 << 7)) && (
1881 (int_mant
& (1 << 8)) ||
1882 (int_mant
& 0x7f) ||
1884 if (((int_mant
& (1<<31)) == 0) && (int_exp
== 255)) {
1886 fp_frac
= extract32(int_mant
, 8, 23);
1887 } else if ((int_mant
& (1<<31)) && (int_exp
>= 127)) {
1890 } else if ((int_mant
& (1<<31)) && (int_exp
<= -128)) {
1893 } else if (int_mant
== 0) {
1897 if (((int_mant
& (1 << 31)) == 0)) {
1900 temp_exp
= int_exp
+ 128;
1902 fp_exp_frac
= (((temp_exp
& 0xff) << 23) |
1903 extract32(int_mant
, 8, 23))
1905 fp_exp
= extract32(fp_exp_frac
, 23, 8);
1906 fp_frac
= extract32(fp_exp_frac
, 0, 23);
1908 ret
= r2
& (1 << 31);
1909 ret
= ret
+ (fp_exp
<< 23);
1910 ret
= ret
+ (fp_frac
& 0x7fffff);
1915 uint64_t helper_unpack(target_ulong arg1
)
1917 int32_t fp_exp
= extract32(arg1
, 23, 8);
1918 int32_t fp_frac
= extract32(arg1
, 0, 23);
1920 int32_t int_exp
, int_mant
;
1922 if (fp_exp
== 255) {
1924 int_mant
= (fp_frac
<< 7);
1925 } else if ((fp_exp
== 0) && (fp_frac
== 0)) {
1928 } else if ((fp_exp
== 0) && (fp_frac
!= 0)) {
1930 int_mant
= (fp_frac
<< 7);
1932 int_exp
= fp_exp
- 127;
1933 int_mant
= (fp_frac
<< 7);
1934 int_mant
|= (1 << 30);
1943 uint64_t helper_dvinit_b_13(CPUTriCoreState
*env
, uint32_t r1
, uint32_t r2
)
1946 int32_t abs_sig_dividend
, abs_divisor
;
1948 ret
= sextract32(r1
, 0, 32);
1950 if (!((r1
& 0x80000000) == (r2
& 0x80000000))) {
1954 abs_sig_dividend
= abs((int32_t)r1
) >> 8;
1955 abs_divisor
= abs((int32_t)r2
);
1957 ofv if (a/b >= 255) <=> (a/255 >= b) */
1958 env
->PSW_USB_V
= (abs_sig_dividend
>= abs_divisor
) << 31;
1959 env
->PSW_USB_V
= env
->PSW_USB_V
<< 31;
1960 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1961 env
->PSW_USB_AV
= 0;
1966 uint64_t helper_dvinit_b_131(CPUTriCoreState
*env
, uint32_t r1
, uint32_t r2
)
1968 uint64_t ret
= sextract32(r1
, 0, 32);
1971 if (!((r1
& 0x80000000) == (r2
& 0x80000000))) {
1975 env
->PSW_USB_V
= ((r2
== 0) || ((r2
== 0xffffffff) && (r1
== 0xffffff80)));
1976 env
->PSW_USB_V
= env
->PSW_USB_V
<< 31;
1977 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1978 env
->PSW_USB_AV
= 0;
1983 uint64_t helper_dvinit_h_13(CPUTriCoreState
*env
, uint32_t r1
, uint32_t r2
)
1986 int32_t abs_sig_dividend
, abs_divisor
;
1988 ret
= sextract32(r1
, 0, 32);
1990 if (!((r1
& 0x80000000) == (r2
& 0x80000000))) {
1994 abs_sig_dividend
= abs((int32_t)r1
) >> 16;
1995 abs_divisor
= abs((int32_t)r2
);
1997 ofv if (a/b >= 0xffff) <=> (a/0xffff >= b) */
1998 env
->PSW_USB_V
= (abs_sig_dividend
>= abs_divisor
) << 31;
1999 env
->PSW_USB_V
= env
->PSW_USB_V
<< 31;
2000 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
2001 env
->PSW_USB_AV
= 0;
2006 uint64_t helper_dvinit_h_131(CPUTriCoreState
*env
, uint32_t r1
, uint32_t r2
)
2008 uint64_t ret
= sextract32(r1
, 0, 32);
2011 if (!((r1
& 0x80000000) == (r2
& 0x80000000))) {
2015 env
->PSW_USB_V
= ((r2
== 0) || ((r2
== 0xffffffff) && (r1
== 0xffff8000)));
2016 env
->PSW_USB_V
= env
->PSW_USB_V
<< 31;
2017 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
2018 env
->PSW_USB_AV
= 0;
2023 uint64_t helper_dvadj(uint64_t r1
, uint32_t r2
)
2025 int32_t x_sign
= (r1
>> 63);
2026 int32_t q_sign
= x_sign
^ (r2
>> 31);
2027 int32_t eq_pos
= x_sign
& ((r1
>> 32) == r2
);
2028 int32_t eq_neg
= x_sign
& ((r1
>> 32) == -r2
);
2030 uint64_t ret
, remainder
;
2032 if ((q_sign
& ~eq_neg
) | eq_pos
) {
2033 quotient
= (r1
+ 1) & 0xffffffff;
2035 quotient
= r1
& 0xffffffff;
2038 if (eq_pos
| eq_neg
) {
2041 remainder
= (r1
& 0xffffffff00000000ull
);
2043 ret
= remainder
|quotient
;
2047 uint64_t helper_dvstep(uint64_t r1
, uint32_t r2
)
2049 int32_t dividend_sign
= extract64(r1
, 63, 1);
2050 int32_t divisor_sign
= extract32(r2
, 31, 1);
2051 int32_t quotient_sign
= (dividend_sign
!= divisor_sign
);
2052 int32_t addend
, dividend_quotient
, remainder
;
2055 if (quotient_sign
) {
2060 dividend_quotient
= (int32_t)r1
;
2061 remainder
= (int32_t)(r1
>> 32);
2063 for (i
= 0; i
< 8; i
++) {
2064 remainder
= (remainder
<< 1) | extract32(dividend_quotient
, 31, 1);
2065 dividend_quotient
<<= 1;
2066 temp
= remainder
+ addend
;
2067 if ((temp
< 0) == dividend_sign
) {
2070 if (((temp
< 0) == dividend_sign
)) {
2071 dividend_quotient
= dividend_quotient
| !quotient_sign
;
2073 dividend_quotient
= dividend_quotient
| quotient_sign
;
2076 return ((uint64_t)remainder
<< 32) | (uint32_t)dividend_quotient
;
2079 uint64_t helper_dvstep_u(uint64_t r1
, uint32_t r2
)
2081 int32_t dividend_quotient
= extract64(r1
, 0, 32);
2082 int64_t remainder
= extract64(r1
, 32, 32);
2085 for (i
= 0; i
< 8; i
++) {
2086 remainder
= (remainder
<< 1) | extract32(dividend_quotient
, 31, 1);
2087 dividend_quotient
<<= 1;
2088 temp
= (remainder
& 0xffffffff) - r2
;
2092 dividend_quotient
= dividend_quotient
| !(temp
< 0);
2094 return ((uint64_t)remainder
<< 32) | (uint32_t)dividend_quotient
;
2097 uint64_t helper_divide(CPUTriCoreState
*env
, uint32_t r1
, uint32_t r2
)
2099 int32_t quotient
, remainder
;
2100 int32_t dividend
= (int32_t)r1
;
2101 int32_t divisor
= (int32_t)r2
;
2104 if (dividend
>= 0) {
2105 quotient
= 0x7fffffff;
2108 quotient
= 0x80000000;
2111 env
->PSW_USB_V
= (1 << 31);
2112 } else if ((divisor
== 0xffffffff) && (dividend
== 0x80000000)) {
2113 quotient
= 0x7fffffff;
2115 env
->PSW_USB_V
= (1 << 31);
2117 remainder
= dividend
% divisor
;
2118 quotient
= (dividend
- remainder
)/divisor
;
2121 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
2122 env
->PSW_USB_AV
= 0;
2123 return ((uint64_t)remainder
<< 32) | (uint32_t)quotient
;
2126 uint64_t helper_divide_u(CPUTriCoreState
*env
, uint32_t r1
, uint32_t r2
)
2128 uint32_t quotient
, remainder
;
2129 uint32_t dividend
= r1
;
2130 uint32_t divisor
= r2
;
2133 quotient
= 0xffffffff;
2135 env
->PSW_USB_V
= (1 << 31);
2137 remainder
= dividend
% divisor
;
2138 quotient
= (dividend
- remainder
)/divisor
;
2141 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
2142 env
->PSW_USB_AV
= 0;
2143 return ((uint64_t)remainder
<< 32) | quotient
;
2146 uint64_t helper_mul_h(uint32_t arg00
, uint32_t arg01
,
2147 uint32_t arg10
, uint32_t arg11
, uint32_t n
)
2150 uint32_t result0
, result1
;
2152 int32_t sc1
= ((arg00
& 0xffff) == 0x8000) &&
2153 ((arg10
& 0xffff) == 0x8000) && (n
== 1);
2154 int32_t sc0
= ((arg01
& 0xffff) == 0x8000) &&
2155 ((arg11
& 0xffff) == 0x8000) && (n
== 1);
2157 result1
= 0x7fffffff;
2159 result1
= (((uint32_t)(arg00
* arg10
)) << n
);
2162 result0
= 0x7fffffff;
2164 result0
= (((uint32_t)(arg01
* arg11
)) << n
);
2166 ret
= (((uint64_t)result1
<< 32)) | result0
;
2170 uint64_t helper_mulm_h(uint32_t arg00
, uint32_t arg01
,
2171 uint32_t arg10
, uint32_t arg11
, uint32_t n
)
2174 int64_t result0
, result1
;
2176 int32_t sc1
= ((arg00
& 0xffff) == 0x8000) &&
2177 ((arg10
& 0xffff) == 0x8000) && (n
== 1);
2178 int32_t sc0
= ((arg01
& 0xffff) == 0x8000) &&
2179 ((arg11
& 0xffff) == 0x8000) && (n
== 1);
2182 result1
= 0x7fffffff;
2184 result1
= (((int32_t)arg00
* (int32_t)arg10
) << n
);
2187 result0
= 0x7fffffff;
2189 result0
= (((int32_t)arg01
* (int32_t)arg11
) << n
);
2191 ret
= (result1
+ result0
);
2195 uint32_t helper_mulr_h(uint32_t arg00
, uint32_t arg01
,
2196 uint32_t arg10
, uint32_t arg11
, uint32_t n
)
2198 uint32_t result0
, result1
;
2200 int32_t sc1
= ((arg00
& 0xffff) == 0x8000) &&
2201 ((arg10
& 0xffff) == 0x8000) && (n
== 1);
2202 int32_t sc0
= ((arg01
& 0xffff) == 0x8000) &&
2203 ((arg11
& 0xffff) == 0x8000) && (n
== 1);
2206 result1
= 0x7fffffff;
2208 result1
= ((arg00
* arg10
) << n
) + 0x8000;
2211 result0
= 0x7fffffff;
2213 result0
= ((arg01
* arg11
) << n
) + 0x8000;
2215 return (result1
& 0xffff0000) | (result0
>> 16);
2218 uint32_t helper_crc32(uint32_t arg0
, uint32_t arg1
)
2222 stl_be_p(buf
, arg0
);
2224 ret
= crc32(arg1
, buf
, 4);
2228 /* context save area (CSA) related helpers */
2230 static int cdc_increment(target_ulong
*psw
)
2232 if ((*psw
& MASK_PSW_CDC
) == 0x7f) {
2237 /* check for overflow */
2238 int lo
= clo32((*psw
& MASK_PSW_CDC
) << (32 - 7));
2239 int mask
= (1u << (7 - lo
)) - 1;
2240 int count
= *psw
& mask
;
2248 static int cdc_decrement(target_ulong
*psw
)
2250 if ((*psw
& MASK_PSW_CDC
) == 0x7f) {
2253 /* check for underflow */
2254 int lo
= clo32((*psw
& MASK_PSW_CDC
) << (32 - 7));
2255 int mask
= (1u << (7 - lo
)) - 1;
2256 int count
= *psw
& mask
;
2264 static bool cdc_zero(target_ulong
*psw
)
2266 int cdc
= *psw
& MASK_PSW_CDC
;
2267 /* Returns TRUE if PSW.CDC.COUNT == 0 or if PSW.CDC ==
2268 7'b1111111, otherwise returns FALSE. */
2272 /* find CDC.COUNT */
2273 int lo
= clo32((*psw
& MASK_PSW_CDC
) << (32 - 7));
2274 int mask
= (1u << (7 - lo
)) - 1;
2275 int count
= *psw
& mask
;
2279 static void save_context_upper(CPUTriCoreState
*env
, int ea
)
2281 cpu_stl_data(env
, ea
, env
->PCXI
);
2282 cpu_stl_data(env
, ea
+4, env
->PSW
);
2283 cpu_stl_data(env
, ea
+8, env
->gpr_a
[10]);
2284 cpu_stl_data(env
, ea
+12, env
->gpr_a
[11]);
2285 cpu_stl_data(env
, ea
+16, env
->gpr_d
[8]);
2286 cpu_stl_data(env
, ea
+20, env
->gpr_d
[9]);
2287 cpu_stl_data(env
, ea
+24, env
->gpr_d
[10]);
2288 cpu_stl_data(env
, ea
+28, env
->gpr_d
[11]);
2289 cpu_stl_data(env
, ea
+32, env
->gpr_a
[12]);
2290 cpu_stl_data(env
, ea
+36, env
->gpr_a
[13]);
2291 cpu_stl_data(env
, ea
+40, env
->gpr_a
[14]);
2292 cpu_stl_data(env
, ea
+44, env
->gpr_a
[15]);
2293 cpu_stl_data(env
, ea
+48, env
->gpr_d
[12]);
2294 cpu_stl_data(env
, ea
+52, env
->gpr_d
[13]);
2295 cpu_stl_data(env
, ea
+56, env
->gpr_d
[14]);
2296 cpu_stl_data(env
, ea
+60, env
->gpr_d
[15]);
2299 static void save_context_lower(CPUTriCoreState
*env
, int ea
)
2301 cpu_stl_data(env
, ea
, env
->PCXI
);
2302 cpu_stl_data(env
, ea
+4, env
->gpr_a
[11]);
2303 cpu_stl_data(env
, ea
+8, env
->gpr_a
[2]);
2304 cpu_stl_data(env
, ea
+12, env
->gpr_a
[3]);
2305 cpu_stl_data(env
, ea
+16, env
->gpr_d
[0]);
2306 cpu_stl_data(env
, ea
+20, env
->gpr_d
[1]);
2307 cpu_stl_data(env
, ea
+24, env
->gpr_d
[2]);
2308 cpu_stl_data(env
, ea
+28, env
->gpr_d
[3]);
2309 cpu_stl_data(env
, ea
+32, env
->gpr_a
[4]);
2310 cpu_stl_data(env
, ea
+36, env
->gpr_a
[5]);
2311 cpu_stl_data(env
, ea
+40, env
->gpr_a
[6]);
2312 cpu_stl_data(env
, ea
+44, env
->gpr_a
[7]);
2313 cpu_stl_data(env
, ea
+48, env
->gpr_d
[4]);
2314 cpu_stl_data(env
, ea
+52, env
->gpr_d
[5]);
2315 cpu_stl_data(env
, ea
+56, env
->gpr_d
[6]);
2316 cpu_stl_data(env
, ea
+60, env
->gpr_d
[7]);
2319 static void restore_context_upper(CPUTriCoreState
*env
, int ea
,
2320 target_ulong
*new_PCXI
, target_ulong
*new_PSW
)
2322 *new_PCXI
= cpu_ldl_data(env
, ea
);
2323 *new_PSW
= cpu_ldl_data(env
, ea
+4);
2324 env
->gpr_a
[10] = cpu_ldl_data(env
, ea
+8);
2325 env
->gpr_a
[11] = cpu_ldl_data(env
, ea
+12);
2326 env
->gpr_d
[8] = cpu_ldl_data(env
, ea
+16);
2327 env
->gpr_d
[9] = cpu_ldl_data(env
, ea
+20);
2328 env
->gpr_d
[10] = cpu_ldl_data(env
, ea
+24);
2329 env
->gpr_d
[11] = cpu_ldl_data(env
, ea
+28);
2330 env
->gpr_a
[12] = cpu_ldl_data(env
, ea
+32);
2331 env
->gpr_a
[13] = cpu_ldl_data(env
, ea
+36);
2332 env
->gpr_a
[14] = cpu_ldl_data(env
, ea
+40);
2333 env
->gpr_a
[15] = cpu_ldl_data(env
, ea
+44);
2334 env
->gpr_d
[12] = cpu_ldl_data(env
, ea
+48);
2335 env
->gpr_d
[13] = cpu_ldl_data(env
, ea
+52);
2336 env
->gpr_d
[14] = cpu_ldl_data(env
, ea
+56);
2337 env
->gpr_d
[15] = cpu_ldl_data(env
, ea
+60);
2340 static void restore_context_lower(CPUTriCoreState
*env
, int ea
,
2341 target_ulong
*ra
, target_ulong
*pcxi
)
2343 *pcxi
= cpu_ldl_data(env
, ea
);
2344 *ra
= cpu_ldl_data(env
, ea
+4);
2345 env
->gpr_a
[2] = cpu_ldl_data(env
, ea
+8);
2346 env
->gpr_a
[3] = cpu_ldl_data(env
, ea
+12);
2347 env
->gpr_d
[0] = cpu_ldl_data(env
, ea
+16);
2348 env
->gpr_d
[1] = cpu_ldl_data(env
, ea
+20);
2349 env
->gpr_d
[2] = cpu_ldl_data(env
, ea
+24);
2350 env
->gpr_d
[3] = cpu_ldl_data(env
, ea
+28);
2351 env
->gpr_a
[4] = cpu_ldl_data(env
, ea
+32);
2352 env
->gpr_a
[5] = cpu_ldl_data(env
, ea
+36);
2353 env
->gpr_a
[6] = cpu_ldl_data(env
, ea
+40);
2354 env
->gpr_a
[7] = cpu_ldl_data(env
, ea
+44);
2355 env
->gpr_d
[4] = cpu_ldl_data(env
, ea
+48);
2356 env
->gpr_d
[5] = cpu_ldl_data(env
, ea
+52);
2357 env
->gpr_d
[6] = cpu_ldl_data(env
, ea
+56);
2358 env
->gpr_d
[7] = cpu_ldl_data(env
, ea
+60);
2361 void helper_call(CPUTriCoreState
*env
, uint32_t next_pc
)
2363 target_ulong tmp_FCX
;
2365 target_ulong new_FCX
;
2368 psw
= psw_read(env
);
2369 /* if (FCX == 0) trap(FCU); */
2370 if (env
->FCX
== 0) {
2373 /* if (PSW.CDE) then if (cdc_increment()) then trap(CDO); */
2374 if (psw
& MASK_PSW_CDE
) {
2375 if (cdc_increment(&psw
)) {
2380 psw
|= MASK_PSW_CDE
;
2381 /* tmp_FCX = FCX; */
2383 /* EA = {FCX.FCXS, 6'b0, FCX.FCXO, 6'b0}; */
2384 ea
= ((env
->FCX
& MASK_FCX_FCXS
) << 12) +
2385 ((env
->FCX
& MASK_FCX_FCXO
) << 6);
2386 /* new_FCX = M(EA, word); */
2387 new_FCX
= cpu_ldl_data(env
, ea
);
2388 /* M(EA, 16 * word) = {PCXI, PSW, A[10], A[11], D[8], D[9], D[10], D[11],
2389 A[12], A[13], A[14], A[15], D[12], D[13], D[14],
2391 save_context_upper(env
, ea
);
2393 /* PCXI.PCPN = ICR.CCPN; */
2394 env
->PCXI
= (env
->PCXI
& 0xffffff) +
2395 ((env
->ICR
& MASK_ICR_CCPN
) << 24);
2396 /* PCXI.PIE = ICR.IE; */
2397 env
->PCXI
= ((env
->PCXI
& ~MASK_PCXI_PIE
) +
2398 ((env
->ICR
& MASK_ICR_IE
) << 15));
2400 env
->PCXI
|= MASK_PCXI_UL
;
2402 /* PCXI[19: 0] = FCX[19: 0]; */
2403 env
->PCXI
= (env
->PCXI
& 0xfff00000) + (env
->FCX
& 0xfffff);
2404 /* FCX[19: 0] = new_FCX[19: 0]; */
2405 env
->FCX
= (env
->FCX
& 0xfff00000) + (new_FCX
& 0xfffff);
2406 /* A[11] = next_pc[31: 0]; */
2407 env
->gpr_a
[11] = next_pc
;
2409 /* if (tmp_FCX == LCX) trap(FCD);*/
2410 if (tmp_FCX
== env
->LCX
) {
2413 psw_write(env
, psw
);
2416 void helper_ret(CPUTriCoreState
*env
)
2419 target_ulong new_PCXI
;
2420 target_ulong new_PSW
, psw
;
2422 psw
= psw_read(env
);
2423 /* if (PSW.CDE) then if (cdc_decrement()) then trap(CDU);*/
2424 if (env
->PSW
& MASK_PSW_CDE
) {
2425 if (cdc_decrement(&(env
->PSW
))) {
2429 /* if (PCXI[19: 0] == 0) then trap(CSU); */
2430 if ((env
->PCXI
& 0xfffff) == 0) {
2433 /* if (PCXI.UL == 0) then trap(CTYP); */
2434 if ((env
->PCXI
& MASK_PCXI_UL
) == 0) {
2437 /* PC = {A11 [31: 1], 1’b0}; */
2438 env
->PC
= env
->gpr_a
[11] & 0xfffffffe;
2440 /* EA = {PCXI.PCXS, 6'b0, PCXI.PCXO, 6'b0}; */
2441 ea
= ((env
->PCXI
& MASK_PCXI_PCXS
) << 12) +
2442 ((env
->PCXI
& MASK_PCXI_PCXO
) << 6);
2443 /* {new_PCXI, new_PSW, A[10], A[11], D[8], D[9], D[10], D[11], A[12],
2444 A[13], A[14], A[15], D[12], D[13], D[14], D[15]} = M(EA, 16 * word); */
2445 restore_context_upper(env
, ea
, &new_PCXI
, &new_PSW
);
2446 /* M(EA, word) = FCX; */
2447 cpu_stl_data(env
, ea
, env
->FCX
);
2448 /* FCX[19: 0] = PCXI[19: 0]; */
2449 env
->FCX
= (env
->FCX
& 0xfff00000) + (env
->PCXI
& 0x000fffff);
2450 /* PCXI = new_PCXI; */
2451 env
->PCXI
= new_PCXI
;
2453 if (tricore_feature(env
, TRICORE_FEATURE_13
)) {
2455 psw_write(env
, new_PSW
);
2457 /* PSW = {new_PSW[31:26], PSW[25:24], new_PSW[23:0]}; */
2458 psw_write(env
, (new_PSW
& ~(0x3000000)) + (psw
& (0x3000000)));
2462 void helper_bisr(CPUTriCoreState
*env
, uint32_t const9
)
2464 target_ulong tmp_FCX
;
2466 target_ulong new_FCX
;
2468 if (env
->FCX
== 0) {
2473 ea
= ((env
->FCX
& 0xf0000) << 12) + ((env
->FCX
& 0xffff) << 6);
2475 /* new_FCX = M(EA, word); */
2476 new_FCX
= cpu_ldl_data(env
, ea
);
2477 /* M(EA, 16 * word) = {PCXI, A[11], A[2], A[3], D[0], D[1], D[2], D[3], A[4]
2478 , A[5], A[6], A[7], D[4], D[5], D[6], D[7]}; */
2479 save_context_lower(env
, ea
);
2482 /* PCXI.PCPN = ICR.CCPN */
2483 env
->PCXI
= (env
->PCXI
& 0xffffff) +
2484 ((env
->ICR
& MASK_ICR_CCPN
) << 24);
2485 /* PCXI.PIE = ICR.IE */
2486 env
->PCXI
= ((env
->PCXI
& ~MASK_PCXI_PIE
) +
2487 ((env
->ICR
& MASK_ICR_IE
) << 15));
2489 env
->PCXI
&= ~(MASK_PCXI_UL
);
2490 /* PCXI[19: 0] = FCX[19: 0] */
2491 env
->PCXI
= (env
->PCXI
& 0xfff00000) + (env
->FCX
& 0xfffff);
2492 /* FXC[19: 0] = new_FCX[19: 0] */
2493 env
->FCX
= (env
->FCX
& 0xfff00000) + (new_FCX
& 0xfffff);
2495 env
->ICR
|= MASK_ICR_IE
;
2497 env
->ICR
|= const9
; /* ICR.CCPN = const9[7: 0];*/
2499 if (tmp_FCX
== env
->LCX
) {
2504 void helper_rfe(CPUTriCoreState
*env
)
2507 target_ulong new_PCXI
;
2508 target_ulong new_PSW
;
2509 /* if (PCXI[19: 0] == 0) then trap(CSU); */
2510 if ((env
->PCXI
& 0xfffff) == 0) {
2511 /* raise csu trap */
2513 /* if (PCXI.UL == 0) then trap(CTYP); */
2514 if ((env
->PCXI
& MASK_PCXI_UL
) == 0) {
2515 /* raise CTYP trap */
2517 /* if (!cdc_zero() AND PSW.CDE) then trap(NEST); */
2518 if (!cdc_zero(&(env
->PSW
)) && (env
->PSW
& MASK_PSW_CDE
)) {
2519 /* raise MNG trap */
2521 env
->PC
= env
->gpr_a
[11] & ~0x1;
2522 /* ICR.IE = PCXI.PIE; */
2523 env
->ICR
= (env
->ICR
& ~MASK_ICR_IE
) + ((env
->PCXI
& MASK_PCXI_PIE
) >> 15);
2524 /* ICR.CCPN = PCXI.PCPN; */
2525 env
->ICR
= (env
->ICR
& ~MASK_ICR_CCPN
) +
2526 ((env
->PCXI
& MASK_PCXI_PCPN
) >> 24);
2527 /*EA = {PCXI.PCXS, 6'b0, PCXI.PCXO, 6'b0};*/
2528 ea
= ((env
->PCXI
& MASK_PCXI_PCXS
) << 12) +
2529 ((env
->PCXI
& MASK_PCXI_PCXO
) << 6);
2530 /*{new_PCXI, PSW, A[10], A[11], D[8], D[9], D[10], D[11], A[12],
2531 A[13], A[14], A[15], D[12], D[13], D[14], D[15]} = M(EA, 16 * word); */
2532 restore_context_upper(env
, ea
, &new_PCXI
, &new_PSW
);
2533 /* M(EA, word) = FCX;*/
2534 cpu_stl_data(env
, ea
, env
->FCX
);
2535 /* FCX[19: 0] = PCXI[19: 0]; */
2536 env
->FCX
= (env
->FCX
& 0xfff00000) + (env
->PCXI
& 0x000fffff);
2537 /* PCXI = new_PCXI; */
2538 env
->PCXI
= new_PCXI
;
2540 psw_write(env
, new_PSW
);
2543 void helper_rfm(CPUTriCoreState
*env
)
2545 env
->PC
= (env
->gpr_a
[11] & ~0x1);
2546 /* ICR.IE = PCXI.PIE; */
2547 env
->ICR
= (env
->ICR
& ~MASK_ICR_IE
) |
2548 ((env
->PCXI
& MASK_PCXI_PIE
) >> 15);
2549 /* ICR.CCPN = PCXI.PCPN; */
2550 env
->ICR
= (env
->ICR
& ~MASK_ICR_CCPN
) |
2551 ((env
->PCXI
& MASK_PCXI_PCPN
) >> 24);
2552 /* {PCXI, PSW, A[10], A[11]} = M(DCX, 4 * word); */
2553 env
->PCXI
= cpu_ldl_data(env
, env
->DCX
);
2554 psw_write(env
, cpu_ldl_data(env
, env
->DCX
+4));
2555 env
->gpr_a
[10] = cpu_ldl_data(env
, env
->DCX
+8);
2556 env
->gpr_a
[11] = cpu_ldl_data(env
, env
->DCX
+12);
2558 if (tricore_feature(env
, TRICORE_FEATURE_131
)) {
2563 void helper_ldlcx(CPUTriCoreState
*env
, uint32_t ea
)
2566 /* insn doesn't load PCXI and RA */
2567 restore_context_lower(env
, ea
, &dummy
, &dummy
);
2570 void helper_lducx(CPUTriCoreState
*env
, uint32_t ea
)
2573 /* insn doesn't load PCXI and PSW */
2574 restore_context_upper(env
, ea
, &dummy
, &dummy
);
2577 void helper_stlcx(CPUTriCoreState
*env
, uint32_t ea
)
2579 save_context_lower(env
, ea
);
2582 void helper_stucx(CPUTriCoreState
*env
, uint32_t ea
)
2584 save_context_upper(env
, ea
);
2587 void helper_svlcx(CPUTriCoreState
*env
)
2589 target_ulong tmp_FCX
;
2591 target_ulong new_FCX
;
2593 if (env
->FCX
== 0) {
2596 /* tmp_FCX = FCX; */
2598 /* EA = {FCX.FCXS, 6'b0, FCX.FCXO, 6'b0}; */
2599 ea
= ((env
->FCX
& MASK_FCX_FCXS
) << 12) +
2600 ((env
->FCX
& MASK_FCX_FCXO
) << 6);
2601 /* new_FCX = M(EA, word); */
2602 new_FCX
= cpu_ldl_data(env
, ea
);
2603 /* M(EA, 16 * word) = {PCXI, PSW, A[10], A[11], D[8], D[9], D[10], D[11],
2604 A[12], A[13], A[14], A[15], D[12], D[13], D[14],
2606 save_context_lower(env
, ea
);
2608 /* PCXI.PCPN = ICR.CCPN; */
2609 env
->PCXI
= (env
->PCXI
& 0xffffff) +
2610 ((env
->ICR
& MASK_ICR_CCPN
) << 24);
2611 /* PCXI.PIE = ICR.IE; */
2612 env
->PCXI
= ((env
->PCXI
& ~MASK_PCXI_PIE
) +
2613 ((env
->ICR
& MASK_ICR_IE
) << 15));
2615 env
->PCXI
&= ~MASK_PCXI_UL
;
2617 /* PCXI[19: 0] = FCX[19: 0]; */
2618 env
->PCXI
= (env
->PCXI
& 0xfff00000) + (env
->FCX
& 0xfffff);
2619 /* FCX[19: 0] = new_FCX[19: 0]; */
2620 env
->FCX
= (env
->FCX
& 0xfff00000) + (new_FCX
& 0xfffff);
2622 /* if (tmp_FCX == LCX) trap(FCD);*/
2623 if (tmp_FCX
== env
->LCX
) {
2628 void helper_rslcx(CPUTriCoreState
*env
)
2631 target_ulong new_PCXI
;
2632 /* if (PCXI[19: 0] == 0) then trap(CSU); */
2633 if ((env
->PCXI
& 0xfffff) == 0) {
2636 /* if (PCXI.UL == 1) then trap(CTYP); */
2637 if ((env
->PCXI
& MASK_PCXI_UL
) != 0) {
2640 /* EA = {PCXI.PCXS, 6'b0, PCXI.PCXO, 6'b0}; */
2641 ea
= ((env
->PCXI
& MASK_PCXI_PCXS
) << 12) +
2642 ((env
->PCXI
& MASK_PCXI_PCXO
) << 6);
2643 /* {new_PCXI, A[11], A[10], A[11], D[8], D[9], D[10], D[11], A[12],
2644 A[13], A[14], A[15], D[12], D[13], D[14], D[15]} = M(EA, 16 * word); */
2645 restore_context_lower(env
, ea
, &env
->gpr_a
[11], &new_PCXI
);
2646 /* M(EA, word) = FCX; */
2647 cpu_stl_data(env
, ea
, env
->FCX
);
2648 /* M(EA, word) = FCX; */
2649 cpu_stl_data(env
, ea
, env
->FCX
);
2650 /* FCX[19: 0] = PCXI[19: 0]; */
2651 env
->FCX
= (env
->FCX
& 0xfff00000) + (env
->PCXI
& 0x000fffff);
2652 /* PCXI = new_PCXI; */
2653 env
->PCXI
= new_PCXI
;
2656 void helper_psw_write(CPUTriCoreState
*env
, uint32_t arg
)
2658 psw_write(env
, arg
);
2661 uint32_t helper_psw_read(CPUTriCoreState
*env
)
2663 return psw_read(env
);
2667 static inline void QEMU_NORETURN
do_raise_exception_err(CPUTriCoreState
*env
,
2672 CPUState
*cs
= CPU(tricore_env_get_cpu(env
));
2673 cs
->exception_index
= exception
;
2674 env
->error_code
= error_code
;
2677 /* now we have a real cpu fault */
2678 cpu_restore_state(cs
, pc
);
2684 void tlb_fill(CPUState
*cs
, target_ulong addr
, int is_write
, int mmu_idx
,
2688 ret
= cpu_tricore_handle_mmu_fault(cs
, addr
, is_write
, mmu_idx
);
2690 TriCoreCPU
*cpu
= TRICORE_CPU(cs
);
2691 CPUTriCoreState
*env
= &cpu
->env
;
2692 do_raise_exception_err(env
, cs
->exception_index
,
2693 env
->error_code
, retaddr
);