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"
23 /* Addressing mode helper */
25 static uint16_t reverse16(uint16_t val
)
27 uint8_t high
= (uint8_t)(val
>> 8);
28 uint8_t low
= (uint8_t)(val
& 0xff);
32 rl
= (uint16_t)((high
* 0x0202020202ULL
& 0x010884422010ULL
) % 1023);
33 rh
= (uint16_t)((low
* 0x0202020202ULL
& 0x010884422010ULL
) % 1023);
35 return (rh
<< 8) | rl
;
38 uint32_t helper_br_update(uint32_t reg
)
40 uint32_t index
= reg
& 0xffff;
41 uint32_t incr
= reg
>> 16;
42 uint32_t new_index
= reverse16(reverse16(index
) + reverse16(incr
));
43 return reg
- index
+ new_index
;
46 uint32_t helper_circ_update(uint32_t reg
, uint32_t off
)
48 uint32_t index
= reg
& 0xffff;
49 uint32_t length
= reg
>> 16;
50 int32_t new_index
= index
+ off
;
56 return reg
- index
+ new_index
;
59 static uint32_t ssov32(CPUTriCoreState
*env
, int64_t arg
)
62 int64_t max_pos
= INT32_MAX
;
63 int64_t max_neg
= INT32_MIN
;
65 env
->PSW_USB_V
= (1 << 31);
66 env
->PSW_USB_SV
= (1 << 31);
67 ret
= (target_ulong
)max_pos
;
70 env
->PSW_USB_V
= (1 << 31);
71 env
->PSW_USB_SV
= (1 << 31);
72 ret
= (target_ulong
)max_neg
;
75 ret
= (target_ulong
)arg
;
78 env
->PSW_USB_AV
= arg
^ arg
* 2u;
79 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
83 static uint32_t suov32_pos(CPUTriCoreState
*env
, uint64_t arg
)
86 uint64_t max_pos
= UINT32_MAX
;
88 env
->PSW_USB_V
= (1 << 31);
89 env
->PSW_USB_SV
= (1 << 31);
90 ret
= (target_ulong
)max_pos
;
93 ret
= (target_ulong
)arg
;
95 env
->PSW_USB_AV
= arg
^ arg
* 2u;
96 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
100 static uint32_t suov32_neg(CPUTriCoreState
*env
, int64_t arg
)
105 env
->PSW_USB_V
= (1 << 31);
106 env
->PSW_USB_SV
= (1 << 31);
110 ret
= (target_ulong
)arg
;
112 env
->PSW_USB_AV
= arg
^ arg
* 2u;
113 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
117 static uint32_t ssov16(CPUTriCoreState
*env
, int32_t hw0
, int32_t hw1
)
119 int32_t max_pos
= INT16_MAX
;
120 int32_t max_neg
= INT16_MIN
;
124 av0
= hw0
^ hw0
* 2u;
126 env
->PSW_USB_V
= (1 << 31);
128 } else if (hw0
< max_neg
) {
129 env
->PSW_USB_V
= (1 << 31);
133 av1
= hw1
^ hw1
* 2u;
135 env
->PSW_USB_V
= (1 << 31);
137 } else if (hw1
< max_neg
) {
138 env
->PSW_USB_V
= (1 << 31);
142 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
143 env
->PSW_USB_AV
= (av0
| av1
) << 16;
144 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
145 return (hw0
& 0xffff) | (hw1
<< 16);
148 static uint32_t suov16(CPUTriCoreState
*env
, int32_t hw0
, int32_t hw1
)
150 int32_t max_pos
= UINT16_MAX
;
154 av0
= hw0
^ hw0
* 2u;
156 env
->PSW_USB_V
= (1 << 31);
158 } else if (hw0
< 0) {
159 env
->PSW_USB_V
= (1 << 31);
163 av1
= hw1
^ hw1
* 2u;
165 env
->PSW_USB_V
= (1 << 31);
167 } else if (hw1
< 0) {
168 env
->PSW_USB_V
= (1 << 31);
172 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
173 env
->PSW_USB_AV
= (av0
| av1
) << 16;
174 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
175 return (hw0
& 0xffff) | (hw1
<< 16);
178 target_ulong
helper_add_ssov(CPUTriCoreState
*env
, target_ulong r1
,
181 int64_t t1
= sextract64(r1
, 0, 32);
182 int64_t t2
= sextract64(r2
, 0, 32);
183 int64_t result
= t1
+ t2
;
184 return ssov32(env
, result
);
187 uint64_t helper_add64_ssov(CPUTriCoreState
*env
, uint64_t r1
, uint64_t r2
)
193 ovf
= (result
^ r1
) & ~(r1
^ r2
);
194 env
->PSW_USB_AV
= (result
^ result
* 2u) >> 32;
195 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
197 env
->PSW_USB_V
= (1 << 31);
198 env
->PSW_USB_SV
= (1 << 31);
199 /* ext_ret > MAX_INT */
200 if ((int64_t)r1
>= 0) {
202 /* ext_ret < MIN_INT */
212 target_ulong
helper_add_h_ssov(CPUTriCoreState
*env
, target_ulong r1
,
215 int32_t ret_hw0
, ret_hw1
;
217 ret_hw0
= sextract32(r1
, 0, 16) + sextract32(r2
, 0, 16);
218 ret_hw1
= sextract32(r1
, 16, 16) + sextract32(r2
, 16, 16);
219 return ssov16(env
, ret_hw0
, ret_hw1
);
222 uint32_t helper_addr_h_ssov(CPUTriCoreState
*env
, uint64_t r1
, uint32_t r2_l
,
225 int64_t mul_res0
= sextract64(r1
, 0, 32);
226 int64_t mul_res1
= sextract64(r1
, 32, 32);
227 int64_t r2_low
= sextract64(r2_l
, 0, 32);
228 int64_t r2_high
= sextract64(r2_h
, 0, 32);
229 int64_t result0
, result1
;
235 result0
= r2_low
+ mul_res0
+ 0x8000;
236 result1
= r2_high
+ mul_res1
+ 0x8000;
239 avf0
= result0
^ avf0
;
241 avf1
= result1
^ avf1
;
243 if (result0
> INT32_MAX
) {
246 } else if (result0
< INT32_MIN
) {
251 if (result1
> INT32_MAX
) {
254 } else if (result1
< INT32_MIN
) {
259 env
->PSW_USB_V
= ovf0
| ovf1
;
260 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
262 env
->PSW_USB_AV
= avf0
| avf1
;
263 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
265 return (result1
& 0xffff0000ULL
) | ((result0
>> 16) & 0xffffULL
);
268 uint32_t helper_addsur_h_ssov(CPUTriCoreState
*env
, uint64_t r1
, uint32_t r2_l
,
271 int64_t mul_res0
= sextract64(r1
, 0, 32);
272 int64_t mul_res1
= sextract64(r1
, 32, 32);
273 int64_t r2_low
= sextract64(r2_l
, 0, 32);
274 int64_t r2_high
= sextract64(r2_h
, 0, 32);
275 int64_t result0
, result1
;
281 result0
= r2_low
- mul_res0
+ 0x8000;
282 result1
= r2_high
+ mul_res1
+ 0x8000;
285 avf0
= result0
^ avf0
;
287 avf1
= result1
^ avf1
;
289 if (result0
> INT32_MAX
) {
292 } else if (result0
< INT32_MIN
) {
297 if (result1
> INT32_MAX
) {
300 } else if (result1
< INT32_MIN
) {
305 env
->PSW_USB_V
= ovf0
| ovf1
;
306 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
308 env
->PSW_USB_AV
= avf0
| avf1
;
309 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
311 return (result1
& 0xffff0000ULL
) | ((result0
>> 16) & 0xffffULL
);
315 target_ulong
helper_add_suov(CPUTriCoreState
*env
, target_ulong r1
,
318 int64_t t1
= extract64(r1
, 0, 32);
319 int64_t t2
= extract64(r2
, 0, 32);
320 int64_t result
= t1
+ t2
;
321 return suov32_pos(env
, result
);
324 target_ulong
helper_add_h_suov(CPUTriCoreState
*env
, target_ulong r1
,
327 int32_t ret_hw0
, ret_hw1
;
329 ret_hw0
= extract32(r1
, 0, 16) + extract32(r2
, 0, 16);
330 ret_hw1
= extract32(r1
, 16, 16) + extract32(r2
, 16, 16);
331 return suov16(env
, ret_hw0
, ret_hw1
);
334 target_ulong
helper_sub_ssov(CPUTriCoreState
*env
, target_ulong r1
,
337 int64_t t1
= sextract64(r1
, 0, 32);
338 int64_t t2
= sextract64(r2
, 0, 32);
339 int64_t result
= t1
- t2
;
340 return ssov32(env
, result
);
343 uint64_t helper_sub64_ssov(CPUTriCoreState
*env
, uint64_t r1
, uint64_t r2
)
349 ovf
= (result
^ r1
) & (r1
^ r2
);
350 env
->PSW_USB_AV
= (result
^ result
* 2u) >> 32;
351 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
353 env
->PSW_USB_V
= (1 << 31);
354 env
->PSW_USB_SV
= (1 << 31);
355 /* ext_ret > MAX_INT */
356 if ((int64_t)r1
>= 0) {
358 /* ext_ret < MIN_INT */
368 target_ulong
helper_sub_h_ssov(CPUTriCoreState
*env
, target_ulong r1
,
371 int32_t ret_hw0
, ret_hw1
;
373 ret_hw0
= sextract32(r1
, 0, 16) - sextract32(r2
, 0, 16);
374 ret_hw1
= sextract32(r1
, 16, 16) - sextract32(r2
, 16, 16);
375 return ssov16(env
, ret_hw0
, ret_hw1
);
378 uint32_t helper_subr_h_ssov(CPUTriCoreState
*env
, uint64_t r1
, uint32_t r2_l
,
381 int64_t mul_res0
= sextract64(r1
, 0, 32);
382 int64_t mul_res1
= sextract64(r1
, 32, 32);
383 int64_t r2_low
= sextract64(r2_l
, 0, 32);
384 int64_t r2_high
= sextract64(r2_h
, 0, 32);
385 int64_t result0
, result1
;
391 result0
= r2_low
- mul_res0
+ 0x8000;
392 result1
= r2_high
- mul_res1
+ 0x8000;
395 avf0
= result0
^ avf0
;
397 avf1
= result1
^ avf1
;
399 if (result0
> INT32_MAX
) {
402 } else if (result0
< INT32_MIN
) {
407 if (result1
> INT32_MAX
) {
410 } else if (result1
< INT32_MIN
) {
415 env
->PSW_USB_V
= ovf0
| ovf1
;
416 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
418 env
->PSW_USB_AV
= avf0
| avf1
;
419 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
421 return (result1
& 0xffff0000ULL
) | ((result0
>> 16) & 0xffffULL
);
424 uint32_t helper_subadr_h_ssov(CPUTriCoreState
*env
, uint64_t r1
, uint32_t r2_l
,
427 int64_t mul_res0
= sextract64(r1
, 0, 32);
428 int64_t mul_res1
= sextract64(r1
, 32, 32);
429 int64_t r2_low
= sextract64(r2_l
, 0, 32);
430 int64_t r2_high
= sextract64(r2_h
, 0, 32);
431 int64_t result0
, result1
;
437 result0
= r2_low
+ mul_res0
+ 0x8000;
438 result1
= r2_high
- mul_res1
+ 0x8000;
441 avf0
= result0
^ avf0
;
443 avf1
= result1
^ avf1
;
445 if (result0
> INT32_MAX
) {
448 } else if (result0
< INT32_MIN
) {
453 if (result1
> INT32_MAX
) {
456 } else if (result1
< INT32_MIN
) {
461 env
->PSW_USB_V
= ovf0
| ovf1
;
462 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
464 env
->PSW_USB_AV
= avf0
| avf1
;
465 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
467 return (result1
& 0xffff0000ULL
) | ((result0
>> 16) & 0xffffULL
);
470 target_ulong
helper_sub_suov(CPUTriCoreState
*env
, target_ulong r1
,
473 int64_t t1
= extract64(r1
, 0, 32);
474 int64_t t2
= extract64(r2
, 0, 32);
475 int64_t result
= t1
- t2
;
476 return suov32_neg(env
, result
);
479 target_ulong
helper_sub_h_suov(CPUTriCoreState
*env
, target_ulong r1
,
482 int32_t ret_hw0
, ret_hw1
;
484 ret_hw0
= extract32(r1
, 0, 16) - extract32(r2
, 0, 16);
485 ret_hw1
= extract32(r1
, 16, 16) - extract32(r2
, 16, 16);
486 return suov16(env
, ret_hw0
, ret_hw1
);
489 target_ulong
helper_mul_ssov(CPUTriCoreState
*env
, target_ulong r1
,
492 int64_t t1
= sextract64(r1
, 0, 32);
493 int64_t t2
= sextract64(r2
, 0, 32);
494 int64_t result
= t1
* t2
;
495 return ssov32(env
, result
);
498 target_ulong
helper_mul_suov(CPUTriCoreState
*env
, target_ulong r1
,
501 int64_t t1
= extract64(r1
, 0, 32);
502 int64_t t2
= extract64(r2
, 0, 32);
503 int64_t result
= t1
* t2
;
505 return suov32_pos(env
, result
);
508 target_ulong
helper_sha_ssov(CPUTriCoreState
*env
, target_ulong r1
,
511 int64_t t1
= sextract64(r1
, 0, 32);
512 int32_t t2
= sextract64(r2
, 0, 6);
521 return ssov32(env
, result
);
524 uint32_t helper_abs_ssov(CPUTriCoreState
*env
, target_ulong r1
)
527 result
= ((int32_t)r1
>= 0) ? r1
: (0 - r1
);
528 return ssov32(env
, result
);
531 uint32_t helper_abs_h_ssov(CPUTriCoreState
*env
, target_ulong r1
)
533 int32_t ret_h0
, ret_h1
;
535 ret_h0
= sextract32(r1
, 0, 16);
536 ret_h0
= (ret_h0
>= 0) ? ret_h0
: (0 - ret_h0
);
538 ret_h1
= sextract32(r1
, 16, 16);
539 ret_h1
= (ret_h1
>= 0) ? ret_h1
: (0 - ret_h1
);
541 return ssov16(env
, ret_h0
, ret_h1
);
544 target_ulong
helper_absdif_ssov(CPUTriCoreState
*env
, target_ulong r1
,
547 int64_t t1
= sextract64(r1
, 0, 32);
548 int64_t t2
= sextract64(r2
, 0, 32);
556 return ssov32(env
, result
);
559 uint32_t helper_absdif_h_ssov(CPUTriCoreState
*env
, target_ulong r1
,
563 int32_t ret_h0
, ret_h1
;
565 t1
= sextract32(r1
, 0, 16);
566 t2
= sextract32(r2
, 0, 16);
573 t1
= sextract32(r1
, 16, 16);
574 t2
= sextract32(r2
, 16, 16);
581 return ssov16(env
, ret_h0
, ret_h1
);
584 target_ulong
helper_madd32_ssov(CPUTriCoreState
*env
, target_ulong r1
,
585 target_ulong r2
, target_ulong r3
)
587 int64_t t1
= sextract64(r1
, 0, 32);
588 int64_t t2
= sextract64(r2
, 0, 32);
589 int64_t t3
= sextract64(r3
, 0, 32);
592 result
= t2
+ (t1
* t3
);
593 return ssov32(env
, result
);
596 target_ulong
helper_madd32_suov(CPUTriCoreState
*env
, target_ulong r1
,
597 target_ulong r2
, target_ulong r3
)
599 uint64_t t1
= extract64(r1
, 0, 32);
600 uint64_t t2
= extract64(r2
, 0, 32);
601 uint64_t t3
= extract64(r3
, 0, 32);
604 result
= t2
+ (t1
* t3
);
605 return suov32_pos(env
, result
);
608 uint64_t helper_madd64_ssov(CPUTriCoreState
*env
, target_ulong r1
,
609 uint64_t r2
, target_ulong r3
)
612 int64_t t1
= sextract64(r1
, 0, 32);
613 int64_t t3
= sextract64(r3
, 0, 32);
618 ovf
= (ret
^ mul
) & ~(mul
^ r2
);
621 env
->PSW_USB_AV
= t1
^ t1
* 2u;
622 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
624 if ((int64_t)ovf
< 0) {
625 env
->PSW_USB_V
= (1 << 31);
626 env
->PSW_USB_SV
= (1 << 31);
627 /* ext_ret > MAX_INT */
630 /* ext_ret < MIN_INT */
642 helper_madd32_q_add_ssov(CPUTriCoreState
*env
, uint64_t r1
, uint64_t r2
)
648 env
->PSW_USB_AV
= (result
^ result
* 2u);
649 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
651 /* we do the saturation by hand, since we produce an overflow on the host
652 if the mul before was (0x80000000 * 0x80000000) << 1). If this is the
653 case, we flip the saturated value. */
654 if (r2
== 0x8000000000000000LL
) {
655 if (result
> 0x7fffffffLL
) {
656 env
->PSW_USB_V
= (1 << 31);
657 env
->PSW_USB_SV
= (1 << 31);
659 } else if (result
< -0x80000000LL
) {
660 env
->PSW_USB_V
= (1 << 31);
661 env
->PSW_USB_SV
= (1 << 31);
667 if (result
> 0x7fffffffLL
) {
668 env
->PSW_USB_V
= (1 << 31);
669 env
->PSW_USB_SV
= (1 << 31);
671 } else if (result
< -0x80000000LL
) {
672 env
->PSW_USB_V
= (1 << 31);
673 env
->PSW_USB_SV
= (1 << 31);
679 return (uint32_t)result
;
682 uint64_t helper_madd64_q_ssov(CPUTriCoreState
*env
, uint64_t r1
, uint32_t r2
,
683 uint32_t r3
, uint32_t n
)
685 int64_t t1
= (int64_t)r1
;
686 int64_t t2
= sextract64(r2
, 0, 32);
687 int64_t t3
= sextract64(r3
, 0, 32);
691 mul
= (t2
* t3
) << n
;
694 env
->PSW_USB_AV
= (result
^ result
* 2u) >> 32;
695 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
697 ovf
= (result
^ mul
) & ~(mul
^ t1
);
698 /* we do the saturation by hand, since we produce an overflow on the host
699 if the mul was (0x80000000 * 0x80000000) << 1). If this is the
700 case, we flip the saturated value. */
701 if ((r2
== 0x80000000) && (r3
== 0x80000000) && (n
== 1)) {
703 env
->PSW_USB_V
= (1 << 31);
704 env
->PSW_USB_SV
= (1 << 31);
705 /* ext_ret > MAX_INT */
708 /* ext_ret < MIN_INT */
717 env
->PSW_USB_V
= (1 << 31);
718 env
->PSW_USB_SV
= (1 << 31);
719 /* ext_ret > MAX_INT */
722 /* ext_ret < MIN_INT */
730 return (uint64_t)result
;
733 uint32_t helper_maddr_q_ssov(CPUTriCoreState
*env
, uint32_t r1
, uint32_t r2
,
734 uint32_t r3
, uint32_t n
)
736 int64_t t1
= sextract64(r1
, 0, 32);
737 int64_t t2
= sextract64(r2
, 0, 32);
738 int64_t t3
= sextract64(r3
, 0, 32);
741 if ((t2
== -0x8000ll
) && (t3
== -0x8000ll
) && (n
== 1)) {
744 mul
= (t2
* t3
) << n
;
747 ret
= t1
+ mul
+ 0x8000;
749 env
->PSW_USB_AV
= ret
^ ret
* 2u;
750 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
752 if (ret
> 0x7fffffffll
) {
753 env
->PSW_USB_V
= (1 << 31);
754 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
756 } else if (ret
< -0x80000000ll
) {
757 env
->PSW_USB_V
= (1 << 31);
758 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
763 return ret
& 0xffff0000ll
;
766 uint64_t helper_madd64_suov(CPUTriCoreState
*env
, target_ulong r1
,
767 uint64_t r2
, target_ulong r3
)
770 uint64_t t1
= extract64(r1
, 0, 32);
771 uint64_t t3
= extract64(r3
, 0, 32);
777 env
->PSW_USB_AV
= t1
^ t1
* 2u;
778 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
781 env
->PSW_USB_V
= (1 << 31);
782 env
->PSW_USB_SV
= (1 << 31);
791 target_ulong
helper_msub32_ssov(CPUTriCoreState
*env
, target_ulong r1
,
792 target_ulong r2
, target_ulong r3
)
794 int64_t t1
= sextract64(r1
, 0, 32);
795 int64_t t2
= sextract64(r2
, 0, 32);
796 int64_t t3
= sextract64(r3
, 0, 32);
799 result
= t2
- (t1
* t3
);
800 return ssov32(env
, result
);
803 target_ulong
helper_msub32_suov(CPUTriCoreState
*env
, target_ulong r1
,
804 target_ulong r2
, target_ulong r3
)
806 uint64_t t1
= extract64(r1
, 0, 32);
807 uint64_t t2
= extract64(r2
, 0, 32);
808 uint64_t t3
= extract64(r3
, 0, 32);
815 env
->PSW_USB_AV
= result
^ result
* 2u;
816 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
817 /* we calculate ovf by hand here, because the multiplication can overflow on
818 the host, which would give false results if we compare to less than
821 env
->PSW_USB_V
= (1 << 31);
822 env
->PSW_USB_SV
= (1 << 31);
830 uint64_t helper_msub64_ssov(CPUTriCoreState
*env
, target_ulong r1
,
831 uint64_t r2
, target_ulong r3
)
834 int64_t t1
= sextract64(r1
, 0, 32);
835 int64_t t3
= sextract64(r3
, 0, 32);
840 ovf
= (ret
^ r2
) & (mul
^ r2
);
843 env
->PSW_USB_AV
= t1
^ t1
* 2u;
844 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
846 if ((int64_t)ovf
< 0) {
847 env
->PSW_USB_V
= (1 << 31);
848 env
->PSW_USB_SV
= (1 << 31);
849 /* ext_ret > MAX_INT */
852 /* ext_ret < MIN_INT */
862 uint64_t helper_msub64_suov(CPUTriCoreState
*env
, target_ulong r1
,
863 uint64_t r2
, target_ulong r3
)
866 uint64_t t1
= extract64(r1
, 0, 32);
867 uint64_t t3
= extract64(r3
, 0, 32);
873 env
->PSW_USB_AV
= t1
^ t1
* 2u;
874 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
877 env
->PSW_USB_V
= (1 << 31);
878 env
->PSW_USB_SV
= (1 << 31);
888 helper_msub32_q_sub_ssov(CPUTriCoreState
*env
, uint64_t r1
, uint64_t r2
)
891 int64_t t1
= (int64_t)r1
;
892 int64_t t2
= (int64_t)r2
;
896 env
->PSW_USB_AV
= (result
^ result
* 2u);
897 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
899 /* we do the saturation by hand, since we produce an overflow on the host
900 if the mul before was (0x80000000 * 0x80000000) << 1). If this is the
901 case, we flip the saturated value. */
902 if (r2
== 0x8000000000000000LL
) {
903 if (result
> 0x7fffffffLL
) {
904 env
->PSW_USB_V
= (1 << 31);
905 env
->PSW_USB_SV
= (1 << 31);
907 } else if (result
< -0x80000000LL
) {
908 env
->PSW_USB_V
= (1 << 31);
909 env
->PSW_USB_SV
= (1 << 31);
915 if (result
> 0x7fffffffLL
) {
916 env
->PSW_USB_V
= (1 << 31);
917 env
->PSW_USB_SV
= (1 << 31);
919 } else if (result
< -0x80000000LL
) {
920 env
->PSW_USB_V
= (1 << 31);
921 env
->PSW_USB_SV
= (1 << 31);
927 return (uint32_t)result
;
930 uint64_t helper_msub64_q_ssov(CPUTriCoreState
*env
, uint64_t r1
, uint32_t r2
,
931 uint32_t r3
, uint32_t n
)
933 int64_t t1
= (int64_t)r1
;
934 int64_t t2
= sextract64(r2
, 0, 32);
935 int64_t t3
= sextract64(r3
, 0, 32);
939 mul
= (t2
* t3
) << n
;
942 env
->PSW_USB_AV
= (result
^ result
* 2u) >> 32;
943 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
945 ovf
= (result
^ t1
) & (t1
^ mul
);
946 /* we do the saturation by hand, since we produce an overflow on the host
947 if the mul before was (0x80000000 * 0x80000000) << 1). If this is the
948 case, we flip the saturated value. */
949 if (mul
== 0x8000000000000000LL
) {
951 env
->PSW_USB_V
= (1 << 31);
952 env
->PSW_USB_SV
= (1 << 31);
953 /* ext_ret > MAX_INT */
956 /* ext_ret < MIN_INT */
963 env
->PSW_USB_V
= (1 << 31);
964 env
->PSW_USB_SV
= (1 << 31);
965 /* ext_ret > MAX_INT */
968 /* ext_ret < MIN_INT */
977 return (uint64_t)result
;
980 uint32_t helper_msubr_q_ssov(CPUTriCoreState
*env
, uint32_t r1
, uint32_t r2
,
981 uint32_t r3
, uint32_t n
)
983 int64_t t1
= sextract64(r1
, 0, 32);
984 int64_t t2
= sextract64(r2
, 0, 32);
985 int64_t t3
= sextract64(r3
, 0, 32);
988 if ((t2
== -0x8000ll
) && (t3
== -0x8000ll
) && (n
== 1)) {
991 mul
= (t2
* t3
) << n
;
994 ret
= t1
- mul
+ 0x8000;
996 env
->PSW_USB_AV
= ret
^ ret
* 2u;
997 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
999 if (ret
> 0x7fffffffll
) {
1000 env
->PSW_USB_V
= (1 << 31);
1001 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1003 } else if (ret
< -0x80000000ll
) {
1004 env
->PSW_USB_V
= (1 << 31);
1005 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1010 return ret
& 0xffff0000ll
;
1013 uint32_t helper_abs_b(CPUTriCoreState
*env
, target_ulong arg
)
1020 for (i
= 0; i
< 4; i
++) {
1021 b
= sextract32(arg
, i
* 8, 8);
1022 b
= (b
>= 0) ? b
: (0 - b
);
1023 ovf
|= (b
> 0x7F) || (b
< -0x80);
1025 ret
|= (b
& 0xff) << (i
* 8);
1028 env
->PSW_USB_V
= ovf
<< 31;
1029 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1030 env
->PSW_USB_AV
= avf
<< 24;
1031 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1036 uint32_t helper_abs_h(CPUTriCoreState
*env
, target_ulong arg
)
1043 for (i
= 0; i
< 2; i
++) {
1044 h
= sextract32(arg
, i
* 16, 16);
1045 h
= (h
>= 0) ? h
: (0 - h
);
1046 ovf
|= (h
> 0x7FFF) || (h
< -0x8000);
1048 ret
|= (h
& 0xffff) << (i
* 16);
1051 env
->PSW_USB_V
= ovf
<< 31;
1052 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1053 env
->PSW_USB_AV
= avf
<< 16;
1054 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1059 uint32_t helper_absdif_b(CPUTriCoreState
*env
, target_ulong r1
, target_ulong r2
)
1067 for (i
= 0; i
< 4; i
++) {
1068 extr_r2
= sextract32(r2
, i
* 8, 8);
1069 b
= sextract32(r1
, i
* 8, 8);
1070 b
= (b
> extr_r2
) ? (b
- extr_r2
) : (extr_r2
- b
);
1071 ovf
|= (b
> 0x7F) || (b
< -0x80);
1073 ret
|= (b
& 0xff) << (i
* 8);
1076 env
->PSW_USB_V
= ovf
<< 31;
1077 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1078 env
->PSW_USB_AV
= avf
<< 24;
1079 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1083 uint32_t helper_absdif_h(CPUTriCoreState
*env
, target_ulong r1
, target_ulong r2
)
1091 for (i
= 0; i
< 2; i
++) {
1092 extr_r2
= sextract32(r2
, i
* 16, 16);
1093 h
= sextract32(r1
, i
* 16, 16);
1094 h
= (h
> extr_r2
) ? (h
- extr_r2
) : (extr_r2
- h
);
1095 ovf
|= (h
> 0x7FFF) || (h
< -0x8000);
1097 ret
|= (h
& 0xffff) << (i
* 16);
1100 env
->PSW_USB_V
= ovf
<< 31;
1101 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1102 env
->PSW_USB_AV
= avf
<< 16;
1103 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1108 uint32_t helper_addr_h(CPUTriCoreState
*env
, uint64_t r1
, uint32_t r2_l
,
1111 int64_t mul_res0
= sextract64(r1
, 0, 32);
1112 int64_t mul_res1
= sextract64(r1
, 32, 32);
1113 int64_t r2_low
= sextract64(r2_l
, 0, 32);
1114 int64_t r2_high
= sextract64(r2_h
, 0, 32);
1115 int64_t result0
, result1
;
1116 uint32_t ovf0
, ovf1
;
1117 uint32_t avf0
, avf1
;
1121 result0
= r2_low
+ mul_res0
+ 0x8000;
1122 result1
= r2_high
+ mul_res1
+ 0x8000;
1124 if ((result0
> INT32_MAX
) || (result0
< INT32_MIN
)) {
1128 if ((result1
> INT32_MAX
) || (result1
< INT32_MIN
)) {
1132 env
->PSW_USB_V
= ovf0
| ovf1
;
1133 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1135 avf0
= result0
* 2u;
1136 avf0
= result0
^ avf0
;
1137 avf1
= result1
* 2u;
1138 avf1
= result1
^ avf1
;
1140 env
->PSW_USB_AV
= avf0
| avf1
;
1141 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1143 return (result1
& 0xffff0000ULL
) | ((result0
>> 16) & 0xffffULL
);
1146 uint32_t helper_addsur_h(CPUTriCoreState
*env
, uint64_t r1
, uint32_t r2_l
,
1149 int64_t mul_res0
= sextract64(r1
, 0, 32);
1150 int64_t mul_res1
= sextract64(r1
, 32, 32);
1151 int64_t r2_low
= sextract64(r2_l
, 0, 32);
1152 int64_t r2_high
= sextract64(r2_h
, 0, 32);
1153 int64_t result0
, result1
;
1154 uint32_t ovf0
, ovf1
;
1155 uint32_t avf0
, avf1
;
1159 result0
= r2_low
- mul_res0
+ 0x8000;
1160 result1
= r2_high
+ mul_res1
+ 0x8000;
1162 if ((result0
> INT32_MAX
) || (result0
< INT32_MIN
)) {
1166 if ((result1
> INT32_MAX
) || (result1
< INT32_MIN
)) {
1170 env
->PSW_USB_V
= ovf0
| ovf1
;
1171 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1173 avf0
= result0
* 2u;
1174 avf0
= result0
^ avf0
;
1175 avf1
= result1
* 2u;
1176 avf1
= result1
^ avf1
;
1178 env
->PSW_USB_AV
= avf0
| avf1
;
1179 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1181 return (result1
& 0xffff0000ULL
) | ((result0
>> 16) & 0xffffULL
);
1184 uint32_t helper_maddr_q(CPUTriCoreState
*env
, uint32_t r1
, uint32_t r2
,
1185 uint32_t r3
, uint32_t n
)
1187 int64_t t1
= sextract64(r1
, 0, 32);
1188 int64_t t2
= sextract64(r2
, 0, 32);
1189 int64_t t3
= sextract64(r3
, 0, 32);
1192 if ((t2
== -0x8000ll
) && (t3
== -0x8000ll
) && (n
== 1)) {
1195 mul
= (t2
* t3
) << n
;
1198 ret
= t1
+ mul
+ 0x8000;
1200 if ((ret
> 0x7fffffffll
) || (ret
< -0x80000000ll
)) {
1201 env
->PSW_USB_V
= (1 << 31);
1202 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1206 env
->PSW_USB_AV
= ret
^ ret
* 2u;
1207 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1209 return ret
& 0xffff0000ll
;
1212 uint32_t helper_add_b(CPUTriCoreState
*env
, target_ulong r1
, target_ulong r2
)
1215 int32_t extr_r1
, extr_r2
;
1220 for (i
= 0; i
< 4; i
++) {
1221 extr_r1
= sextract32(r1
, i
* 8, 8);
1222 extr_r2
= sextract32(r2
, i
* 8, 8);
1224 b
= extr_r1
+ extr_r2
;
1225 ovf
|= ((b
> 0x7f) || (b
< -0x80));
1227 ret
|= ((b
& 0xff) << (i
*8));
1230 env
->PSW_USB_V
= (ovf
<< 31);
1231 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1232 env
->PSW_USB_AV
= avf
<< 24;
1233 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1238 uint32_t helper_add_h(CPUTriCoreState
*env
, target_ulong r1
, target_ulong r2
)
1241 int32_t extr_r1
, extr_r2
;
1246 for (i
= 0; i
< 2; i
++) {
1247 extr_r1
= sextract32(r1
, i
* 16, 16);
1248 extr_r2
= sextract32(r2
, i
* 16, 16);
1249 h
= extr_r1
+ extr_r2
;
1250 ovf
|= ((h
> 0x7fff) || (h
< -0x8000));
1252 ret
|= (h
& 0xffff) << (i
* 16);
1255 env
->PSW_USB_V
= (ovf
<< 31);
1256 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1257 env
->PSW_USB_AV
= (avf
<< 16);
1258 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1263 uint32_t helper_subr_h(CPUTriCoreState
*env
, uint64_t r1
, uint32_t r2_l
,
1266 int64_t mul_res0
= sextract64(r1
, 0, 32);
1267 int64_t mul_res1
= sextract64(r1
, 32, 32);
1268 int64_t r2_low
= sextract64(r2_l
, 0, 32);
1269 int64_t r2_high
= sextract64(r2_h
, 0, 32);
1270 int64_t result0
, result1
;
1271 uint32_t ovf0
, ovf1
;
1272 uint32_t avf0
, avf1
;
1276 result0
= r2_low
- mul_res0
+ 0x8000;
1277 result1
= r2_high
- mul_res1
+ 0x8000;
1279 if ((result0
> INT32_MAX
) || (result0
< INT32_MIN
)) {
1283 if ((result1
> INT32_MAX
) || (result1
< INT32_MIN
)) {
1287 env
->PSW_USB_V
= ovf0
| ovf1
;
1288 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1290 avf0
= result0
* 2u;
1291 avf0
= result0
^ avf0
;
1292 avf1
= result1
* 2u;
1293 avf1
= result1
^ avf1
;
1295 env
->PSW_USB_AV
= avf0
| avf1
;
1296 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1298 return (result1
& 0xffff0000ULL
) | ((result0
>> 16) & 0xffffULL
);
1301 uint32_t helper_subadr_h(CPUTriCoreState
*env
, uint64_t r1
, uint32_t r2_l
,
1304 int64_t mul_res0
= sextract64(r1
, 0, 32);
1305 int64_t mul_res1
= sextract64(r1
, 32, 32);
1306 int64_t r2_low
= sextract64(r2_l
, 0, 32);
1307 int64_t r2_high
= sextract64(r2_h
, 0, 32);
1308 int64_t result0
, result1
;
1309 uint32_t ovf0
, ovf1
;
1310 uint32_t avf0
, avf1
;
1314 result0
= r2_low
+ mul_res0
+ 0x8000;
1315 result1
= r2_high
- mul_res1
+ 0x8000;
1317 if ((result0
> INT32_MAX
) || (result0
< INT32_MIN
)) {
1321 if ((result1
> INT32_MAX
) || (result1
< INT32_MIN
)) {
1325 env
->PSW_USB_V
= ovf0
| ovf1
;
1326 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1328 avf0
= result0
* 2u;
1329 avf0
= result0
^ avf0
;
1330 avf1
= result1
* 2u;
1331 avf1
= result1
^ avf1
;
1333 env
->PSW_USB_AV
= avf0
| avf1
;
1334 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1336 return (result1
& 0xffff0000ULL
) | ((result0
>> 16) & 0xffffULL
);
1339 uint32_t helper_msubr_q(CPUTriCoreState
*env
, uint32_t r1
, uint32_t r2
,
1340 uint32_t r3
, uint32_t n
)
1342 int64_t t1
= sextract64(r1
, 0, 32);
1343 int64_t t2
= sextract64(r2
, 0, 32);
1344 int64_t t3
= sextract64(r3
, 0, 32);
1347 if ((t2
== -0x8000ll
) && (t3
== -0x8000ll
) && (n
== 1)) {
1350 mul
= (t2
* t3
) << n
;
1353 ret
= t1
- mul
+ 0x8000;
1355 if ((ret
> 0x7fffffffll
) || (ret
< -0x80000000ll
)) {
1356 env
->PSW_USB_V
= (1 << 31);
1357 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1361 env
->PSW_USB_AV
= ret
^ ret
* 2u;
1362 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1364 return ret
& 0xffff0000ll
;
1367 uint32_t helper_sub_b(CPUTriCoreState
*env
, target_ulong r1
, target_ulong r2
)
1370 int32_t extr_r1
, extr_r2
;
1375 for (i
= 0; i
< 4; i
++) {
1376 extr_r1
= sextract32(r1
, i
* 8, 8);
1377 extr_r2
= sextract32(r2
, i
* 8, 8);
1379 b
= extr_r1
- extr_r2
;
1380 ovf
|= ((b
> 0x7f) || (b
< -0x80));
1382 ret
|= ((b
& 0xff) << (i
*8));
1385 env
->PSW_USB_V
= (ovf
<< 31);
1386 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1387 env
->PSW_USB_AV
= avf
<< 24;
1388 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1393 uint32_t helper_sub_h(CPUTriCoreState
*env
, target_ulong r1
, target_ulong r2
)
1396 int32_t extr_r1
, extr_r2
;
1401 for (i
= 0; i
< 2; i
++) {
1402 extr_r1
= sextract32(r1
, i
* 16, 16);
1403 extr_r2
= sextract32(r2
, i
* 16, 16);
1404 h
= extr_r1
- extr_r2
;
1405 ovf
|= ((h
> 0x7fff) || (h
< -0x8000));
1407 ret
|= (h
& 0xffff) << (i
* 16);
1410 env
->PSW_USB_V
= (ovf
<< 31);
1411 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1412 env
->PSW_USB_AV
= avf
<< 16;
1413 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1418 uint32_t helper_eq_b(target_ulong r1
, target_ulong r2
)
1425 for (i
= 0; i
< 4; i
++) {
1426 if ((r1
& msk
) == (r2
& msk
)) {
1435 uint32_t helper_eq_h(target_ulong r1
, target_ulong r2
)
1439 if ((r1
& 0xffff) == (r2
& 0xffff)) {
1443 if ((r1
& 0xffff0000) == (r2
& 0xffff0000)) {
1450 uint32_t helper_eqany_b(target_ulong r1
, target_ulong r2
)
1455 for (i
= 0; i
< 4; i
++) {
1456 ret
|= (sextract32(r1
, i
* 8, 8) == sextract32(r2
, i
* 8, 8));
1462 uint32_t helper_eqany_h(target_ulong r1
, target_ulong r2
)
1466 ret
= (sextract32(r1
, 0, 16) == sextract32(r2
, 0, 16));
1467 ret
|= (sextract32(r1
, 16, 16) == sextract32(r2
, 16, 16));
1472 uint32_t helper_lt_b(target_ulong r1
, target_ulong r2
)
1477 for (i
= 0; i
< 4; i
++) {
1478 if (sextract32(r1
, i
* 8, 8) < sextract32(r2
, i
* 8, 8)) {
1479 ret
|= (0xff << (i
* 8));
1486 uint32_t helper_lt_bu(target_ulong r1
, target_ulong r2
)
1491 for (i
= 0; i
< 4; i
++) {
1492 if (extract32(r1
, i
* 8, 8) < extract32(r2
, i
* 8, 8)) {
1493 ret
|= (0xff << (i
* 8));
1500 uint32_t helper_lt_h(target_ulong r1
, target_ulong r2
)
1504 if (sextract32(r1
, 0, 16) < sextract32(r2
, 0, 16)) {
1508 if (sextract32(r1
, 16, 16) < sextract32(r2
, 16, 16)) {
1515 uint32_t helper_lt_hu(target_ulong r1
, target_ulong r2
)
1519 if (extract32(r1
, 0, 16) < extract32(r2
, 0, 16)) {
1523 if (extract32(r1
, 16, 16) < extract32(r2
, 16, 16)) {
1530 #define EXTREMA_H_B(name, op) \
1531 uint32_t helper_##name ##_b(target_ulong r1, target_ulong r2) \
1533 int32_t i, extr_r1, extr_r2; \
1536 for (i = 0; i < 4; i++) { \
1537 extr_r1 = sextract32(r1, i * 8, 8); \
1538 extr_r2 = sextract32(r2, i * 8, 8); \
1539 extr_r1 = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
1540 ret |= (extr_r1 & 0xff) << (i * 8); \
1545 uint32_t helper_##name ##_bu(target_ulong r1, target_ulong r2)\
1548 uint32_t extr_r1, extr_r2; \
1551 for (i = 0; i < 4; i++) { \
1552 extr_r1 = extract32(r1, i * 8, 8); \
1553 extr_r2 = extract32(r2, i * 8, 8); \
1554 extr_r1 = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
1555 ret |= (extr_r1 & 0xff) << (i * 8); \
1560 uint32_t helper_##name ##_h(target_ulong r1, target_ulong r2) \
1562 int32_t extr_r1, extr_r2; \
1565 extr_r1 = sextract32(r1, 0, 16); \
1566 extr_r2 = sextract32(r2, 0, 16); \
1567 ret = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
1568 ret = ret & 0xffff; \
1570 extr_r1 = sextract32(r1, 16, 16); \
1571 extr_r2 = sextract32(r2, 16, 16); \
1572 extr_r1 = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
1573 ret |= extr_r1 << 16; \
1578 uint32_t helper_##name ##_hu(target_ulong r1, target_ulong r2)\
1580 uint32_t extr_r1, extr_r2; \
1583 extr_r1 = extract32(r1, 0, 16); \
1584 extr_r2 = extract32(r2, 0, 16); \
1585 ret = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
1586 ret = ret & 0xffff; \
1588 extr_r1 = extract32(r1, 16, 16); \
1589 extr_r2 = extract32(r2, 16, 16); \
1590 extr_r1 = (extr_r1 op extr_r2) ? extr_r1 : extr_r2; \
1591 ret |= extr_r1 << (16); \
1596 uint64_t helper_ix##name(uint64_t r1, uint32_t r2) \
1598 int64_t r2l, r2h, r1hl; \
1601 ret = ((r1 + 2) & 0xffff); \
1602 r2l = sextract64(r2, 0, 16); \
1603 r2h = sextract64(r2, 16, 16); \
1604 r1hl = sextract64(r1, 32, 16); \
1606 if ((r2l op ## = r2h) && (r2l op r1hl)) { \
1607 ret |= (r2l & 0xffff) << 32; \
1608 ret |= extract64(r1, 0, 16) << 16; \
1609 } else if ((r2h op r2l) && (r2h op r1hl)) { \
1610 ret |= extract64(r2, 16, 16) << 32; \
1611 ret |= extract64(r1 + 1, 0, 16) << 16; \
1613 ret |= r1 & 0xffffffff0000ull; \
1618 uint64_t helper_ix##name ##_u(uint64_t r1, uint32_t r2) \
1620 int64_t r2l, r2h, r1hl; \
1623 ret = ((r1 + 2) & 0xffff); \
1624 r2l = extract64(r2, 0, 16); \
1625 r2h = extract64(r2, 16, 16); \
1626 r1hl = extract64(r1, 32, 16); \
1628 if ((r2l op ## = r2h) && (r2l op r1hl)) { \
1629 ret |= (r2l & 0xffff) << 32; \
1630 ret |= extract64(r1, 0, 16) << 16; \
1631 } else if ((r2h op r2l) && (r2h op r1hl)) { \
1632 ret |= extract64(r2, 16, 16) << 32; \
1633 ret |= extract64(r1 + 1, 0, 16) << 16; \
1635 ret |= r1 & 0xffffffff0000ull; \
1645 uint32_t helper_clo(target_ulong r1
)
1650 uint32_t helper_clo_h(target_ulong r1
)
1652 uint32_t ret_hw0
= extract32(r1
, 0, 16);
1653 uint32_t ret_hw1
= extract32(r1
, 16, 16);
1655 ret_hw0
= clo32(ret_hw0
<< 16);
1656 ret_hw1
= clo32(ret_hw1
<< 16);
1665 return ret_hw0
| (ret_hw1
<< 16);
1668 uint32_t helper_clz(target_ulong r1
)
1673 uint32_t helper_clz_h(target_ulong r1
)
1675 uint32_t ret_hw0
= extract32(r1
, 0, 16);
1676 uint32_t ret_hw1
= extract32(r1
, 16, 16);
1678 ret_hw0
= clz32(ret_hw0
<< 16);
1679 ret_hw1
= clz32(ret_hw1
<< 16);
1688 return ret_hw0
| (ret_hw1
<< 16);
1691 uint32_t helper_cls(target_ulong r1
)
1696 uint32_t helper_cls_h(target_ulong r1
)
1698 uint32_t ret_hw0
= extract32(r1
, 0, 16);
1699 uint32_t ret_hw1
= extract32(r1
, 16, 16);
1701 ret_hw0
= clrsb32(ret_hw0
<< 16);
1702 ret_hw1
= clrsb32(ret_hw1
<< 16);
1711 return ret_hw0
| (ret_hw1
<< 16);
1714 uint32_t helper_sh(target_ulong r1
, target_ulong r2
)
1716 int32_t shift_count
= sextract32(r2
, 0, 6);
1718 if (shift_count
== -32) {
1720 } else if (shift_count
< 0) {
1721 return r1
>> -shift_count
;
1723 return r1
<< shift_count
;
1727 uint32_t helper_sh_h(target_ulong r1
, target_ulong r2
)
1729 int32_t ret_hw0
, ret_hw1
;
1730 int32_t shift_count
;
1732 shift_count
= sextract32(r2
, 0, 5);
1734 if (shift_count
== -16) {
1736 } else if (shift_count
< 0) {
1737 ret_hw0
= extract32(r1
, 0, 16) >> -shift_count
;
1738 ret_hw1
= extract32(r1
, 16, 16) >> -shift_count
;
1739 return (ret_hw0
& 0xffff) | (ret_hw1
<< 16);
1741 ret_hw0
= extract32(r1
, 0, 16) << shift_count
;
1742 ret_hw1
= extract32(r1
, 16, 16) << shift_count
;
1743 return (ret_hw0
& 0xffff) | (ret_hw1
<< 16);
1747 uint32_t helper_sha(CPUTriCoreState
*env
, target_ulong r1
, target_ulong r2
)
1749 int32_t shift_count
;
1753 shift_count
= sextract32(r2
, 0, 6);
1754 t1
= sextract32(r1
, 0, 32);
1756 if (shift_count
== 0) {
1757 env
->PSW_USB_C
= env
->PSW_USB_V
= 0;
1759 } else if (shift_count
== -32) {
1760 env
->PSW_USB_C
= r1
;
1763 } else if (shift_count
> 0) {
1764 result
= t1
<< shift_count
;
1766 env
->PSW_USB_C
= ((result
& 0xffffffff00000000ULL
) != 0);
1768 env
->PSW_USB_V
= (((result
> 0x7fffffffLL
) ||
1769 (result
< -0x80000000LL
)) << 31);
1771 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1772 ret
= (uint32_t)result
;
1775 env
->PSW_USB_C
= (r1
& ((1 << -shift_count
) - 1));
1776 ret
= t1
>> -shift_count
;
1779 env
->PSW_USB_AV
= ret
^ ret
* 2u;
1780 env
->PSW_USB_SAV
|= env
->PSW_USB_AV
;
1785 uint32_t helper_sha_h(target_ulong r1
, target_ulong r2
)
1787 int32_t shift_count
;
1788 int32_t ret_hw0
, ret_hw1
;
1790 shift_count
= sextract32(r2
, 0, 5);
1792 if (shift_count
== 0) {
1794 } else if (shift_count
< 0) {
1795 ret_hw0
= sextract32(r1
, 0, 16) >> -shift_count
;
1796 ret_hw1
= sextract32(r1
, 16, 16) >> -shift_count
;
1797 return (ret_hw0
& 0xffff) | (ret_hw1
<< 16);
1799 ret_hw0
= sextract32(r1
, 0, 16) << shift_count
;
1800 ret_hw1
= sextract32(r1
, 16, 16) << shift_count
;
1801 return (ret_hw0
& 0xffff) | (ret_hw1
<< 16);
1805 uint32_t helper_bmerge(target_ulong r1
, target_ulong r2
)
1810 for (i
= 0; i
< 16; i
++) {
1811 ret
|= (r1
& 1) << (2 * i
+ 1);
1812 ret
|= (r2
& 1) << (2 * i
);
1819 uint64_t helper_bsplit(uint32_t r1
)
1825 for (i
= 0; i
< 32; i
= i
+ 2) {
1827 ret
|= (r1
& 1) << (i
/2);
1830 ret
|= (uint64_t)(r1
& 1) << (i
/2 + 32);
1836 uint32_t helper_parity(target_ulong r1
)
1843 for (i
= 0; i
< 8; i
++) {
1849 for (i
= 0; i
< 8; i
++) {
1856 for (i
= 0; i
< 8; i
++) {
1863 for (i
= 0; i
< 8; i
++) {
1872 uint32_t helper_pack(uint32_t carry
, uint32_t r1_low
, uint32_t r1_high
,
1876 int32_t fp_exp
, fp_frac
, temp_exp
, fp_exp_frac
;
1877 int32_t int_exp
= r1_high
;
1878 int32_t int_mant
= r1_low
;
1879 uint32_t flag_rnd
= (int_mant
& (1 << 7)) && (
1880 (int_mant
& (1 << 8)) ||
1881 (int_mant
& 0x7f) ||
1883 if (((int_mant
& (1<<31)) == 0) && (int_exp
== 255)) {
1885 fp_frac
= extract32(int_mant
, 8, 23);
1886 } else if ((int_mant
& (1<<31)) && (int_exp
>= 127)) {
1889 } else if ((int_mant
& (1<<31)) && (int_exp
<= -128)) {
1892 } else if (int_mant
== 0) {
1896 if (((int_mant
& (1 << 31)) == 0)) {
1899 temp_exp
= int_exp
+ 128;
1901 fp_exp_frac
= (((temp_exp
& 0xff) << 23) |
1902 extract32(int_mant
, 8, 23))
1904 fp_exp
= extract32(fp_exp_frac
, 23, 8);
1905 fp_frac
= extract32(fp_exp_frac
, 0, 23);
1907 ret
= r2
& (1 << 31);
1908 ret
= ret
+ (fp_exp
<< 23);
1909 ret
= ret
+ (fp_frac
& 0x7fffff);
1914 uint64_t helper_unpack(target_ulong arg1
)
1916 int32_t fp_exp
= extract32(arg1
, 23, 8);
1917 int32_t fp_frac
= extract32(arg1
, 0, 23);
1919 int32_t int_exp
, int_mant
;
1921 if (fp_exp
== 255) {
1923 int_mant
= (fp_frac
<< 7);
1924 } else if ((fp_exp
== 0) && (fp_frac
== 0)) {
1927 } else if ((fp_exp
== 0) && (fp_frac
!= 0)) {
1929 int_mant
= (fp_frac
<< 7);
1931 int_exp
= fp_exp
- 127;
1932 int_mant
= (fp_frac
<< 7);
1933 int_mant
|= (1 << 30);
1942 uint64_t helper_dvinit_b_13(CPUTriCoreState
*env
, uint32_t r1
, uint32_t r2
)
1945 int32_t abs_sig_dividend
, abs_base_dividend
, abs_divisor
;
1946 int32_t quotient_sign
;
1948 ret
= sextract32(r1
, 0, 32);
1951 if (!((r1
& 0x80000000) == (r2
& 0x80000000))) {
1956 abs_sig_dividend
= abs(r1
) >> 7;
1957 abs_base_dividend
= abs(r1
) & 0x7f;
1958 abs_divisor
= abs(r1
);
1961 if ((quotient_sign
) && (abs_divisor
)) {
1962 env
->PSW_USB_V
= (((abs_sig_dividend
== abs_divisor
) &&
1963 (abs_base_dividend
>= abs_divisor
)) ||
1964 (abs_sig_dividend
> abs_divisor
));
1966 env
->PSW_USB_V
= (abs_sig_dividend
>= abs_divisor
);
1968 env
->PSW_USB_V
= env
->PSW_USB_V
<< 31;
1969 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1970 env
->PSW_USB_AV
= 0;
1975 uint64_t helper_dvinit_b_131(CPUTriCoreState
*env
, uint32_t r1
, uint32_t r2
)
1977 uint64_t ret
= sextract32(r1
, 0, 32);
1980 if (!((r1
& 0x80000000) == (r2
& 0x80000000))) {
1984 env
->PSW_USB_V
= ((r2
== 0) || ((r2
== 0xffffffff) && (r1
== 0xffffff80)));
1985 env
->PSW_USB_V
= env
->PSW_USB_V
<< 31;
1986 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
1987 env
->PSW_USB_AV
= 0;
1992 uint64_t helper_dvinit_h_13(CPUTriCoreState
*env
, uint32_t r1
, uint32_t r2
)
1995 int32_t abs_sig_dividend
, abs_base_dividend
, abs_divisor
;
1996 int32_t quotient_sign
;
1998 ret
= sextract32(r1
, 0, 32);
2001 if (!((r1
& 0x80000000) == (r2
& 0x80000000))) {
2006 abs_sig_dividend
= abs(r1
) >> 7;
2007 abs_base_dividend
= abs(r1
) & 0x7f;
2008 abs_divisor
= abs(r1
);
2011 if ((quotient_sign
) && (abs_divisor
)) {
2012 env
->PSW_USB_V
= (((abs_sig_dividend
== abs_divisor
) &&
2013 (abs_base_dividend
>= abs_divisor
)) ||
2014 (abs_sig_dividend
> abs_divisor
));
2016 env
->PSW_USB_V
= (abs_sig_dividend
>= abs_divisor
);
2018 env
->PSW_USB_V
= env
->PSW_USB_V
<< 31;
2019 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
2020 env
->PSW_USB_AV
= 0;
2025 uint64_t helper_dvinit_h_131(CPUTriCoreState
*env
, uint32_t r1
, uint32_t r2
)
2027 uint64_t ret
= sextract32(r1
, 0, 32);
2030 if (!((r1
& 0x80000000) == (r2
& 0x80000000))) {
2034 env
->PSW_USB_V
= ((r2
== 0) || ((r2
== 0xffffffff) && (r1
== 0xffff8000)));
2035 env
->PSW_USB_V
= env
->PSW_USB_V
<< 31;
2036 env
->PSW_USB_SV
|= env
->PSW_USB_V
;
2037 env
->PSW_USB_AV
= 0;
2042 uint64_t helper_dvadj(uint64_t r1
, uint32_t r2
)
2044 int32_t x_sign
= (r1
>> 63);
2045 int32_t q_sign
= x_sign
^ (r2
>> 31);
2046 int32_t eq_pos
= x_sign
& ((r1
>> 32) == r2
);
2047 int32_t eq_neg
= x_sign
& ((r1
>> 32) == -r2
);
2049 uint64_t ret
, remainder
;
2051 if ((q_sign
& ~eq_neg
) | eq_pos
) {
2052 quotient
= (r1
+ 1) & 0xffffffff;
2054 quotient
= r1
& 0xffffffff;
2057 if (eq_pos
| eq_neg
) {
2060 remainder
= (r1
& 0xffffffff00000000ull
);
2062 ret
= remainder
|quotient
;
2066 uint64_t helper_dvstep(uint64_t r1
, uint32_t r2
)
2068 int32_t dividend_sign
= extract64(r1
, 63, 1);
2069 int32_t divisor_sign
= extract32(r2
, 31, 1);
2070 int32_t quotient_sign
= (dividend_sign
!= divisor_sign
);
2071 int32_t addend
, dividend_quotient
, remainder
;
2074 if (quotient_sign
) {
2079 dividend_quotient
= (int32_t)r1
;
2080 remainder
= (int32_t)(r1
>> 32);
2082 for (i
= 0; i
< 8; i
++) {
2083 remainder
= (remainder
<< 1) | extract32(dividend_quotient
, 31, 1);
2084 dividend_quotient
<<= 1;
2085 temp
= remainder
+ addend
;
2086 if ((temp
< 0) == dividend_sign
) {
2089 if (((temp
< 0) == dividend_sign
)) {
2090 dividend_quotient
= dividend_quotient
| !quotient_sign
;
2092 dividend_quotient
= dividend_quotient
| quotient_sign
;
2095 return ((uint64_t)remainder
<< 32) | (uint32_t)dividend_quotient
;
2098 uint64_t helper_dvstep_u(uint64_t r1
, uint32_t r2
)
2100 int32_t dividend_quotient
= extract64(r1
, 0, 32);
2101 int64_t remainder
= extract64(r1
, 32, 32);
2104 for (i
= 0; i
< 8; i
++) {
2105 remainder
= (remainder
<< 1) | extract32(dividend_quotient
, 31, 1);
2106 dividend_quotient
<<= 1;
2107 temp
= (remainder
& 0xffffffff) - r2
;
2111 dividend_quotient
= dividend_quotient
| !(temp
< 0);
2113 return ((uint64_t)remainder
<< 32) | (uint32_t)dividend_quotient
;
2116 uint64_t helper_mul_h(uint32_t arg00
, uint32_t arg01
,
2117 uint32_t arg10
, uint32_t arg11
, uint32_t n
)
2120 uint32_t result0
, result1
;
2122 int32_t sc1
= ((arg00
& 0xffff) == 0x8000) &&
2123 ((arg10
& 0xffff) == 0x8000) && (n
== 1);
2124 int32_t sc0
= ((arg01
& 0xffff) == 0x8000) &&
2125 ((arg11
& 0xffff) == 0x8000) && (n
== 1);
2127 result1
= 0x7fffffff;
2129 result1
= (((uint32_t)(arg00
* arg10
)) << n
);
2132 result0
= 0x7fffffff;
2134 result0
= (((uint32_t)(arg01
* arg11
)) << n
);
2136 ret
= (((uint64_t)result1
<< 32)) | result0
;
2140 uint64_t helper_mulm_h(uint32_t arg00
, uint32_t arg01
,
2141 uint32_t arg10
, uint32_t arg11
, uint32_t n
)
2144 int64_t result0
, result1
;
2146 int32_t sc1
= ((arg00
& 0xffff) == 0x8000) &&
2147 ((arg10
& 0xffff) == 0x8000) && (n
== 1);
2148 int32_t sc0
= ((arg01
& 0xffff) == 0x8000) &&
2149 ((arg11
& 0xffff) == 0x8000) && (n
== 1);
2152 result1
= 0x7fffffff;
2154 result1
= (((int32_t)arg00
* (int32_t)arg10
) << n
);
2157 result0
= 0x7fffffff;
2159 result0
= (((int32_t)arg01
* (int32_t)arg11
) << n
);
2161 ret
= (result1
+ result0
);
2165 uint32_t helper_mulr_h(uint32_t arg00
, uint32_t arg01
,
2166 uint32_t arg10
, uint32_t arg11
, uint32_t n
)
2168 uint32_t result0
, result1
;
2170 int32_t sc1
= ((arg00
& 0xffff) == 0x8000) &&
2171 ((arg10
& 0xffff) == 0x8000) && (n
== 1);
2172 int32_t sc0
= ((arg01
& 0xffff) == 0x8000) &&
2173 ((arg11
& 0xffff) == 0x8000) && (n
== 1);
2176 result1
= 0x7fffffff;
2178 result1
= ((arg00
* arg10
) << n
) + 0x8000;
2181 result0
= 0x7fffffff;
2183 result0
= ((arg01
* arg11
) << n
) + 0x8000;
2185 return (result1
& 0xffff0000) | (result0
>> 16);
2188 /* context save area (CSA) related helpers */
2190 static int cdc_increment(target_ulong
*psw
)
2192 if ((*psw
& MASK_PSW_CDC
) == 0x7f) {
2197 /* check for overflow */
2198 int lo
= clo32((*psw
& MASK_PSW_CDC
) << (32 - 7));
2199 int mask
= (1u << (7 - lo
)) - 1;
2200 int count
= *psw
& mask
;
2208 static int cdc_decrement(target_ulong
*psw
)
2210 if ((*psw
& MASK_PSW_CDC
) == 0x7f) {
2213 /* check for underflow */
2214 int lo
= clo32((*psw
& MASK_PSW_CDC
) << (32 - 7));
2215 int mask
= (1u << (7 - lo
)) - 1;
2216 int count
= *psw
& mask
;
2224 static bool cdc_zero(target_ulong
*psw
)
2226 int cdc
= *psw
& MASK_PSW_CDC
;
2227 /* Returns TRUE if PSW.CDC.COUNT == 0 or if PSW.CDC ==
2228 7'b1111111, otherwise returns FALSE. */
2232 /* find CDC.COUNT */
2233 int lo
= clo32((*psw
& MASK_PSW_CDC
) << (32 - 7));
2234 int mask
= (1u << (7 - lo
)) - 1;
2235 int count
= *psw
& mask
;
2239 static void save_context_upper(CPUTriCoreState
*env
, int ea
)
2241 cpu_stl_data(env
, ea
, env
->PCXI
);
2242 cpu_stl_data(env
, ea
+4, env
->PSW
);
2243 cpu_stl_data(env
, ea
+8, env
->gpr_a
[10]);
2244 cpu_stl_data(env
, ea
+12, env
->gpr_a
[11]);
2245 cpu_stl_data(env
, ea
+16, env
->gpr_d
[8]);
2246 cpu_stl_data(env
, ea
+20, env
->gpr_d
[9]);
2247 cpu_stl_data(env
, ea
+24, env
->gpr_d
[10]);
2248 cpu_stl_data(env
, ea
+28, env
->gpr_d
[11]);
2249 cpu_stl_data(env
, ea
+32, env
->gpr_a
[12]);
2250 cpu_stl_data(env
, ea
+36, env
->gpr_a
[13]);
2251 cpu_stl_data(env
, ea
+40, env
->gpr_a
[14]);
2252 cpu_stl_data(env
, ea
+44, env
->gpr_a
[15]);
2253 cpu_stl_data(env
, ea
+48, env
->gpr_d
[12]);
2254 cpu_stl_data(env
, ea
+52, env
->gpr_d
[13]);
2255 cpu_stl_data(env
, ea
+56, env
->gpr_d
[14]);
2256 cpu_stl_data(env
, ea
+60, env
->gpr_d
[15]);
2259 static void save_context_lower(CPUTriCoreState
*env
, int ea
)
2261 cpu_stl_data(env
, ea
, env
->PCXI
);
2262 cpu_stl_data(env
, ea
+4, env
->gpr_a
[11]);
2263 cpu_stl_data(env
, ea
+8, env
->gpr_a
[2]);
2264 cpu_stl_data(env
, ea
+12, env
->gpr_a
[3]);
2265 cpu_stl_data(env
, ea
+16, env
->gpr_d
[0]);
2266 cpu_stl_data(env
, ea
+20, env
->gpr_d
[1]);
2267 cpu_stl_data(env
, ea
+24, env
->gpr_d
[2]);
2268 cpu_stl_data(env
, ea
+28, env
->gpr_d
[3]);
2269 cpu_stl_data(env
, ea
+32, env
->gpr_a
[4]);
2270 cpu_stl_data(env
, ea
+36, env
->gpr_a
[5]);
2271 cpu_stl_data(env
, ea
+40, env
->gpr_a
[6]);
2272 cpu_stl_data(env
, ea
+44, env
->gpr_a
[7]);
2273 cpu_stl_data(env
, ea
+48, env
->gpr_d
[4]);
2274 cpu_stl_data(env
, ea
+52, env
->gpr_d
[5]);
2275 cpu_stl_data(env
, ea
+56, env
->gpr_d
[6]);
2276 cpu_stl_data(env
, ea
+60, env
->gpr_d
[7]);
2279 static void restore_context_upper(CPUTriCoreState
*env
, int ea
,
2280 target_ulong
*new_PCXI
, target_ulong
*new_PSW
)
2282 *new_PCXI
= cpu_ldl_data(env
, ea
);
2283 *new_PSW
= cpu_ldl_data(env
, ea
+4);
2284 env
->gpr_a
[10] = cpu_ldl_data(env
, ea
+8);
2285 env
->gpr_a
[11] = cpu_ldl_data(env
, ea
+12);
2286 env
->gpr_d
[8] = cpu_ldl_data(env
, ea
+16);
2287 env
->gpr_d
[9] = cpu_ldl_data(env
, ea
+20);
2288 env
->gpr_d
[10] = cpu_ldl_data(env
, ea
+24);
2289 env
->gpr_d
[11] = cpu_ldl_data(env
, ea
+28);
2290 env
->gpr_a
[12] = cpu_ldl_data(env
, ea
+32);
2291 env
->gpr_a
[13] = cpu_ldl_data(env
, ea
+36);
2292 env
->gpr_a
[14] = cpu_ldl_data(env
, ea
+40);
2293 env
->gpr_a
[15] = cpu_ldl_data(env
, ea
+44);
2294 env
->gpr_d
[12] = cpu_ldl_data(env
, ea
+48);
2295 env
->gpr_d
[13] = cpu_ldl_data(env
, ea
+52);
2296 env
->gpr_d
[14] = cpu_ldl_data(env
, ea
+56);
2297 env
->gpr_d
[15] = cpu_ldl_data(env
, ea
+60);
2300 static void restore_context_lower(CPUTriCoreState
*env
, int ea
,
2301 target_ulong
*ra
, target_ulong
*pcxi
)
2303 *pcxi
= cpu_ldl_data(env
, ea
);
2304 *ra
= cpu_ldl_data(env
, ea
+4);
2305 env
->gpr_a
[2] = cpu_ldl_data(env
, ea
+8);
2306 env
->gpr_a
[3] = cpu_ldl_data(env
, ea
+12);
2307 env
->gpr_d
[0] = cpu_ldl_data(env
, ea
+16);
2308 env
->gpr_d
[1] = cpu_ldl_data(env
, ea
+20);
2309 env
->gpr_d
[2] = cpu_ldl_data(env
, ea
+24);
2310 env
->gpr_d
[3] = cpu_ldl_data(env
, ea
+28);
2311 env
->gpr_a
[4] = cpu_ldl_data(env
, ea
+32);
2312 env
->gpr_a
[5] = cpu_ldl_data(env
, ea
+36);
2313 env
->gpr_a
[6] = cpu_ldl_data(env
, ea
+40);
2314 env
->gpr_a
[7] = cpu_ldl_data(env
, ea
+44);
2315 env
->gpr_d
[4] = cpu_ldl_data(env
, ea
+48);
2316 env
->gpr_d
[5] = cpu_ldl_data(env
, ea
+52);
2317 env
->gpr_d
[6] = cpu_ldl_data(env
, ea
+56);
2318 env
->gpr_d
[7] = cpu_ldl_data(env
, ea
+60);
2321 void helper_call(CPUTriCoreState
*env
, uint32_t next_pc
)
2323 target_ulong tmp_FCX
;
2325 target_ulong new_FCX
;
2328 psw
= psw_read(env
);
2329 /* if (FCX == 0) trap(FCU); */
2330 if (env
->FCX
== 0) {
2333 /* if (PSW.CDE) then if (cdc_increment()) then trap(CDO); */
2334 if (psw
& MASK_PSW_CDE
) {
2335 if (cdc_increment(&psw
)) {
2340 psw
|= MASK_PSW_CDE
;
2341 /* tmp_FCX = FCX; */
2343 /* EA = {FCX.FCXS, 6'b0, FCX.FCXO, 6'b0}; */
2344 ea
= ((env
->FCX
& MASK_FCX_FCXS
) << 12) +
2345 ((env
->FCX
& MASK_FCX_FCXO
) << 6);
2346 /* new_FCX = M(EA, word); */
2347 new_FCX
= cpu_ldl_data(env
, ea
);
2348 /* M(EA, 16 * word) = {PCXI, PSW, A[10], A[11], D[8], D[9], D[10], D[11],
2349 A[12], A[13], A[14], A[15], D[12], D[13], D[14],
2351 save_context_upper(env
, ea
);
2353 /* PCXI.PCPN = ICR.CCPN; */
2354 env
->PCXI
= (env
->PCXI
& 0xffffff) +
2355 ((env
->ICR
& MASK_ICR_CCPN
) << 24);
2356 /* PCXI.PIE = ICR.IE; */
2357 env
->PCXI
= ((env
->PCXI
& ~MASK_PCXI_PIE
) +
2358 ((env
->ICR
& MASK_ICR_IE
) << 15));
2360 env
->PCXI
|= MASK_PCXI_UL
;
2362 /* PCXI[19: 0] = FCX[19: 0]; */
2363 env
->PCXI
= (env
->PCXI
& 0xfff00000) + (env
->FCX
& 0xfffff);
2364 /* FCX[19: 0] = new_FCX[19: 0]; */
2365 env
->FCX
= (env
->FCX
& 0xfff00000) + (new_FCX
& 0xfffff);
2366 /* A[11] = next_pc[31: 0]; */
2367 env
->gpr_a
[11] = next_pc
;
2369 /* if (tmp_FCX == LCX) trap(FCD);*/
2370 if (tmp_FCX
== env
->LCX
) {
2373 psw_write(env
, psw
);
2376 void helper_ret(CPUTriCoreState
*env
)
2379 target_ulong new_PCXI
;
2380 target_ulong new_PSW
, psw
;
2382 psw
= psw_read(env
);
2383 /* if (PSW.CDE) then if (cdc_decrement()) then trap(CDU);*/
2384 if (env
->PSW
& MASK_PSW_CDE
) {
2385 if (cdc_decrement(&(env
->PSW
))) {
2389 /* if (PCXI[19: 0] == 0) then trap(CSU); */
2390 if ((env
->PCXI
& 0xfffff) == 0) {
2393 /* if (PCXI.UL == 0) then trap(CTYP); */
2394 if ((env
->PCXI
& MASK_PCXI_UL
) == 0) {
2397 /* PC = {A11 [31: 1], 1’b0}; */
2398 env
->PC
= env
->gpr_a
[11] & 0xfffffffe;
2400 /* EA = {PCXI.PCXS, 6'b0, PCXI.PCXO, 6'b0}; */
2401 ea
= ((env
->PCXI
& MASK_PCXI_PCXS
) << 12) +
2402 ((env
->PCXI
& MASK_PCXI_PCXO
) << 6);
2403 /* {new_PCXI, new_PSW, A[10], A[11], D[8], D[9], D[10], D[11], A[12],
2404 A[13], A[14], A[15], D[12], D[13], D[14], D[15]} = M(EA, 16 * word); */
2405 restore_context_upper(env
, ea
, &new_PCXI
, &new_PSW
);
2406 /* M(EA, word) = FCX; */
2407 cpu_stl_data(env
, ea
, env
->FCX
);
2408 /* FCX[19: 0] = PCXI[19: 0]; */
2409 env
->FCX
= (env
->FCX
& 0xfff00000) + (env
->PCXI
& 0x000fffff);
2410 /* PCXI = new_PCXI; */
2411 env
->PCXI
= new_PCXI
;
2413 if (tricore_feature(env
, TRICORE_FEATURE_13
)) {
2415 psw_write(env
, new_PSW
);
2417 /* PSW = {new_PSW[31:26], PSW[25:24], new_PSW[23:0]}; */
2418 psw_write(env
, (new_PSW
& ~(0x3000000)) + (psw
& (0x3000000)));
2422 void helper_bisr(CPUTriCoreState
*env
, uint32_t const9
)
2424 target_ulong tmp_FCX
;
2426 target_ulong new_FCX
;
2428 if (env
->FCX
== 0) {
2433 ea
= ((env
->FCX
& 0xf0000) << 12) + ((env
->FCX
& 0xffff) << 6);
2435 /* new_FCX = M(EA, word); */
2436 new_FCX
= cpu_ldl_data(env
, ea
);
2437 /* M(EA, 16 * word) = {PCXI, A[11], A[2], A[3], D[0], D[1], D[2], D[3], A[4]
2438 , A[5], A[6], A[7], D[4], D[5], D[6], D[7]}; */
2439 save_context_lower(env
, ea
);
2442 /* PCXI.PCPN = ICR.CCPN */
2443 env
->PCXI
= (env
->PCXI
& 0xffffff) +
2444 ((env
->ICR
& MASK_ICR_CCPN
) << 24);
2445 /* PCXI.PIE = ICR.IE */
2446 env
->PCXI
= ((env
->PCXI
& ~MASK_PCXI_PIE
) +
2447 ((env
->ICR
& MASK_ICR_IE
) << 15));
2449 env
->PCXI
&= ~(MASK_PCXI_UL
);
2450 /* PCXI[19: 0] = FCX[19: 0] */
2451 env
->PCXI
= (env
->PCXI
& 0xfff00000) + (env
->FCX
& 0xfffff);
2452 /* FXC[19: 0] = new_FCX[19: 0] */
2453 env
->FCX
= (env
->FCX
& 0xfff00000) + (new_FCX
& 0xfffff);
2455 env
->ICR
|= MASK_ICR_IE
;
2457 env
->ICR
|= const9
; /* ICR.CCPN = const9[7: 0];*/
2459 if (tmp_FCX
== env
->LCX
) {
2464 void helper_rfe(CPUTriCoreState
*env
)
2467 target_ulong new_PCXI
;
2468 target_ulong new_PSW
;
2469 /* if (PCXI[19: 0] == 0) then trap(CSU); */
2470 if ((env
->PCXI
& 0xfffff) == 0) {
2471 /* raise csu trap */
2473 /* if (PCXI.UL == 0) then trap(CTYP); */
2474 if ((env
->PCXI
& MASK_PCXI_UL
) == 0) {
2475 /* raise CTYP trap */
2477 /* if (!cdc_zero() AND PSW.CDE) then trap(NEST); */
2478 if (!cdc_zero(&(env
->PSW
)) && (env
->PSW
& MASK_PSW_CDE
)) {
2479 /* raise MNG trap */
2481 /* ICR.IE = PCXI.PIE; */
2482 env
->ICR
= (env
->ICR
& ~MASK_ICR_IE
) + ((env
->PCXI
& MASK_PCXI_PIE
) >> 15);
2483 /* ICR.CCPN = PCXI.PCPN; */
2484 env
->ICR
= (env
->ICR
& ~MASK_ICR_CCPN
) +
2485 ((env
->PCXI
& MASK_PCXI_PCPN
) >> 24);
2486 /*EA = {PCXI.PCXS, 6'b0, PCXI.PCXO, 6'b0};*/
2487 ea
= ((env
->PCXI
& MASK_PCXI_PCXS
) << 12) +
2488 ((env
->PCXI
& MASK_PCXI_PCXO
) << 6);
2489 /*{new_PCXI, PSW, A[10], A[11], D[8], D[9], D[10], D[11], A[12],
2490 A[13], A[14], A[15], D[12], D[13], D[14], D[15]} = M(EA, 16 * word); */
2491 restore_context_upper(env
, ea
, &new_PCXI
, &new_PSW
);
2492 /* M(EA, word) = FCX;*/
2493 cpu_stl_data(env
, ea
, env
->FCX
);
2494 /* FCX[19: 0] = PCXI[19: 0]; */
2495 env
->FCX
= (env
->FCX
& 0xfff00000) + (env
->PCXI
& 0x000fffff);
2496 /* PCXI = new_PCXI; */
2497 env
->PCXI
= new_PCXI
;
2499 psw_write(env
, new_PSW
);
2502 void helper_ldlcx(CPUTriCoreState
*env
, uint32_t ea
)
2505 /* insn doesn't load PCXI and RA */
2506 restore_context_lower(env
, ea
, &dummy
, &dummy
);
2509 void helper_lducx(CPUTriCoreState
*env
, uint32_t ea
)
2512 /* insn doesn't load PCXI and PSW */
2513 restore_context_upper(env
, ea
, &dummy
, &dummy
);
2516 void helper_stlcx(CPUTriCoreState
*env
, uint32_t ea
)
2518 save_context_lower(env
, ea
);
2521 void helper_stucx(CPUTriCoreState
*env
, uint32_t ea
)
2523 save_context_upper(env
, ea
);
2526 void helper_psw_write(CPUTriCoreState
*env
, uint32_t arg
)
2528 psw_write(env
, arg
);
2531 uint32_t helper_psw_read(CPUTriCoreState
*env
)
2533 return psw_read(env
);
2537 static inline void QEMU_NORETURN
do_raise_exception_err(CPUTriCoreState
*env
,
2542 CPUState
*cs
= CPU(tricore_env_get_cpu(env
));
2543 cs
->exception_index
= exception
;
2544 env
->error_code
= error_code
;
2547 /* now we have a real cpu fault */
2548 cpu_restore_state(cs
, pc
);
2554 void tlb_fill(CPUState
*cs
, target_ulong addr
, int is_write
, int mmu_idx
,
2558 ret
= cpu_tricore_handle_mmu_fault(cs
, addr
, is_write
, mmu_idx
);
2560 TriCoreCPU
*cpu
= TRICORE_CPU(cs
);
2561 CPUTriCoreState
*env
= &cpu
->env
;
2562 do_raise_exception_err(env
, cs
->exception_index
,
2563 env
->error_code
, retaddr
);